|
@@ -568,46 +568,11 @@ THREE.Object3D.prototype = {
|
|
|
|
|
|
},
|
|
|
|
|
|
- toJSON: function( meta ) {
|
|
|
-
|
|
|
- var textures = [];
|
|
|
- var images = [];
|
|
|
-
|
|
|
- var parseTexture = function ( texture ) {
|
|
|
-
|
|
|
- console.log(texture);
|
|
|
-
|
|
|
-
|
|
|
- if ( meta.textures === undefined ) {
|
|
|
-
|
|
|
- meta.textures = [];
|
|
|
- meta.images = [];
|
|
|
- }
|
|
|
-
|
|
|
- if ( textures[ texture.uuid ] === undefined ) {
|
|
|
-
|
|
|
- var json = texture.toJSON();
|
|
|
- var jsonImage = texture.toJSONImage(json.image);
|
|
|
-
|
|
|
- delete json.metadata;
|
|
|
- delete jsonImage.metadata;
|
|
|
-
|
|
|
- textures[ texture.uuid ] = json;
|
|
|
- images[ texture.uuid ] = jsonImage;
|
|
|
-
|
|
|
- meta.textures.push( json );
|
|
|
- meta.images.push(jsonImage);
|
|
|
- }
|
|
|
-
|
|
|
- return texture.uuid;
|
|
|
-
|
|
|
- };
|
|
|
+ toJSON: function ( meta ) {
|
|
|
|
|
|
var isRootObject = ( meta === undefined );
|
|
|
|
|
|
- // we will store all serialization data on 'data'
|
|
|
var data = {};
|
|
|
- var metadata;
|
|
|
|
|
|
// meta is a hash used to collect geometries, materials.
|
|
|
// not providing it implies that this is the root object
|
|
@@ -618,16 +583,15 @@ THREE.Object3D.prototype = {
|
|
|
meta = {
|
|
|
geometries: {},
|
|
|
materials: {},
|
|
|
- textures: [],
|
|
|
- images: []
|
|
|
+ textures: {},
|
|
|
+ images: {}
|
|
|
};
|
|
|
|
|
|
- // add metadata
|
|
|
- metadata = {
|
|
|
- version: 4.41,
|
|
|
+ data.metadata = {
|
|
|
+ version: 4.4,
|
|
|
type: 'Object',
|
|
|
generator: 'Object3D.toJSON'
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
}
|
|
|
|
|
@@ -635,6 +599,7 @@ THREE.Object3D.prototype = {
|
|
|
|
|
|
data.uuid = this.uuid;
|
|
|
data.type = this.type;
|
|
|
+
|
|
|
if ( this.name !== '' ) data.name = this.name;
|
|
|
if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
|
|
|
if ( this.visible !== true ) data.visible = this.visible;
|
|
@@ -649,64 +614,23 @@ THREE.Object3D.prototype = {
|
|
|
|
|
|
data.children.push( this.children[ i ].toJSON( meta ).object );
|
|
|
|
|
|
- if(this.children[ i ].material instanceof THREE.MeshPhongMaterial){
|
|
|
- var _mat = this.children[ i ].material;
|
|
|
-
|
|
|
-
|
|
|
- if(_mat.map !== null){
|
|
|
-
|
|
|
- console.log(_mat.map);
|
|
|
- parseTexture(_mat.map);
|
|
|
-
|
|
|
- }
|
|
|
- if(_mat.alphaMap !== null) parseTexture(_mat.alphaMap);
|
|
|
- if(_mat.lightMap !== null) parseTexture(_mat.lightMap);
|
|
|
- if(_mat.bumpMap !== null) parseTexture(_mat.bumpMap);
|
|
|
- if(_mat.normalMap !== null) parseTexture(_mat.normalMap);
|
|
|
- if(_mat.specularMap !== null) parseTexture(_mat.specularMap);
|
|
|
- if(_mat.envMap !== null) parseTexture(_mat.envMap);
|
|
|
-
|
|
|
-
|
|
|
- // if(object.material.reflectivity !== null) data.reflectivity = object.material.reflectivity;
|
|
|
- // if(object.material.bumpScale !== null) data.bumpScale = object.material.bumpScale;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- // wrap serialized object with additional data
|
|
|
-
|
|
|
- // if(object.material instanceof THREE.MeshPhongMaterial){
|
|
|
- // if(object.material.map !== null) data.texture = parseTexture(object.material.map);
|
|
|
- // if(object.material.alphaMap !== null) data.texture = parseTexture(object.material.alphaMap);
|
|
|
- // if(object.material.lightMap !== null) data.texture = parseTexture(object.material.lightMap);
|
|
|
- // if(object.material.bumpMap !== null) data.texture = parseTexture(object.material.bumpMap);
|
|
|
- // if(object.material.normalMap !== null) data.texture = parseTexture(object.material.normalMap);
|
|
|
- // if(object.material.specularMap !== null) data.texture = parseTexture(object.material.specularMap);
|
|
|
- // if(object.material.envMap !== null) data.texture = parseTexture(object.material.envMap);
|
|
|
- // console.log(data.texture);
|
|
|
-
|
|
|
- // if(object.material.reflectivity !== null) data.reflectivity = object.material.reflectivity;
|
|
|
- // if(object.material.bumpScale !== null) data.bumpScale = object.material.bumpScale;
|
|
|
- // }
|
|
|
-
|
|
|
var output = {};
|
|
|
|
|
|
if ( isRootObject ) {
|
|
|
|
|
|
- output.metadata = metadata;
|
|
|
-
|
|
|
var geometries = extractFromCache( meta.geometries );
|
|
|
var materials = extractFromCache( meta.materials );
|
|
|
- // var textures1 = extractFromCache( meta.textures );
|
|
|
- // var images1 = extractFromCache( meta.images );
|
|
|
-
|
|
|
- console.log(meta.textures);
|
|
|
+ var textures = extractFromCache( meta.textures );
|
|
|
+ var images = extractFromCache( meta.images );
|
|
|
|
|
|
if ( geometries.length > 0 ) output.geometries = geometries;
|
|
|
if ( materials.length > 0 ) output.materials = materials;
|
|
|
- if ( meta.textures.length > 0 ) output.textures = meta.textures;
|
|
|
- if ( meta.images.length > 0 ) output.images = meta.images;
|
|
|
+ if ( textures.length > 0 ) output.textures = textures;
|
|
|
+ if ( images.length > 0 ) output.images = images;
|
|
|
|
|
|
}
|
|
|
|