|
@@ -5,25 +5,32 @@ import { _Math } from '../math/Math';
|
|
|
|
|
|
/**
|
|
|
* @author WestLangley / http://github.com/WestLangley
|
|
|
+ * @author Mugen87 / https://github.com/Mugen87
|
|
|
*/
|
|
|
|
|
|
function EdgesGeometry( geometry, thresholdAngle ) {
|
|
|
|
|
|
BufferGeometry.call( this );
|
|
|
|
|
|
- thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
|
|
|
+ this.type = 'EdgesGeometry';
|
|
|
|
|
|
- var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
|
|
|
+ this.parameters = {
|
|
|
+ thresholdAngle: thresholdAngle
|
|
|
+ };
|
|
|
|
|
|
- var edge = [ 0, 0 ], hash = {};
|
|
|
+ thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
|
|
|
|
|
|
- function sortFunction( a, b ) {
|
|
|
+ // buffer
|
|
|
|
|
|
- return a - b;
|
|
|
+ var vertices = [];
|
|
|
|
|
|
- }
|
|
|
+ // helper variables
|
|
|
+
|
|
|
+ var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
|
|
|
+ var edge = [ 0, 0 ], hash = {};
|
|
|
+ var key, keys = [ 'a', 'b', 'c' ];
|
|
|
|
|
|
- var keys = [ 'a', 'b', 'c' ];
|
|
|
+ // prepare source geometry
|
|
|
|
|
|
var geometry2;
|
|
|
|
|
@@ -41,9 +48,11 @@ function EdgesGeometry( geometry, thresholdAngle ) {
|
|
|
geometry2.mergeVertices();
|
|
|
geometry2.computeFaceNormals();
|
|
|
|
|
|
- var vertices = geometry2.vertices;
|
|
|
+ var sourceVertices = geometry2.vertices;
|
|
|
var faces = geometry2.faces;
|
|
|
|
|
|
+ // now create a data structure (hash) where each entry represents an edge with its adjoining faces
|
|
|
+
|
|
|
for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
|
|
|
|
|
var face = faces[ i ];
|
|
@@ -54,7 +63,7 @@ function EdgesGeometry( geometry, thresholdAngle ) {
|
|
|
edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
|
|
|
edge.sort( sortFunction );
|
|
|
|
|
|
- var key = edge.toString();
|
|
|
+ key = edge.toString();
|
|
|
|
|
|
if ( hash[ key ] === undefined ) {
|
|
|
|
|
@@ -70,31 +79,37 @@ function EdgesGeometry( geometry, thresholdAngle ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var coords = [];
|
|
|
+ // generate vertices
|
|
|
|
|
|
- for ( var key in hash ) {
|
|
|
+ for ( key in hash ) {
|
|
|
|
|
|
var h = hash[ key ];
|
|
|
|
|
|
- // An edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
|
|
|
+ // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
|
|
|
|
|
|
if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
|
|
|
|
|
|
- var vertex = vertices[ h.vert1 ];
|
|
|
- coords.push( vertex.x );
|
|
|
- coords.push( vertex.y );
|
|
|
- coords.push( vertex.z );
|
|
|
+ var vertex = sourceVertices[ h.vert1 ];
|
|
|
+ vertices.push( vertex.x, vertex.y, vertex.z );
|
|
|
|
|
|
- vertex = vertices[ h.vert2 ];
|
|
|
- coords.push( vertex.x );
|
|
|
- coords.push( vertex.y );
|
|
|
- coords.push( vertex.z );
|
|
|
+ vertex = sourceVertices[ h.vert2 ];
|
|
|
+ vertices.push( vertex.x, vertex.y, vertex.z );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.addAttribute( 'position', new Float32BufferAttribute( coords, 3 ) );
|
|
|
+ // build geometry
|
|
|
+
|
|
|
+ this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
|
|
|
+
|
|
|
+ // custom array sort function
|
|
|
+
|
|
|
+ function sortFunction( a, b ) {
|
|
|
+
|
|
|
+ return a - b;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|