Skip to content

Commit

Permalink
fix(draco): modifying check to ensure globalSettings are ready for ev…
Browse files Browse the repository at this point in the history
…aluation
  • Loading branch information
mumanity committed Oct 16, 2024
1 parent 63afb47 commit 80c3295
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ describe('GLTFLoader', () => {
it('should execute without draco decoder enabled', async () => {
const getGlobalSettingsMock = getGlobalSettings as jest.Mock;
const dracoDecoder: DracoDecoderConfig = {
enable: true,
path: 'draco/path',
enable: false,
};
const basisuDecoder: BasisuDecoderConfig = {
enable: false,
Expand All @@ -109,8 +108,7 @@ describe('GLTFLoader', () => {
extensionsCb(mockLoader);

expect(extendLoader).toBeCalledTimes(1);
expect(setDecoderPathSpy).toBeCalledWith('draco/path');
expect(mockLoader.setDRACOLoader).toBeCalledTimes(1);
expect(mockLoader.setDRACOLoader).toBeCalledTimes(0);
});
});

Expand Down
4 changes: 4 additions & 0 deletions packages/scene-composer/src/three/loaderUtilsHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('dracoSupport', () => {

getGlobalSettingsMock.mockReturnValue({
dracoDecoder,
getSceneObjectFunction: jest.fn(),
});

const loader = {
Expand All @@ -41,6 +42,7 @@ describe('dracoSupport', () => {

getGlobalSettingsMock.mockReturnValue({
dracoDecoder,
getSceneObjectFunction: jest.fn(),
});

const loader = {
Expand Down Expand Up @@ -73,6 +75,7 @@ describe('setupBasisu', () => {
};
getGlobalSettingsMock.mockReturnValue({
basisuDecoder,
getSceneObjectFunction: jest.fn(),
});

const loader = {
Expand All @@ -94,6 +97,7 @@ describe('setupBasisu', () => {
};
getGlobalSettingsMock.mockReturnValue({
basisuDecoder,
getSceneObjectFunction: jest.fn(),
});
const loader = {
setKTX2Loader: jest.fn(),
Expand Down
11 changes: 6 additions & 5 deletions packages/scene-composer/src/three/loaderUtilsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { TwinMakerTextureLoader } from './TwinMakerTextureLoader';
import { GLTFLoader, GLTFLoader as TwinMakerGLTFLoader } from './GLTFLoader';

export const setupDracoSupport = (loader: GLTFLoader, dracoLoader: DRACOLoader = new DRACOLoader()): void => {
const { dracoDecoder } = getGlobalSettings();
if (dracoDecoder.enable) {
const { dracoDecoder, getSceneObjectFunction } = getGlobalSettings();
// getSceneObjectFunction is needed for the check to ensure that globalSettings are ready to be evaluated against
if (dracoDecoder.enable && getSceneObjectFunction) {
const dracoDecoderPath = dracoDecoder.path ?? `${THREE_PATH}/examples/jsm/libs/draco/gltf/`;
// TODO: with CSP issues, Chrome/Edge and some other unknown browsers may fail to load WASM, so we enforce to
// only JS DRACO decoder for now. Please fix once we found a better solution
Expand All @@ -26,10 +27,10 @@ export const setupBasisuSupport = (
renderer: WebGLRenderer,
ktx2Loader: KTX2Loader = new KTX2Loader(),
): void => {
const { basisuDecoder } = getGlobalSettings();
if (basisuDecoder.enable) {
const { basisuDecoder, getSceneObjectFunction } = getGlobalSettings();
// getSceneObjectFunction is needed for the check to ensure that globalSettings are ready to be evaluated against
if (basisuDecoder.enable && getSceneObjectFunction) {
const ktx2DecoderPath = basisuDecoder.path ?? `${THREE_PATH}/examples/jsm/libs/basis/`;

ktx2Loader.setTranscoderPath(ktx2DecoderPath).detectSupport(renderer);

(loader as TwinMakerGLTFLoader).setKTX2Loader(ktx2Loader);
Expand Down

0 comments on commit 80c3295

Please sign in to comment.