@@ -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
@@ -920,7 +920,7 @@ class Renderer {
920920 const previousRenderContext = this . _currentRenderContext ;
921921 const previousRenderObjectFunction = this . _currentRenderObjectFunction ;
922922 const previousHandleObjectFunction = this . _handleObjectFunction ;
923- const previousCompilationPromises = this . _compilationPromises ;
923+ const previousCompilationRenderObjects = this . _compilationRenderObjects ;
924924
925925 //
926926
@@ -936,14 +936,14 @@ class Renderer {
936936 const renderContext = this . _renderContexts . get ( renderTarget , this . _mrt ) ;
937937 const activeMipmapLevel = this . _activeMipmapLevel ;
938938
939- const compilationPromises = [ ] ;
939+ const compilationRenderObjects = [ ] ;
940940
941941 this . _currentRenderContext = renderContext ;
942942 this . _currentRenderObjectFunction = this . renderObject ;
943943
944944 this . _handleObjectFunction = this . _createObjectPipeline ;
945945
946- this . _compilationPromises = compilationPromises ;
946+ this . _compilationRenderObjects = compilationRenderObjects ;
947947
948948 nodeFrame . renderId ++ ;
949949
@@ -1036,7 +1036,7 @@ class Renderer {
10361036
10371037 }
10381038
1039- // process render lists - _createObjectPipeline will push async promises to _compilationPromises
1039+ // process render lists - _createObjectPipeline will push render objects to _compilationRenderObjects
10401040
10411041 const opaqueObjects = renderList . opaque ;
10421042 const transparentObjects = renderList . transparent ;
@@ -1053,16 +1053,12 @@ class Renderer {
10531053 this . _currentRenderContext = previousRenderContext ;
10541054 this . _currentRenderObjectFunction = previousRenderObjectFunction ;
10551055 this . _handleObjectFunction = previousHandleObjectFunction ;
1056- this . _compilationPromises = previousCompilationPromises ;
1056+ this . _compilationRenderObjects = previousCompilationRenderObjects ;
10571057
10581058 // Process compilation work items sequentially to avoid freezing
10591059 // Yields between objects to keep animation smooth
10601060
1061- for ( const item of compilationPromises ) {
1062-
1063- const renderObject = this . _objects . get ( item . object , item . material , item . scene , item . camera , item . lightsNode , item . renderContext , item . clippingContext , item . passId ) ;
1064- renderObject . drawRange = item . object . geometry . drawRange ;
1065- renderObject . group = item . group ;
1061+ for ( const renderObject of compilationRenderObjects ) {
10661062
10671063 // Use async node building to yield to main thread
10681064 await this . _nodes . getForRenderAsync ( renderObject ) ;
@@ -1077,6 +1073,7 @@ class Renderer {
10771073 // Wait for pipeline creation
10781074 const pipelinePromises = [ ] ;
10791075 this . _pipelines . getForRender ( renderObject , pipelinePromises ) ;
1076+
10801077 if ( pipelinePromises . length > 0 ) {
10811078
10821079 await Promise . all ( pipelinePromises ) ;
@@ -3806,31 +3803,24 @@ class Renderer {
38063803 */
38073804 _createObjectPipeline ( object , material , scene , camera , lightsNode , group , clippingContext , passId ) {
38083805
3809- // If in async compilation mode, queue the work for sequential execution
3810- if ( this . _compilationPromises !== null ) {
3806+ // the render object must be requested during the traversal since the renderer temporarily
3807+ // overwrites `material.side` for the back side pass. `RenderObject.materialSide` preserves
3808+ // that value for the deferred compilation in `compileAsync()`.
38113809
3812- // Store work items instead of promises - will be processed sequentially
3813- this . _compilationPromises . push ( {
3814- object,
3815- material,
3816- scene,
3817- camera,
3818- lightsNode,
3819- group,
3820- clippingContext,
3821- passId,
3822- renderContext : this . _currentRenderContext
3823- } ) ;
3810+ const renderObject = this . _objects . get ( object , material , scene , camera , lightsNode , this . _currentRenderContext , clippingContext , passId ) ;
3811+ renderObject . drawRange = object . geometry . drawRange ;
3812+ renderObject . group = group ;
3813+
3814+ // if in async compilation mode, queue the render object for sequential execution
3815+
3816+ if ( this . _compilationRenderObjects !== null ) {
3817+
3818+ this . _compilationRenderObjects . push ( renderObject ) ;
38243819
38253820 return ;
38263821
38273822 }
38283823
3829- // Sync path
3830- const renderObject = this . _objects . get ( object , material , scene , camera , lightsNode , this . _currentRenderContext , clippingContext , passId ) ;
3831- renderObject . drawRange = object . geometry . drawRange ;
3832- renderObject . group = group ;
3833-
38343824 //
38353825
38363826 this . _nodes . updateBefore ( renderObject ) ;
@@ -3840,7 +3830,7 @@ class Renderer {
38403830 this . _nodes . updateForRender ( renderObject ) ;
38413831 this . _bindings . updateForRender ( renderObject ) ;
38423832
3843- this . _pipelines . getForRender ( renderObject , this . _compilationPromises ) ;
3833+ this . _pipelines . getForRender ( renderObject ) ;
38443834
38453835 this . _nodes . updateAfter ( renderObject ) ;
38463836
0 commit comments