|
@@ -10,6 +10,8 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
|
|
|
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
|
|
|
import { BufferGeometry } from '../core/BufferGeometry.js';
|
|
|
|
|
|
+var _v1, _v2, _normalMatrix, _keys;
|
|
|
+
|
|
|
function VertexNormalsHelper( object, size, hex, linewidth ) {
|
|
|
|
|
|
this.object = object;
|
|
@@ -57,97 +59,96 @@ function VertexNormalsHelper( object, size, hex, linewidth ) {
|
|
|
VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
|
|
|
VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
|
|
|
|
|
|
-VertexNormalsHelper.prototype.update = ( function () {
|
|
|
-
|
|
|
- var v1 = new Vector3();
|
|
|
- var v2 = new Vector3();
|
|
|
- var normalMatrix = new Matrix3();
|
|
|
+VertexNormalsHelper.prototype.update = function () {
|
|
|
|
|
|
- return function update() {
|
|
|
+ if ( _normalMatrix === undefined ) {
|
|
|
|
|
|
- var keys = [ 'a', 'b', 'c' ];
|
|
|
+ _v1 = new Vector3();
|
|
|
+ _v2 = new Vector3();
|
|
|
+ _normalMatrix = new Matrix3();
|
|
|
+ _keys = [ 'a', 'b', 'c' ];
|
|
|
|
|
|
- this.object.updateMatrixWorld( true );
|
|
|
+ }
|
|
|
|
|
|
- normalMatrix.getNormalMatrix( this.object.matrixWorld );
|
|
|
+ this.object.updateMatrixWorld( true );
|
|
|
|
|
|
- var matrixWorld = this.object.matrixWorld;
|
|
|
+ _normalMatrix.getNormalMatrix( this.object.matrixWorld );
|
|
|
|
|
|
- var position = this.geometry.attributes.position;
|
|
|
+ var matrixWorld = this.object.matrixWorld;
|
|
|
|
|
|
- //
|
|
|
+ var position = this.geometry.attributes.position;
|
|
|
|
|
|
- var objGeometry = this.object.geometry;
|
|
|
+ //
|
|
|
|
|
|
- if ( objGeometry && objGeometry.isGeometry ) {
|
|
|
+ var objGeometry = this.object.geometry;
|
|
|
|
|
|
- var vertices = objGeometry.vertices;
|
|
|
+ if ( objGeometry && objGeometry.isGeometry ) {
|
|
|
|
|
|
- var faces = objGeometry.faces;
|
|
|
+ var vertices = objGeometry.vertices;
|
|
|
|
|
|
- var idx = 0;
|
|
|
+ var faces = objGeometry.faces;
|
|
|
|
|
|
- for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
|
|
+ var idx = 0;
|
|
|
|
|
|
- var face = faces[ i ];
|
|
|
+ for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
|
|
|
|
|
- for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
|
|
|
+ var face = faces[ i ];
|
|
|
|
|
|
- var vertex = vertices[ face[ keys[ j ] ] ];
|
|
|
+ for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
|
|
|
|
|
|
- var normal = face.vertexNormals[ j ];
|
|
|
+ var vertex = vertices[ face[ _keys[ j ] ] ];
|
|
|
|
|
|
- v1.copy( vertex ).applyMatrix4( matrixWorld );
|
|
|
+ var normal = face.vertexNormals[ j ];
|
|
|
|
|
|
- v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
|
|
+ _v1.copy( vertex ).applyMatrix4( matrixWorld );
|
|
|
|
|
|
- position.setXYZ( idx, v1.x, v1.y, v1.z );
|
|
|
+ _v2.copy( normal ).applyMatrix3( _normalMatrix ).normalize().multiplyScalar( this.size ).add( _v1 );
|
|
|
|
|
|
- idx = idx + 1;
|
|
|
+ position.setXYZ( idx, _v1.x, _v1.y, _v1.z );
|
|
|
|
|
|
- position.setXYZ( idx, v2.x, v2.y, v2.z );
|
|
|
+ idx = idx + 1;
|
|
|
|
|
|
- idx = idx + 1;
|
|
|
+ position.setXYZ( idx, _v2.x, _v2.y, _v2.z );
|
|
|
|
|
|
- }
|
|
|
+ idx = idx + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
- } else if ( objGeometry && objGeometry.isBufferGeometry ) {
|
|
|
+ }
|
|
|
|
|
|
- var objPos = objGeometry.attributes.position;
|
|
|
+ } else if ( objGeometry && objGeometry.isBufferGeometry ) {
|
|
|
|
|
|
- var objNorm = objGeometry.attributes.normal;
|
|
|
+ var objPos = objGeometry.attributes.position;
|
|
|
|
|
|
- var idx = 0;
|
|
|
+ var objNorm = objGeometry.attributes.normal;
|
|
|
|
|
|
- // for simplicity, ignore index and drawcalls, and render every normal
|
|
|
+ var idx = 0;
|
|
|
|
|
|
- for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
|
|
|
+ // for simplicity, ignore index and drawcalls, and render every normal
|
|
|
|
|
|
- v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
|
|
|
+ for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
|
|
|
|
|
|
- v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
|
|
|
+ _v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
|
|
|
|
|
|
- v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
|
|
+ _v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
|
|
|
|
|
|
- position.setXYZ( idx, v1.x, v1.y, v1.z );
|
|
|
+ _v2.applyMatrix3( _normalMatrix ).normalize().multiplyScalar( this.size ).add( _v1 );
|
|
|
|
|
|
- idx = idx + 1;
|
|
|
+ position.setXYZ( idx, _v1.x, _v1.y, _v1.z );
|
|
|
|
|
|
- position.setXYZ( idx, v2.x, v2.y, v2.z );
|
|
|
+ idx = idx + 1;
|
|
|
|
|
|
- idx = idx + 1;
|
|
|
+ position.setXYZ( idx, _v2.x, _v2.y, _v2.z );
|
|
|
|
|
|
- }
|
|
|
+ idx = idx + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
- position.needsUpdate = true;
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
+ position.needsUpdate = true;
|
|
|
|
|
|
-}() );
|
|
|
+};
|
|
|
|
|
|
|
|
|
export { VertexNormalsHelper };
|