提交 8e6339f5 编写于 作者: M Mugen87

QuickHull3: Enhance API

上级 d3655968
......@@ -168,7 +168,7 @@ Object.assign( Face.prototype, {
// right edge
while ( adjacentEdgeNext.opposite.face === oppositeFace ) {
while ( adjacentEdgeNext.twin.face === oppositeFace ) {
adjacentEdgeNext = adjacentEdgeNext.next;
twinEdgePrev = twinEdgePrev.prev;
......
......@@ -12,7 +12,25 @@ import { MergeNonConvexLargerFace, MergeNonConvex } from '../../constants';
*
*/
function QuickHull3( points ) {
var c = 0;
function QuickHull3() {
this.tolerance = - 1;
this.faces = [];
this.newFaces = [];
this.assigned = new VertexList();
this.unassigned = new VertexList();
this.vertices = []; // vertices of the hull (internal representation of given points)
}
Object.assign( QuickHull3.prototype, {
setFromPoints: function ( points ) {
if ( Array.isArray( points ) !== true ) {
......@@ -26,25 +44,87 @@ function QuickHull3( points ) {
}
this.tolerance = - 1;
this.makeEmpty();
this.faces = [];
this.newFaces = [];
for ( var i = 0, l = points.length; i < l; i ++ ) {
this.assigned = new VertexList();
this.unassigned = new VertexList();
this.vertices.push( new Vertex( points[ i ] ) );
this.vertices = []; // vertices of the hull (internal representation of given points)
}
for ( var i = 0, l = points.length; i < l; i ++ ) {
this.compute();
return this;
},
setFromObject: function ( object ) {
var scope = this;
this.makeEmpty();
object.updateMatrixWorld( true );
object.traverse( function ( node ) {
var i, l, point;
this.vertices.push( new Vertex( points[ i ], i ) );
var geometry = node.geometry;
if ( geometry !== undefined ) {
if ( geometry.isGeometry ) {
var vertices = geometry.vertices;
for ( i = 0, l = vertices.length; i < l; i ++ ) {
point = vertices[ i ].clone();
point.applyMatrix4( node.matrixWorld );
scope.vertices.push( new Vertex( point ) );
}
}
} else if ( geometry.isBufferGeometry ) {
Object.assign( QuickHull3.prototype, {
var attribute = geometry.attributes.position;
if ( attribute !== undefined ) {
for ( i = 0, l = attribute.count; i < l; i ++ ) {
point = new Vector3();
point.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
scope.vertices.push( new Vertex( point ) );
}
}
}
}
} );
this.compute();
return this;
},
makeEmpty: function () {
this.faces = [];
this.vertices = [];
return this;
},
// Adds a 'vertex' to the 'assigned' list of vertices and assigns it to the given face.
......@@ -699,8 +779,8 @@ Object.assign( QuickHull3.prototype, {
// The result is:
//
// - a positive number when the centroid of the opposite face is above the face i.e. when the faces are concave
// - a negative number when the centroid of the opposite face is below the face i.e. when the faces are convex
// - a positive number when the midpoint of the opposite face is above the face i.e. when the faces are concave
// - a negative number when the midpoint of the opposite face is below the face i.e. when the faces are convex
return edge.face.distanceToPoint( edge.twin.face.midpoint );
......@@ -720,7 +800,7 @@ Object.assign( QuickHull3.prototype, {
if ( mergeType === MergeNonConvex ) {
if ( this.oppositeFaceDistance( edge ) > this.tolerance ||
if ( this.oppositeFaceDistance( edge ) > - this.tolerance ||
this.oppositeFaceDistance( edge.twin ) > - this.tolerance ) {
merge = true;
......@@ -757,7 +837,7 @@ Object.assign( QuickHull3.prototype, {
if ( merge === true ) {
var discardedFaces = this.mergeAdjacentFaces( edge, [] );
var discardedFaces = face.mergeAdjacentFaces( edge, [] );
for ( var i = 0; i < discardedFaces.length; i ++ ) {
......@@ -811,7 +891,7 @@ Object.assign( QuickHull3.prototype, {
if ( face.mark === Visible ) {
while ( this.doAdjacentMerge( face, MergeNonConvexLargerFace ) ) {}
// while ( this.doAdjacentMerge( face, MergeNonConvexLargerFace ) ) {}
}
......@@ -828,7 +908,7 @@ Object.assign( QuickHull3.prototype, {
face.mark = Visible;
while ( this.doAdjacentMerge( face, MergeNonConvex ) ) {}
// while ( this.doAdjacentMerge( face, MergeNonConvex ) ) {}
}
......@@ -848,7 +928,7 @@ Object.assign( QuickHull3.prototype, {
},
build: function () {
compute: function () {
var vertex;
......
......@@ -5,10 +5,9 @@
*
*/
function Vertex( point, index ) {
function Vertex( point ) {
this.point = point;
this.index = index; // index in the input array of points
this.next = null;
this.prev = null;
this.face = null; // the face that is able to see this point
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册