提交 9a9d0ca7 编写于 作者: M Mr.doob

Updated ObjectLoader with new LoadingManager.

Still not really using it though...
上级 3e6aae08
......@@ -10793,19 +10793,23 @@ THREE.ObjectLoader.prototype = {
constructor: THREE.ObjectLoader,
load: function ( url, callback ) {
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
this.manager.add( url, 'text', function ( event ) {
var loader = new THREE.XHRLoader();
loader.setCrossOrigin( this.crossOrigin );
loader.load( url, function ( text ) {
if ( callback !== undefined ) {
onLoad( scope.parse( JSON.parse( text ) ) );
callback( scope.parse( JSON.parse( event.target.responseText ) ) );
} );
}
},
} );
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
},
......
......@@ -217,13 +217,13 @@ G=c.morphColors[h].colors;C=a.morphColors[h].colors;d=0;for(z=C.length;d<z;d+=3)
THREE.MaterialLoader.prototype={constructor:THREE.MaterialLoader,load:function(a,b){var c=this,d=new THREE.XHRLoader;d.setCrossOrigin(this.crossOrigin);d.load(a,function(a){b(c.parse(JSON.parse(a)))})},setCrossOrigin:function(a){this.crossOrigin=a},parse:function(a){var b;switch(a.type){case "MeshBasicMaterial":b=new THREE.MeshBasicMaterial({color:a.color,opacity:a.opacity,transparent:a.transparent,wireframe:a.wireframe});break;case "MeshLambertMaterial":b=new THREE.MeshLambertMaterial({color:a.color,
ambient:a.ambient,emissive:a.emissive,opacity:a.opacity,transparent:a.transparent,wireframe:a.wireframe});break;case "MeshPhongMaterial":b=new THREE.MeshPhongMaterial({color:a.color,ambient:a.ambient,emissive:a.emissive,specular:a.specular,shininess:a.shininess,opacity:a.opacity,transparent:a.transparent,wireframe:a.wireframe});break;case "MeshNormalMaterial":b=new THREE.MeshNormalMaterial({opacity:a.opacity,transparent:a.transparent,wireframe:a.wireframe});break;case "MeshDepthMaterial":b=new THREE.MeshDepthMaterial({opacity:a.opacity,
transparent:a.transparent,wireframe:a.wireframe})}return b}};THREE.ObjectLoader=function(a){this.manager=void 0!==a?a:THREE.DefaultLoadingManager};
THREE.ObjectLoader.prototype={constructor:THREE.ObjectLoader,load:function(a,b){var c=this;this.manager.add(a,"text",function(a){void 0!==b&&b(c.parse(JSON.parse(a.target.responseText)))})},parse:function(a){var b=this.parseGeometries(a.geometries),c=this.parseMaterials(a.materials);return this.parseObject(a.object,b,c)},parseGeometries:function(a){var b={};if(void 0!==a)for(var c=new THREE.JSONLoader,d=0,e=a.length;d<e;d++){var f,g=a[d];switch(g.type){case "PlaneGeometry":f=new THREE.PlaneGeometry(g.width,
g.height,g.widthSegments,g.heightSegments);break;case "CubeGeometry":f=new THREE.CubeGeometry(g.width,g.height,g.depth,g.widthSegments,g.heightSegments,g.depthSegments);break;case "CylinderGeometry":f=new THREE.CylinderGeometry(g.radiusTop,g.radiusBottom,g.height,g.radiusSegments,g.heightSegments,g.openEnded);break;case "SphereGeometry":f=new THREE.SphereGeometry(g.radius,g.widthSegments,g.heightSegments,g.phiStart,g.phiLength,g.thetaStart,g.thetaLength);break;case "IcosahedronGeometry":f=new THREE.IcosahedronGeometry(g.radius,
g.detail);break;case "TorusGeometry":f=new THREE.TorusGeometry(g.radius,g.tube,g.radialSegments,g.tubularSegments,g.arc);break;case "TorusKnotGeometry":f=new THREE.TorusKnotGeometry(g.radius,g.tube,g.radialSegments,g.tubularSegments,g.p,g.q,g.heightScale);break;case "Geometry":f=c.parse(g.data).geometry}void 0!==g.id&&(f.id=g.id);void 0!==g.name&&(f.name=g.name);b[g.id]=f}return b},parseMaterials:function(a){var b={};if(void 0!==a)for(var c=new THREE.MaterialLoader,d=0,e=a.length;d<e;d++){var f=a[d],
g=c.parse(f);void 0!==f.id&&(g.id=f.id);void 0!==f.name&&(g.name=f.name);b[f.id]=g}return b},parseObject:function(a,b,c){var d;switch(a.type){case "Scene":d=new THREE.Scene;break;case "PerspectiveCamera":d=new THREE.PerspectiveCamera(a.fov,a.aspect,a.near,a.far);d.position.fromArray(a.position);d.rotation.fromArray(a.rotation);break;case "OrthographicCamera":d=new THREE.OrthographicCamera(a.left,a.right,a.top,a.bottom,a.near,a.far);d.position.fromArray(a.position);d.rotation.fromArray(a.rotation);
break;case "AmbientLight":d=new THREE.AmbientLight(a.color);break;case "DirectionalLight":d=new THREE.DirectionalLight(a.color,a.intensity);d.position.fromArray(a.position);break;case "PointLight":d=new THREE.PointLight(a.color,a.intensity,a.distance);d.position.fromArray(a.position);break;case "SpotLight":d=new THREE.SpotLight(a.color,a.intensity,a.distance,a.angle,a.exponent);d.position.fromArray(a.position);break;case "HemisphereLight":d=new THREE.HemisphereLight(a.color,a.groundColor,a.intensity);
d.position.fromArray(a.position);break;case "Mesh":d=new THREE.Mesh(b[a.geometry],c[a.material]);d.position.fromArray(a.position);d.rotation.fromArray(a.rotation);d.scale.fromArray(a.scale);break;default:d=new THREE.Object3D,d.position.fromArray(a.position),d.rotation.fromArray(a.rotation),d.scale.fromArray(a.scale)}void 0!==a.id&&(d.id=a.id);void 0!==a.name&&(d.name=a.name);void 0!==a.visible&&(d.visible=a.visible);void 0!==a.userData&&(d.userData=a.userData);if(void 0!==a.children)for(var e in a.children)d.add(this.parseObject(a.children[e],
b,c));return d}};THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){};this.geometryHandlerMap={};this.hierarchyHandlerMap={};this.addGeometryHandler("ascii",THREE.JSONLoader)};THREE.SceneLoader.prototype.constructor=THREE.SceneLoader;
THREE.ObjectLoader.prototype={constructor:THREE.ObjectLoader,load:function(a,b){var c=this,d=new THREE.XHRLoader;d.setCrossOrigin(this.crossOrigin);d.load(a,function(a){b(c.parse(JSON.parse(a)))})},setCrossOrigin:function(a){this.crossOrigin=a},parse:function(a){var b=this.parseGeometries(a.geometries),c=this.parseMaterials(a.materials);return this.parseObject(a.object,b,c)},parseGeometries:function(a){var b={};if(void 0!==a)for(var c=new THREE.JSONLoader,d=0,e=a.length;d<e;d++){var f,g=a[d];switch(g.type){case "PlaneGeometry":f=
new THREE.PlaneGeometry(g.width,g.height,g.widthSegments,g.heightSegments);break;case "CubeGeometry":f=new THREE.CubeGeometry(g.width,g.height,g.depth,g.widthSegments,g.heightSegments,g.depthSegments);break;case "CylinderGeometry":f=new THREE.CylinderGeometry(g.radiusTop,g.radiusBottom,g.height,g.radiusSegments,g.heightSegments,g.openEnded);break;case "SphereGeometry":f=new THREE.SphereGeometry(g.radius,g.widthSegments,g.heightSegments,g.phiStart,g.phiLength,g.thetaStart,g.thetaLength);break;case "IcosahedronGeometry":f=
new THREE.IcosahedronGeometry(g.radius,g.detail);break;case "TorusGeometry":f=new THREE.TorusGeometry(g.radius,g.tube,g.radialSegments,g.tubularSegments,g.arc);break;case "TorusKnotGeometry":f=new THREE.TorusKnotGeometry(g.radius,g.tube,g.radialSegments,g.tubularSegments,g.p,g.q,g.heightScale);break;case "Geometry":f=c.parse(g.data).geometry}void 0!==g.id&&(f.id=g.id);void 0!==g.name&&(f.name=g.name);b[g.id]=f}return b},parseMaterials:function(a){var b={};if(void 0!==a)for(var c=new THREE.MaterialLoader,
d=0,e=a.length;d<e;d++){var f=a[d],g=c.parse(f);void 0!==f.id&&(g.id=f.id);void 0!==f.name&&(g.name=f.name);b[f.id]=g}return b},parseObject:function(a,b,c){var d;switch(a.type){case "Scene":d=new THREE.Scene;break;case "PerspectiveCamera":d=new THREE.PerspectiveCamera(a.fov,a.aspect,a.near,a.far);d.position.fromArray(a.position);d.rotation.fromArray(a.rotation);break;case "OrthographicCamera":d=new THREE.OrthographicCamera(a.left,a.right,a.top,a.bottom,a.near,a.far);d.position.fromArray(a.position);
d.rotation.fromArray(a.rotation);break;case "AmbientLight":d=new THREE.AmbientLight(a.color);break;case "DirectionalLight":d=new THREE.DirectionalLight(a.color,a.intensity);d.position.fromArray(a.position);break;case "PointLight":d=new THREE.PointLight(a.color,a.intensity,a.distance);d.position.fromArray(a.position);break;case "SpotLight":d=new THREE.SpotLight(a.color,a.intensity,a.distance,a.angle,a.exponent);d.position.fromArray(a.position);break;case "HemisphereLight":d=new THREE.HemisphereLight(a.color,
a.groundColor,a.intensity);d.position.fromArray(a.position);break;case "Mesh":d=new THREE.Mesh(b[a.geometry],c[a.material]);d.position.fromArray(a.position);d.rotation.fromArray(a.rotation);d.scale.fromArray(a.scale);break;default:d=new THREE.Object3D,d.position.fromArray(a.position),d.rotation.fromArray(a.rotation),d.scale.fromArray(a.scale)}void 0!==a.id&&(d.id=a.id);void 0!==a.name&&(d.name=a.name);void 0!==a.visible&&(d.visible=a.visible);void 0!==a.userData&&(d.userData=a.userData);if(void 0!==
a.children)for(var e in a.children)d.add(this.parseObject(a.children[e],b,c));return d}};THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){};this.geometryHandlerMap={};this.hierarchyHandlerMap={};this.addGeometryHandler("ascii",THREE.JSONLoader)};THREE.SceneLoader.prototype.constructor=THREE.SceneLoader;
THREE.SceneLoader.prototype.load=function(a,b){var c=this,d=new XMLHttpRequest;d.onreadystatechange=function(){if(4===d.readyState)if(200===d.status||0===d.status){var e=JSON.parse(d.responseText);c.parse(e,b,a)}else console.error("THREE.SceneLoader: Couldn't load ["+a+"] ["+d.status+"]")};d.open("GET",a,!0);d.send(null)};THREE.SceneLoader.prototype.addGeometryHandler=function(a,b){this.geometryHandlerMap[a]={loaderClass:b}};
THREE.SceneLoader.prototype.addHierarchyHandler=function(a,b){this.hierarchyHandlerMap[a]={loaderClass:b}};
THREE.SceneLoader.prototype.parse=function(a,b,c){function d(a,b){return"relativeToHTML"==b?a:m+"/"+a}function e(){f(A.scene,B.objects)}function f(a,b){var c,e,g,i,j,l,m;for(m in b){var r=A.objects[m],s=b[m];if(void 0===r){if(s.type&&s.type in n.hierarchyHandlerMap){if(void 0===s.loading){e={type:1,url:1,material:1,position:1,rotation:1,scale:1,visible:1,children:1,userData:1,skin:1,morph:1,mirroredLoop:1,duration:1};g={};for(var y in s)y in e||(g[y]=s[y]);t=A.materials[s.material];s.loading=!0;e=
......
......@@ -12,19 +12,23 @@ THREE.ObjectLoader.prototype = {
constructor: THREE.ObjectLoader,
load: function ( url, callback ) {
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
this.manager.add( url, 'text', function ( event ) {
var loader = new THREE.XHRLoader();
loader.setCrossOrigin( this.crossOrigin );
loader.load( url, function ( text ) {
if ( callback !== undefined ) {
onLoad( scope.parse( JSON.parse( text ) ) );
callback( scope.parse( JSON.parse( event.target.responseText ) ) );
} );
}
},
} );
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册