|
@@ -11,505 +11,499 @@ THREE.SceneLoader = function () {
|
|
|
this.callbackSync = function () {};
|
|
|
this.callbackProgress = function () {};
|
|
|
|
|
|
- this.geometryHandlerMap = {};
|
|
|
- this.hierarchyHandlerMap = {};
|
|
|
+ this.geometryHandlers = {};
|
|
|
+ this.hierarchyHandlers = {};
|
|
|
|
|
|
this.addGeometryHandler( "ascii", THREE.JSONLoader );
|
|
|
|
|
|
};
|
|
|
|
|
|
-THREE.SceneLoader.prototype.constructor = THREE.SceneLoader;
|
|
|
+THREE.SceneLoader.prototype = {
|
|
|
|
|
|
-THREE.SceneLoader.prototype.load = function ( url, callbackFinished ) {
|
|
|
+ constructor: THREE.SceneLoader,
|
|
|
|
|
|
- var scope = this;
|
|
|
+ load: function ( url, onLoad, onProgress, onError ) {
|
|
|
|
|
|
- var xhr = new XMLHttpRequest();
|
|
|
+ var scope = this;
|
|
|
|
|
|
- xhr.onreadystatechange = function () {
|
|
|
+ var loader = new THREE.XHRLoader( scope.manager );
|
|
|
+ loader.setCrossOrigin( this.crossOrigin );
|
|
|
+ loader.load( url, function ( text ) {
|
|
|
|
|
|
- if ( xhr.readyState === 4 ) {
|
|
|
+ scope.parse( JSON.parse( text ), onLoad, url );
|
|
|
|
|
|
- if ( xhr.status === 200 || xhr.status === 0 ) {
|
|
|
-
|
|
|
- var json = JSON.parse( xhr.responseText );
|
|
|
- scope.parse( json, callbackFinished, url );
|
|
|
+ } );
|
|
|
|
|
|
- } else {
|
|
|
+ },
|
|
|
|
|
|
- console.error( "THREE.SceneLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
|
|
|
+ setCrossOrigin: function ( value ) {
|
|
|
|
|
|
- }
|
|
|
+ this.crossOrigin = value;
|
|
|
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
- };
|
|
|
+ addGeometryHandler: function ( typeID, loaderClass ) {
|
|
|
|
|
|
- xhr.open( "GET", url, true );
|
|
|
- xhr.send( null );
|
|
|
+ this.geometryHandlers[ typeID ] = { "loaderClass": loaderClass };
|
|
|
|
|
|
-};
|
|
|
+ },
|
|
|
|
|
|
-THREE.SceneLoader.prototype.addGeometryHandler = function ( typeID, loaderClass ) {
|
|
|
+ addHierarchyHandler: function ( typeID, loaderClass ) {
|
|
|
|
|
|
- this.geometryHandlerMap[ typeID ] = { "loaderClass": loaderClass };
|
|
|
+ this.hierarchyHandlers[ typeID ] = { "loaderClass": loaderClass };
|
|
|
|
|
|
-};
|
|
|
+ },
|
|
|
|
|
|
-THREE.SceneLoader.prototype.addHierarchyHandler = function ( typeID, loaderClass ) {
|
|
|
+ parse: function ( json, callbackFinished, url ) {
|
|
|
|
|
|
- this.hierarchyHandlerMap[ typeID ] = { "loaderClass": loaderClass };
|
|
|
+ var scope = this;
|
|
|
|
|
|
-};
|
|
|
+ var urlBase = THREE.Loader.prototype.extractUrlBase( url );
|
|
|
|
|
|
-THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
|
|
|
+ var geometry, material, camera, fog,
|
|
|
+ texture, images, color,
|
|
|
+ light, hex, intensity,
|
|
|
+ counter_models, counter_textures,
|
|
|
+ total_models, total_textures,
|
|
|
+ result;
|
|
|
|
|
|
- var scope = this;
|
|
|
+ var target_array = [];
|
|
|
|
|
|
- var urlBase = THREE.Loader.prototype.extractUrlBase( url );
|
|
|
+ var data = json;
|
|
|
|
|
|
- var geometry, material, camera, fog,
|
|
|
- texture, images, color,
|
|
|
- light, hex, intensity,
|
|
|
- counter_models, counter_textures,
|
|
|
- total_models, total_textures,
|
|
|
- result;
|
|
|
+ // async geometry loaders
|
|
|
|
|
|
- var target_array = [];
|
|
|
+ for ( var typeID in this.geometryHandlers ) {
|
|
|
|
|
|
- var data = json;
|
|
|
+ var loaderClass = this.geometryHandlers[ typeID ][ "loaderClass" ];
|
|
|
+ this.geometryHandlers[ typeID ][ "loaderObject" ] = new loaderClass();
|
|
|
|
|
|
- // async geometry loaders
|
|
|
-
|
|
|
- for ( var typeID in this.geometryHandlerMap ) {
|
|
|
-
|
|
|
- var loaderClass = this.geometryHandlerMap[ typeID ][ "loaderClass" ];
|
|
|
- this.geometryHandlerMap[ typeID ][ "loaderObject" ] = new loaderClass();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // async hierachy loaders
|
|
|
|
|
|
- // async hierachy loaders
|
|
|
+ for ( var typeID in this.hierarchyHandlers ) {
|
|
|
|
|
|
- for ( var typeID in this.hierarchyHandlerMap ) {
|
|
|
+ var loaderClass = this.hierarchyHandlers[ typeID ][ "loaderClass" ];
|
|
|
+ this.hierarchyHandlers[ typeID ][ "loaderObject" ] = new loaderClass();
|
|
|
|
|
|
- var loaderClass = this.hierarchyHandlerMap[ typeID ][ "loaderClass" ];
|
|
|
- this.hierarchyHandlerMap[ typeID ][ "loaderObject" ] = new loaderClass();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ counter_models = 0;
|
|
|
+ counter_textures = 0;
|
|
|
|
|
|
- counter_models = 0;
|
|
|
- counter_textures = 0;
|
|
|
+ result = {
|
|
|
|
|
|
- result = {
|
|
|
+ scene: new THREE.Scene(),
|
|
|
+ geometries: {},
|
|
|
+ face_materials: {},
|
|
|
+ materials: {},
|
|
|
+ textures: {},
|
|
|
+ objects: {},
|
|
|
+ cameras: {},
|
|
|
+ lights: {},
|
|
|
+ fogs: {},
|
|
|
+ empties: {},
|
|
|
+ groups: {}
|
|
|
|
|
|
- scene: new THREE.Scene(),
|
|
|
- geometries: {},
|
|
|
- face_materials: {},
|
|
|
- materials: {},
|
|
|
- textures: {},
|
|
|
- objects: {},
|
|
|
- cameras: {},
|
|
|
- lights: {},
|
|
|
- fogs: {},
|
|
|
- empties: {},
|
|
|
- groups: {}
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ if ( data.transform ) {
|
|
|
|
|
|
- if ( data.transform ) {
|
|
|
+ var position = data.transform.position,
|
|
|
+ rotation = data.transform.rotation,
|
|
|
+ scale = data.transform.scale;
|
|
|
|
|
|
- var position = data.transform.position,
|
|
|
- rotation = data.transform.rotation,
|
|
|
- scale = data.transform.scale;
|
|
|
+ if ( position ) {
|
|
|
|
|
|
- if ( position ) {
|
|
|
+ result.scene.position.fromArray( position );
|
|
|
|
|
|
- result.scene.position.fromArray( position );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( rotation ) {
|
|
|
|
|
|
- if ( rotation ) {
|
|
|
+ result.scene.rotation.fromArray( rotation );
|
|
|
|
|
|
- result.scene.rotation.fromArray( rotation );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( scale ) {
|
|
|
|
|
|
- if ( scale ) {
|
|
|
+ result.scene.scale.fromArray( scale );
|
|
|
|
|
|
- result.scene.scale.fromArray( scale );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( position || rotation || scale ) {
|
|
|
|
|
|
- if ( position || rotation || scale ) {
|
|
|
+ result.scene.updateMatrix();
|
|
|
+ result.scene.updateMatrixWorld();
|
|
|
|
|
|
- result.scene.updateMatrix();
|
|
|
- result.scene.updateMatrixWorld();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ function get_url( source_url, url_type ) {
|
|
|
|
|
|
- function get_url( source_url, url_type ) {
|
|
|
+ if ( url_type == "relativeToHTML" ) {
|
|
|
|
|
|
- if ( url_type == "relativeToHTML" ) {
|
|
|
+ return source_url;
|
|
|
|
|
|
- return source_url;
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ return urlBase + "/" + source_url;
|
|
|
|
|
|
- return urlBase + "/" + source_url;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ // toplevel loader function, delegates to handle_children
|
|
|
|
|
|
- // toplevel loader function, delegates to handle_children
|
|
|
+ function handle_objects() {
|
|
|
|
|
|
- function handle_objects() {
|
|
|
+ handle_children( result.scene, data.objects );
|
|
|
|
|
|
- handle_children( result.scene, data.objects );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // handle all the children from the loaded json and attach them to given parent
|
|
|
|
|
|
- // handle all the children from the loaded json and attach them to given parent
|
|
|
+ function handle_children( parent, children ) {
|
|
|
|
|
|
- function handle_children( parent, children ) {
|
|
|
+ var mat, dst, pos, rot, scl, quat;
|
|
|
|
|
|
- var mat, dst, pos, rot, scl, quat;
|
|
|
+ for ( var objID in children ) {
|
|
|
|
|
|
- for ( var objID in children ) {
|
|
|
+ // check by id if child has already been handled,
|
|
|
+ // if not, create new object
|
|
|
|
|
|
- // check by id if child has already been handled,
|
|
|
- // if not, create new object
|
|
|
+ var object = result.objects[ objID ];
|
|
|
+ var objJSON = children[ objID ];
|
|
|
|
|
|
- var object = result.objects[ objID ];
|
|
|
- var objJSON = children[ objID ];
|
|
|
+ if ( object === undefined ) {
|
|
|
|
|
|
- if ( object === undefined ) {
|
|
|
+ // meshes
|
|
|
|
|
|
- // meshes
|
|
|
+ if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlers ) ) {
|
|
|
|
|
|
- if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) ) {
|
|
|
+ if ( objJSON.loading === undefined ) {
|
|
|
|
|
|
- if ( objJSON.loading === undefined ) {
|
|
|
+ var reservedTypes = {
|
|
|
+ "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
|
|
|
+ };
|
|
|
|
|
|
- var reservedTypes = {
|
|
|
- "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
|
|
|
- };
|
|
|
+ var loaderParameters = {};
|
|
|
|
|
|
- var loaderParameters = {};
|
|
|
+ for ( var parType in objJSON ) {
|
|
|
|
|
|
- for ( var parType in objJSON ) {
|
|
|
+ if ( ! ( parType in reservedTypes ) ) {
|
|
|
|
|
|
- if ( ! ( parType in reservedTypes ) ) {
|
|
|
+ loaderParameters[ parType ] = objJSON[ parType ];
|
|
|
|
|
|
- loaderParameters[ parType ] = objJSON[ parType ];
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ material = result.materials[ objJSON.material ];
|
|
|
|
|
|
- material = result.materials[ objJSON.material ];
|
|
|
+ objJSON.loading = true;
|
|
|
|
|
|
- objJSON.loading = true;
|
|
|
+ var loader = scope.hierarchyHandlers[ objJSON.type ][ "loaderObject" ];
|
|
|
|
|
|
- var loader = scope.hierarchyHandlerMap[ objJSON.type ][ "loaderObject" ];
|
|
|
+ // ColladaLoader
|
|
|
|
|
|
- // ColladaLoader
|
|
|
+ if ( loader.options ) {
|
|
|
|
|
|
- if ( loader.options ) {
|
|
|
+ loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ) );
|
|
|
|
|
|
- loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ) );
|
|
|
+ // UTF8Loader
|
|
|
+ // OBJLoader
|
|
|
|
|
|
- // UTF8Loader
|
|
|
- // OBJLoader
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ), loaderParameters );
|
|
|
|
|
|
- loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ), loaderParameters );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ } else if ( objJSON.geometry !== undefined ) {
|
|
|
|
|
|
- } else if ( objJSON.geometry !== undefined ) {
|
|
|
+ geometry = result.geometries[ objJSON.geometry ];
|
|
|
|
|
|
- geometry = result.geometries[ objJSON.geometry ];
|
|
|
+ // geometry already loaded
|
|
|
|
|
|
- // geometry already loaded
|
|
|
+ if ( geometry ) {
|
|
|
|
|
|
- if ( geometry ) {
|
|
|
+ var needsTangents = false;
|
|
|
|
|
|
- var needsTangents = false;
|
|
|
+ material = result.materials[ objJSON.material ];
|
|
|
+ needsTangents = material instanceof THREE.ShaderMaterial;
|
|
|
|
|
|
- material = result.materials[ objJSON.material ];
|
|
|
- needsTangents = material instanceof THREE.ShaderMaterial;
|
|
|
+ pos = objJSON.position;
|
|
|
+ rot = objJSON.rotation;
|
|
|
+ scl = objJSON.scale;
|
|
|
+ mat = objJSON.matrix;
|
|
|
+ quat = objJSON.quaternion;
|
|
|
|
|
|
- pos = objJSON.position;
|
|
|
- rot = objJSON.rotation;
|
|
|
- scl = objJSON.scale;
|
|
|
- mat = objJSON.matrix;
|
|
|
- quat = objJSON.quaternion;
|
|
|
+ // use materials from the model file
|
|
|
+ // if there is no material specified in the object
|
|
|
|
|
|
- // use materials from the model file
|
|
|
- // if there is no material specified in the object
|
|
|
+ if ( ! objJSON.material ) {
|
|
|
|
|
|
- if ( ! objJSON.material ) {
|
|
|
+ material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
|
|
|
|
|
|
- material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // use materials from the model file
|
|
|
+ // if there is just empty face material
|
|
|
+ // (must create new material as each model has its own face material)
|
|
|
|
|
|
- // use materials from the model file
|
|
|
- // if there is just empty face material
|
|
|
- // (must create new material as each model has its own face material)
|
|
|
+ if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) {
|
|
|
|
|
|
- if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) {
|
|
|
+ material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
|
|
|
|
|
|
- material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( material instanceof THREE.MeshFaceMaterial ) {
|
|
|
|
|
|
- if ( material instanceof THREE.MeshFaceMaterial ) {
|
|
|
+ for ( var i = 0; i < material.materials.length; i ++ ) {
|
|
|
|
|
|
- for ( var i = 0; i < material.materials.length; i ++ ) {
|
|
|
+ needsTangents = needsTangents || ( material.materials[ i ] instanceof THREE.ShaderMaterial );
|
|
|
|
|
|
- needsTangents = needsTangents || ( material.materials[ i ] instanceof THREE.ShaderMaterial );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ if ( needsTangents ) {
|
|
|
|
|
|
- if ( needsTangents ) {
|
|
|
+ geometry.computeTangents();
|
|
|
|
|
|
- geometry.computeTangents();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( objJSON.skin ) {
|
|
|
|
|
|
- if ( objJSON.skin ) {
|
|
|
+ object = new THREE.SkinnedMesh( geometry, material );
|
|
|
|
|
|
- object = new THREE.SkinnedMesh( geometry, material );
|
|
|
+ } else if ( objJSON.morph ) {
|
|
|
|
|
|
- } else if ( objJSON.morph ) {
|
|
|
+ object = new THREE.MorphAnimMesh( geometry, material );
|
|
|
|
|
|
- object = new THREE.MorphAnimMesh( geometry, material );
|
|
|
+ if ( objJSON.duration !== undefined ) {
|
|
|
|
|
|
- if ( objJSON.duration !== undefined ) {
|
|
|
+ object.duration = objJSON.duration;
|
|
|
|
|
|
- object.duration = objJSON.duration;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( objJSON.time !== undefined ) {
|
|
|
|
|
|
- if ( objJSON.time !== undefined ) {
|
|
|
+ object.time = objJSON.time;
|
|
|
|
|
|
- object.time = objJSON.time;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( objJSON.mirroredLoop !== undefined ) {
|
|
|
|
|
|
- if ( objJSON.mirroredLoop !== undefined ) {
|
|
|
+ object.mirroredLoop = objJSON.mirroredLoop;
|
|
|
|
|
|
- object.mirroredLoop = objJSON.mirroredLoop;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( material.morphNormals ) {
|
|
|
|
|
|
- if ( material.morphNormals ) {
|
|
|
+ geometry.computeMorphNormals();
|
|
|
|
|
|
- geometry.computeMorphNormals();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ object = new THREE.Mesh( geometry, material );
|
|
|
|
|
|
- object = new THREE.Mesh( geometry, material );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ object.name = objID;
|
|
|
|
|
|
- object.name = objID;
|
|
|
+ if ( mat ) {
|
|
|
|
|
|
- if ( mat ) {
|
|
|
+ object.matrixAutoUpdate = false;
|
|
|
+ object.matrix.set(
|
|
|
+ mat[0], mat[1], mat[2], mat[3],
|
|
|
+ mat[4], mat[5], mat[6], mat[7],
|
|
|
+ mat[8], mat[9], mat[10], mat[11],
|
|
|
+ mat[12], mat[13], mat[14], mat[15]
|
|
|
+ );
|
|
|
|
|
|
- object.matrixAutoUpdate = false;
|
|
|
- object.matrix.set(
|
|
|
- mat[0], mat[1], mat[2], mat[3],
|
|
|
- mat[4], mat[5], mat[6], mat[7],
|
|
|
- mat[8], mat[9], mat[10], mat[11],
|
|
|
- mat[12], mat[13], mat[14], mat[15]
|
|
|
- );
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ object.position.fromArray( pos );
|
|
|
|
|
|
- object.position.fromArray( pos );
|
|
|
+ if ( quat ) {
|
|
|
|
|
|
- if ( quat ) {
|
|
|
+ object.quaternion.fromArray( quat );
|
|
|
+ object.useQuaternion = true;
|
|
|
|
|
|
- object.quaternion.fromArray( quat );
|
|
|
- object.useQuaternion = true;
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ object.rotation.fromArray( rot );
|
|
|
|
|
|
- object.rotation.fromArray( rot );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ object.scale.fromArray( scl );
|
|
|
|
|
|
- object.scale.fromArray( scl );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ object.visible = objJSON.visible;
|
|
|
+ object.castShadow = objJSON.castShadow;
|
|
|
+ object.receiveShadow = objJSON.receiveShadow;
|
|
|
|
|
|
- object.visible = objJSON.visible;
|
|
|
- object.castShadow = objJSON.castShadow;
|
|
|
- object.receiveShadow = objJSON.receiveShadow;
|
|
|
+ parent.add( object );
|
|
|
|
|
|
- parent.add( object );
|
|
|
+ result.objects[ objID ] = object;
|
|
|
|
|
|
- result.objects[ objID ] = object;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // lights
|
|
|
|
|
|
- // lights
|
|
|
+ } else if ( objJSON.type === "DirectionalLight" || objJSON.type === "PointLight" || objJSON.type === "AmbientLight" ) {
|
|
|
|
|
|
- } else if ( objJSON.type === "DirectionalLight" || objJSON.type === "PointLight" || objJSON.type === "AmbientLight" ) {
|
|
|
+ hex = ( objJSON.color !== undefined ) ? objJSON.color : 0xffffff;
|
|
|
+ intensity = ( objJSON.intensity !== undefined ) ? objJSON.intensity : 1;
|
|
|
|
|
|
- hex = ( objJSON.color !== undefined ) ? objJSON.color : 0xffffff;
|
|
|
- intensity = ( objJSON.intensity !== undefined ) ? objJSON.intensity : 1;
|
|
|
+ if ( objJSON.type === "DirectionalLight" ) {
|
|
|
|
|
|
- if ( objJSON.type === "DirectionalLight" ) {
|
|
|
+ pos = objJSON.direction;
|
|
|
|
|
|
- pos = objJSON.direction;
|
|
|
+ light = new THREE.DirectionalLight( hex, intensity );
|
|
|
+ light.position.fromArray( pos );
|
|
|
|
|
|
- light = new THREE.DirectionalLight( hex, intensity );
|
|
|
- light.position.fromArray( pos );
|
|
|
+ if ( objJSON.target ) {
|
|
|
|
|
|
- if ( objJSON.target ) {
|
|
|
+ target_array.push( { "object": light, "targetName" : objJSON.target } );
|
|
|
|
|
|
- target_array.push( { "object": light, "targetName" : objJSON.target } );
|
|
|
+ // kill existing default target
|
|
|
+ // otherwise it gets added to scene when parent gets added
|
|
|
|
|
|
- // kill existing default target
|
|
|
- // otherwise it gets added to scene when parent gets added
|
|
|
+ light.target = null;
|
|
|
|
|
|
- light.target = null;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ } else if ( objJSON.type === "PointLight" ) {
|
|
|
|
|
|
- } else if ( objJSON.type === "PointLight" ) {
|
|
|
+ pos = objJSON.position;
|
|
|
+ dst = objJSON.distance;
|
|
|
|
|
|
- pos = objJSON.position;
|
|
|
- dst = objJSON.distance;
|
|
|
+ light = new THREE.PointLight( hex, intensity, dst );
|
|
|
+ light.position.fromArray( pos );
|
|
|
|
|
|
- light = new THREE.PointLight( hex, intensity, dst );
|
|
|
- light.position.fromArray( pos );
|
|
|
+ } else if ( objJSON.type === "AmbientLight" ) {
|
|
|
|
|
|
- } else if ( objJSON.type === "AmbientLight" ) {
|
|
|
+ light = new THREE.AmbientLight( hex );
|
|
|
|
|
|
- light = new THREE.AmbientLight( hex );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ parent.add( light );
|
|
|
|
|
|
- parent.add( light );
|
|
|
+ light.name = objID;
|
|
|
+ result.lights[ objID ] = light;
|
|
|
+ result.objects[ objID ] = light;
|
|
|
|
|
|
- light.name = objID;
|
|
|
- result.lights[ objID ] = light;
|
|
|
- result.objects[ objID ] = light;
|
|
|
+ // cameras
|
|
|
|
|
|
- // cameras
|
|
|
+ } else if ( objJSON.type === "PerspectiveCamera" || objJSON.type === "OrthographicCamera" ) {
|
|
|
|
|
|
- } else if ( objJSON.type === "PerspectiveCamera" || objJSON.type === "OrthographicCamera" ) {
|
|
|
+ pos = objJSON.position;
|
|
|
+ rot = objJSON.rotation;
|
|
|
+ quat = objJSON.quaternion;
|
|
|
|
|
|
- pos = objJSON.position;
|
|
|
- rot = objJSON.rotation;
|
|
|
- quat = objJSON.quaternion;
|
|
|
+ if ( objJSON.type === "PerspectiveCamera" ) {
|
|
|
|
|
|
- if ( objJSON.type === "PerspectiveCamera" ) {
|
|
|
+ camera = new THREE.PerspectiveCamera( objJSON.fov, objJSON.aspect, objJSON.near, objJSON.far );
|
|
|
|
|
|
- camera = new THREE.PerspectiveCamera( objJSON.fov, objJSON.aspect, objJSON.near, objJSON.far );
|
|
|
+ } else if ( objJSON.type === "OrthographicCamera" ) {
|
|
|
|
|
|
- } else if ( objJSON.type === "OrthographicCamera" ) {
|
|
|
+ camera = new THREE.OrthographicCamera( objJSON.left, objJSON.right, objJSON.top, objJSON.bottom, objJSON.near, objJSON.far );
|
|
|
|
|
|
- camera = new THREE.OrthographicCamera( objJSON.left, objJSON.right, objJSON.top, objJSON.bottom, objJSON.near, objJSON.far );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ camera.name = objID;
|
|
|
+ camera.position.fromArray( pos );
|
|
|
|
|
|
- camera.name = objID;
|
|
|
- camera.position.fromArray( pos );
|
|
|
+ if ( quat !== undefined ) {
|
|
|
|
|
|
- if ( quat !== undefined ) {
|
|
|
+ camera.quaternion.fromArray( quat );
|
|
|
+ camera.useQuaternion = true;
|
|
|
|
|
|
- camera.quaternion.fromArray( quat );
|
|
|
- camera.useQuaternion = true;
|
|
|
+ } else if ( rot !== undefined ) {
|
|
|
|
|
|
- } else if ( rot !== undefined ) {
|
|
|
+ camera.rotation.fromArray( rot );
|
|
|
|
|
|
- camera.rotation.fromArray( rot );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ parent.add( camera );
|
|
|
|
|
|
- parent.add( camera );
|
|
|
+ result.cameras[ objID ] = camera;
|
|
|
+ result.objects[ objID ] = camera;
|
|
|
|
|
|
- result.cameras[ objID ] = camera;
|
|
|
- result.objects[ objID ] = camera;
|
|
|
+ // pure Object3D
|
|
|
|
|
|
- // pure Object3D
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ pos = objJSON.position;
|
|
|
+ rot = objJSON.rotation;
|
|
|
+ scl = objJSON.scale;
|
|
|
+ quat = objJSON.quaternion;
|
|
|
|
|
|
- pos = objJSON.position;
|
|
|
- rot = objJSON.rotation;
|
|
|
- scl = objJSON.scale;
|
|
|
- quat = objJSON.quaternion;
|
|
|
+ object = new THREE.Object3D();
|
|
|
+ object.name = objID;
|
|
|
+ object.position.fromArray( pos );
|
|
|
|
|
|
- object = new THREE.Object3D();
|
|
|
- object.name = objID;
|
|
|
- object.position.fromArray( pos );
|
|
|
+ if ( quat ) {
|
|
|
|
|
|
- if ( quat ) {
|
|
|
+ object.quaternion.fromArray( quat );
|
|
|
+ object.useQuaternion = true;
|
|
|
|
|
|
- object.quaternion.fromArray( quat );
|
|
|
- object.useQuaternion = true;
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ object.rotation.fromArray( rot );
|
|
|
|
|
|
- object.rotation.fromArray( rot );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ object.scale.fromArray( scl );
|
|
|
+ object.visible = ( objJSON.visible !== undefined ) ? objJSON.visible : false;
|
|
|
|
|
|
- object.scale.fromArray( scl );
|
|
|
- object.visible = ( objJSON.visible !== undefined ) ? objJSON.visible : false;
|
|
|
+ parent.add( object );
|
|
|
|
|
|
- parent.add( object );
|
|
|
+ result.objects[ objID ] = object;
|
|
|
+ result.empties[ objID ] = object;
|
|
|
|
|
|
- result.objects[ objID ] = object;
|
|
|
- result.empties[ objID ] = object;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( object ) {
|
|
|
|
|
|
- if ( object ) {
|
|
|
+ if ( objJSON.userData !== undefined ) {
|
|
|
|
|
|
- if ( objJSON.userData !== undefined ) {
|
|
|
+ for ( var key in objJSON.userData ) {
|
|
|
|
|
|
- for ( var key in objJSON.userData ) {
|
|
|
+ var value = objJSON.userData[ key ];
|
|
|
+ object.userData[ key ] = value;
|
|
|
|
|
|
- var value = objJSON.userData[ key ];
|
|
|
- object.userData[ key ] = value;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ if ( objJSON.groups !== undefined ) {
|
|
|
|
|
|
- if ( objJSON.groups !== undefined ) {
|
|
|
+ for ( var i = 0; i < objJSON.groups.length; i ++ ) {
|
|
|
|
|
|
- for ( var i = 0; i < objJSON.groups.length; i ++ ) {
|
|
|
+ var groupID = objJSON.groups[ i ];
|
|
|
|
|
|
- var groupID = objJSON.groups[ i ];
|
|
|
+ if ( result.groups[ groupID ] === undefined ) {
|
|
|
|
|
|
- if ( result.groups[ groupID ] === undefined ) {
|
|
|
+ result.groups[ groupID ] = [];
|
|
|
|
|
|
- result.groups[ groupID ] = [];
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ result.groups[ groupID ].push( objID );
|
|
|
|
|
|
- result.groups[ groupID ].push( objID );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -517,720 +511,720 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ if ( object !== undefined && objJSON.children !== undefined ) {
|
|
|
|
|
|
- if ( object !== undefined && objJSON.children !== undefined ) {
|
|
|
+ handle_children( object, objJSON.children );
|
|
|
|
|
|
- handle_children( object, objJSON.children );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ function handle_mesh( geo, mat, id ) {
|
|
|
|
|
|
- function handle_mesh( geo, mat, id ) {
|
|
|
+ result.geometries[ id ] = geo;
|
|
|
+ result.face_materials[ id ] = mat;
|
|
|
+ handle_objects();
|
|
|
|
|
|
- result.geometries[ id ] = geo;
|
|
|
- result.face_materials[ id ] = mat;
|
|
|
- handle_objects();
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ function handle_hierarchy( node, id, parent, material, obj ) {
|
|
|
|
|
|
- function handle_hierarchy( node, id, parent, material, obj ) {
|
|
|
+ var p = obj.position;
|
|
|
+ var r = obj.rotation;
|
|
|
+ var q = obj.quaternion;
|
|
|
+ var s = obj.scale;
|
|
|
|
|
|
- var p = obj.position;
|
|
|
- var r = obj.rotation;
|
|
|
- var q = obj.quaternion;
|
|
|
- var s = obj.scale;
|
|
|
+ node.position.fromArray( p );
|
|
|
|
|
|
- node.position.fromArray( p );
|
|
|
+ if ( q ) {
|
|
|
|
|
|
- if ( q ) {
|
|
|
+ node.quaternion.fromArray( q );
|
|
|
+ node.useQuaternion = true;
|
|
|
|
|
|
- node.quaternion.fromArray( q );
|
|
|
- node.useQuaternion = true;
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ node.rotation.fromArray( r );
|
|
|
|
|
|
- node.rotation.fromArray( r );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ node.scale.fromArray( s );
|
|
|
|
|
|
- node.scale.fromArray( s );
|
|
|
+ // override children materials
|
|
|
+ // if object material was specified in JSON explicitly
|
|
|
|
|
|
- // override children materials
|
|
|
- // if object material was specified in JSON explicitly
|
|
|
+ if ( material ) {
|
|
|
|
|
|
- if ( material ) {
|
|
|
+ node.traverse( function ( child ) {
|
|
|
|
|
|
- node.traverse( function ( child ) {
|
|
|
+ child.material = material;
|
|
|
|
|
|
- child.material = material;
|
|
|
+ } );
|
|
|
|
|
|
- } );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // override children visibility
|
|
|
+ // with root node visibility as specified in JSON
|
|
|
|
|
|
- // override children visibility
|
|
|
- // with root node visibility as specified in JSON
|
|
|
+ var visible = ( obj.visible !== undefined ) ? obj.visible : true;
|
|
|
|
|
|
- var visible = ( obj.visible !== undefined ) ? obj.visible : true;
|
|
|
+ node.traverse( function ( child ) {
|
|
|
|
|
|
- node.traverse( function ( child ) {
|
|
|
+ child.visible = visible;
|
|
|
|
|
|
- child.visible = visible;
|
|
|
+ } );
|
|
|
|
|
|
- } );
|
|
|
+ parent.add( node );
|
|
|
|
|
|
- parent.add( node );
|
|
|
+ node.name = id;
|
|
|
|
|
|
- node.name = id;
|
|
|
+ result.objects[ id ] = node;
|
|
|
+ handle_objects();
|
|
|
|
|
|
- result.objects[ id ] = node;
|
|
|
- handle_objects();
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ function create_callback_geometry( id ) {
|
|
|
|
|
|
- function create_callback_geometry( id ) {
|
|
|
+ return function ( geo, mat ) {
|
|
|
|
|
|
- return function ( geo, mat ) {
|
|
|
+ geo.name = id;
|
|
|
|
|
|
- geo.name = id;
|
|
|
+ handle_mesh( geo, mat, id );
|
|
|
|
|
|
- handle_mesh( geo, mat, id );
|
|
|
+ counter_models -= 1;
|
|
|
|
|
|
- counter_models -= 1;
|
|
|
+ scope.onLoadComplete();
|
|
|
|
|
|
- scope.onLoadComplete();
|
|
|
+ async_callback_gate();
|
|
|
|
|
|
- async_callback_gate();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ function create_callback_hierachy( id, parent, material, obj ) {
|
|
|
|
|
|
- function create_callback_hierachy( id, parent, material, obj ) {
|
|
|
+ return function ( event ) {
|
|
|
|
|
|
- return function ( event ) {
|
|
|
+ var result;
|
|
|
|
|
|
- var result;
|
|
|
+ // loaders which use EventDispatcher
|
|
|
|
|
|
- // loaders which use EventDispatcher
|
|
|
+ if ( event.content ) {
|
|
|
|
|
|
- if ( event.content ) {
|
|
|
+ result = event.content;
|
|
|
|
|
|
- result = event.content;
|
|
|
+ // ColladaLoader
|
|
|
|
|
|
- // ColladaLoader
|
|
|
+ } else if ( event.dae ) {
|
|
|
|
|
|
- } else if ( event.dae ) {
|
|
|
+ result = event.scene;
|
|
|
|
|
|
- result = event.scene;
|
|
|
|
|
|
+ // UTF8Loader
|
|
|
|
|
|
- // UTF8Loader
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ result = event;
|
|
|
|
|
|
- result = event;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ handle_hierarchy( result, id, parent, material, obj );
|
|
|
|
|
|
- handle_hierarchy( result, id, parent, material, obj );
|
|
|
+ counter_models -= 1;
|
|
|
|
|
|
- counter_models -= 1;
|
|
|
+ scope.onLoadComplete();
|
|
|
|
|
|
- scope.onLoadComplete();
|
|
|
+ async_callback_gate();
|
|
|
|
|
|
- async_callback_gate();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ function create_callback_embed( id ) {
|
|
|
|
|
|
- function create_callback_embed( id ) {
|
|
|
+ return function ( geo, mat ) {
|
|
|
|
|
|
- return function ( geo, mat ) {
|
|
|
+ geo.name = id;
|
|
|
|
|
|
- geo.name = id;
|
|
|
+ result.geometries[ id ] = geo;
|
|
|
+ result.face_materials[ id ] = mat;
|
|
|
|
|
|
- result.geometries[ id ] = geo;
|
|
|
- result.face_materials[ id ] = mat;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ function async_callback_gate() {
|
|
|
|
|
|
- function async_callback_gate() {
|
|
|
+ var progress = {
|
|
|
|
|
|
- var progress = {
|
|
|
+ totalModels : total_models,
|
|
|
+ totalTextures : total_textures,
|
|
|
+ loadedModels : total_models - counter_models,
|
|
|
+ loadedTextures : total_textures - counter_textures
|
|
|
|
|
|
- totalModels : total_models,
|
|
|
- totalTextures : total_textures,
|
|
|
- loadedModels : total_models - counter_models,
|
|
|
- loadedTextures : total_textures - counter_textures
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ scope.callbackProgress( progress, result );
|
|
|
|
|
|
- scope.callbackProgress( progress, result );
|
|
|
+ scope.onLoadProgress();
|
|
|
|
|
|
- scope.onLoadProgress();
|
|
|
+ if ( counter_models === 0 && counter_textures === 0 ) {
|
|
|
|
|
|
- if ( counter_models === 0 && counter_textures === 0 ) {
|
|
|
+ finalize();
|
|
|
+ callbackFinished( result );
|
|
|
|
|
|
- finalize();
|
|
|
- callbackFinished( result );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
+ function finalize() {
|
|
|
|
|
|
- };
|
|
|
+ // take care of targets which could be asynchronously loaded objects
|
|
|
|
|
|
- function finalize() {
|
|
|
+ for ( var i = 0; i < target_array.length; i ++ ) {
|
|
|
|
|
|
- // take care of targets which could be asynchronously loaded objects
|
|
|
+ var ta = target_array[ i ];
|
|
|
|
|
|
- for ( var i = 0; i < target_array.length; i ++ ) {
|
|
|
+ var target = result.objects[ ta.targetName ];
|
|
|
|
|
|
- var ta = target_array[ i ];
|
|
|
+ if ( target ) {
|
|
|
|
|
|
- var target = result.objects[ ta.targetName ];
|
|
|
+ ta.object.target = target;
|
|
|
|
|
|
- if ( target ) {
|
|
|
+ } else {
|
|
|
|
|
|
- ta.object.target = target;
|
|
|
+ // if there was error and target of specified name doesn't exist in the scene file
|
|
|
+ // create instead dummy target
|
|
|
+ // (target must be added to scene explicitly as parent is already added)
|
|
|
|
|
|
- } else {
|
|
|
+ ta.object.target = new THREE.Object3D();
|
|
|
+ result.scene.add( ta.object.target );
|
|
|
|
|
|
- // if there was error and target of specified name doesn't exist in the scene file
|
|
|
- // create instead dummy target
|
|
|
- // (target must be added to scene explicitly as parent is already added)
|
|
|
+ }
|
|
|
|
|
|
- ta.object.target = new THREE.Object3D();
|
|
|
- result.scene.add( ta.object.target );
|
|
|
+ ta.object.target.userData.targetInverse = ta.object;
|
|
|
|
|
|
}
|
|
|
|
|
|
- ta.object.target.userData.targetInverse = ta.object;
|
|
|
-
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ var callbackTexture = function ( count ) {
|
|
|
|
|
|
- var callbackTexture = function ( count ) {
|
|
|
+ counter_textures -= count;
|
|
|
+ async_callback_gate();
|
|
|
|
|
|
- counter_textures -= count;
|
|
|
- async_callback_gate();
|
|
|
+ scope.onLoadComplete();
|
|
|
|
|
|
- scope.onLoadComplete();
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ // must use this instead of just directly calling callbackTexture
|
|
|
+ // because of closure in the calling context loop
|
|
|
|
|
|
- // must use this instead of just directly calling callbackTexture
|
|
|
- // because of closure in the calling context loop
|
|
|
+ var generateTextureCallback = function ( count ) {
|
|
|
|
|
|
- var generateTextureCallback = function ( count ) {
|
|
|
+ return function () {
|
|
|
|
|
|
- return function () {
|
|
|
+ callbackTexture( count );
|
|
|
|
|
|
- callbackTexture( count );
|
|
|
+ };
|
|
|
|
|
|
};
|
|
|
|
|
|
- };
|
|
|
+ function traverse_json_hierarchy( objJSON, callback ) {
|
|
|
|
|
|
- function traverse_json_hierarchy( objJSON, callback ) {
|
|
|
+ callback( objJSON );
|
|
|
|
|
|
- callback( objJSON );
|
|
|
+ if ( objJSON.children !== undefined ) {
|
|
|
|
|
|
- if ( objJSON.children !== undefined ) {
|
|
|
+ for ( var objChildID in objJSON.children ) {
|
|
|
|
|
|
- for ( var objChildID in objJSON.children ) {
|
|
|
+ traverse_json_hierarchy( objJSON.children[ objChildID ], callback );
|
|
|
|
|
|
- traverse_json_hierarchy( objJSON.children[ objChildID ], callback );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- };
|
|
|
+ // first go synchronous elements
|
|
|
|
|
|
- // first go synchronous elements
|
|
|
+ // fogs
|
|
|
|
|
|
- // fogs
|
|
|
+ var fogID, fogJSON;
|
|
|
|
|
|
- var fogID, fogJSON;
|
|
|
+ for ( fogID in data.fogs ) {
|
|
|
|
|
|
- for ( fogID in data.fogs ) {
|
|
|
+ fogJSON = data.fogs[ fogID ];
|
|
|
|
|
|
- fogJSON = data.fogs[ fogID ];
|
|
|
+ if ( fogJSON.type === "linear" ) {
|
|
|
|
|
|
- if ( fogJSON.type === "linear" ) {
|
|
|
+ fog = new THREE.Fog( 0x000000, fogJSON.near, fogJSON.far );
|
|
|
|
|
|
- fog = new THREE.Fog( 0x000000, fogJSON.near, fogJSON.far );
|
|
|
+ } else if ( fogJSON.type === "exp2" ) {
|
|
|
|
|
|
- } else if ( fogJSON.type === "exp2" ) {
|
|
|
+ fog = new THREE.FogExp2( 0x000000, fogJSON.density );
|
|
|
|
|
|
- fog = new THREE.FogExp2( 0x000000, fogJSON.density );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ color = fogJSON.color;
|
|
|
+ fog.color.setRGB( color[0], color[1], color[2] );
|
|
|
|
|
|
- color = fogJSON.color;
|
|
|
- fog.color.setRGB( color[0], color[1], color[2] );
|
|
|
+ result.fogs[ fogID ] = fog;
|
|
|
|
|
|
- result.fogs[ fogID ] = fog;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // now come potentially asynchronous elements
|
|
|
|
|
|
- // now come potentially asynchronous elements
|
|
|
+ // geometries
|
|
|
|
|
|
- // geometries
|
|
|
+ // count how many geometries will be loaded asynchronously
|
|
|
|
|
|
- // count how many geometries will be loaded asynchronously
|
|
|
+ var geoID, geoJSON;
|
|
|
|
|
|
- var geoID, geoJSON;
|
|
|
+ for ( geoID in data.geometries ) {
|
|
|
|
|
|
- for ( geoID in data.geometries ) {
|
|
|
+ geoJSON = data.geometries[ geoID ];
|
|
|
|
|
|
- geoJSON = data.geometries[ geoID ];
|
|
|
+ if ( geoJSON.type in this.geometryHandlers ) {
|
|
|
|
|
|
- if ( geoJSON.type in this.geometryHandlerMap ) {
|
|
|
+ counter_models += 1;
|
|
|
|
|
|
- counter_models += 1;
|
|
|
+ scope.onLoadStart();
|
|
|
|
|
|
- scope.onLoadStart();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // count how many hierarchies will be loaded asynchronously
|
|
|
|
|
|
- // count how many hierarchies will be loaded asynchronously
|
|
|
+ for ( var objID in data.objects ) {
|
|
|
|
|
|
- for ( var objID in data.objects ) {
|
|
|
+ traverse_json_hierarchy( data.objects[ objID ], function ( objJSON ) {
|
|
|
|
|
|
- traverse_json_hierarchy( data.objects[ objID ], function ( objJSON ) {
|
|
|
+ if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlers ) ) {
|
|
|
|
|
|
- if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) ) {
|
|
|
+ counter_models += 1;
|
|
|
|
|
|
- counter_models += 1;
|
|
|
+ scope.onLoadStart();
|
|
|
|
|
|
- scope.onLoadStart();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ total_models = counter_models;
|
|
|
|
|
|
- total_models = counter_models;
|
|
|
+ for ( geoID in data.geometries ) {
|
|
|
|
|
|
- for ( geoID in data.geometries ) {
|
|
|
+ geoJSON = data.geometries[ geoID ];
|
|
|
|
|
|
- geoJSON = data.geometries[ geoID ];
|
|
|
+ if ( geoJSON.type === "cube" ) {
|
|
|
|
|
|
- if ( geoJSON.type === "cube" ) {
|
|
|
+ geometry = new THREE.CubeGeometry( geoJSON.width, geoJSON.height, geoJSON.depth, geoJSON.widthSegments, geoJSON.heightSegments, geoJSON.depthSegments );
|
|
|
+ geometry.name = geoID;
|
|
|
+ result.geometries[ geoID ] = geometry;
|
|
|
|
|
|
- geometry = new THREE.CubeGeometry( geoJSON.width, geoJSON.height, geoJSON.depth, geoJSON.widthSegments, geoJSON.heightSegments, geoJSON.depthSegments );
|
|
|
- geometry.name = geoID;
|
|
|
- result.geometries[ geoID ] = geometry;
|
|
|
+ } else if ( geoJSON.type === "plane" ) {
|
|
|
|
|
|
- } else if ( geoJSON.type === "plane" ) {
|
|
|
+ geometry = new THREE.PlaneGeometry( geoJSON.width, geoJSON.height, geoJSON.widthSegments, geoJSON.heightSegments );
|
|
|
+ geometry.name = geoID;
|
|
|
+ result.geometries[ geoID ] = geometry;
|
|
|
|
|
|
- geometry = new THREE.PlaneGeometry( geoJSON.width, geoJSON.height, geoJSON.widthSegments, geoJSON.heightSegments );
|
|
|
- geometry.name = geoID;
|
|
|
- result.geometries[ geoID ] = geometry;
|
|
|
+ } else if ( geoJSON.type === "sphere" ) {
|
|
|
|
|
|
- } else if ( geoJSON.type === "sphere" ) {
|
|
|
+ geometry = new THREE.SphereGeometry( geoJSON.radius, geoJSON.widthSegments, geoJSON.heightSegments );
|
|
|
+ geometry.name = geoID;
|
|
|
+ result.geometries[ geoID ] = geometry;
|
|
|
|
|
|
- geometry = new THREE.SphereGeometry( geoJSON.radius, geoJSON.widthSegments, geoJSON.heightSegments );
|
|
|
- geometry.name = geoID;
|
|
|
- result.geometries[ geoID ] = geometry;
|
|
|
+ } else if ( geoJSON.type === "cylinder" ) {
|
|
|
|
|
|
- } else if ( geoJSON.type === "cylinder" ) {
|
|
|
+ geometry = new THREE.CylinderGeometry( geoJSON.topRad, geoJSON.botRad, geoJSON.height, geoJSON.radSegs, geoJSON.heightSegs );
|
|
|
+ geometry.name = geoID;
|
|
|
+ result.geometries[ geoID ] = geometry;
|
|
|
|
|
|
- geometry = new THREE.CylinderGeometry( geoJSON.topRad, geoJSON.botRad, geoJSON.height, geoJSON.radSegs, geoJSON.heightSegs );
|
|
|
- geometry.name = geoID;
|
|
|
- result.geometries[ geoID ] = geometry;
|
|
|
+ } else if ( geoJSON.type === "torus" ) {
|
|
|
|
|
|
- } else if ( geoJSON.type === "torus" ) {
|
|
|
+ geometry = new THREE.TorusGeometry( geoJSON.radius, geoJSON.tube, geoJSON.segmentsR, geoJSON.segmentsT );
|
|
|
+ geometry.name = geoID;
|
|
|
+ result.geometries[ geoID ] = geometry;
|
|
|
|
|
|
- geometry = new THREE.TorusGeometry( geoJSON.radius, geoJSON.tube, geoJSON.segmentsR, geoJSON.segmentsT );
|
|
|
- geometry.name = geoID;
|
|
|
- result.geometries[ geoID ] = geometry;
|
|
|
+ } else if ( geoJSON.type === "icosahedron" ) {
|
|
|
|
|
|
- } else if ( geoJSON.type === "icosahedron" ) {
|
|
|
+ geometry = new THREE.IcosahedronGeometry( geoJSON.radius, geoJSON.subdivisions );
|
|
|
+ geometry.name = geoID;
|
|
|
+ result.geometries[ geoID ] = geometry;
|
|
|
|
|
|
- geometry = new THREE.IcosahedronGeometry( geoJSON.radius, geoJSON.subdivisions );
|
|
|
- geometry.name = geoID;
|
|
|
- result.geometries[ geoID ] = geometry;
|
|
|
+ } else if ( geoJSON.type in this.geometryHandlers ) {
|
|
|
|
|
|
- } else if ( geoJSON.type in this.geometryHandlerMap ) {
|
|
|
+ var loaderParameters = {};
|
|
|
|
|
|
- var loaderParameters = {};
|
|
|
+ for ( var parType in geoJSON ) {
|
|
|
|
|
|
- for ( var parType in geoJSON ) {
|
|
|
+ if ( parType !== "type" && parType !== "url" ) {
|
|
|
|
|
|
- if ( parType !== "type" && parType !== "url" ) {
|
|
|
+ loaderParameters[ parType ] = geoJSON[ parType ];
|
|
|
|
|
|
- loaderParameters[ parType ] = geoJSON[ parType ];
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ var loader = this.geometryHandlers[ geoJSON.type ][ "loaderObject" ];
|
|
|
+ loader.load( get_url( geoJSON.url, data.urlBaseType ), create_callback_geometry( geoID ), loaderParameters );
|
|
|
|
|
|
- var loader = this.geometryHandlerMap[ geoJSON.type ][ "loaderObject" ];
|
|
|
- loader.load( get_url( geoJSON.url, data.urlBaseType ), create_callback_geometry( geoID ), loaderParameters );
|
|
|
+ } else if ( geoJSON.type === "embedded" ) {
|
|
|
|
|
|
- } else if ( geoJSON.type === "embedded" ) {
|
|
|
+ var modelJson = data.embeds[ geoJSON.id ],
|
|
|
+ texture_path = "";
|
|
|
|
|
|
- var modelJson = data.embeds[ geoJSON.id ],
|
|
|
- texture_path = "";
|
|
|
+ // pass metadata along to jsonLoader so it knows the format version
|
|
|
|
|
|
- // pass metadata along to jsonLoader so it knows the format version
|
|
|
+ modelJson.metadata = data.metadata;
|
|
|
|
|
|
- modelJson.metadata = data.metadata;
|
|
|
+ if ( modelJson ) {
|
|
|
|
|
|
- if ( modelJson ) {
|
|
|
+ var jsonLoader = this.geometryHandlers[ "ascii" ][ "loaderObject" ];
|
|
|
+ var model = jsonLoader.parse( modelJson, texture_path );
|
|
|
+ create_callback_embed( geoID )( model.geometry, model.materials );
|
|
|
|
|
|
- var jsonLoader = this.geometryHandlerMap[ "ascii" ][ "loaderObject" ];
|
|
|
- var model = jsonLoader.parse( modelJson, texture_path );
|
|
|
- create_callback_embed( geoID )( model.geometry, model.materials );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // textures
|
|
|
|
|
|
- // textures
|
|
|
+ // count how many textures will be loaded asynchronously
|
|
|
|
|
|
- // count how many textures will be loaded asynchronously
|
|
|
+ var textureID, textureJSON;
|
|
|
|
|
|
- var textureID, textureJSON;
|
|
|
+ for ( textureID in data.textures ) {
|
|
|
|
|
|
- for ( textureID in data.textures ) {
|
|
|
+ textureJSON = data.textures[ textureID ];
|
|
|
|
|
|
- textureJSON = data.textures[ textureID ];
|
|
|
+ if ( textureJSON.url instanceof Array ) {
|
|
|
|
|
|
- if ( textureJSON.url instanceof Array ) {
|
|
|
+ counter_textures += textureJSON.url.length;
|
|
|
|
|
|
- counter_textures += textureJSON.url.length;
|
|
|
+ for( var n = 0; n < textureJSON.url.length; n ++ ) {
|
|
|
|
|
|
- for( var n = 0; n < textureJSON.url.length; n ++ ) {
|
|
|
+ scope.onLoadStart();
|
|
|
|
|
|
- scope.onLoadStart();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ counter_textures += 1;
|
|
|
|
|
|
- counter_textures += 1;
|
|
|
+ scope.onLoadStart();
|
|
|
|
|
|
- scope.onLoadStart();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ total_textures = counter_textures;
|
|
|
|
|
|
- total_textures = counter_textures;
|
|
|
+ for ( textureID in data.textures ) {
|
|
|
|
|
|
- for ( textureID in data.textures ) {
|
|
|
+ textureJSON = data.textures[ textureID ];
|
|
|
|
|
|
- textureJSON = data.textures[ textureID ];
|
|
|
+ if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined ) {
|
|
|
|
|
|
- if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined ) {
|
|
|
+ textureJSON.mapping = new THREE[ textureJSON.mapping ]();
|
|
|
|
|
|
- textureJSON.mapping = new THREE[ textureJSON.mapping ]();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( textureJSON.url instanceof Array ) {
|
|
|
|
|
|
- if ( textureJSON.url instanceof Array ) {
|
|
|
+ var count = textureJSON.url.length;
|
|
|
+ var url_array = [];
|
|
|
|
|
|
- var count = textureJSON.url.length;
|
|
|
- var url_array = [];
|
|
|
+ for( var i = 0; i < count; i ++ ) {
|
|
|
|
|
|
- for( var i = 0; i < count; i ++ ) {
|
|
|
+ url_array[ i ] = get_url( textureJSON.url[ i ], data.urlBaseType );
|
|
|
|
|
|
- url_array[ i ] = get_url( textureJSON.url[ i ], data.urlBaseType );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ var isCompressed = /\.dds$/i.test( url_array[ 0 ] );
|
|
|
|
|
|
- var isCompressed = /\.dds$/i.test( url_array[ 0 ] );
|
|
|
+ if ( isCompressed ) {
|
|
|
|
|
|
- if ( isCompressed ) {
|
|
|
+ texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
|
|
|
|
|
|
- texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ texture = THREE.ImageUtils.loadTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
|
|
|
|
|
|
- texture = THREE.ImageUtils.loadTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ var isCompressed = /\.dds$/i.test( textureJSON.url );
|
|
|
+ var fullUrl = get_url( textureJSON.url, data.urlBaseType );
|
|
|
+ var textureCallback = generateTextureCallback( 1 );
|
|
|
|
|
|
- var isCompressed = /\.dds$/i.test( textureJSON.url );
|
|
|
- var fullUrl = get_url( textureJSON.url, data.urlBaseType );
|
|
|
- var textureCallback = generateTextureCallback( 1 );
|
|
|
+ if ( isCompressed ) {
|
|
|
|
|
|
- if ( isCompressed ) {
|
|
|
+ texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, textureJSON.mapping, textureCallback );
|
|
|
|
|
|
- texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, textureJSON.mapping, textureCallback );
|
|
|
+ } else {
|
|
|
|
|
|
- } else {
|
|
|
+ texture = THREE.ImageUtils.loadTexture( fullUrl, textureJSON.mapping, textureCallback );
|
|
|
|
|
|
- texture = THREE.ImageUtils.loadTexture( fullUrl, textureJSON.mapping, textureCallback );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( THREE[ textureJSON.minFilter ] !== undefined )
|
|
|
+ texture.minFilter = THREE[ textureJSON.minFilter ];
|
|
|
|
|
|
- if ( THREE[ textureJSON.minFilter ] !== undefined )
|
|
|
- texture.minFilter = THREE[ textureJSON.minFilter ];
|
|
|
+ if ( THREE[ textureJSON.magFilter ] !== undefined )
|
|
|
+ texture.magFilter = THREE[ textureJSON.magFilter ];
|
|
|
|
|
|
- if ( THREE[ textureJSON.magFilter ] !== undefined )
|
|
|
- texture.magFilter = THREE[ textureJSON.magFilter ];
|
|
|
+ if ( textureJSON.anisotropy ) texture.anisotropy = textureJSON.anisotropy;
|
|
|
|
|
|
- if ( textureJSON.anisotropy ) texture.anisotropy = textureJSON.anisotropy;
|
|
|
+ if ( textureJSON.repeat ) {
|
|
|
|
|
|
- if ( textureJSON.repeat ) {
|
|
|
+ texture.repeat.set( textureJSON.repeat[ 0 ], textureJSON.repeat[ 1 ] );
|
|
|
|
|
|
- texture.repeat.set( textureJSON.repeat[ 0 ], textureJSON.repeat[ 1 ] );
|
|
|
+ if ( textureJSON.repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
|
|
|
+ if ( textureJSON.repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
|
|
|
|
|
|
- if ( textureJSON.repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
|
|
|
- if ( textureJSON.repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( textureJSON.offset ) {
|
|
|
|
|
|
- if ( textureJSON.offset ) {
|
|
|
+ texture.offset.set( textureJSON.offset[ 0 ], textureJSON.offset[ 1 ] );
|
|
|
|
|
|
- texture.offset.set( textureJSON.offset[ 0 ], textureJSON.offset[ 1 ] );
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // handle wrap after repeat so that default repeat can be overriden
|
|
|
+
|
|
|
+ if ( textureJSON.wrap ) {
|
|
|
|
|
|
- // handle wrap after repeat so that default repeat can be overriden
|
|
|
+ var wrapMap = {
|
|
|
+ "repeat": THREE.RepeatWrapping,
|
|
|
+ "mirror": THREE.MirroredRepeatWrapping
|
|
|
+ }
|
|
|
|
|
|
- if ( textureJSON.wrap ) {
|
|
|
+ if ( wrapMap[ textureJSON.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ textureJSON.wrap[ 0 ] ];
|
|
|
+ if ( wrapMap[ textureJSON.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ textureJSON.wrap[ 1 ] ];
|
|
|
|
|
|
- var wrapMap = {
|
|
|
- "repeat": THREE.RepeatWrapping,
|
|
|
- "mirror": THREE.MirroredRepeatWrapping
|
|
|
}
|
|
|
|
|
|
- if ( wrapMap[ textureJSON.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ textureJSON.wrap[ 0 ] ];
|
|
|
- if ( wrapMap[ textureJSON.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ textureJSON.wrap[ 1 ] ];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ result.textures[ textureID ] = texture;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- result.textures[ textureID ] = texture;
|
|
|
+ // materials
|
|
|
|
|
|
- }
|
|
|
+ var matID, matJSON;
|
|
|
+ var parID;
|
|
|
|
|
|
- // materials
|
|
|
+ for ( matID in data.materials ) {
|
|
|
|
|
|
- var matID, matJSON;
|
|
|
- var parID;
|
|
|
+ matJSON = data.materials[ matID ];
|
|
|
|
|
|
- for ( matID in data.materials ) {
|
|
|
+ for ( parID in matJSON.parameters ) {
|
|
|
|
|
|
- matJSON = data.materials[ matID ];
|
|
|
+ if ( parID === "envMap" || parID === "map" || parID === "lightMap" || parID === "bumpMap" ) {
|
|
|
|
|
|
- for ( parID in matJSON.parameters ) {
|
|
|
+ matJSON.parameters[ parID ] = result.textures[ matJSON.parameters[ parID ] ];
|
|
|
|
|
|
- if ( parID === "envMap" || parID === "map" || parID === "lightMap" || parID === "bumpMap" ) {
|
|
|
+ } else if ( parID === "shading" ) {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = result.textures[ matJSON.parameters[ parID ] ];
|
|
|
+ matJSON.parameters[ parID ] = ( matJSON.parameters[ parID ] === "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
|
|
|
|
|
|
- } else if ( parID === "shading" ) {
|
|
|
+ } else if ( parID === "side" ) {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = ( matJSON.parameters[ parID ] === "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
|
|
|
+ if ( matJSON.parameters[ parID ] == "double" ) {
|
|
|
|
|
|
- } else if ( parID === "side" ) {
|
|
|
+ matJSON.parameters[ parID ] = THREE.DoubleSide;
|
|
|
|
|
|
- if ( matJSON.parameters[ parID ] == "double" ) {
|
|
|
+ } else if ( matJSON.parameters[ parID ] == "back" ) {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = THREE.DoubleSide;
|
|
|
+ matJSON.parameters[ parID ] = THREE.BackSide;
|
|
|
|
|
|
- } else if ( matJSON.parameters[ parID ] == "back" ) {
|
|
|
+ } else {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = THREE.BackSide;
|
|
|
+ matJSON.parameters[ parID ] = THREE.FrontSide;
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- matJSON.parameters[ parID ] = THREE.FrontSide;
|
|
|
+ } else if ( parID === "blending" ) {
|
|
|
|
|
|
- }
|
|
|
+ matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.NormalBlending;
|
|
|
|
|
|
- } else if ( parID === "blending" ) {
|
|
|
+ } else if ( parID === "combine" ) {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.NormalBlending;
|
|
|
+ matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.MultiplyOperation;
|
|
|
|
|
|
- } else if ( parID === "combine" ) {
|
|
|
+ } else if ( parID === "vertexColors" ) {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.MultiplyOperation;
|
|
|
+ if ( matJSON.parameters[ parID ] == "face" ) {
|
|
|
|
|
|
- } else if ( parID === "vertexColors" ) {
|
|
|
+ matJSON.parameters[ parID ] = THREE.FaceColors;
|
|
|
|
|
|
- if ( matJSON.parameters[ parID ] == "face" ) {
|
|
|
+ // default to vertex colors if "vertexColors" is anything else face colors or 0 / null / false
|
|
|
|
|
|
- matJSON.parameters[ parID ] = THREE.FaceColors;
|
|
|
+ } else if ( matJSON.parameters[ parID ] ) {
|
|
|
|
|
|
- // default to vertex colors if "vertexColors" is anything else face colors or 0 / null / false
|
|
|
+ matJSON.parameters[ parID ] = THREE.VertexColors;
|
|
|
|
|
|
- } else if ( matJSON.parameters[ parID ] ) {
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ( parID === "wrapRGB" ) {
|
|
|
|
|
|
- matJSON.parameters[ parID ] = THREE.VertexColors;
|
|
|
+ var v3 = matJSON.parameters[ parID ];
|
|
|
+ matJSON.parameters[ parID ] = new THREE.Vector3( v3[ 0 ], v3[ 1 ], v3[ 2 ] );
|
|
|
|
|
|
}
|
|
|
|
|
|
- } else if ( parID === "wrapRGB" ) {
|
|
|
+ }
|
|
|
|
|
|
- var v3 = matJSON.parameters[ parID ];
|
|
|
- matJSON.parameters[ parID ] = new THREE.Vector3( v3[ 0 ], v3[ 1 ], v3[ 2 ] );
|
|
|
+ if ( matJSON.parameters.opacity !== undefined && matJSON.parameters.opacity < 1.0 ) {
|
|
|
|
|
|
- }
|
|
|
+ matJSON.parameters.transparent = true;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.opacity !== undefined && matJSON.parameters.opacity < 1.0 ) {
|
|
|
+ if ( matJSON.parameters.normalMap ) {
|
|
|
|
|
|
- matJSON.parameters.transparent = true;
|
|
|
+ var shader = THREE.ShaderLib[ "normalmap" ];
|
|
|
+ var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
|
|
|
|
|
|
- }
|
|
|
+ var diffuse = matJSON.parameters.color;
|
|
|
+ var specular = matJSON.parameters.specular;
|
|
|
+ var ambient = matJSON.parameters.ambient;
|
|
|
+ var shininess = matJSON.parameters.shininess;
|
|
|
|
|
|
- if ( matJSON.parameters.normalMap ) {
|
|
|
+ uniforms[ "tNormal" ].value = result.textures[ matJSON.parameters.normalMap ];
|
|
|
|
|
|
- var shader = THREE.ShaderLib[ "normalmap" ];
|
|
|
- var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
|
|
|
+ if ( matJSON.parameters.normalScale ) {
|
|
|
|
|
|
- var diffuse = matJSON.parameters.color;
|
|
|
- var specular = matJSON.parameters.specular;
|
|
|
- var ambient = matJSON.parameters.ambient;
|
|
|
- var shininess = matJSON.parameters.shininess;
|
|
|
+ uniforms[ "uNormalScale" ].value.set( matJSON.parameters.normalScale[ 0 ], matJSON.parameters.normalScale[ 1 ] );
|
|
|
|
|
|
- uniforms[ "tNormal" ].value = result.textures[ matJSON.parameters.normalMap ];
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.normalScale ) {
|
|
|
+ if ( matJSON.parameters.map ) {
|
|
|
|
|
|
- uniforms[ "uNormalScale" ].value.set( matJSON.parameters.normalScale[ 0 ], matJSON.parameters.normalScale[ 1 ] );
|
|
|
+ uniforms[ "tDiffuse" ].value = matJSON.parameters.map;
|
|
|
+ uniforms[ "enableDiffuse" ].value = true;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.map ) {
|
|
|
+ if ( matJSON.parameters.envMap ) {
|
|
|
|
|
|
- uniforms[ "tDiffuse" ].value = matJSON.parameters.map;
|
|
|
- uniforms[ "enableDiffuse" ].value = true;
|
|
|
+ uniforms[ "tCube" ].value = matJSON.parameters.envMap;
|
|
|
+ uniforms[ "enableReflection" ].value = true;
|
|
|
+ uniforms[ "uReflectivity" ].value = matJSON.parameters.reflectivity;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.envMap ) {
|
|
|
+ if ( matJSON.parameters.lightMap ) {
|
|
|
|
|
|
- uniforms[ "tCube" ].value = matJSON.parameters.envMap;
|
|
|
- uniforms[ "enableReflection" ].value = true;
|
|
|
- uniforms[ "uReflectivity" ].value = matJSON.parameters.reflectivity;
|
|
|
+ uniforms[ "tAO" ].value = matJSON.parameters.lightMap;
|
|
|
+ uniforms[ "enableAO" ].value = true;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.lightMap ) {
|
|
|
+ if ( matJSON.parameters.specularMap ) {
|
|
|
|
|
|
- uniforms[ "tAO" ].value = matJSON.parameters.lightMap;
|
|
|
- uniforms[ "enableAO" ].value = true;
|
|
|
+ uniforms[ "tSpecular" ].value = result.textures[ matJSON.parameters.specularMap ];
|
|
|
+ uniforms[ "enableSpecular" ].value = true;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.specularMap ) {
|
|
|
+ if ( matJSON.parameters.displacementMap ) {
|
|
|
|
|
|
- uniforms[ "tSpecular" ].value = result.textures[ matJSON.parameters.specularMap ];
|
|
|
- uniforms[ "enableSpecular" ].value = true;
|
|
|
+ uniforms[ "tDisplacement" ].value = result.textures[ matJSON.parameters.displacementMap ];
|
|
|
+ uniforms[ "enableDisplacement" ].value = true;
|
|
|
|
|
|
- }
|
|
|
+ uniforms[ "uDisplacementBias" ].value = matJSON.parameters.displacementBias;
|
|
|
+ uniforms[ "uDisplacementScale" ].value = matJSON.parameters.displacementScale;
|
|
|
|
|
|
- if ( matJSON.parameters.displacementMap ) {
|
|
|
+ }
|
|
|
|
|
|
- uniforms[ "tDisplacement" ].value = result.textures[ matJSON.parameters.displacementMap ];
|
|
|
- uniforms[ "enableDisplacement" ].value = true;
|
|
|
+ uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
|
|
|
+ uniforms[ "uSpecularColor" ].value.setHex( specular );
|
|
|
+ uniforms[ "uAmbientColor" ].value.setHex( ambient );
|
|
|
|
|
|
- uniforms[ "uDisplacementBias" ].value = matJSON.parameters.displacementBias;
|
|
|
- uniforms[ "uDisplacementScale" ].value = matJSON.parameters.displacementScale;
|
|
|
+ uniforms[ "uShininess" ].value = shininess;
|
|
|
|
|
|
- }
|
|
|
+ if ( matJSON.parameters.opacity ) {
|
|
|
|
|
|
- uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
|
|
|
- uniforms[ "uSpecularColor" ].value.setHex( specular );
|
|
|
- uniforms[ "uAmbientColor" ].value.setHex( ambient );
|
|
|
+ uniforms[ "uOpacity" ].value = matJSON.parameters.opacity;
|
|
|
|
|
|
- uniforms[ "uShininess" ].value = shininess;
|
|
|
+ }
|
|
|
|
|
|
- if ( matJSON.parameters.opacity ) {
|
|
|
+ var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
|
|
|
|
|
|
- uniforms[ "uOpacity" ].value = matJSON.parameters.opacity;
|
|
|
+ material = new THREE.ShaderMaterial( parameters );
|
|
|
|
|
|
- }
|
|
|
+ } else {
|
|
|
|
|
|
- var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
|
|
|
+ material = new THREE[ matJSON.type ]( matJSON.parameters );
|
|
|
|
|
|
- material = new THREE.ShaderMaterial( parameters );
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
+ material.name = matID;
|
|
|
|
|
|
- material = new THREE[ matJSON.type ]( matJSON.parameters );
|
|
|
+ result.materials[ matID ] = material;
|
|
|
|
|
|
}
|
|
|
|
|
|
- material.name = matID;
|
|
|
-
|
|
|
- result.materials[ matID ] = material;
|
|
|
+ // second pass through all materials to initialize MeshFaceMaterials
|
|
|
+ // that could be referring to other materials out of order
|
|
|
|
|
|
- }
|
|
|
+ for ( matID in data.materials ) {
|
|
|
|
|
|
- // second pass through all materials to initialize MeshFaceMaterials
|
|
|
- // that could be referring to other materials out of order
|
|
|
+ matJSON = data.materials[ matID ];
|
|
|
|
|
|
- for ( matID in data.materials ) {
|
|
|
+ if ( matJSON.parameters.materials ) {
|
|
|
|
|
|
- matJSON = data.materials[ matID ];
|
|
|
+ var materialArray = [];
|
|
|
|
|
|
- if ( matJSON.parameters.materials ) {
|
|
|
+ for ( var i = 0; i < matJSON.parameters.materials.length; i ++ ) {
|
|
|
|
|
|
- var materialArray = [];
|
|
|
+ var label = matJSON.parameters.materials[ i ];
|
|
|
+ materialArray.push( result.materials[ label ] );
|
|
|
|
|
|
- for ( var i = 0; i < matJSON.parameters.materials.length; i ++ ) {
|
|
|
+ }
|
|
|
|
|
|
- var label = matJSON.parameters.materials[ i ];
|
|
|
- materialArray.push( result.materials[ label ] );
|
|
|
+ result.materials[ matID ].materials = materialArray;
|
|
|
|
|
|
}
|
|
|
|
|
|
- result.materials[ matID ].materials = materialArray;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ // objects ( synchronous init of procedural primitives )
|
|
|
|
|
|
- // objects ( synchronous init of procedural primitives )
|
|
|
+ handle_objects();
|
|
|
|
|
|
- handle_objects();
|
|
|
+ // defaults
|
|
|
|
|
|
- // defaults
|
|
|
+ if ( result.cameras && data.defaults.camera ) {
|
|
|
|
|
|
- if ( result.cameras && data.defaults.camera ) {
|
|
|
+ result.currentCamera = result.cameras[ data.defaults.camera ];
|
|
|
|
|
|
- result.currentCamera = result.cameras[ data.defaults.camera ];
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ( result.fogs && data.defaults.fog ) {
|
|
|
|
|
|
- if ( result.fogs && data.defaults.fog ) {
|
|
|
+ result.scene.fog = result.fogs[ data.defaults.fog ];
|
|
|
|
|
|
- result.scene.fog = result.fogs[ data.defaults.fog ];
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ // synchronous callback
|
|
|
|
|
|
- // synchronous callback
|
|
|
+ scope.callbackSync( result );
|
|
|
|
|
|
- scope.callbackSync( result );
|
|
|
+ // just in case there are no async elements
|
|
|
|
|
|
- // just in case there are no async elements
|
|
|
+ async_callback_gate();
|
|
|
|
|
|
- async_callback_gate();
|
|
|
+ }
|
|
|
|
|
|
-};
|
|
|
+}
|