mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
remove cache from useModel
This commit is contained in:
1 parent
3edf4a25be
commit
042a1afa74
1 file changed
+9
-21
@@ -3,28 +3,16 @@ import { type ObjectMap, useLoader } from "@react-three/fiber";
|
|||||||
import { Mesh, MeshStandardMaterial } from "three";
|
import { Mesh, MeshStandardMaterial } from "three";
|
||||||
import { type GLTF, GLTFLoader } from "three-stdlib";
|
import { type GLTF, GLTFLoader } from "three-stdlib";
|
||||||
|
|
||||||
const cache: Record<
|
|
||||||
number,
|
|
||||||
{
|
|
||||||
gltf: GLTF & ObjectMap;
|
|
||||||
hasPbr: boolean;
|
|
||||||
}
|
|
||||||
> = {};
|
|
||||||
|
|
||||||
export function useModel(id: number) {
|
export function useModel(id: number) {
|
||||||
const gltf = useLoader(GLTFLoader, asset(`3d/tanks/models/${id}.glb`));
|
const gltf = useLoader(GLTFLoader, asset(`3d/tanks/models/${id}.glb`));
|
||||||
|
|
||||||
if (!cache[id]) {
|
return {
|
||||||
cache[id] = {
|
gltf,
|
||||||
gltf,
|
hasPbr: Object.values(gltf.nodes).some(
|
||||||
hasPbr: Object.values(gltf.nodes).some(
|
(node) =>
|
||||||
(node) =>
|
node instanceof Mesh &&
|
||||||
node instanceof Mesh &&
|
node.material instanceof MeshStandardMaterial &&
|
||||||
node.material instanceof MeshStandardMaterial &&
|
node.material.roughnessMap !== null
|
||||||
node.material.roughnessMap !== null
|
),
|
||||||
),
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return cache[id];
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user