/** * @author WestLangley / http://github.com/WestLangley */ THREE.EdgesHelper = function ( object, hex ) { var color = ( hex !== undefined ) ? hex : 0xffffff; var edge = [ 0, 0 ], hash = {}; var sortFunction = function ( a, b ) { return a - b }; var keys = [ 'a', 'b', 'c' ]; var geometry = new THREE.BufferGeometry(); var geometry2 = object.geometry.clone(); geometry2.mergeVertices(); geometry2.computeFaceNormals(); var vertices = geometry2.vertices; var faces = geometry2.faces; var numEdges = 0; for ( var i = 0, l = faces.length; i < l; i ++ ) { var face = faces[ i ]; for ( var j = 0; j < 3; j ++ ) { edge[ 0 ] = face[ keys[ j ] ]; edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ]; edge.sort( sortFunction ); var key = edge.toString(); if ( hash[ key ] === undefined ) { hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined }; numEdges ++; } else { hash[ key ].face2 = i; } } } geometry.addAttribute( 'position', Float32Array, 2 * numEdges, 3 ); var coords = geometry.attributes.position.array; var index = 0; for ( var key in hash ) { var h = hash[ key ]; if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) < 0.9999 ) { // hardwired const OK var vertex = vertices[ h.vert1 ]; coords[ index ++ ] = vertex.x; coords[ index ++ ] = vertex.y; coords[ index ++ ] = vertex.z; vertex = vertices[ h.vert2 ]; coords[ index ++ ] = vertex.x; coords[ index ++ ] = vertex.y; coords[ index ++ ] = vertex.z; } } THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ), THREE.LinePieces ); this.matrixAutoUpdate = false; this.matrixWorld = object.matrixWorld; }; THREE.EdgesHelper.prototype = Object.create( THREE.Line.prototype );