Browse Source

Merge remote-tracking branch 'zz85/master' into dev

Mr.doob 13 years ago
parent
commit
4eebf6af92

+ 7 - 5
examples/webgl_geometry_shapes.html

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

+ 1 - 0
src/extras/core/Curve.js

@@ -18,6 +18,7 @@
  * THREE.CubicBezierCurve
  * THREE.SplineCurve
  * THREE.ArcCurve
+ * THREE.EllipseCurve
  *
  * -- 3d classes --
  * THREE.LineCurve3

+ 28 - 7
src/extras/core/CurvePath.js

@@ -140,15 +140,17 @@ THREE.CurvePath.prototype.getBoundingBox = function () {
 
 	var points = this.getPoints();
 
-	var maxX, maxY;
-	var minX, minY;
+	var maxX, maxY, maxZ;
+	var minX, minY, minZ;
 
 	maxX = maxY = Number.NEGATIVE_INFINITY;
 	minX = minY = Number.POSITIVE_INFINITY;
 
 	var p, i, il, sum;
 
-	sum = new THREE.Vector2();
+	var v3 = points[0] instanceof THREE.Vector3;
+
+	sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
 
 	for ( i = 0, il = points.length; i < il; i ++ ) {
 
@@ -160,20 +162,39 @@ THREE.CurvePath.prototype.getBoundingBox = function () {
 		if ( p.y > maxY ) maxY = p.y;
 		else if ( p.y < minY ) minY = p.y;
 
-		sum.addSelf( p.x, p.y );
+		if (v3) {
+
+			if ( p.z > maxZ ) maxZ = p.z;
+			else if ( p.z < minZ ) minZ = p.z;
+
+			sum.addSelf( p.x, p.y, p.z );
+
+		} else {
 
+			sum.addSelf( p.x, p.y );
+
+		}
 	}
 
-	return {
+	var ret = {
 
 		minX: minX,
 		minY: minY,
 		maxX: maxX,
 		maxY: maxY,
 		centroid: sum.divideScalar( il )
-
+	
 	};
 
+	if (v3) {
+
+		ret.maxZ = maxZ;
+		ret.minZ = minZ;
+	
+	}
+
+	return ret;
+
 };
 
 /**************************************************************
@@ -204,7 +225,7 @@ THREE.CurvePath.prototype.createGeometry = function( points ) {
 
 	for ( var i = 0; i < points.length; i ++ ) {
 
-		geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, 0 ) );
+		geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0) );
 
 	}
 

+ 22 - 21
src/extras/core/Path.js

@@ -132,35 +132,44 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
 
 // FUTURE: Change the API or follow canvas API?
 
-THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
+THREE.Path.prototype.arc = function ( aX, aY, aRadius,
 									  aStartAngle, aEndAngle, aClockwise ) {
 
-	var laste = this.actions[ this.actions.length - 1];
-	this.absellipse(laste.x + aX, laste.y + aY, xRadius, yRadius,
-									aStartAngle, aEndAngle, aClockwise );
+	var lastargs = this.actions[ this.actions.length - 1].args;
+	var x0 = lastargs[ lastargs.length - 2 ];
+	var y0 = lastargs[ lastargs.length - 1 ];
+
+	this.absarc(aX + x0, aY + y0, aRadius,
+		aStartAngle, aEndAngle, aClockwise );
+	
+ };
+
+ THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
+									  aStartAngle, aEndAngle, aClockwise ) {
+	this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  };
  
-THREE.Path.prototype.arc = function ( aX, aY, aRadius,
+THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
 									  aStartAngle, aEndAngle, aClockwise ) {
 
-	var laste = this.actions[ this.actions.length - 1];
-	this.absarc(laste.x + aX, laste.y + aY, aRadius,
-									aStartAngle, aEndAngle, aClockwise );
+	var lastargs = this.actions[ this.actions.length - 1].args;
+	var x0 = lastargs[ lastargs.length - 2 ];
+	var y0 = lastargs[ lastargs.length - 1 ];
+
+	this.absellipse(aX + x0, aY + y0, xRadius, yRadius,
+		aStartAngle, aEndAngle, aClockwise );
+
  };
  
 
-
 THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
 									  aStartAngle, aEndAngle, aClockwise ) {
 
 	var args = Array.prototype.slice.call( arguments );
-
 	var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
 									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);
@@ -169,13 +178,6 @@ THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
 
  };
 
-THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
-									  aStartAngle, aEndAngle, aClockwise ) {
-	this.absellipse(aX, aY, aRadius, aRadius,
-		aStartAngle, aEndAngle, aClockwise);
- };
-
-
 THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
 
 	if ( ! divisions ) divisions = 40;
@@ -345,7 +347,6 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
 				aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
 				aClockwise = !!args[ 5 ];
 
-
 			var deltaAngle = aEndAngle - aStartAngle;
 			var angle;
 			var tdivisions = divisions * 2;
@@ -379,7 +380,7 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
 
 			var aX = args[ 0 ], aY = args[ 1 ],
 				xRadius = args[ 2 ],
-				yRadius = args[3]
+				yRadius = args[ 3 ],
 				aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
 				aClockwise = !!args[ 6 ];