Browse Source

ShapeGeometry: Refacto .toJSON()

Mugen87 7 years ago
parent
commit
407262ccb2
3 changed files with 46 additions and 52 deletions
  1. 0 26
      src/core/BufferGeometry.js
  2. 0 26
      src/core/Geometry.js
  3. 46 0
      src/geometries/ShapeGeometry.js

+ 0 - 26
src/core/BufferGeometry.js

@@ -923,32 +923,6 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
 
 			}
 
-			// ShapeBufferGeometry
-
-			if ( data.type === 'ShapeBufferGeometry' ) {
-
-				var shapes = parameters.shapes;
-
-				data.shapes = [];
-
-				if ( Array.isArray( shapes ) ) {
-
-					for ( var i = 0, l = shapes.length; i < l; i ++ ) {
-
-						var shape = shapes[ i ];
-
-						data.shapes.push( shape.uuid );
-
-					}
-
-				} else {
-
-					data.shapes.push( shapes.uuid );
-
-				}
-
-			}
-
 			return data;
 
 		}

+ 0 - 26
src/core/Geometry.js

@@ -1009,32 +1009,6 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
 
 			}
 
-			// ShapeGeometry
-
-			if ( data.type === 'ShapeGeometry' ) {
-
-				var shapes = parameters.shapes;
-
-				data.shapes = [];
-
-				if ( Array.isArray( shapes ) ) {
-
-					for ( var i = 0, l = shapes.length; i < l; i ++ ) {
-
-						var shape = shapes[ i ];
-
-						data.shapes.push( shape.uuid );
-
-					}
-
-				} else {
-
-					data.shapes.push( shapes.uuid );
-
-				}
-
-			}
-
 			return data;
 
 		}

+ 46 - 0
src/geometries/ShapeGeometry.js

@@ -37,6 +37,16 @@ function ShapeGeometry( shapes, curveSegments ) {
 ShapeGeometry.prototype = Object.create( Geometry.prototype );
 ShapeGeometry.prototype.constructor = ShapeGeometry;
 
+ShapeGeometry.prototype.toJSON = function () {
+
+	var data = Geometry.prototype.toJSON.call( this );
+
+	var shapes = this.parameters.shapes;
+
+	return toJSON( shapes, data );
+
+};
+
 // ShapeBufferGeometry
 
 function ShapeBufferGeometry( shapes, curveSegments ) {
@@ -172,5 +182,41 @@ function ShapeBufferGeometry( shapes, curveSegments ) {
 ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
 ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
 
+ShapeBufferGeometry.prototype.toJSON = function () {
+
+	var data = BufferGeometry.prototype.toJSON.call( this );
+
+	var shapes = this.parameters.shapes;
+
+	return toJSON( shapes, data );
+
+};
+
+//
+
+function toJSON( shapes, data ) {
+
+	data.shapes = [];
+
+	if ( Array.isArray( shapes ) ) {
+
+		for ( var i = 0, l = shapes.length; i < l; i ++ ) {
+
+			var shape = shapes[ i ];
+
+			data.shapes.push( shape.uuid );
+
+		}
+
+	} else {
+
+		data.shapes.push( shapes.uuid );
+
+	}
+
+	return data;
+
+}
+
 
 export { ShapeGeometry, ShapeBufferGeometry };