diff --git a/src/extras/core/Shape.js b/src/extras/core/Shape.js index 5d2a5edc29739ce6377685cb186c09864364dbe4..e071b3c59c186d12b8ef82bfac3fb8a993d9f4af 100644 --- a/src/extras/core/Shape.js +++ b/src/extras/core/Shape.js @@ -123,207 +123,6 @@ THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) { THREE.Shape.Utils = { - /* - contour - array of vector2 for contour - holes - array of array of vector2 - */ - - removeHoles: function ( contour, holes ) { - - var shape = contour.concat(); // work on this shape - var allpoints = shape.concat(); - - /* For each isolated shape, find the closest points and break to the hole to allow triangulation */ - - - var prevShapeVert, nextShapeVert, - prevHoleVert, nextHoleVert, - holeIndex, shapeIndex, - shapeId, shapeGroup, - h, h2, - hole, shortest, d, - p, pts1, pts2, - tmpShape1, tmpShape2, - tmpHole1, tmpHole2, - verts = []; - - for ( h = 0; h < holes.length; h ++ ) { - - hole = holes[ h ]; - - /* - shapeholes[ h ].concat(); // preserves original - holes.push( hole ); - */ - - Array.prototype.push.apply( allpoints, hole ); - - shortest = Number.POSITIVE_INFINITY; - - - // Find the shortest pair of pts between shape and hole - - // Note: Actually, I'm not sure now if we could optimize this to be faster than O(m*n) - // Using distanceToSquared() intead of distanceTo() should speed a little - // since running square roots operations are reduced. - - for ( h2 = 0; h2 < hole.length; h2 ++ ) { - - pts1 = hole[ h2 ]; - var dist = []; - - for ( p = 0; p < shape.length; p++ ) { - - pts2 = shape[ p ]; - d = pts1.distanceToSquared( pts2 ); - dist.push( d ); - - if ( d < shortest ) { - - shortest = d; - holeIndex = h2; - shapeIndex = p; - - } - - } - - } - - //console.log("shortest", shortest, dist); - - prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1; - prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1; - - var areaapts = [ - - hole[ holeIndex ], - shape[ shapeIndex ], - shape[ prevShapeVert ] - - ]; - - var areaa = THREE.FontUtils.Triangulate.area( areaapts ); - - var areabpts = [ - - hole[ holeIndex ], - hole[ prevHoleVert ], - shape[ shapeIndex ] - - ]; - - var areab = THREE.FontUtils.Triangulate.area( areabpts ); - - var shapeOffset = 1; - var holeOffset = -1; - - var oldShapeIndex = shapeIndex, oldHoleIndex = holeIndex; - shapeIndex += shapeOffset; - holeIndex += holeOffset; - - if ( shapeIndex < 0 ) { shapeIndex += shape.length; } - shapeIndex %= shape.length; - - if ( holeIndex < 0 ) { holeIndex += hole.length; } - holeIndex %= hole.length; - - prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1; - prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1; - - areaapts = [ - - hole[ holeIndex ], - shape[ shapeIndex ], - shape[ prevShapeVert ] - - ]; - - var areaa2 = THREE.FontUtils.Triangulate.area( areaapts ); - - areabpts = [ - - hole[ holeIndex ], - hole[ prevHoleVert ], - shape[ shapeIndex ] - - ]; - - var areab2 = THREE.FontUtils.Triangulate.area( areabpts ); - //console.log(areaa,areab ,areaa2,areab2, ( areaa + areab ), ( areaa2 + areab2 )); - - if ( ( areaa + areab ) > ( areaa2 + areab2 ) ) { - - // In case areas are not correct. - //console.log("USE THIS"); - - shapeIndex = oldShapeIndex; - holeIndex = oldHoleIndex ; - - if ( shapeIndex < 0 ) { shapeIndex += shape.length; } - shapeIndex %= shape.length; - - if ( holeIndex < 0 ) { holeIndex += hole.length; } - holeIndex %= hole.length; - - prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1; - prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1; - - } else { - - //console.log("USE THAT ") - - } - - tmpShape1 = shape.slice( 0, shapeIndex ); - tmpShape2 = shape.slice( shapeIndex ); - tmpHole1 = hole.slice( holeIndex ); - tmpHole2 = hole.slice( 0, holeIndex ); - - // Should check orders here again? - - var trianglea = [ - - hole[ holeIndex ], - shape[ shapeIndex ], - shape[ prevShapeVert ] - - ]; - - var triangleb = [ - - hole[ holeIndex ] , - hole[ prevHoleVert ], - shape[ shapeIndex ] - - ]; - - verts.push( trianglea ); - verts.push( triangleb ); - - shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 ); - - } - - return { - - shape:shape, /* shape with no holes */ - isolatedPts: verts, /* isolated faces */ - allpoints: allpoints - - } - - - }, - - /* - * Modified Triangulation. - * - * basically rewritten 'removeHoles': - * - doesn't cut out an area anymore, but slices from shape to hole by adding two edges - * - ATTENTION: this requires small change to 'THREE.FontUtils.snip' to account for duplicate coordinates - * - checks whether such a cut line lies inside the shape doesn't intersect any other edge (shape and holes) - */ triangulateShape: function ( contour, holes ) { function point_in_segment_2D( inSegPt1, inSegPt2, inOtherPt ) {