mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
add persistent count for the number of model users to unload only when
uses drops to 0
This commit is contained in:
1 parent
cdbb7647f0
commit
f2f6d4ff49
1 file changed
+10
@@ -3,9 +3,19 @@ import { useEffect } from "react";
|
|||||||
import { Cache, Group, Mesh, MeshStandardMaterial, Object3D } from "three";
|
import { Cache, Group, Mesh, MeshStandardMaterial, Object3D } from "three";
|
||||||
import { GLTFLoader, type GLTF } from "three-stdlib";
|
import { GLTFLoader, type GLTF } from "three-stdlib";
|
||||||
|
|
||||||
|
const users: Record<string, number> = {};
|
||||||
|
|
||||||
export function useDispose(gltf: GLTF & ObjectMap, path: string) {
|
export function useDispose(gltf: GLTF & ObjectMap, path: string) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (path in users) {
|
||||||
|
users[path]++;
|
||||||
|
} else {
|
||||||
|
users[path] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
if (--users[path] > 0) return;
|
||||||
|
|
||||||
gltf.scene.traverse((object) => {
|
gltf.scene.traverse((object) => {
|
||||||
if (object instanceof Mesh) {
|
if (object instanceof Mesh) {
|
||||||
if (object.material instanceof MeshStandardMaterial) {
|
if (object.material instanceof MeshStandardMaterial) {
|
||||||
|
|||||||
Reference in new issue
Block a user