Skip to content

Commit

Permalink
fix(composer): hdr url is sometimes wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
sheilaXu authored and TheEvilDev committed Dec 7, 2022
1 parent a0ddc37 commit c12f3ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Loader, LoadingManager, DefaultLoadingManager } from 'three';
import { Loader, LoadingManager } from 'three';
import { useLoader } from '@react-three/fiber';

import { TwinMakerGLTFLoader } from '../../../three/GLTFLoader';
Expand All @@ -14,6 +14,8 @@ function extensions(extendLoader?: (loader: TwinMakerGLTFLoader) => void) {
};
}

const manager = new LoadingManager();

/**
* Extend the drei useGLTF hook to explicitly support loading manager.
*/
Expand All @@ -28,11 +30,11 @@ export function useGLTF<T extends string | string[]>(
path,
extensions((loader) => {
if (extendLoader) extendLoader(loader);
if (!loader.manager) {
loader.manager = DefaultLoadingManager;
}

if (uriModifier) loader.manager.setURLModifier(uriModifier);
if (uriModifier) {
loader.manager = manager;
loader.manager.setURLModifier(uriModifier);
}
}),
onProgress,
);
Expand All @@ -49,11 +51,11 @@ useGLTF.preload = (
path,
extensions((loader) => {
if (extendLoader) extendLoader(loader);
if (!loader.manager) {
loader.manager = new LoadingManager();
}

if (uriModifier) loader.manager.setURLModifier(uriModifier);
if (uriModifier) {
loader.manager = manager;
loader.manager.setURLModifier(uriModifier);
}
}),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { DRACOLoader } from 'three-stdlib';
import { DefaultLoadingManager } from 'three';
import { useLoader as mockUseLoader } from '@react-three/fiber';

import { TwinMakerGLTFLoader } from '../../../../three/GLTFLoader';
import { useGLTF } from '../GLTFLoader';
import { getGlobalSettings as mockGetGlobalSettings } from '../../../../common/GlobalSettings';

jest.mock('three', () => {
/* eslint-disable */
const setURLModifierMock = jest.fn();
jest.doMock('three', () => {
const originalModule = jest.requireActual('three');
return {
...originalModule,
LoadingManager: class {
setURLModifier = jest.fn();
setURLModifier = setURLModifierMock;
},
};
});
/* eslint-ensable */

import { DRACOLoader } from 'three-stdlib';
import { useLoader as mockUseLoader } from '@react-three/fiber';

import { TwinMakerGLTFLoader } from '../../../../three/GLTFLoader';
import { useGLTF } from '../GLTFLoader';
import { getGlobalSettings as mockGetGlobalSettings } from '../../../../common/GlobalSettings';

jest.mock('@react-three/fiber', () => {
const originalModule = jest.requireActual('@react-three/fiber');
Expand Down Expand Up @@ -102,15 +104,13 @@ describe('GLTFLoader', () => {
});

it('should call useLoader', async () => {
const setURLModifierSpy = jest.spyOn(DefaultLoadingManager, 'setURLModifier');

useGLTF('mock/path', uriModifier, extendLoader, onProgress);
extensionsCb(mockLoader);

expect(mockUseLoader).toBeCalledWith(TwinMakerGLTFLoader, 'mock/path', expect.anything(), onProgress);
expect(extendLoader).toBeCalledTimes(1);
expect(mockLoader.manager).toBeDefined();
expect(setURLModifierSpy).toBeCalledWith(uriModifier);
expect(setURLModifierMock).toBeCalledWith(uriModifier);
});
});

Expand Down

0 comments on commit c12f3ee

Please sign in to comment.