2025-09-06 00:48:39 -05:00
|
|
|
import { asset } from "@blitzkit/core";
|
2025-09-05 23:34:59 -05:00
|
|
|
import { type ObjectMap, useLoader } from "@react-three/fiber";
|
|
|
|
|
import { Mesh, MeshStandardMaterial } from "three";
|
|
|
|
|
import { type GLTF, GLTFLoader } from "three-stdlib";
|
2024-01-16 13:16:06 -06:00
|
|
|
|
2024-01-22 15:42:49 -06:00
|
|
|
const cache: Record<
|
|
|
|
|
number,
|
|
|
|
|
{
|
|
|
|
|
gltf: GLTF & ObjectMap;
|
|
|
|
|
hasPbr: boolean;
|
|
|
|
|
}
|
|
|
|
|
> = {};
|
|
|
|
|
|
2024-01-16 13:16:06 -06:00
|
|
|
export function useModel(id: number) {
|
2025-09-06 00:48:39 -05:00
|
|
|
const gltf = useLoader(GLTFLoader, asset(`3d/tanks/models/${id}.glb`));
|
2024-10-29 16:21:44 -05:00
|
|
|
|
2024-01-22 15:42:49 -06:00
|
|
|
if (!cache[id]) {
|
|
|
|
|
cache[id] = {
|
|
|
|
|
gltf,
|
|
|
|
|
hasPbr: Object.values(gltf.nodes).some(
|
|
|
|
|
(node) =>
|
|
|
|
|
node instanceof Mesh &&
|
|
|
|
|
node.material instanceof MeshStandardMaterial &&
|
2025-09-05 23:34:59 -05:00
|
|
|
node.material.roughnessMap !== null
|
2024-01-22 15:42:49 -06:00
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-08-10 14:03:13 -05:00
|
|
|
|
2024-01-22 15:42:49 -06:00
|
|
|
return cache[id];
|
2024-01-16 13:16:06 -06:00
|
|
|
}
|