Parcourir la source

Adapted to mrdoob's style

Changed style to make https://zz85.github.io/mrdoobapproves/ happy.
Alberto Passalacqua il y a 6 ans
Parent
commit
9ece2588c2
2 fichiers modifiés avec 72 ajouts et 68 suppressions
  1. 36 34
      examples/js/loaders/STLLoader.js
  2. 36 34
      examples/jsm/loaders/STLLoader.js

+ 36 - 34
examples/js/loaders/STLLoader.js

@@ -28,15 +28,15 @@
  *    material = new THREE.MeshPhongMaterial({ opacity: geometry.alpha, vertexColors: THREE.VertexColors });
  *  } else { .... }
  *  var mesh = new THREE.Mesh( geometry, material );
- * 
- * For ASCII STLs containing multiple solids, each solid is assigned to a different group. 
- * Groups can be used to assign a different color by defining an array of materials with the same length of 
+ *
+ * For ASCII STLs containing multiple solids, each solid is assigned to a different group.
+ * Groups can be used to assign a different color by defining an array of materials with the same length of
  * geometry.groups and passing it to the Mesh constructor:
- * 
+ *
  * var mesh = new THREE.Mesh( geometry, material );
- * 
+ *
  * For example:
- * 
+ *
  *  var materials = [];
  *  var nGeometryGroups = geometry.groups.length;
  *
@@ -132,7 +132,7 @@ THREE.STLLoader.prototype = {
 
 				// If "solid" text is matched to the current offset, declare it to be an ASCII STL.
 
-				if ( matchDataViewAt ( solid, reader, off ) ) return false;
+				if ( matchDataViewAt( solid, reader, off ) ) return false;
 
 			}
 
@@ -226,7 +226,7 @@ THREE.STLLoader.prototype = {
 
 					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 );
@@ -285,74 +285,75 @@ THREE.STLLoader.prototype = {
 			var startVertex = 0;
 			var endVertex = 0;
 
-			while ( ( result = patternSolid.exec(data) ) !== null ) {
+			while ( ( result = patternSolid.exec( data ) ) !== null ) {
 
 				startVertex = endVertex;
 
-				var solid = result[0];
+				var solid = result[ 0 ];
 
 				while ( ( result = patternFace.exec( solid ) ) !== null ) {
 
 					var vertexCountPerFace = 0;
 					var normalCountPerFace = 0;
-		
+
 					var text = result[ 0 ];
-		
+
 					while ( ( result = patternNormal.exec( text ) ) !== null ) {
-		
+
 						normal.x = parseFloat( result[ 1 ] );
 						normal.y = parseFloat( result[ 2 ] );
 						normal.z = parseFloat( result[ 3 ] );
 						normalCountPerFace ++;
-		
+
 					}
-		
+
 					while ( ( result = patternVertex.exec( text ) ) !== null ) {
-		
+
 						vertices.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
 						normals.push( normal.x, normal.y, normal.z );
 						vertexCountPerFace ++;
-						endVertex++;
-		
+						endVertex ++;
+
 					}
-		
+
 					// every face have to own ONE valid normal
-		
+
 					if ( normalCountPerFace !== 1 ) {
-		
+
 						console.error( 'THREE.STLLoader: Something isn\'t right with the normal of face number ' + faceCounter );
-		
+
 					}
-		
+
 					// each face have to own THREE valid vertices
-		
+
 					if ( vertexCountPerFace !== 3 ) {
-		
+
 						console.error( 'THREE.STLLoader: Something isn\'t right with the vertices of face number ' + faceCounter );
-		
+
 					}
-		
+
 					faceCounter ++;
-		
+
 				}
 
 				groupVertexes.push( { startVertex: startVertex, endVertex: endVertex } );
-				groupCount++;
+				groupCount ++;
 
 			}
-				
+
 			geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
 			geometry.addAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
 
 			if ( groupCount > 0 ) {
 
-				for ( var i = 0; i < groupVertexes.length; i++ ) {
+				for ( var i = 0; i < groupVertexes.length; i ++ ) {
+
+					geometry.addGroup( groupVertexes[ i ].startVertex, groupVertexes[ i ].endVertex, i );
 
-					geometry.addGroup( groupVertexes[i].startVertex, groupVertexes[i].endVertex, i );
-					
 				}
+
 			}
-				
+
 			return geometry;
 
 		}
@@ -379,6 +380,7 @@ THREE.STLLoader.prototype = {
 					array_buffer[ i ] = buffer.charCodeAt( i ) & 0xff; // implicitly assumes little-endian
 
 				}
+
 				return array_buffer.buffer || array_buffer;
 
 			} else {

+ 36 - 34
examples/jsm/loaders/STLLoader.js

@@ -28,15 +28,15 @@
  *    material = new THREE.MeshPhongMaterial({ opacity: geometry.alpha, vertexColors: THREE.VertexColors });
  *  } else { .... }
  *  var mesh = new THREE.Mesh( geometry, material );
- * 
- * For ASCII STLs containing multiple solids, each solid is assigned to a different group. 
- * Groups can be used to assign a different color by defining an array of materials with the same length of 
+ *
+ * For ASCII STLs containing multiple solids, each solid is assigned to a different group.
+ * Groups can be used to assign a different color by defining an array of materials with the same length of
  * geometry.groups and passing it to the Mesh constructor:
- * 
+ *
  * var mesh = new THREE.Mesh( geometry, material );
- * 
+ *
  * For example:
- * 
+ *
  *  var materials = [];
  *  var nGeometryGroups = geometry.groups.length;
  *
@@ -142,7 +142,7 @@ STLLoader.prototype = {
 
 				// If "solid" text is matched to the current offset, declare it to be an ASCII STL.
 
-				if ( matchDataViewAt ( solid, reader, off ) ) return false;
+				if ( matchDataViewAt( solid, reader, off ) ) return false;
 
 			}
 
@@ -236,7 +236,7 @@ STLLoader.prototype = {
 
 					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 );
@@ -295,74 +295,75 @@ STLLoader.prototype = {
 			var startVertex = 0;
 			var endVertex = 0;
 
-			while ( ( result = patternSolid.exec( data ) ) !== null) {
+			while ( ( result = patternSolid.exec( data ) ) !== null ) {
 
 				startVertex = endVertex;
 
-				var solid = result[0];
+				var solid = result[ 0 ];
 
 				while ( ( result = patternFace.exec( solid ) ) !== null ) {
 
 					var vertexCountPerFace = 0;
 					var normalCountPerFace = 0;
-		
+
 					var text = result[ 0 ];
-		
+
 					while ( ( result = patternNormal.exec( text ) ) !== null ) {
-		
+
 						normal.x = parseFloat( result[ 1 ] );
 						normal.y = parseFloat( result[ 2 ] );
 						normal.z = parseFloat( result[ 3 ] );
 						normalCountPerFace ++;
-		
+
 					}
-		
+
 					while ( ( result = patternVertex.exec( text ) ) !== null ) {
-		
+
 						vertices.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
 						normals.push( normal.x, normal.y, normal.z );
 						vertexCountPerFace ++;
-						endVertex++;
-		
+						endVertex ++;
+
 					}
-		
+
 					// every face have to own ONE valid normal
-		
+
 					if ( normalCountPerFace !== 1 ) {
-		
+
 						console.error( 'THREE.STLLoader: Something isn\'t right with the normal of face number ' + faceCounter );
-		
+
 					}
-		
+
 					// each face have to own THREE valid vertices
-		
+
 					if ( vertexCountPerFace !== 3 ) {
-		
+
 						console.error( 'THREE.STLLoader: Something isn\'t right with the vertices of face number ' + faceCounter );
-		
+
 					}
-		
+
 					faceCounter ++;
-		
+
 				}
 
 				groupVertexes.push( { startVertex: startVertex, endVertex: endVertex } );
-				groupCount++;
+				groupCount ++;
 
 			}
-				
+
 			geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 			geometry.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 
 			if ( groupCount > 0 ) {
 
-				for ( var i = 0; i < groupVertexes.length; i++ ) {
+				for ( var i = 0; i < groupVertexes.length; i ++ ) {
+
+					geometry.addGroup( groupVertexes[ i ].startVertex, groupVertexes[ i ].endVertex, i );
 
-					geometry.addGroup( groupVertexes[i].startVertex, groupVertexes[i].endVertex, i );
-					
 				}
+
 			}
-				
+
 			return geometry;
 
 		}
@@ -389,6 +390,7 @@ STLLoader.prototype = {
 					array_buffer[ i ] = buffer.charCodeAt( i ) & 0xff; // implicitly assumes little-endian
 
 				}
+
 				return array_buffer.buffer || array_buffer;
 
 			} else {