Pārlūkot izejas kodu

Merge remote-tracking branch 'asutherland/master'

zz85 13 gadi atpakaļ
vecāks
revīzija
9de038ae6a
2 mainītis faili ar 43 papildinājumiem un 17 dzēšanām
  1. 5 5
      examples/webgl_geometry_shapes.html
  2. 38 12
      src/extras/core/Path.js

+ 5 - 5
examples/webgl_geometry_shapes.html

@@ -277,11 +277,11 @@
 				// Arc circle
 
 				var arcShape = new THREE.Shape();
-				arcShape.moveTo( 0, 0 );
+				arcShape.moveTo( 50, 10 );
 				arcShape.arc( 10, 10, 40, 0, Math.PI*2, false );
 
 				var holePath = new THREE.Path();
-				holePath.moveTo( 0, 0 );
+				holePath.moveTo( 20, 10 );
 				holePath.arc( 10, 10, 10, 0, Math.PI*2, true );
 				arcShape.holes.push( holePath );
 
@@ -293,16 +293,16 @@
 				// Smiley
 
 				var smileyShape = new THREE.Shape();
-				smileyShape.moveTo( 0, 0 );
+				smileyShape.moveTo( 80, 40 );
 				smileyShape.arc( 40, 40, 40, 0, Math.PI*2, false );
 
 				var smileyEye1Path = new THREE.Path();
-				smileyEye1Path.moveTo( 0, 0 );
+				smileyEye1Path.moveTo( 35, 20 );
 				smileyEye1Path.arc( 25, 20, 10, 0, Math.PI*2, true );
 				smileyShape.holes.push( smileyEye1Path );
 
 				var smileyEye2Path = new THREE.Path();
-				smileyEye2Path.moveTo( 0, 0 );
+				smileyEye2Path.moveTo( 65, 20 );
 				smileyEye2Path.arc( 55, 20, 10, 0, Math.PI*2, true );
 				smileyShape.holes.push( smileyEye2Path );
 

+ 38 - 12
src/extras/core/Path.js

@@ -140,12 +140,39 @@ THREE.Path.prototype.arc = function ( aX, aY, aRadius,
 
 	var args = Array.prototype.slice.call( arguments );
 
+	var laste = this.actions[ this.actions.length - 1];
+
+	var curve = new THREE.ArcCurve( laste.x + aX, laste.y + aY, aRadius,
+									aStartAngle, aEndAngle, aClockwise );
+	this.curves.push( curve );
+
+	// All of the other actions look to the last two elements in the list to
+	// find the ending point, so we need to append them.
+	var lastPoint = curve.getPoint(aClockwise ? 1 : 0);
+	args.push(lastPoint.x);
+	args.push(lastPoint.y);
+
+	this.actions.push( { action: THREE.PathActions.ARC, args: args } );
+
+ };
+
+THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
+									  aStartAngle, aEndAngle, aClockwise ) {
+
+	var args = Array.prototype.slice.call( arguments );
+
 	var curve = new THREE.ArcCurve( aX, aY, aRadius,
 									aStartAngle, aEndAngle, aClockwise );
 	this.curves.push( curve );
 
 	// console.log( 'arc', args );
 
+        // All of the other actions look to the last two elements in the list to
+        // find the ending point, so we need to append them.
+        var lastPoint = curve.getPoint(aClockwise ? 1 : 0);
+        args.push(lastPoint.x);
+        args.push(lastPoint.y);
+
 	this.actions.push( { action: THREE.PathActions.ARC, args: args } );
 
  };
@@ -199,7 +226,7 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
 
 		case THREE.PathActions.MOVE_TO:
 
-			// points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
+			points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
 
 			break;
 
@@ -317,15 +344,6 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
 				aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
 				aClockwise = !!args[ 5 ];
 
-			var lastx = laste[ laste.length - 2 ],
-				lasty = laste[ laste.length - 1 ];
-
-			if ( laste.length == 0 ) {
-
-				lastx = lasty = 0;
-
-			}
-
 
 			var deltaAngle = aEndAngle - aStartAngle;
 			var angle;
@@ -343,8 +361,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
 
 				angle = aStartAngle + t * deltaAngle;
 
-				tx = lastx + aX + aRadius * Math.cos( angle );
-				ty = lasty + aY + aRadius * Math.sin( angle );
+				tx = aX + aRadius * Math.cos( angle );
+				ty = aY + aRadius * Math.sin( angle );
 
 				//console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
 
@@ -360,6 +378,14 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
 
 	}
 
+
+
+	// Normalize to remove the closing point by default.
+	var lastPoint = points[ points.length - 1];
+	var EPSILON = 0.0000000001;
+	if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
+             Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
+		points.splice( points.length - 1, 1);
 	if ( closedPath ) {
 
 		points.push( points[ 0 ] );