|
@@ -5952,7 +5952,7 @@ THREE.BufferGeometry.prototype = {
|
|
|
|
|
|
computeVertexNormals: function () {
|
|
computeVertexNormals: function () {
|
|
|
|
|
|
- if ( this.attributes[ "position" ] && this.attributes[ "index" ] ) {
|
|
|
|
|
|
+ if ( this.attributes[ "position" ] ) {
|
|
|
|
|
|
var i, il;
|
|
var i, il;
|
|
var j, jl;
|
|
var j, jl;
|
|
@@ -5981,9 +5981,6 @@ THREE.BufferGeometry.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var offsets = this.offsets;
|
|
|
|
-
|
|
|
|
- var indices = this.attributes[ "index" ].array;
|
|
|
|
var positions = this.attributes[ "position" ].array;
|
|
var positions = this.attributes[ "position" ].array;
|
|
var normals = this.attributes[ "normal" ].array;
|
|
var normals = this.attributes[ "normal" ].array;
|
|
|
|
|
|
@@ -5996,48 +5993,97 @@ THREE.BufferGeometry.prototype = {
|
|
cb = new THREE.Vector3(),
|
|
cb = new THREE.Vector3(),
|
|
ab = new THREE.Vector3();
|
|
ab = new THREE.Vector3();
|
|
|
|
|
|
- for ( j = 0, jl = offsets.length; j < jl; ++ j ) {
|
|
|
|
|
|
+ // indexed elements
|
|
|
|
+
|
|
|
|
+ if ( this.attributes[ "index" ] ) {
|
|
|
|
+
|
|
|
|
+ var indices = this.attributes[ "index" ].array;
|
|
|
|
+
|
|
|
|
+ var offsets = this.offsets;
|
|
|
|
+
|
|
|
|
+ for ( j = 0, jl = offsets.length; j < jl; ++ j ) {
|
|
|
|
+
|
|
|
|
+ var start = offsets[ j ].start;
|
|
|
|
+ var count = offsets[ j ].count;
|
|
|
|
+ var index = offsets[ j ].index;
|
|
|
|
+
|
|
|
|
+ for ( i = start, il = start + count; i < il; i += 3 ) {
|
|
|
|
+
|
|
|
|
+ vA = index + indices[ i ];
|
|
|
|
+ vB = index + indices[ i + 1 ];
|
|
|
|
+ vC = index + indices[ i + 2 ];
|
|
|
|
+
|
|
|
|
+ x = positions[ vA * 3 ];
|
|
|
|
+ y = positions[ vA * 3 + 1 ];
|
|
|
|
+ z = positions[ vA * 3 + 2 ];
|
|
|
|
+ pA.set( x, y, z );
|
|
|
|
+
|
|
|
|
+ x = positions[ vB * 3 ];
|
|
|
|
+ y = positions[ vB * 3 + 1 ];
|
|
|
|
+ z = positions[ vB * 3 + 2 ];
|
|
|
|
+ pB.set( x, y, z );
|
|
|
|
|
|
- var start = offsets[ j ].start;
|
|
|
|
- var count = offsets[ j ].count;
|
|
|
|
- var index = offsets[ j ].index;
|
|
|
|
|
|
+ x = positions[ vC * 3 ];
|
|
|
|
+ y = positions[ vC * 3 + 1 ];
|
|
|
|
+ z = positions[ vC * 3 + 2 ];
|
|
|
|
+ pC.set( x, y, z );
|
|
|
|
|
|
- for ( i = start, il = start + count; i < il; i += 3 ) {
|
|
|
|
|
|
+ cb.sub( pC, pB );
|
|
|
|
+ ab.sub( pA, pB );
|
|
|
|
+ cb.crossSelf( ab );
|
|
|
|
+
|
|
|
|
+ normals[ vA * 3 ] += cb.x;
|
|
|
|
+ normals[ vA * 3 + 1 ] += cb.y;
|
|
|
|
+ normals[ vA * 3 + 2 ] += cb.z;
|
|
|
|
+
|
|
|
|
+ normals[ vB * 3 ] += cb.x;
|
|
|
|
+ normals[ vB * 3 + 1 ] += cb.y;
|
|
|
|
+ normals[ vB * 3 + 2 ] += cb.z;
|
|
|
|
+
|
|
|
|
+ normals[ vC * 3 ] += cb.x;
|
|
|
|
+ normals[ vC * 3 + 1 ] += cb.y;
|
|
|
|
+ normals[ vC * 3 + 2 ] += cb.z;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // non-indexed elements (unconnected triangle soup)
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
|
|
- vA = index + indices[ i ];
|
|
|
|
- vB = index + indices[ i + 1 ];
|
|
|
|
- vC = index + indices[ i + 2 ];
|
|
|
|
|
|
+ for ( i = 0, il = positions.length; i < il; i += 9 ) {
|
|
|
|
|
|
- x = positions[ vA * 3 ];
|
|
|
|
- y = positions[ vA * 3 + 1 ];
|
|
|
|
- z = positions[ vA * 3 + 2 ];
|
|
|
|
|
|
+ x = positions[ i ];
|
|
|
|
+ y = positions[ i + 1 ];
|
|
|
|
+ z = positions[ i + 2 ];
|
|
pA.set( x, y, z );
|
|
pA.set( x, y, z );
|
|
|
|
|
|
- x = positions[ vB * 3 ];
|
|
|
|
- y = positions[ vB * 3 + 1 ];
|
|
|
|
- z = positions[ vB * 3 + 2 ];
|
|
|
|
|
|
+ x = positions[ i + 3 ];
|
|
|
|
+ y = positions[ i + 4 ];
|
|
|
|
+ z = positions[ i + 5 ];
|
|
pB.set( x, y, z );
|
|
pB.set( x, y, z );
|
|
|
|
|
|
- x = positions[ vC * 3 ];
|
|
|
|
- y = positions[ vC * 3 + 1 ];
|
|
|
|
- z = positions[ vC * 3 + 2 ];
|
|
|
|
|
|
+ x = positions[ i + 6 ];
|
|
|
|
+ y = positions[ i + 7 ];
|
|
|
|
+ z = positions[ i + 8 ];
|
|
pC.set( x, y, z );
|
|
pC.set( x, y, z );
|
|
|
|
|
|
cb.sub( pC, pB );
|
|
cb.sub( pC, pB );
|
|
ab.sub( pA, pB );
|
|
ab.sub( pA, pB );
|
|
cb.crossSelf( ab );
|
|
cb.crossSelf( ab );
|
|
|
|
|
|
- normals[ vA * 3 ] += cb.x;
|
|
|
|
- normals[ vA * 3 + 1 ] += cb.y;
|
|
|
|
- normals[ vA * 3 + 2 ] += cb.z;
|
|
|
|
|
|
+ normals[ i ] = cb.x;
|
|
|
|
+ normals[ i + 1 ] = cb.y;
|
|
|
|
+ normals[ i + 2 ] = cb.z;
|
|
|
|
|
|
- normals[ vB * 3 ] += cb.x;
|
|
|
|
- normals[ vB * 3 + 1 ] += cb.y;
|
|
|
|
- normals[ vB * 3 + 2 ] += cb.z;
|
|
|
|
|
|
+ normals[ i + 3 ] = cb.x;
|
|
|
|
+ normals[ i + 4 ] = cb.y;
|
|
|
|
+ normals[ i + 5 ] = cb.z;
|
|
|
|
|
|
- normals[ vC * 3 ] += cb.x;
|
|
|
|
- normals[ vC * 3 + 1 ] += cb.y;
|
|
|
|
- normals[ vC * 3 + 2 ] += cb.z;
|
|
|
|
|
|
+ normals[ i + 6 ] = cb.x;
|
|
|
|
+ normals[ i + 7 ] = cb.y;
|
|
|
|
+ normals[ i + 8 ] = cb.z;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|