Hi, I have a problem with keeping models loaded with useGLTF in the cache, well when calling the method useGLTF.clear(modelUrl) it is not removed and even if the model in the modelUrl changes, the previous model is constantly loaded. All my code looks like this:
.clear just clears the thing from cache, the gltf data will be gone. threejs geometry and materials will be cleared by r3f automatically if the components unmounts, ifdispose={null} isn’t present.
// Will be destroyed if unmounted
return <mesh geometry={nodes.foo.geometry} material={materials.bar} />
// Will *not* be destroyed if unmounted
return <mesh geometry={nodes.foo.geometry} material={materials.bar} dispose={null} />
the problem is that you’re swiming against the stream. useGLTF is specifically made for cache. cache and uncache on every url change is using cache for nothing. if you don’t want that, why not just using THREE GLTFLoader as is?
it pops up the same error An error happened [TypeError: Cannot read property ‘match’ of undefined]. On the other hand doing exactly the same thing like this works:
import Floor1 from '@/assets/models/floor1_2.glb'
const models: Record<string, string> = {
1: Floor1,
}
type ModelProps = {
model: number
}
export const Model = (props: ModelProps) => {
const gltf_model = models[props.model]
const { nodes } = useGLTF(gltf_model)