提交 d324144d 编写于 作者: A Andreas Plesch 提交者: GitHub

remove duplicate start end points

上级 f9582a1b
......@@ -47,38 +47,54 @@
<!-- replace built-in triangulation with Earcut -->
<script src="js/libs/earcut.js"></script>
<script>
function removeDupEndPts(points) {
var l = points.length;
if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
points.pop();
}
}
function addContour( vertices, contour ) {
for ( var i = 0; i < contour.length; i++ ) {
vertices.push( contour[i].x );
vertices.push( contour[i].y );
}
for ( var i = 0; i < contour.length; i++ ) {
vertices.push( contour[i].x );
vertices.push( contour[i].y );
}
}
THREE.ShapeUtils.triangulateShape = function ( contour, holes ) {
var vertices = [];
removeDupEndPts( contour );
holes.forEach( removeDupEndPts );
addContour( vertices, contour );
var vertices = [];
var holeIndices = [];
var holeIndex = contour.length;
addContour( vertices, contour );
for ( i = 0; i < holes.length; i++ ) {
holeIndices.push( holeIndex );
holeIndex += holes[i].length;
addContour( vertices, holes[i] );
}
var holeIndices = [];
var holeIndex = contour.length;
var result = earcut( vertices, holeIndices, 2 );
for ( i = 0; i < holes.length; i++ ) {
holeIndices.push( holeIndex );
holeIndex += holes[i].length;
addContour( vertices, holes[i] );
}
var grouped = [];
for ( var i = 0; i < result.length; i += 3 ) {
grouped.push( result.slice( i, i + 3 ) );
}
return grouped;
var result = earcut( vertices, holeIndices, 2 );
var grouped = [];
for ( var i = 0; i < result.length; i += 3 ) {
grouped.push( result.slice( i, i + 3 ) );
}
return grouped;
};
</script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册