|
@@ -29094,14 +29094,18 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.compile = function ( scene, camera ) {
|
|
|
+ this.compile = function ( scene, camera, targetScene = null ) {
|
|
|
|
|
|
- currentRenderState = renderStates.get( scene );
|
|
|
+ if ( targetScene === null ) targetScene = scene;
|
|
|
+
|
|
|
+ currentRenderState = renderStates.get( targetScene );
|
|
|
currentRenderState.init();
|
|
|
|
|
|
renderStateStack.push( currentRenderState );
|
|
|
|
|
|
- scene.traverseVisible( function ( object ) {
|
|
|
+ // gather lights from both the target scene and the new object that will be added to the scene.
|
|
|
+
|
|
|
+ targetScene.traverseVisible( function ( object ) {
|
|
|
|
|
|
if ( object.isLight && object.layers.test( camera.layers ) ) {
|
|
|
|
|
@@ -29117,67 +29121,31 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
|
|
|
} );
|
|
|
|
|
|
- currentRenderState.setupLights( _this._useLegacyLights );
|
|
|
-
|
|
|
- scene.traverse( function ( object ) {
|
|
|
-
|
|
|
- const material = object.material;
|
|
|
+ if ( scene !== targetScene ) {
|
|
|
|
|
|
- if ( material ) {
|
|
|
+ scene.traverseVisible( function ( object ) {
|
|
|
|
|
|
- if ( Array.isArray( material ) ) {
|
|
|
+ if ( object.isLight && object.layers.test( camera.layers ) ) {
|
|
|
|
|
|
- for ( let i = 0; i < material.length; i ++ ) {
|
|
|
+ currentRenderState.pushLight( object );
|
|
|
|
|
|
- const material2 = material[ i ];
|
|
|
+ if ( object.castShadow ) {
|
|
|
|
|
|
- prepareMaterial( material2, scene, object );
|
|
|
+ currentRenderState.pushShadow( object );
|
|
|
|
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
-
|
|
|
- prepareMaterial( material, scene, object );
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- } );
|
|
|
-
|
|
|
- renderStateStack.pop();
|
|
|
- currentRenderState = null;
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- // compileAsync
|
|
|
-
|
|
|
- this.compileAsync = function ( scene, camera ) {
|
|
|
-
|
|
|
- currentRenderState = renderStates.get( scene );
|
|
|
- currentRenderState.init();
|
|
|
-
|
|
|
- renderStateStack.push( currentRenderState );
|
|
|
-
|
|
|
- scene.traverseVisible( function ( object ) {
|
|
|
-
|
|
|
- if ( object.isLight && object.layers.test( camera.layers ) ) {
|
|
|
-
|
|
|
- currentRenderState.pushLight( object );
|
|
|
-
|
|
|
- if ( object.castShadow ) {
|
|
|
-
|
|
|
- currentRenderState.pushShadow( object );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ } );
|
|
|
|
|
|
- } );
|
|
|
+ }
|
|
|
|
|
|
currentRenderState.setupLights( _this._useLegacyLights );
|
|
|
|
|
|
- const compiling = new Set();
|
|
|
+ // Only initialize materials in the new scene, not the targetScene.
|
|
|
+
|
|
|
+ const materials = new Set();
|
|
|
|
|
|
scene.traverse( function ( object ) {
|
|
|
|
|
@@ -29191,15 +29159,15 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
|
|
|
const material2 = material[ i ];
|
|
|
|
|
|
- prepareMaterial( material2, scene, object );
|
|
|
- compiling.add( material2 );
|
|
|
+ prepareMaterial( material2, targetScene, object );
|
|
|
+ materials.add( material2 );
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- prepareMaterial( material, scene, object );
|
|
|
- compiling.add( material );
|
|
|
+ prepareMaterial( material, targetScene, object );
|
|
|
+ materials.add( material );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -29210,6 +29178,16 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
renderStateStack.pop();
|
|
|
currentRenderState = null;
|
|
|
|
|
|
+ return materials;
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ // compileAsync
|
|
|
+
|
|
|
+ this.compileAsync = function ( scene, camera, targetScene = null ) {
|
|
|
+
|
|
|
+ const materials = this.compile( scene, camera, targetScene );
|
|
|
+
|
|
|
// Wait for all the materials in the new object to indicate that they're
|
|
|
// ready to be used before resolving the promise.
|
|
|
|
|
@@ -29217,7 +29195,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
|
|
|
function checkMaterialsReady() {
|
|
|
|
|
|
- compiling.forEach( function ( material ) {
|
|
|
+ materials.forEach( function ( material ) {
|
|
|
|
|
|
const materialProperties = properties.get( material );
|
|
|
const program = materialProperties.currentProgram;
|
|
@@ -29225,7 +29203,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
if ( program.isReady() ) {
|
|
|
|
|
|
// remove any programs that report they're ready to use from the list
|
|
|
- compiling.delete( material );
|
|
|
+ materials.delete( material );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -29233,7 +29211,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
|
|
|
|
|
|
// once the list of compiling materials is empty, call the callback
|
|
|
|
|
|
- if ( compiling.size === 0 ) {
|
|
|
+ if ( materials.size === 0 ) {
|
|
|
|
|
|
resolve( scene );
|
|
|
return;
|