/** * @author mrdoob / http://mrdoob.com/ * @author WestLangley / http://github.com/WestLangley */ THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) { this.object = object; this.size = ( size !== undefined ) ? size : 1; var color = ( hex !== undefined ) ? hex : 0xffff00; var width = ( linewidth !== undefined ) ? linewidth : 1; var geometry = new THREE.Geometry(); var faces = this.object.geometry.faces; for ( var i = 0, l = faces.length; i < l; i ++ ) { 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.FaceNormalsHelper.prototype = Object.create( THREE.Line.prototype ); THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper; THREE.FaceNormalsHelper.prototype.update = function () { var vertices = this.geometry.vertices; var object = this.object; var objectVertices = object.geometry.vertices; var objectFaces = object.geometry.faces; var objectWorldMatrix = object.matrixWorld; object.updateMatrixWorld( true ); this.normalMatrix.getNormalMatrix( objectWorldMatrix ); for ( var i = 0, i2 = 0, l = objectFaces.length; i < l; i ++, i2 += 2 ) { var face = objectFaces[ i ]; vertices[ i2 ].copy( objectVertices[ face.a ] ) .add( objectVertices[ face.b ] ) .add( objectVertices[ face.c ] ) .divideScalar( 3 ) .applyMatrix4( objectWorldMatrix ); vertices[ i2 + 1 ].copy( face.normal ) .applyMatrix3( this.normalMatrix ) .normalize() .multiplyScalar( this.size ) .add( vertices[ i2 ] ); } this.geometry.verticesNeedUpdate = true; return this; };