@@ -73,8 +73,6 @@ function getLights( objects ) {
73
73
74
74
}
75
75
76
- let materialUuids = null ;
77
-
78
76
export class PathTracingSceneGenerator {
79
77
80
78
get initialized ( ) {
@@ -97,6 +95,7 @@ export class PathTracingSceneGenerator {
97
95
this . _bvhWorker = null ;
98
96
this . _pendingGenerate = null ;
99
97
this . _buildAsync = false ;
98
+ this . _materialUuids = null ;
100
99
101
100
}
102
101
@@ -178,27 +177,29 @@ export class PathTracingSceneGenerator {
178
177
// generate the geometry
179
178
const result = staticGeometryGenerator . generate ( geometry ) ;
180
179
const materials = result . materials ;
181
- let needsMaterialIndexUpdate = result . changeType !== NO_CHANGE || materialUuids === null || materialUuids . length !== length ;
182
- for ( let index = 0 , length = materials . length ; ( index < length ) && ! needsMaterialIndexUpdate ; index ++ ) {
180
+ let needsMaterialIndexUpdate = result . changeType !== NO_CHANGE || this . _materialUuids === null || this . _materialUuids . length !== length ;
181
+ if ( ! needsMaterialIndexUpdate ) {
183
182
184
- if ( materialUuids === null || materialUuids . length !== length ) {
183
+ for ( let i = 0 , length = materials . length ; ( i < length ) ; i ++ ) {
185
184
186
- needsMaterialIndexUpdate = true ;
187
- break ;
185
+ const material = materials [ i ] ;
186
+ if ( material . uuid !== this . _materialUuids [ i ] ) {
188
187
189
- }
188
+ needsMaterialIndexUpdate = true ;
189
+ break ;
190
190
191
- const material = materials [ index ] ;
192
- if ( material . uuid !== materialUuids [ index ] ) needsMaterialIndexUpdate = true ;
191
+ }
192
+
193
+ }
193
194
194
195
}
195
196
196
- materialUuids = materials . map ( material => material . uuid ) ;
197
197
const textures = getTextures ( materials ) ;
198
198
const { lights, iesTextures } = getLights ( objects ) ;
199
199
if ( needsMaterialIndexUpdate ) {
200
200
201
201
updateMaterialIndexAttribute ( geometry , materials , materials ) ;
202
+ this . _materialUuids = materials . map ( material => material . uuid ) ;
202
203
203
204
}
204
205
0 commit comments