@@ -653,13 +653,13 @@ class Renderer {
653653 this . _initPromise = null ;
654654
655655 /**
656- * An array of compilation promises which are used in `compileAsync()`.
656+ * An array of render objects which are precompiled in `compileAsync()`.
657657 *
658658 * @private
659- * @type {?Array<Promise > }
659+ * @type {?Array<RenderObject > }
660660 * @default null
661661 */
662- this . _compilationPromises = null ;
662+ this . _compilationRenderObjects = null ;
663663
664664 /**
665665 * Whether the renderer is currently precompiling a render object in
@@ -921,7 +921,7 @@ class Renderer {
921921 const previousRenderContext = this . _currentRenderContext ;
922922 const previousRenderObjectFunction = this . _currentRenderObjectFunction ;
923923 const previousHandleObjectFunction = this . _handleObjectFunction ;
924- const previousCompilationPromises = this . _compilationPromises ;
924+ const previousCompilationRenderObjects = this . _compilationRenderObjects ;
925925
926926 //
927927
@@ -939,14 +939,14 @@ class Renderer {
939939 const renderContext = this . _renderContexts . get ( renderTarget , this . _mrt ) ;
940940 const activeMipmapLevel = this . _activeMipmapLevel ;
941941
942- const compilationPromises = [ ] ;
942+ const compilationRenderObjects = [ ] ;
943943
944944 this . _currentRenderContext = renderContext ;
945945 this . _currentRenderObjectFunction = this . renderObject ;
946946
947947 this . _handleObjectFunction = this . _createObjectPipeline ;
948948
949- this . _compilationPromises = compilationPromises ;
949+ this . _compilationRenderObjects = compilationRenderObjects ;
950950
951951 nodeFrame . renderId ++ ;
952952
@@ -1039,7 +1039,7 @@ class Renderer {
10391039
10401040 }
10411041
1042- // process render lists - _createObjectPipeline will push async promises to _compilationPromises
1042+ // process render lists - _createObjectPipeline will push render objects to _compilationRenderObjects
10431043
10441044 const opaqueObjects = renderList . opaque ;
10451045 const transparentObjects = renderList . transparent ;
@@ -1056,19 +1056,15 @@ class Renderer {
10561056 this . _currentRenderContext = previousRenderContext ;
10571057 this . _currentRenderObjectFunction = previousRenderObjectFunction ;
10581058 this . _handleObjectFunction = previousHandleObjectFunction ;
1059- this . _compilationPromises = previousCompilationPromises ;
1059+ this . _compilationRenderObjects = previousCompilationRenderObjects ;
10601060
10611061 // Process compilation work items sequentially to avoid freezing
10621062 // Yields between objects to keep animation smooth
10631063
1064- const total = compilationPromises . length ;
1064+ const total = compilationRenderObjects . length ;
10651065 let loaded = 0 ;
10661066
1067- for ( const item of compilationPromises ) {
1068-
1069- const renderObject = this . _objects . get ( item . object , item . material , item . scene , item . camera , item . lightsNode , item . renderContext , item . clippingContext , item . passId ) ;
1070- renderObject . drawRange = item . object . geometry . drawRange ;
1071- renderObject . group = item . group ;
1067+ for ( const renderObject of compilationRenderObjects ) {
10721068
10731069 // Use async node building to yield to main thread
10741070 await this . _nodes . getForRenderAsync ( renderObject ) ;
@@ -1083,6 +1079,7 @@ class Renderer {
10831079 // Wait for pipeline creation
10841080 const pipelinePromises = [ ] ;
10851081 this . _pipelines . getForRender ( renderObject , pipelinePromises ) ;
1082+
10861083 if ( pipelinePromises . length > 0 ) {
10871084
10881085 await Promise . all ( pipelinePromises ) ;
@@ -3906,31 +3903,24 @@ class Renderer {
39063903 */
39073904 _createObjectPipeline ( object , material , scene , camera , lightsNode , group , clippingContext , passId ) {
39083905
3909- // If in async compilation mode, queue the work for sequential execution
3910- if ( this . _compilationPromises !== null ) {
3906+ // the render object must be requested during the traversal since the renderer temporarily
3907+ // overwrites `material.side` for the back side pass. `RenderObject.materialSide` preserves
3908+ // that value for the deferred compilation in `compileAsync()`.
39113909
3912- // Store work items instead of promises - will be processed sequentially
3913- this . _compilationPromises . push ( {
3914- object,
3915- material,
3916- scene,
3917- camera,
3918- lightsNode,
3919- group,
3920- clippingContext,
3921- passId,
3922- renderContext : this . _currentRenderContext
3923- } ) ;
3910+ const renderObject = this . _objects . get ( object , material , scene , camera , lightsNode , this . _currentRenderContext , clippingContext , passId ) ;
3911+ renderObject . drawRange = object . geometry . drawRange ;
3912+ renderObject . group = group ;
3913+
3914+ // if in async compilation mode, queue the render object for sequential execution
3915+
3916+ if ( this . _compilationRenderObjects !== null ) {
3917+
3918+ this . _compilationRenderObjects . push ( renderObject ) ;
39243919
39253920 return ;
39263921
39273922 }
39283923
3929- // Sync path
3930- const renderObject = this . _objects . get ( object , material , scene , camera , lightsNode , this . _currentRenderContext , clippingContext , passId ) ;
3931- renderObject . drawRange = object . geometry . drawRange ;
3932- renderObject . group = group ;
3933-
39343924 //
39353925
39363926 this . _nodes . updateBefore ( renderObject ) ;
@@ -3940,7 +3930,7 @@ class Renderer {
39403930 this . _nodes . updateForRender ( renderObject ) ;
39413931 this . _bindings . updateForRender ( renderObject ) ;
39423932
3943- this . _pipelines . getForRender ( renderObject , this . _compilationPromises ) ;
3933+ this . _pipelines . getForRender ( renderObject ) ;
39443934
39453935 this . _nodes . updateAfter ( renderObject ) ;
39463936
0 commit comments