提交 aac5b611 编写于 作者: A alteredq

Refactored SceneLoader.

Just a single callback is now passed  to loader.load( "scene.js", callbackFinal ) - callback which is called when everything from the scene was already loaded.

If you want to use also callbacks for initialization of procedural synchronously created elements, you can set property of loader:

loader.callbackSync = function( result ) { ... }

If you want to get callback for load progress, set:

loader.callbackProgress = function( progress, result ) { ... }

Also added per scene creation of collision systems (it used to be singleton).
上级 f51d3f4d
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -99,7 +99,7 @@ THREE.Sound=function(a,b,c,d){THREE.Object3D.call(this);this.isLoaded=!1;this.is
THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded){this.removeEventListener("canplay",this.onLoad,!0);a.isLoaded=!0;a.duration=this.duration;a.isPlaying&&a.play()}};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded){this.domElement.play();if(a)this.domElement.currentTime=a%this.duration}};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
THREE.Sound.prototype.update=function(a,b,c){if(this.matrixAutoUpdate){this.matrix.setPosition(this.position);b=!0}if(b||this.matrixWorldNeedsUpdate){a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=!1;b=!0}var d=this.children.length;for(a=0;a<d;a++)this.children[a].update(this.matrixWorld,b,c)};
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1){this.objects.push(a);this.__objectsAdded.push(a)}for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else if(a instanceof THREE.Sound){b=this.sounds.indexOf(a);b!==-1&&this.sounds.splice(b,1)}else if(!(a instanceof THREE.Camera)){b=this.objects.indexOf(a);if(b!==-1){this.objects.splice(b,1);this.__objectsRemoved.push(a)}}for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
......
......@@ -65,7 +65,7 @@ THREE.Sound=function(a,b,c,d){THREE.Object3D.call(this);this.isLoaded=!1;this.is
THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded){this.removeEventListener("canplay",this.onLoad,!0);a.isLoaded=!0;a.duration=this.duration;a.isPlaying&&a.play()}};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded){this.domElement.play();if(a)this.domElement.currentTime=a%this.duration}};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
THREE.Sound.prototype.update=function(a,b,c){if(this.matrixAutoUpdate){this.matrix.setPosition(this.position);b=!0}if(b||this.matrixWorldNeedsUpdate){a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=!1;b=!0}var d=this.children.length;for(a=0;a<d;a++)this.children[a].update(this.matrixWorld,b,c)};
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1){this.objects.push(a);this.__objectsAdded.push(a)}for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else if(a instanceof THREE.Sound){b=this.sounds.indexOf(a);b!==-1&&this.sounds.splice(b,1)}else if(!(a instanceof THREE.Camera)){b=this.objects.indexOf(a);if(b!==-1){this.objects.splice(b,1);this.__objectsRemoved.push(a)}}for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
......
此差异已折叠。
......@@ -95,7 +95,7 @@ THREE.Sound=function(a,b,c,d){THREE.Object3D.call(this);this.isLoaded=!1;this.is
THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded){this.removeEventListener("canplay",this.onLoad,!0);a.isLoaded=!0;a.duration=this.duration;a.isPlaying&&a.play()}};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded){this.domElement.play();if(a)this.domElement.currentTime=a%this.duration}};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
THREE.Sound.prototype.update=function(a,b,c){if(this.matrixAutoUpdate){this.matrix.setPosition(this.position);b=!0}if(b||this.matrixWorldNeedsUpdate){a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=!1;b=!0}var d=this.children.length;for(a=0;a<d;a++)this.children[a].update(this.matrixWorld,b,c)};
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1){this.objects.push(a);this.__objectsAdded.push(a)}for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else if(a instanceof THREE.Sound){b=this.sounds.indexOf(a);b!==-1&&this.sounds.splice(b,1)}else if(!(a instanceof THREE.Camera)){b=this.objects.indexOf(a);if(b!==-1){this.objects.splice(b,1);this.__objectsRemoved.push(a)}}for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;
......
......@@ -124,7 +124,7 @@ n){v="d";H=L[o]+3}if(g.a===p){v+="a";I=L[o]+0}else if(g.b===p){v+="b";I=L[o]+1}e
THREE.ShadowVolume.prototype.calculateShadowVolumeGeometryWithoutEdgeInfo=function(b){this.geometry=new THREE.Geometry;this.geometry.boundingSphere=b.boundingSphere;this.geometry.edgeFaces=[];var d=this.geometry.vertices,e=this.geometry.faces,g=this.geometry.edgeFaces,h=b.faces;b=b.vertices;var o=h.length,n,p,q,v,E,F=["a","b","c","d"];for(q=0;q<o;q++){p=d.length;n=h[q];if(n instanceof THREE.Face4){v=4;p=new THREE.Face4(p,p+1,p+2,p+3)}else{v=3;p=new THREE.Face3(p,p+1,p+2)}p.normal.copy(n.normal);e.push(p);
for(p=0;p<v;p++){E=b[n[F[p]]];d.push(new THREE.Vertex(E.position.clone()))}}for(o=0;o<h.length-1;o++){b=e[o];for(n=o+1;n<h.length;n++){p=e[n];p=this.facesShareEdge(d,b,p);if(p!==undefined){p=new THREE.Face4(p.indices[0],p.indices[3],p.indices[2],p.indices[1]);p.normal.set(1,0,0);g.push(p)}}}};
THREE.ShadowVolume.prototype.facesShareEdge=function(b,d,e){var g,h,o,n,p,q,v,E,F,H,I,M,N,U=0,L=["a","b","c","d"];g=d instanceof THREE.Face4?4:3;h=e instanceof THREE.Face4?4:3;for(M=0;M<g;M++){o=d[L[M]];p=b[o];for(N=0;N<h;N++){n=e[L[N]];q=b[n];if(Math.abs(p.position.x-q.position.x)<1.0E-4&&Math.abs(p.position.y-q.position.y)<1.0E-4&&Math.abs(p.position.z-q.position.z)<1.0E-4){U++;if(U===1){v=p;E=q;F=o;H=n;I=L[M]}if(U===2){I+=L[M];return I==="ad"||I==="ac"?{faces:[d,e],vertices:[v,E,q,p],indices:[F,
H,n,o],vertexTypes:[1,2,2,1],extrudable:!0}:{faces:[d,e],vertices:[v,p,q,E],indices:[F,o,n,H],vertexTypes:[1,1,2,2],extrudable:!0}}}}}};THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;
H,n,o],vertexTypes:[1,2,2,1],extrudable:!0}:{faces:[d,e],vertices:[v,p,q,E],indices:[F,o,n,H],vertexTypes:[1,1,2,2],extrudable:!0}}}}}};THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.fog=null;this.objects=[];this.lights=[];this.sounds=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;
THREE.Scene.prototype.addChild=function(b){this.supr.addChild.call(this,b);this.addChildRecurse(b)};THREE.Scene.prototype.addChildRecurse=function(b){if(b instanceof THREE.Light)this.lights.indexOf(b)===-1&&this.lights.push(b);else if(b instanceof THREE.Sound)this.sounds.indexOf(b)===-1&&this.sounds.push(b);else if(!(b instanceof THREE.Camera||b instanceof THREE.Bone)&&this.objects.indexOf(b)===-1){this.objects.push(b);this.__objectsAdded.push(b)}for(var d=0;d<b.children.length;d++)this.addChildRecurse(b.children[d])};
THREE.Scene.prototype.removeChild=function(b){this.supr.removeChild.call(this,b);this.removeChildRecurse(b)};THREE.Scene.prototype.removeChildRecurse=function(b){if(b instanceof THREE.Light){var d=this.lights.indexOf(b);d!==-1&&this.lights.splice(d,1)}else if(b instanceof THREE.Sound){d=this.sounds.indexOf(b);d!==-1&&this.sounds.splice(d,1)}else if(!(b instanceof THREE.Camera)){d=this.objects.indexOf(b);if(d!==-1){this.objects.splice(d,1);this.__objectsRemoved.push(b)}}for(d=0;d<b.children.length;d++)this.removeChildRecurse(b.children[d])};
THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;THREE.Fog=function(b,d,e){this.color=new THREE.Color(b);this.near=d||1;this.far=e||1E3};THREE.FogExp2=function(b,d){this.color=new THREE.Color(b);this.density=d!==undefined?d:2.5E-4};
......
......@@ -241,11 +241,11 @@
$( "start" ).addEventListener( 'click', onStartClick, false );
var callback_progress = function( progress, result ) {
var callbackProgress = function( progress, result ) {
var bar = 250,
total = progress.total_models + progress.total_textures,
loaded = progress.loaded_models + progress.loaded_textures;
total = progress.totalModels + progress.totalTextures,
loaded = progress.loadedModels + progress.loadedTextures;
if ( total )
bar = Math.floor( bar * loaded / total );
......@@ -259,7 +259,7 @@
}
var callback_sync = function( result ) {
var callbackSync = function( result ) {
/*
......@@ -279,7 +279,7 @@
}
var callback_async = function( result ) {
var callbackFinised = function( result ) {
loaded = result;
......@@ -306,7 +306,11 @@
$( "progress" ).style.display = "block";
var loader = new THREE.SceneLoader();
loader.load( "scenes/test_scene.js", callback_sync, callback_async, callback_progress );
loader.callbackSync = callbackSync;
loader.callbackProgress = callbackProgress;
loader.load( "scenes/test_scene.js", callbackFinised );
$( "plus_exp" ).addEventListener( 'click', createToggle( "exp" ), false );
......
......@@ -241,7 +241,7 @@
$( "start" ).addEventListener( 'click', onStartClick, false );
var callback_progress = function( progress, result ) {
var callbackProgress = function( progress, result ) {
var bar = 250,
total = progress.total_models + progress.total_textures,
......@@ -259,27 +259,7 @@
}
var callback_sync = function( result ) {
/*
// uncomment to see progressive scene loading
scene = result.scene;
camera = result.currentCamera;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setClearColor( result.bgColor, result.bgAlpha );
*/
//handle_update( result, 1 );
}
var callback_async = function( result ) {
var callbackFinished = function( result ) {
loaded = result;
......@@ -295,7 +275,9 @@
$( "progress" ).style.display = "block";
var loader = new THREE.SceneLoader();
loader.load( "obj/blenderscene/scene.js", callback_sync, callback_async, callback_progress );
loader.callbackProgress = callbackProgress;
loader.load( "obj/blenderscene/scene.js", callbackFinished );
$( "plus_exp" ).addEventListener( 'click', createToggle( "exp" ), false );
......
......@@ -7,12 +7,15 @@ THREE.SceneLoader = function () {
this.onLoadStart = function () {};
this.onLoadProgress = function() {};
this.onLoadComplete = function () {};
this.callbackSync = function () {};
this.callbackProgress = function () {};
};
THREE.SceneLoader.prototype = {
load : function ( url, callback_sync, callback_async, callback_progress ) {
load : function ( url, callbackFinished ) {
var scope = this;
......@@ -54,6 +57,29 @@ THREE.SceneLoader.prototype = {
};
// find out if there are some colliders
var hasColliders = false;
for( dd in data.objects ) {
o = data.objects[ dd ];
if ( o.meshCollider ) {
hasColliders = true;
break;
}
}
if ( hasColliders ) {
result.scene.collisions = new THREE.CollisionSystem();
}
if ( data.transform ) {
var position = data.transform.position,
......@@ -156,7 +182,7 @@ THREE.SceneLoader.prototype = {
if ( o.meshCollider ) {
var meshCollider = THREE.CollisionUtils.MeshColliderWBox( object );
THREE.Collisions.colliders.push( meshCollider );
result.scene.collisions.colliders.push( meshCollider );
}
......@@ -210,26 +236,26 @@ THREE.SceneLoader.prototype = {
var progress = {
total_models: total_models,
total_textures: total_textures,
loaded_models: total_models - counter_models,
loaded_textures: total_textures - counter_textures
totalModels : total_models,
totalTextures : total_textures,
loadedModels : total_models - counter_models,
loadedTextures : total_textures - counter_textures
};
callback_progress( progress, result );
scope.callbackProgress( progress, result );
scope.onLoadProgress();
if( counter_models == 0 && counter_textures == 0 ) {
callback_async( result );
callbackFinished( result );
}
};
var callback_texture = function( images ) {
var callbackTexture = function( images ) {
counter_textures -= 1;
async_callback_gate();
......@@ -465,11 +491,11 @@ THREE.SceneLoader.prototype = {
}
texture = THREE.ImageUtils.loadTextureCube( url_array, tt.mapping, callback_texture );
texture = THREE.ImageUtils.loadTextureCube( url_array, tt.mapping, callbackTexture );
} else {
texture = THREE.ImageUtils.loadTexture( get_url( tt.url, data.urlBaseType ), tt.mapping, callback_texture );
texture = THREE.ImageUtils.loadTexture( get_url( tt.url, data.urlBaseType ), tt.mapping, callbackTexture );
if ( THREE[ tt.minFilter ] != undefined )
texture.minFilter = THREE[ tt.minFilter ];
......@@ -542,7 +568,7 @@ THREE.SceneLoader.prototype = {
// synchronous callback
callback_sync( result );
scope.callbackSync( result );
};
......
......@@ -11,6 +11,8 @@ THREE.Scene = function () {
this.fog = null;
this.collisions = null;
this.objects = [];
this.lights = [];
this.sounds = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册