Ver código fonte

Fix attribute array indexing

Justin 6 anos atrás
pai
commit
dc20e58d5a
2 arquivos alterados com 23 adições e 20 exclusões
  1. 11 10
      examples/js/loaders/STLLoader.js
  2. 12 10
      examples/jsm/loaders/STLLoader.js

+ 11 - 10
examples/js/loaders/STLLoader.js

@@ -200,20 +200,21 @@ THREE.STLLoader.prototype = {
 				for ( var i = 1; i <= 3; i ++ ) {
 
 					var vertexstart = start + i * 12;
+					var componentIdx = (face * 3 * 3) + ((i - 1) * 3);
+					
+					vertices[componentIdx] = reader.getFloat32( vertexstart, true );
+					vertices[componentIdx + 1] = reader.getFloat32( vertexstart + 4, true );
+					vertices[componentIdx + 2] = reader.getFloat32( vertexstart + 8, true );
 
-					vertices[face * 3 * 3] = reader.getFloat32( vertexstart, true );
-					vertices[(face * 3 * 3) + 1] = reader.getFloat32( vertexstart + 4, true );
-					vertices[(face * 3 * 3) + 2] = reader.getFloat32( vertexstart + 8, true );
-
-					normals[face * 3 * 3] = normalX;
-					normals[(face * 3 * 3) + 1] = normalY;
-					normals[(face * 3 * 3) + 2] = normalZ;
+					normals[componentIdx] = normalX;
+					normals[componentIdx + 1] = normalY;
+					normals[componentIdx + 2] = normalZ;
 
 					if ( hasColors ) {
 
-						colors[face * 3 * 3] = r;
-						colors[(face * 3 * 3) + 1] = g;
-						colors[(face * 3 * 3) + 2] = b;
+						colors[componentIdx] = r;
+						colors[componentIdx + 1] = g;
+						colors[componentIdx + 2] = b;
 
 					}
 

+ 12 - 10
examples/jsm/loaders/STLLoader.js

@@ -3,6 +3,7 @@
  * @author mrdoob / http://mrdoob.com/
  * @author gero3 / https://github.com/gero3
  * @author Mugen87 / https://github.com/Mugen87
+ * @author neverhood311 / https://github.com/neverhood311
  *
  * Description: A THREE loader for STL ASCII files, as created by Solidworks and other CAD programs.
  *
@@ -209,20 +210,21 @@ STLLoader.prototype = {
 				for ( var i = 1; i <= 3; i ++ ) {
 
 					var vertexstart = start + i * 12;
+					var componentIdx = (face * 3 * 3) + ((i - 1) * 3);
+					
+					vertices[componentIdx] = reader.getFloat32( vertexstart, true );
+					vertices[componentIdx + 1] = reader.getFloat32( vertexstart + 4, true );
+					vertices[componentIdx + 2] = reader.getFloat32( vertexstart + 8, true );
 
-					vertices[face * 3 * 3] = reader.getFloat32( vertexstart, true );
-					vertices[(face * 3 * 3) + 1] = reader.getFloat32( vertexstart + 4, true );
-					vertices[(face * 3 * 3) + 2] = reader.getFloat32( vertexstart + 8, true );
-
-					normals[face * 3 * 3] = normalX;
-					normals[(face * 3 * 3) + 1] = normalY;
-					normals[(face * 3 * 3) + 2] = normalZ;
+					normals[componentIdx] = normalX;
+					normals[componentIdx + 1] = normalY;
+					normals[componentIdx + 2] = normalZ;
 
 					if ( hasColors ) {
 
-						colors[face * 3 * 3] = r;
-						colors[(face * 3 * 3) + 1] = g;
-						colors[(face * 3 * 3) + 2] = b;
+						colors[componentIdx] = r;
+						colors[componentIdx + 1] = g;
+						colors[componentIdx + 2] = b;
 
 					}