mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
24 lines
608 B
TypeScript
24 lines
608 B
TypeScript
import { asset } from '@blitzkit/core';
|
|
import { type ObjectMap, useLoader } from '@react-three/fiber';
|
|
import { type GLTF, GLTFLoader } from 'three-stdlib';
|
|
|
|
const cache: Record<
|
|
number,
|
|
{ gltf: GLTF & ObjectMap; hasDynamicArmor: boolean }
|
|
> = {};
|
|
|
|
export function useArmor(id: number) {
|
|
const gltf = useLoader(GLTFLoader, asset(`3d/tanks/armor/${id}.glb`));
|
|
|
|
if (!cache[id]) {
|
|
cache[id] = {
|
|
gltf,
|
|
hasDynamicArmor: Object.values(gltf.nodes).some(
|
|
(node) =>
|
|
node.name.includes('state_00') || node.name.includes('state_01'),
|
|
),
|
|
};
|
|
}
|
|
return cache[id];
|
|
}
|