Skip to content

Commit 863d7db

Browse files
committed
fix(plugin): load draco based on transform
1 parent 85b65ac commit 863d7db

File tree

1 file changed

+12
-8
lines changed
  • libs/plugin/src/generators/gltf

1 file changed

+12
-8
lines changed

libs/plugin/src/generators/gltf/gltf.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ function normalizeOptions(tree: Tree, options: GltfGeneratorSchema, gltfJsx: typ
6565
const modelPathFromRoot = join(tree.root, options.modelPath);
6666
const outputDir = dirname(options.output);
6767

68-
const injectGLTFOptions = options.draco ? `{ useDraco: true }` : '';
68+
const injectGLTFOptions =
69+
options.transform && options.draco != null
70+
? `{ useDraco: ${options.draco} }`
71+
: options.transform
72+
? `{ useDraco: true }`
73+
: '';
6974

7075
const selector = `${options.selectorPrefix}-${fileName}`;
7176

@@ -116,24 +121,23 @@ export async function gltfGenerator(tree: Tree, options: GltfGeneratorSchema) {
116121
//
117122
let size = '';
118123
let transformedModelPath: string | undefined = undefined;
124+
let dracoLoader: import('node-three-gltf').DRACOLoader | undefined = undefined; // global instance, instantiate once, dispose once
125+
119126
if (options.transform) {
120127
transformedModelPath = resolve(modelPathFromRoot + '-transformed.glb');
121128
await gltfTransform(modelPathFromRoot, transformedModelPath, Object.assign(transformOptions, gltfJsxOptions));
122129
size = compareFileSizes(modelPathFromRoot, transformedModelPath);
130+
131+
log.debug('Instantiating DracoLoader');
132+
const { DRACOLoader } = await import('node-three-gltf');
133+
dracoLoader = new DRACOLoader();
123134
}
124135

125136
const modelPath = transformedModelPath || modelPathFromRoot;
126137

127138
//
128139
// Read the model
129140
//
130-
let dracoLoader: import('node-three-gltf').DRACOLoader | undefined = undefined; // global instance, instantiate once, dispose once
131-
if (options.draco) {
132-
log.debug('Instantiating DracoLoader');
133-
const { DRACOLoader } = await import('node-three-gltf');
134-
dracoLoader = new DRACOLoader();
135-
}
136-
137141
log.debug('Loading model: ', modelPath);
138142

139143
try {

0 commit comments

Comments
 (0)