Browse Source

Small improvement in scene loading blocking.

Creating all GPU stuff when rendering the first frame doesn't work well with gated initialization :(.
alteredq 14 years ago
parent
commit
549f90854b
3 changed files with 260 additions and 246 deletions
  1. 131 131
      build/ThreeExtras.js
  2. 15 3
      examples/scene_test.html
  3. 114 112
      src/extras/SceneUtils.js

File diff suppressed because it is too large
+ 131 - 131
build/ThreeExtras.js


+ 15 - 3
examples/scene_test.html

@@ -179,6 +179,13 @@
 				
 			}
 			
+			function handle_update( result ) {
+				
+				refreshSceneView( result );
+				renderer.initWebGLObjects( result.scene );
+				
+			}
+			
 			function init() {
 
 				container = document.createElement( 'div' );
@@ -197,7 +204,7 @@
 
 				setInterval( loop, 1000/60 );
 
-				var callback_progress = function( progress ) {
+				var callback_progress = function( progress, result ) {
 				
 					var bar = 250;
 					if ( progress.total_models + progress.total_textures ) 
@@ -205,11 +212,16 @@
 					
 					$( "bar" ).style.width = bar + "px";
 					
+					handle_update( result );
+					
 				}
 				
 				var callback_sync = function( result ) {
 				
 					/*
+					
+					// uncomment to see progressive scene loading
+					
 					scene = result.scene;
 					camera = result.currentCamera;
 					
@@ -220,7 +232,7 @@
 					
 					*/
 
-					refreshSceneView( result );
+					handle_update( result );
 					
 				}
 				
@@ -242,7 +254,7 @@
 					$( "start" ).style.display = "block";
 					$( "start" ).className = "enabled";
 					
-					refreshSceneView( result );
+					handle_update( result );
 					
 				}
 				

+ 114 - 112
src/extras/SceneUtils.js

@@ -91,7 +91,6 @@ var SceneUtils = {
 					handle_mesh( geo, id );
 					
 					counter_models -= 1;
-					//console.log( "models to load:", counter_models );
 					
 					async_callback_gate();
 					
@@ -110,7 +109,7 @@ var SceneUtils = {
 					
 				};
 				
-				callback_progress( progress );
+				callback_progress( progress, result );
 				
 				if( counter_models == 0 && counter_textures == 0 ) {
 					
@@ -120,6 +119,119 @@ var SceneUtils = {
 				
 			};
 			
+			var callback_texture = function( images ) {
+				
+				counter_textures -= 1;
+				async_callback_gate();  
+				
+			};
+			
+			// first go synchronous elements
+			
+			// cameras
+			
+			for( dc in data.cameras ) {
+				
+				c = data.cameras[ dc ];
+				
+				if ( c.type == "perspective" ) {
+					
+					camera = new THREE.Camera( c.fov, c.aspect, c.near, c.far );
+					
+				} else if ( c.type == "ortho" ) {
+					
+					camera = new THREE.Camera();
+					camera.projectionMatrix = THREE.Matrix4.makeOrtho( c.left, c.right, c.top, c.bottom, c.near, c.far );
+					
+				}
+				
+				p = c.position;
+				t = c.target;
+				camera.position.set( p[0], p[1], p[2] );
+				camera.target.position.set( t[0], t[1], t[2] );
+				
+				result.cameras[ dc ] = camera;
+				
+			}
+			
+			// lights
+			
+			for( dl in data.lights ) {
+				
+				l = data.lights[ dl ];
+				
+				if ( l.type == "directional" ) {
+				
+					p = l.direction;
+					
+					light = new THREE.DirectionalLight();
+					light.position.set( p[0], p[1], p[2] );
+					light.position.normalize();
+					
+				} else if ( l.type == "point" ) {
+				
+					p = l.position;
+					
+					light = new THREE.PointLight();
+					light.position.set( p[0], p[1], p[2] );
+					
+				}
+				
+				c = l.color;
+				i = l.intensity || 1;
+				light.color.setRGB( c[0] * i, c[1] * i, c[2] * i );
+				
+				result.scene.addLight( light );
+				
+				result.lights[ dl ] = light;
+				
+			}
+			
+			// fogs
+			
+			for( df in data.fogs ) {
+				
+				f = data.fogs[ df ];
+				
+				if ( f.type == "linear" ) {
+					
+					fog = new THREE.Fog( 0x000000, f.near, f.far );
+				
+				} else if ( f.type == "exp2" ) {
+					
+					fog = new THREE.FogExp2( 0x000000, f.density );
+					
+				}
+				
+				c = f.color;
+				fog.color.setRGB( c[0], c[1], c[2] );
+				
+				result.fogs[ df ] = fog;
+				
+			}
+			
+			// defaults
+			
+			if ( result.cameras && data.defaults.camera ) {
+				
+				result.currentCamera = result.cameras[ data.defaults.camera ];
+				
+			}
+			
+			if ( result.fogs && data.defaults.fog ) {
+			
+				result.scene.fog = result.fogs[ data.defaults.fog ];
+				
+			}
+			
+			c = data.defaults.bgcolor;
+			result.bgColor = new THREE.Color();
+			result.bgColor.setRGB( c[0], c[1], c[2] );
+			
+			result.bgColorAlpha = data.defaults.bgalpha;
+
+			// now come potentially asynchronous elements
+			
 			// geometries
 			
 			// count how many models will be loaded asynchronously
@@ -210,14 +322,6 @@ var SceneUtils = {
 			
 			total_textures = counter_textures;
 			
-			var callback_texture = function( images ) {
-				
-				counter_textures -= 1; 
-				//console.log( "textures to load:", counter_textures ); 
-				async_callback_gate();  
-				
-			};
-			
 			for( dt in data.textures ) {
 				
 				tt = data.textures[ dt ];
@@ -282,108 +386,6 @@ var SceneUtils = {
 			
 			handle_objects();
 			
-			// lights
-			
-			for( dl in data.lights ) {
-				
-				l = data.lights[ dl ];
-				
-				if ( l.type == "directional" ) {
-				
-					p = l.direction;
-					
-					light = new THREE.DirectionalLight();
-					light.position.set( p[0], p[1], p[2] );
-					light.position.normalize();
-					
-				} else if ( l.type == "point" ) {
-				
-					p = l.position;
-					
-					light = new THREE.PointLight();
-					light.position.set( p[0], p[1], p[2] );
-					
-				}
-				
-				c = l.color;
-				i = l.intensity || 1;
-				light.color.setRGB( c[0] * i, c[1] * i, c[2] * i );
-				
-				result.scene.addLight( light );
-				
-				result.lights[ dl ] = light;
-				
-			}
-			
-			// cameras
-			
-			for( dc in data.cameras ) {
-				
-				c = data.cameras[ dc ];
-				
-				if ( c.type == "perspective" ) {
-					
-					camera = new THREE.Camera( c.fov, c.aspect, c.near, c.far );
-					
-				} else if ( c.type == "ortho" ) {
-					
-					camera = new THREE.Camera();
-					camera.projectionMatrix = THREE.Matrix4.makeOrtho( c.left, c.right, c.top, c.bottom, c.near, c.far );
-					
-				}
-				
-				p = c.position;
-				t = c.target;
-				camera.position.set( p[0], p[1], p[2] );
-				camera.target.position.set( t[0], t[1], t[2] );
-				
-				result.cameras[ dc ] = camera;
-				
-			}
-
-			// fogs
-			
-			for( df in data.fogs ) {
-				
-				f = data.fogs[ df ];
-				
-				if ( f.type == "linear" ) {
-					
-					fog = new THREE.Fog( 0x000000, f.near, f.far );
-				
-				} else if ( f.type == "exp2" ) {
-					
-					fog = new THREE.FogExp2( 0x000000, f.density );
-					
-				}
-				
-				c = f.color;
-				fog.color.setRGB( c[0], c[1], c[2] );
-				
-				result.fogs[ df ] = fog;
-				
-			}
-			
-			// defaults
-			
-			if ( result.cameras && data.defaults.camera ) {
-				
-				result.currentCamera = result.cameras[ data.defaults.camera ];
-				
-			}
-			
-			if ( result.fogs && data.defaults.fog ) {
-			
-				result.scene.fog = result.fogs[ data.defaults.fog ];
-				
-			}
-			
-			c = data.defaults.bgcolor;
-			result.bgColor = new THREE.Color();
-			result.bgColor.setRGB( c[0], c[1], c[2] );
-			
-			result.bgColorAlpha = data.defaults.bgalpha;
-			
 			// synchronous callback
 			
 			callback_sync( result );

Some files were not shown because too many files changed in this diff