mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-01 13:55:01 +01:00
apply batched mesh to all things
This commit is contained in:
21 files changed
+844
-892
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import { useMemo } from "react";
|
||||
import type { Object3D } from "three";
|
||||
import { Duel } from "../stores/duel";
|
||||
import { useModel } from "./useModel";
|
||||
import { useTankModelDefinition } from "./useTankModelDefinition";
|
||||
|
||||
interface ModelNodes {
|
||||
hull: Object3D[];
|
||||
wheels: Object3D[];
|
||||
tracks: Object3D[];
|
||||
turret: Object3D[];
|
||||
gun: Object3D[];
|
||||
mask: Object3D[];
|
||||
}
|
||||
|
||||
// the protagonist's visual model split into its parts
|
||||
export function useModelNodes() {
|
||||
const tank = Duel.use((state) => state.protagonist.tank);
|
||||
const turret = Duel.use((state) => state.protagonist.turret);
|
||||
const gun = Duel.use((state) => state.protagonist.gun);
|
||||
const { gltf } = useModel(tank.id);
|
||||
const tankModelDefinition = useTankModelDefinition();
|
||||
|
||||
return useMemo(() => {
|
||||
const turretModelDefinition = tankModelDefinition.turrets[turret.id];
|
||||
const gunModelDefinition = turretModelDefinition.guns[gun.id];
|
||||
const turretName = `turret_${turretModelDefinition.model_id
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
const gunName = `gun_${gunModelDefinition.model_id
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
const maskName = `${gunName}_mask`;
|
||||
const nodes: ModelNodes = {
|
||||
hull: [],
|
||||
wheels: [],
|
||||
tracks: [],
|
||||
turret: [],
|
||||
gun: [],
|
||||
mask: [],
|
||||
};
|
||||
|
||||
for (const node of Object.values(gltf.nodes)) {
|
||||
switch (node.name) {
|
||||
case "hull":
|
||||
nodes.hull.push(node);
|
||||
continue;
|
||||
|
||||
case turretName:
|
||||
nodes.turret.push(node);
|
||||
continue;
|
||||
|
||||
case gunName:
|
||||
nodes.gun.push(node);
|
||||
continue;
|
||||
|
||||
case maskName:
|
||||
nodes.mask.push(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.name.startsWith("chassis_wheel_")) {
|
||||
nodes.wheels.push(node);
|
||||
} else if (node.name.startsWith("chassis_track_")) {
|
||||
nodes.tracks.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}, [gltf, tankModelDefinition, turret.id, gun.id]);
|
||||
}
|
||||
Reference in new issue
Block a user