@@ -73,8 +73,6 @@ function getLights( objects ) {
7373
7474}
7575
76- let materialUuids = null ;
77-
7876export class PathTracingSceneGenerator {
7977
8078 get initialized ( ) {
@@ -97,6 +95,7 @@ export class PathTracingSceneGenerator {
9795 this . _bvhWorker = null ;
9896 this . _pendingGenerate = null ;
9997 this . _buildAsync = false ;
98+ this . _materialUuids = null ;
10099
101100 }
102101
@@ -178,27 +177,29 @@ export class PathTracingSceneGenerator {
178177 // generate the geometry
179178 const result = staticGeometryGenerator . generate ( geometry ) ;
180179 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 ) {
183182
184- if ( materialUuids === null || materialUuids . length !== length ) {
183+ for ( let i = 0 , length = materials . length ; ( i < length ) ; i ++ ) {
185184
186- needsMaterialIndexUpdate = true ;
187- break ;
185+ const material = materials [ i ] ;
186+ if ( material . uuid !== this . _materialUuids [ i ] ) {
188187
189- }
188+ needsMaterialIndexUpdate = true ;
189+ break ;
190190
191- const material = materials [ index ] ;
192- if ( material . uuid !== materialUuids [ index ] ) needsMaterialIndexUpdate = true ;
191+ }
192+
193+ }
193194
194195 }
195196
196- materialUuids = materials . map ( material => material . uuid ) ;
197197 const textures = getTextures ( materials ) ;
198198 const { lights, iesTextures } = getLights ( objects ) ;
199199 if ( needsMaterialIndexUpdate ) {
200200
201201 updateMaterialIndexAttribute ( geometry , materials , materials ) ;
202+ this . _materialUuids = materials . map ( material => material . uuid ) ;
202203
203204 }
204205
0 commit comments