@@ -65,7 +65,12 @@ function normalizeOptions(tree: Tree, options: GltfGeneratorSchema, gltfJsx: typ
65
65
const modelPathFromRoot = join ( tree . root , options . modelPath ) ;
66
66
const outputDir = dirname ( options . output ) ;
67
67
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
+ : '' ;
69
74
70
75
const selector = `${ options . selectorPrefix } -${ fileName } ` ;
71
76
@@ -116,24 +121,23 @@ export async function gltfGenerator(tree: Tree, options: GltfGeneratorSchema) {
116
121
//
117
122
let size = '' ;
118
123
let transformedModelPath : string | undefined = undefined ;
124
+ let dracoLoader : import ( 'node-three-gltf' ) . DRACOLoader | undefined = undefined ; // global instance, instantiate once, dispose once
125
+
119
126
if ( options . transform ) {
120
127
transformedModelPath = resolve ( modelPathFromRoot + '-transformed.glb' ) ;
121
128
await gltfTransform ( modelPathFromRoot , transformedModelPath , Object . assign ( transformOptions , gltfJsxOptions ) ) ;
122
129
size = compareFileSizes ( modelPathFromRoot , transformedModelPath ) ;
130
+
131
+ log . debug ( 'Instantiating DracoLoader' ) ;
132
+ const { DRACOLoader } = await import ( 'node-three-gltf' ) ;
133
+ dracoLoader = new DRACOLoader ( ) ;
123
134
}
124
135
125
136
const modelPath = transformedModelPath || modelPathFromRoot ;
126
137
127
138
//
128
139
// Read the model
129
140
//
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
-
137
141
log . debug ( 'Loading model: ' , modelPath ) ;
138
142
139
143
try {
0 commit comments