Files
blitzkit/packages/website/src/hooks/useModel.ts
T

22 lines
622 B
TypeScript
Raw Normal View History

2026-08-06 20:01:50 -05:00
import { alias } from "@blitzkit/core";
2026-05-12 17:54:50 -05:00
import { useLoader } from "@react-three/fiber";
2025-09-05 23:34:59 -05:00
import { Mesh, MeshStandardMaterial } from "three";
2026-05-12 17:54:50 -05:00
import { GLTFLoader } from "three-stdlib";
import { useDispose } from "./useDispose";
2024-01-16 13:16:06 -06:00
export function useModel(id: number) {
2026-08-06 20:01:50 -05:00
const path = alias("api", `/tanks/${id}/model.glb`);
2026-05-12 17:54:50 -05:00
const gltf = useLoader(GLTFLoader, path);
useDispose(gltf, path);
2024-10-29 16:21:44 -05:00
2026-05-11 16:18:54 -05:00
return {
gltf,
hasPbr: Object.values(gltf.nodes).some(
(node) =>
node instanceof Mesh &&
node.material instanceof MeshStandardMaterial &&
2026-05-12 17:54:50 -05:00
node.material.roughnessMap !== null,
2026-05-11 16:18:54 -05:00
),
};
2024-01-16 13:16:06 -06:00
}