123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /**
- * @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;
- }
- }());
|