|
@@ -13,24 +13,34 @@ THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
|
|
|
|
|
|
var width = ( linewidth !== undefined ) ? linewidth : 1;
|
|
|
|
|
|
- var geometry = new THREE.Geometry();
|
|
|
+ //
|
|
|
|
|
|
- var faces = object.geometry.faces;
|
|
|
+ var nNormals = 0;
|
|
|
|
|
|
- for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
|
|
+ var objGeometry = this.object.geometry;
|
|
|
|
|
|
- var face = faces[ i ];
|
|
|
+ if ( objGeometry instanceof THREE.Geometry ) {
|
|
|
|
|
|
- for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
|
|
|
+ nNormals = objGeometry.faces.length * 3;
|
|
|
|
|
|
- geometry.vertices.push( new THREE.Vector3(), new THREE.Vector3() );
|
|
|
+ } else if ( objGeometry instanceof THREE.BufferGeometry ) {
|
|
|
|
|
|
- }
|
|
|
+ nNormals = objGeometry.attributes.normal.count
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
+ var geometry = new THREE.BufferGeometry();
|
|
|
+
|
|
|
+ var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
|
|
|
+
|
|
|
+ geometry.addAttribute( 'position', positions );
|
|
|
+
|
|
|
THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
|
|
|
|
|
|
+ //
|
|
|
+
|
|
|
this.matrixAutoUpdate = false;
|
|
|
|
|
|
this.normalMatrix = new THREE.Matrix3();
|
|
@@ -42,54 +52,92 @@ THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
|
|
|
THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
|
|
|
THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
|
|
|
|
|
|
-THREE.VertexNormalsHelper.prototype.update = ( function ( object ) {
|
|
|
+THREE.VertexNormalsHelper.prototype.update = ( function () {
|
|
|
|
|
|
var v1 = new THREE.Vector3();
|
|
|
+ var v2 = new THREE.Vector3();
|
|
|
|
|
|
- return function( object ) {
|
|
|
+ return function() {
|
|
|
|
|
|
- var keys = [ 'a', 'b', 'c', 'd' ];
|
|
|
+ var keys = [ 'a', 'b', 'c' ];
|
|
|
|
|
|
this.object.updateMatrixWorld( true );
|
|
|
|
|
|
this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
|
|
|
|
|
|
- var vertices = this.geometry.vertices;
|
|
|
+ var matrixWorld = this.object.matrixWorld;
|
|
|
+
|
|
|
+ var position = this.geometry.attributes.position;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ var objGeometry = this.object.geometry;
|
|
|
+
|
|
|
+ if ( objGeometry instanceof THREE.Geometry ) {
|
|
|
+
|
|
|
+ var vertices = objGeometry.vertices;
|
|
|
+
|
|
|
+ var faces = objGeometry.faces;
|
|
|
+
|
|
|
+ var idx = 0;
|
|
|
+
|
|
|
+ for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
|
|
|
|
|
- var verts = this.object.geometry.vertices;
|
|
|
+ var face = faces[ i ];
|
|
|
|
|
|
- var faces = this.object.geometry.faces;
|
|
|
+ for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
|
|
|
|
|
|
- var worldMatrix = this.object.matrixWorld;
|
|
|
+ var vertex = vertices[ face[ keys[ j ] ] ];
|
|
|
|
|
|
- var idx = 0;
|
|
|
+ var normal = face.vertexNormals[ j ];
|
|
|
|
|
|
- for ( var i = 0, l = faces.length; i < l; i ++ ) {
|
|
|
+ v1.copy( vertex ).applyMatrix4( matrixWorld );
|
|
|
|
|
|
- var face = faces[ i ];
|
|
|
+ v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
|
|
|
|
|
- for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
|
|
|
+ position.setXYZ( idx, v1.x, v1.y, v1.z );
|
|
|
|
|
|
- var vertexId = face[ keys[ j ] ];
|
|
|
- var vertex = verts[ vertexId ];
|
|
|
+ idx = idx + 1;
|
|
|
|
|
|
- var normal = face.vertexNormals[ j ];
|
|
|
+ position.setXYZ( idx, v2.x, v2.y, v2.z );
|
|
|
|
|
|
- vertices[ idx ].copy( vertex ).applyMatrix4( worldMatrix );
|
|
|
+ idx = idx + 1;
|
|
|
|
|
|
- v1.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size );
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if ( objGeometry instanceof THREE.BufferGeometry ) {
|
|
|
+
|
|
|
+ var objPos = objGeometry.attributes.position;
|
|
|
+
|
|
|
+ var objNorm = objGeometry.attributes.normal;
|
|
|
+
|
|
|
+ var idx = 0;
|
|
|
+
|
|
|
+ // for simplicity, ignore index and drawcalls, and render every normal
|
|
|
+
|
|
|
+ for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
|
|
|
+
|
|
|
+ v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
|
|
|
+
|
|
|
+ v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
|
|
|
+
|
|
|
+ v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
|
|
|
+
|
|
|
+ position.setXYZ( idx, v1.x, v1.y, v1.z );
|
|
|
|
|
|
- v1.add( vertices[ idx ] );
|
|
|
idx = idx + 1;
|
|
|
|
|
|
- vertices[ idx ].copy( v1 );
|
|
|
+ position.setXYZ( idx, v2.x, v2.y, v2.z );
|
|
|
+
|
|
|
idx = idx + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.geometry.verticesNeedUpdate = true;
|
|
|
+ position.needsUpdate = true;
|
|
|
|
|
|
return this;
|
|
|
|