Browse Source

CurvePath: getPoints() should respect last point (#9169)

* CurvePath: getPoints() should respect last point

- autoClose behaviour now checks first point
- ShapeUtils.triangulateShape to remove dup points
- #9079
- Thank you @@rfm1201 again!

* Update webgl_geometry_text_pnltri example too
Joshua Koo 9 years ago
parent
commit
9631648acb

+ 16 - 0
examples/webgl_geometry_text_pnltri.html

@@ -49,8 +49,24 @@
 		<script>
 		<script>
 			THREE.ShapeUtils.triangulateShape = ( function () {
 			THREE.ShapeUtils.triangulateShape = ( function () {
 				var pnlTriangulator = new PNLTRI.Triangulator();
 				var pnlTriangulator = new PNLTRI.Triangulator();
+				function removeDupEndPts(points) {
+
+					var l = points.length;
+
+					if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
+
+						points.pop();
+
+					}
+
+				}
+
 				return function triangulateShape( contour, holes ) {
 				return function triangulateShape( contour, holes ) {
 					// console.log("new Triangulation: PnlTri.js " + PNLTRI.REVISION );
 					// console.log("new Triangulation: PnlTri.js " + PNLTRI.REVISION );
+
+					removeDupEndPts( contour );
+					holes.forEach( removeDupEndPts );
+
 					return pnlTriangulator.triangulate_polygon( [ contour ].concat(holes) );
 					return pnlTriangulator.triangulate_polygon( [ contour ].concat(holes) );
 				};
 				};
 			} )();
 			} )();

+ 15 - 0
src/extras/ShapeUtils.js

@@ -191,6 +191,21 @@ THREE.ShapeUtils = {
 
 
 	triangulateShape: function ( contour, holes ) {
 	triangulateShape: function ( contour, holes ) {
 
 
+		function removeDupEndPts(points) {
+
+			var l = points.length;
+
+			if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
+
+				points.pop();
+
+			}
+
+		}
+
+		removeDupEndPts( contour );
+		holes.forEach( removeDupEndPts );
+
 		function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
 		function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
 
 
 			// inOtherPt needs to be collinear to the inSegment
 			// inOtherPt needs to be collinear to the inSegment

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

@@ -178,13 +178,7 @@ THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype
 
 
 		}
 		}
 
 
-		if ( points[ points.length - 1 ].equals( points[ 0 ] ) ) {
-
-			points.pop();
-
-		}
-
-		if ( this.autoClose ) {
+		if ( this.autoClose && points.length > 1 && !points[ points.length - 1 ].equals( points[ 0 ] ) ) {
 
 
 			points.push( points[ 0 ] );
 			points.push( points[ 0 ] );