dispose models on unload

This commit is contained in:
TrèsAbhi committed 2026-05-12 17:54:50 -05:00
1 parent 4f42a31f53
commit 100c7391fb
3 files changed
+90 -23

No files matched your search

+8 -4
View File
@@ -1,10 +1,14 @@
import { asset } from "@blitzkit/core";
import { type ObjectMap, useLoader } from "@react-three/fiber";
import { useLoader } from "@react-three/fiber";
import { Mesh, MeshStandardMaterial } from "three";
import { type GLTF, GLTFLoader } from "three-stdlib";
import { GLTFLoader } from "three-stdlib";
import { useDispose } from "./useDispose";
export function useModel(id: number) {
const gltf = useLoader(GLTFLoader, asset(`3d/tanks/models/${id}.glb`));
const path = asset(`3d/tanks/models/${id}.glb`);
const gltf = useLoader(GLTFLoader, path);
useDispose(gltf, path);
return {
gltf,
@@ -12,7 +16,7 @@ export function useModel(id: number) {
(node) =>
node instanceof Mesh &&
node.material instanceof MeshStandardMaterial &&
node.material.roughnessMap !== null
node.material.roughnessMap !== null,
),
};
}