Explorar o código

Curves: Add remaining .copy() and .clone() methods

Mugen87 %!s(int64=7) %!d(string=hai) anos
pai
achega
abe67d48e5

+ 10 - 1
docs/api/extras/core/Shape.html

@@ -47,7 +47,16 @@
 		<h2>Constructor</h2>
 
 
-		<h3>[name]()</h3>
+		<h3>[name]( [page:Array points] )</h3>
+		<div>
+		points -- (optional) array of [page:Vector2 Vector2s].<br /><br />
+
+		Creates a Shape from the points. The first point defines the offset, then successive points
+		are added to the [page:CurvePath.curves curves] array as [page:LineCurve LineCurves].<br /><br />
+
+		If no points are specified, an empty shape is created and the [page:.currentPoint] is set to
+		the origin.
+		</div>
 
 
 		<h2>Properties</h2>

+ 20 - 0
src/extras/core/CurvePath.js

@@ -197,6 +197,26 @@ CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
 
 		return points;
 
+	},
+
+	copy: function ( source ) {
+
+		Curve.prototype.copy.call( this, source );
+
+		this.curves = [];
+
+		for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
+
+			var curve = source.curves[ i ];
+
+			this.curves.push( curve.clone() );
+
+		}
+
+		this.autoClose = source.autoClose;
+
+		return this;
+
 	}
 
 } );

+ 10 - 0
src/extras/core/PathPrototype.js

@@ -122,6 +122,16 @@ var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
 		var lastPoint = curve.getPoint( 1 );
 		this.currentPoint.copy( lastPoint );
 
+	},
+
+	copy: function ( source ) {
+
+		CurvePath.prototype.copy.call( this, source );
+
+		this.currentPoint.copy( source.currentPoint );
+
+		return this;
+
 	}
 
 } );

+ 20 - 2
src/extras/core/Shape.js

@@ -12,9 +12,9 @@ import { Path } from './Path.js';
 // STEP 3a - Extract points from each shape, turn to vertices
 // STEP 3b - Triangulate each shape, add faces.
 
-function Shape() {
+function Shape( points ) {
 
-	Path.apply( this, arguments );
+	Path.call( this, points );
 
 	this.type = 'Shape';
 
@@ -57,6 +57,24 @@ Shape.prototype = Object.assign( Object.create( PathPrototype ), {
 
 		return this.extractAllPoints( divisions );
 
+	},
+
+	copy: function ( source ) {
+
+		Path.prototype.copy.call( this, source );
+
+		this.holes = [];
+
+		for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
+
+			var hole = source.holes[ i ];
+
+			this.holes.push( hole.clone() );
+
+		}
+
+		return this;
+
 	}
 
 } );