/** * @author mrdoob / http://mrdoob.com/ * @author WestLangley / http://github.com/WestLangley */ THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) { this.object = object; this.size = ( size !== undefined ) ? size : 1; var color = ( hex !== undefined ) ? hex : 0xff0000; var width = ( linewidth !== undefined ) ? linewidth : 1; var geometry = new THREE.Geometry(); var vertices = object.geometry.vertices; var faces = object.geometry.faces; for ( var i = 0, l = faces.length; i < l; i ++ ) { var face = faces[ i ]; for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) { geometry.vertices.push( new THREE.Vector3(), new THREE.Vector3() ); } } THREE.Line.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ), THREE.LinePieces ); this.matrixAutoUpdate = false; this.normalMatrix = new THREE.Matrix3(); this.update(); }; THREE.VertexNormalsHelper.prototype = Object.create( THREE.Line.prototype ); THREE.VertexNormalsHelper.prototype.update = ( function ( object ) { var v1 = new THREE.Vector3(); return function( object ) { var keys = [ 'a', 'b', 'c', 'd' ]; this.object.updateMatrixWorld( true ); this.normalMatrix.getNormalMatrix( this.object.matrixWorld ); var vertices = this.geometry.vertices; var verts = this.object.geometry.vertices; var faces = this.object.geometry.faces; var worldMatrix = this.object.matrixWorld; var idx = 0; for ( var i = 0, l = faces.length; i < l; i ++ ) { var face = faces[ i ]; for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) { var vertexId = face[ keys[ j ] ]; var vertex = verts[ vertexId ]; var normal = face.vertexNormals[ j ]; vertices[ idx ].copy( vertex ).applyMatrix4( worldMatrix ); v1.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ); v1.add( vertices[ idx ] ); idx = idx + 1; vertices[ idx ].copy( v1 ); idx = idx + 1; } } this.geometry.verticesNeedUpdate = true; return this; } }());