1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- /**
- * @author mrdoob / http://mrdoob.com/
- * @author WestLangley / http://github.com/WestLangley
- */
- THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
- this.object = object;
- this.size = ( size !== undefined ) ? size : 1;
- var color = ( hex !== undefined ) ? hex : 0x0000ff;
- var width = ( linewidth !== undefined ) ? linewidth : 1;
- var geometry = new THREE.Geometry();
- 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.vertexTangents.length; j < jl; j ++ ) {
- geometry.vertices.push( new THREE.Vector3() );
- geometry.vertices.push( new THREE.Vector3() );
- }
- }
- THREE.SegmentsLine.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
- this.matrixAutoUpdate = false;
- this.update();
- };
- THREE.VertexTangentsHelper.prototype = Object.create( THREE.SegmentsLine.prototype );
- THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
- THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
- var v1 = new THREE.Vector3();
- return function( object ) {
- var keys = [ 'a', 'b', 'c', 'd' ];
- this.object.updateMatrixWorld( true );
- 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.vertexTangents.length; j < jl; j ++ ) {
- var vertexId = face[ keys[ j ] ];
- var vertex = verts[ vertexId ];
- var tangent = face.vertexTangents[ j ];
- vertices[ idx ].copy( vertex ).applyMatrix4( worldMatrix );
- v1.copy( tangent ).transformDirection( worldMatrix ).multiplyScalar( this.size );
- v1.add( vertices[ idx ] );
- idx = idx + 1;
- vertices[ idx ].copy( v1 );
- idx = idx + 1;
- }
- }
- this.geometry.verticesNeedUpdate = true;
- return this;
- }
- }());
|