Browse Source

toJSON: Moved geometry/material handling to Object3D. Fixes #7262.

Mr.doob 9 years ago
parent
commit
dfd2d8be8d
5 changed files with 16 additions and 49 deletions
  1. 16 0
      src/core/Object3D.js
  2. 0 14
      src/objects/Line.js
  3. 0 14
      src/objects/Mesh.js
  4. 0 14
      src/objects/Points.js
  5. 0 7
      src/objects/Sprite.js

+ 16 - 0
src/core/Object3D.js

@@ -630,6 +630,22 @@ THREE.Object3D.prototype = {
 
 		data.matrix = this.matrix.toArray();
 
+		//
+
+		if ( this.geometry && meta.geometries[ this.geometry.uuid ] === undefined ) {
+
+			meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
+
+		}
+
+		if ( this.material && meta.materials[ this.material.uuid ] === undefined ) {
+
+			meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
+
+		}
+
+		//
+
 		if ( this.children.length > 0 ) {
 
 			data.children = [];

+ 0 - 14
src/objects/Line.js

@@ -185,20 +185,6 @@ THREE.Line.prototype.toJSON = function ( meta ) {
 
 	var data = THREE.Object3D.prototype.toJSON.call( this, meta );
 
-	// only serialize if not in meta geometries cache
-	if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
-
-		meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
-
-	}
-
-	// only serialize if not in meta materials cache
-	if ( meta.materials[ this.material.uuid ] === undefined ) {
-
-		meta.materials[ this.material.uuid ] = this.material.toJSON();
-
-	}
-
 	data.object.geometry = this.geometry.uuid;
 	data.object.material = this.material.uuid;
 

+ 0 - 14
src/objects/Mesh.js

@@ -359,20 +359,6 @@ THREE.Mesh.prototype.toJSON = function ( meta ) {
 
 	var data = THREE.Object3D.prototype.toJSON.call( this, meta );
 
-	// only serialize if not in meta geometries cache
-	if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
-
-		meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
-
-	}
-
-	// only serialize if not in meta materials cache
-	if ( meta.materials[ this.material.uuid ] === undefined ) {
-
-		meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
-
-	}
-
 	data.object.geometry = this.geometry.uuid;
 	data.object.material = this.material.uuid;
 

+ 0 - 14
src/objects/Points.js

@@ -130,20 +130,6 @@ THREE.Points.prototype.toJSON = function ( meta ) {
 
 	var data = THREE.Object3D.prototype.toJSON.call( this, meta );
 
-	// only serialize if not in meta geometries cache
-	if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
-
-		meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
-
-	}
-
-	// only serialize if not in meta materials cache
-	if ( meta.materials[ this.material.uuid ] === undefined ) {
-
-		meta.materials[ this.material.uuid ] = this.material.toJSON();
-
-	}
-
 	data.object.geometry = this.geometry.uuid;
 	data.object.material = this.material.uuid;
 

+ 0 - 7
src/objects/Sprite.js

@@ -70,13 +70,6 @@ THREE.Sprite.prototype.toJSON = function ( meta ) {
 
 	var data = THREE.Object3D.prototype.toJSON.call( this, meta );
 
-	// only serialize if not in meta materials cache
-	if ( meta.materials[ this.material.uuid ] === undefined ) {
-
-		meta.materials[ this.material.uuid ] = this.material.toJSON();
-
-	}
-
 	data.object.material = this.material.uuid;
 
 	return data;