Browse Source

Merge pull request #10819 from Neesnu/feat/normalizeNormals

[BufferGeometry] normalizeNormals
Mr.doob 8 years ago
parent
commit
eca340d40a
1 changed files with 6 additions and 8 deletions
  1. 6 8
      src/core/BufferGeometry.js

+ 6 - 8
src/core/BufferGeometry.js

@@ -814,21 +814,19 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
 
 	normalizeNormals: function () {
 
-		var normals = this.attributes.normal.array;
+		var normals = this.attributes.normal;
 
 		var x, y, z, n;
 
-		for ( var i = 0, il = normals.length; i < il; i += 3 ) {
+		for ( var i = 0, il = normals.count; i < il; i ++ ) {
 
-			x = normals[ i ];
-			y = normals[ i + 1 ];
-			z = normals[ i + 2 ];
+			x = normals.getX( i );
+			y = normals.getY( i );
+			z = normals.getZ( i );
 
 			n = 1.0 / Math.sqrt( x * x + y * y + z * z );
 
-			normals[ i ] *= n;
-			normals[ i + 1 ] *= n;
-			normals[ i + 2 ] *= n;
+			normals.setXYZ(i, x * n, y * n, z * n)
 
 		}