Skip to content

Commit

Permalink
fix: GLTFLoader의 로딩 추적에 LoadingManager 인스턴스 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
chiabi committed Jul 23, 2024
1 parent 4850cc6 commit 890e7d1
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/three/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mesh, Scene } from 'three';
import { LoadingManager, Mesh, Scene } from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { applyMaterials } from './materials';

Expand All @@ -8,23 +8,25 @@ export const loadModel = (
onProgress?: (progress: number) => void,
onLoad?: () => void
): void => {
const loader = new GLTFLoader();
loader.load(
url,
(gltf) => {
gltf.scene.traverse((child) => {
if (child instanceof Mesh) {
applyMaterials(child);
}
});
scene.add(gltf.scene);
onLoad?.();
},
(progress) => {
onProgress?.((progress.loaded / progress.total) * 100);
},
(error) => {
console.error('An error happened', error);
}
);
const manager = new LoadingManager();

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > renders without crashing

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > initializes Three.js scene

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > loads the 3D model

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > initializes OrbitControls

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > calls setupGUI in DEV environment

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > does not call setupGUI in non-DEV environment

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3

Check failure on line 11 in src/three/loader.ts

View workflow job for this annotation

GitHub Actions / test

src/components/ModelViewr.test.tsx > ModelViewer > cleans up resources on unmount

Error: [vitest] No "LoadingManager" export is defined on the "three" mock. Did you forget to return it from "vi.mock"? If you need to partially mock a module, you can use "importOriginal" helper inside: vi.mock("three", async (importOriginal) => { const actual = await importOriginal() return { ...actual, // your mocked methods } }) ❯ Module.loadModel src/three/loader.ts:11:23 ❯ src/components/ModelViewer.tsx:36:5 ❯ commitHookEffectListMount node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:23189:26 ❯ commitPassiveMountOnFiber node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24970:11 ❯ commitPassiveMountEffects_complete node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24930:9 ❯ commitPassiveMountEffects_begin node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24917:7 ❯ commitPassiveMountEffects node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:24905:3 ❯ flushPassiveEffectsImpl node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27078:3
manager.onProgress = (_url, itemsLoaded, itemsTotal) => {
onProgress?.((itemsLoaded / itemsTotal) * 100);
};
manager.onLoad = () => {
onLoad?.();
};
manager.onError = (error) => {
console.error('An error happened', error);
};

const loader = new GLTFLoader(manager);
loader.load(url, (gltf) => {
gltf.scene.traverse((child) => {
if (child instanceof Mesh) {
applyMaterials(child);
}
});
scene.add(gltf.scene);
onLoad?.();
});
};

0 comments on commit 890e7d1

Please sign in to comment.