From e7e1b4a0b217b50246f735c839186687766838a2 Mon Sep 17 00:00:00 2001 From: dan-rpm Date: Tue, 17 Sep 2024 15:31:49 +0300 Subject: [PATCH] fix: imports --- src/components/Avatar/Avatar.component.tsx | 4 +-- src/services/Models.service.tsx | 38 +++++++++------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/components/Avatar/Avatar.component.tsx b/src/components/Avatar/Avatar.component.tsx index acd13d54..d8c0d82e 100644 --- a/src/components/Avatar/Avatar.component.tsx +++ b/src/components/Avatar/Avatar.component.tsx @@ -17,8 +17,8 @@ import Loader from 'src/components/Loader'; import Bloom from 'src/components/Bloom/Bloom.component'; import { BlendFunction } from 'postprocessing'; import Lights from 'src/components/Lights/Lights.component'; -import { spawnState } from '../../state/spawnAtom'; -import { MultipleAnimationModel } from '../Models/MultipleAnimationModel/MultipleAnimationModel.component'; +import { MultipleAnimationModel } from 'src/components/Models/MultipleAnimationModel/MultipleAnimationModel.component'; +import { spawnState } from 'src/state/spawnAtom'; export const CAMERA = { TARGET: { diff --git a/src/services/Models.service.tsx b/src/services/Models.service.tsx index b1cd3aa8..64eb0070 100644 --- a/src/services/Models.service.tsx +++ b/src/services/Models.service.tsx @@ -220,31 +220,23 @@ dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5 loader.setDRACOLoader(dracoLoader); export const useGltfLoader = (source: Blob | string): GLTF => { - const cachedGltf = useRef(null); - const prevSource = useRef(null); + const cachedGltf = useRef>(new Map()); - return suspend( - async (): Promise => { - if (source === prevSource.current && cachedGltf.current) { - return cachedGltf.current; - } - - let gltf: GLTF; - if (source instanceof Blob) { - const buffer = await source.arrayBuffer(); - gltf = (await loader.parseAsync(buffer, '')) as GLTF; - } else { - gltf = await loader.loadAsync(source); - } - - cachedGltf.current = gltf; - prevSource.current = source; + return suspend(async (): Promise => { + if (cachedGltf.current.has(source as string)) { + return cachedGltf.current.get(source as string)!; + } + let result: GLTF; + if (source instanceof Blob) { + const buffer = await source.arrayBuffer(); + result = (await loader.parseAsync(buffer, '')) as GLTF; + } else { + result = await loader.loadAsync(source); + } - return gltf; - }, - [source], - { lifespan: 100 } - ); + cachedGltf.current.set(source as string, result); + return result; + }, [source]); }; export function usePersistantRotation(scene: Group) {