mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
28 lines
703 B
TypeScript
28 lines
703 B
TypeScript
import { useLoader } from "@react-three/fiber";
|
|
import { Mesh, MeshStandardMaterial } from "three";
|
|
import { GLTFLoader } from "three-stdlib";
|
|
|
|
export function useTankModel(url: string) {
|
|
const collision = false;
|
|
const gltf = useLoader(GLTFLoader, url);
|
|
|
|
gltf.scene.traverse((child) => {
|
|
if (
|
|
child instanceof Mesh &&
|
|
child.material instanceof MeshStandardMaterial
|
|
) {
|
|
// TODO: remove this hack and fix the gltf
|
|
child.material.vertexColors = false;
|
|
}
|
|
|
|
child.castShadow = true;
|
|
child.receiveShadow = true;
|
|
});
|
|
|
|
for (const child of gltf.scene.children) {
|
|
child.visible = (child.name === "CollisionMesh") === collision;
|
|
}
|
|
|
|
return gltf.scene;
|
|
}
|