|
@@ -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.
|
|
|
*
|
|
@@ -148,7 +149,7 @@ THREE.STLLoader.prototype = {
|
|
|
( reader.getUint8( index + 5 ) == 0x3D /*'='*/ ) ) {
|
|
|
|
|
|
hasColors = true;
|
|
|
- colors = [];
|
|
|
+ colors = new Float32Array(faces * 3 * 3);
|
|
|
|
|
|
defaultR = reader.getUint8( index + 6 ) / 255;
|
|
|
defaultG = reader.getUint8( index + 7 ) / 255;
|
|
@@ -164,8 +165,8 @@ THREE.STLLoader.prototype = {
|
|
|
|
|
|
var geometry = new THREE.BufferGeometry();
|
|
|
|
|
|
- var vertices = [];
|
|
|
- var normals = [];
|
|
|
+ var vertices = new Float32Array(faces * 3 * 3);
|
|
|
+ var normals = new Float32Array(faces * 3 * 3);
|
|
|
|
|
|
for ( var face = 0; face < faces; face ++ ) {
|
|
|
|
|
@@ -200,15 +201,19 @@ THREE.STLLoader.prototype = {
|
|
|
|
|
|
var vertexstart = start + i * 12;
|
|
|
|
|
|
- vertices.push( reader.getFloat32( vertexstart, true ) );
|
|
|
- vertices.push( reader.getFloat32( vertexstart + 4, true ) );
|
|
|
- vertices.push( 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.push( normalX, normalY, normalZ );
|
|
|
+ normals[face * 3 * 3] = normalX;
|
|
|
+ normals[(face * 3 * 3) + 1] = normalY;
|
|
|
+ normals[(face * 3 * 3) + 2] = normalZ;
|
|
|
|
|
|
if ( hasColors ) {
|
|
|
|
|
|
- colors.push( r, g, b );
|
|
|
+ colors[face * 3 * 3] = r;
|
|
|
+ colors[(face * 3 * 3) + 1] = g;
|
|
|
+ colors[(face * 3 * 3) + 2] = b;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -216,12 +221,12 @@ THREE.STLLoader.prototype = {
|
|
|
|
|
|
}
|
|
|
|
|
|
- geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( vertices ), 3 ) );
|
|
|
- geometry.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( normals ), 3 ) );
|
|
|
+ geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
|
|
|
+ geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
|
|
|
|
|
|
if ( hasColors ) {
|
|
|
|
|
|
- geometry.addAttribute( 'color', new THREE.BufferAttribute( new Float32Array( colors ), 3 ) );
|
|
|
+ geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
|
|
|
geometry.hasColors = true;
|
|
|
geometry.alpha = alpha;
|
|
|
|