|
@@ -571,85 +571,85 @@ THREE.Object3D.prototype = {
|
|
|
|
|
|
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
|
|
|
- // being serialized.
|
|
|
- if ( isRootObject ) {
|
|
|
-
|
|
|
- // initialize meta obj
|
|
|
- meta = {
|
|
|
- geometries: {},
|
|
|
- materials: {}
|
|
|
- }
|
|
|
-
|
|
|
- // add metadata
|
|
|
- metadata = {
|
|
|
+ // 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
|
|
|
+ // being serialized.
|
|
|
+ if ( isRootObject ) {
|
|
|
+
|
|
|
+ // initialize meta obj
|
|
|
+ meta = {
|
|
|
+ geometries: {},
|
|
|
+ materials: {}
|
|
|
+ }
|
|
|
+
|
|
|
+ // add metadata
|
|
|
+ metadata = {
|
|
|
version: 4.4,
|
|
|
type: 'Object',
|
|
|
generator: 'Object3D.toJSON'
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- // standard Object3D serialization
|
|
|
+ }
|
|
|
|
|
|
- data.type = this.type;
|
|
|
- data.uuid = this.uuid;
|
|
|
- if ( this.name !== '' ) data.name = this.name;
|
|
|
- if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
|
|
|
- if ( this.visible !== true ) data.visible = this.visible;
|
|
|
+ // standard Object3D serialization
|
|
|
|
|
|
- data.matrix = this.matrix.toArray();
|
|
|
+ data.type = this.type;
|
|
|
+ data.uuid = this.uuid;
|
|
|
+ if ( this.name !== '' ) data.name = this.name;
|
|
|
+ if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
|
|
|
+ if ( this.visible !== true ) data.visible = this.visible;
|
|
|
|
|
|
- if ( this.children.length > 0 ) {
|
|
|
+ data.matrix = this.matrix.toArray();
|
|
|
|
|
|
- data.children = [];
|
|
|
+ if ( this.children.length > 0 ) {
|
|
|
|
|
|
- for ( var i = 0; i < this.children.length; i ++ ) {
|
|
|
+ data.children = [];
|
|
|
|
|
|
- data.children.push( this.children[ i ].toJSON( meta ).object );
|
|
|
+ for ( var i = 0; i < this.children.length; i ++ ) {
|
|
|
|
|
|
- }
|
|
|
+ data.children.push( this.children[ i ].toJSON( meta ).object );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // wrap serialized object with additional data
|
|
|
+ }
|
|
|
|
|
|
- var output;
|
|
|
+ // wrap serialized object with additional data
|
|
|
|
|
|
- if ( isRootObject ) {
|
|
|
+ var output;
|
|
|
|
|
|
- output = {
|
|
|
- metadata: metadata,
|
|
|
- geometries: extractFromCache(meta.geometries),
|
|
|
- materials: extractFromCache(meta.materials),
|
|
|
- object: data
|
|
|
- };
|
|
|
+ if ( isRootObject ) {
|
|
|
|
|
|
- } else {
|
|
|
+ output = {
|
|
|
+ metadata: metadata,
|
|
|
+ geometries: extractFromCache(meta.geometries),
|
|
|
+ materials: extractFromCache(meta.materials),
|
|
|
+ object: data
|
|
|
+ };
|
|
|
|
|
|
- output = { object: data };
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ output = { object: data };
|
|
|
|
|
|
- return output;
|
|
|
+ }
|
|
|
|
|
|
- // extract data from the cache hash
|
|
|
- // remove metadata on each item
|
|
|
- // and return as array
|
|
|
- function extractFromCache ( cache ) {
|
|
|
- var values = [];
|
|
|
- for ( var key in cache ) {
|
|
|
- var data = cache[ key ];
|
|
|
- delete data.metadata;
|
|
|
- values.push( data );
|
|
|
- }
|
|
|
- return values;
|
|
|
- }
|
|
|
+ return output;
|
|
|
+
|
|
|
+ // extract data from the cache hash
|
|
|
+ // remove metadata on each item
|
|
|
+ // and return as array
|
|
|
+ function extractFromCache ( cache ) {
|
|
|
+ var values = [];
|
|
|
+ for ( var key in cache ) {
|
|
|
+ var data = cache[ key ];
|
|
|
+ delete data.metadata;
|
|
|
+ values.push( data );
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
|
|
|
},
|
|
|
|