How to use KTX2Loader with useGLTF, and without use useKTX2() which seems to need explicit textures URIs #1335
Replies: 6 comments 1 reply
-
Hello, did you found one solution ? I have the same issue. |
Beta Was this translation helpful? Give feedback.
-
The extensionLoader setting must be set in the fourth parameter of useGLTF export declare function useGLTF<T extends string | string[]>(path: T, useDraco?: boolean | string, useMeshOpt?: boolean, extendLoader?: (loader: GLTFLoader) => void): T extends any[] ? GLTF[] : GLTF; I referenced gltf-viewer. import { useGLTF } from '@react-three/drei'
import { REVISION } from 'three'
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader'
import { useThree } from '@react-three/fiber'
const { gl } = useThree()
const { scene } = useGLTF('/myScene-transformed.glb', false, false, (loader) => {
const THREE_PATH = `https://unpkg.com/three@0.${REVISION}.x`
const ktx2Loader = new KTX2Loader().setTranscoderPath(`${THREE_PATH}/examples/jsm/libs/basis/`)
loader.setKTX2Loader(ktx2Loader.detectSupport(gl))
}) |
Beta Was this translation helpful? Give feedback.
-
EDIT: now added into the doc import { KTX2Loader } from "three-stdlib";
import { Canvas, useThree } from "@react-three/fiber";
import { Gltf } from "@react-three/drei";
import facecap from "./facecap.glb?url";
const ktx2Loader = new KTX2Loader();
ktx2Loader.setTranscoderPath(
`https://unpkg.com/[email protected]/examples/jsm/libs/basis/`
);
function App() {
return (
<Canvas>
<Scene />
</Canvas>
);
}
function Scene() {
const { gl } = useThree();
return (
<>
<Gltf
src={facecap}
extendLoader={(loader) => {
loader.setKTX2Loader(ktx2Loader.detectSupport(gl));
}}
/>
</>
);
} see: https://github.com/abernier/poc-facecap/blob/main/src/App.tsx |
Beta Was this translation helpful? Give feedback.
-
I'm having a similar issue right now, I extended the loader to KTX2Loader but console seems to spit out "texture could not be loaded". I've converted the texture via command line with toktx, should I be using a different method to convert it? |
Beta Was this translation helpful? Give feedback.
-
help me how get add texture human images texture face eyes face uv texture get add at facecap.glb |
Beta Was this translation helpful? Give feedback.
-
like this texture how get add at facecap.glb |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a glb + jsx file, coming from gltfjsx cli , and including KTX2 textures (embedded).
I'm trying to extend the loader as seen in sources, like this
but it doesn't work. I don't even see my "coucou" debug test in console.
reported error is :
THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures)
I don't understand ho to achieve same behaviour as in vanilla THREE.js
I also don't want to use useKTX2() as, if I understand well, need to explicit textures URIs and than apply one by one to materials...
for sure there is a way to pass the KTX2Loader to the GLTFLoader no ?
Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions