Browse Source

Simplified BinaryLoader.

Mr.doob 11 years ago
parent
commit
d29a548241
1 changed files with 64 additions and 107 deletions
  1. 64 107
      examples/js/loaders/BinaryLoader.js

+ 64 - 107
examples/js/loaders/BinaryLoader.js

@@ -341,7 +341,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 				y = coordArray[ i * 3 + 1 ];
 				y = coordArray[ i * 3 + 1 ];
 				z = coordArray[ i * 3 + 2 ];
 				z = coordArray[ i * 3 + 2 ];
 
 
-				vertex( scope, x, y, z );
+				scope.vertices.push( new THREE.Vector3( x, y, z ) );
 
 
 			}
 			}
 
 
@@ -421,7 +421,11 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 				u3 = uvs[ uvc*2 ];
 				u3 = uvs[ uvc*2 ];
 				v3 = uvs[ uvc*2 + 1 ];
 				v3 = uvs[ uvc*2 + 1 ];
 
 
-				uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 );
+				scope.faceVertexUvs[ 0 ].push( [
+					new THREE.Vector2( u1, v1 ),
+					new THREE.Vector2( u2, v2 ),
+					new THREE.Vector2( u3, v3 )
+				] );
 
 
 			}
 			}
 
 
@@ -452,7 +456,17 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 				u4 = uvs[ uvd*2 ];
 				u4 = uvs[ uvd*2 ];
 				v4 = uvs[ uvd*2 + 1 ];
 				v4 = uvs[ uvd*2 + 1 ];
 
 
-				uv4( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3, u4, v4 );
+				scope.faceVertexUvs[ 0 ].push( [
+					new THREE.Vector2( u1, v1 ),
+					new THREE.Vector2( u2, v2 ),
+					new THREE.Vector2( u4, v4 )
+				] );
+
+				scope.faceVertexUvs[ 0 ].push( [
+					new THREE.Vector2( u2, v2 ),
+					new THREE.Vector2( u3, v3 ),
+					new THREE.Vector2( u4, v4 )
+				] );
 
 
 			}
 			}
 
 
@@ -473,7 +487,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 
 				m = materialIndexBuffer[ i ];
 				m = materialIndexBuffer[ i ];
 
 
-				f3( scope, a, b, c, m );
+				scope.faces.push( new THREE.Face3( a, b, c, null, null, m ) );
 
 
 			}
 			}
 
 
@@ -495,7 +509,8 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 
 				m = materialIndexBuffer[ i ];
 				m = materialIndexBuffer[ i ];
 
 
-				f4( scope, a, b, c, d, m );
+				scope.faces.push( new THREE.Face3( a, b, d, null, null, m ) );
+				scope.faces.push( new THREE.Face3( b, c, d, null, null, m ) );
 
 
 			}
 			}
 
 
@@ -522,7 +537,23 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 
 				m = materialIndexBuffer[ i ];
 				m = materialIndexBuffer[ i ];
 
 
-				f3n( scope, normals, a, b, c, m, na, nb, nc );
+				var nax = normals[ na*3     ],
+					nay = normals[ na*3 + 1 ],
+					naz = normals[ na*3 + 2 ],
+
+					nbx = normals[ nb*3     ],
+					nby = normals[ nb*3 + 1 ],
+					nbz = normals[ nb*3 + 2 ],
+
+					ncx = normals[ nc*3     ],
+					ncy = normals[ nc*3 + 1 ],
+					ncz = normals[ nc*3 + 2 ];
+
+				scope.faces.push( new THREE.Face3( a, b, c, [
+					new THREE.Vector3( nax, nay, naz ),
+					new THREE.Vector3( nbx, nby, nbz ),
+					new THREE.Vector3( ncx, ncy, ncz )
+				], null, m ) );
 
 
 			}
 			}
 
 
@@ -551,7 +582,33 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 
 				m = materialIndexBuffer[ i ];
 				m = materialIndexBuffer[ i ];
 
 
-				f4n( scope, normals, a, b, c, d, m, na, nb, nc, nd );
+				var nax = normals[ na*3     ],
+					nay = normals[ na*3 + 1 ],
+					naz = normals[ na*3 + 2 ],
+
+					nbx = normals[ nb*3     ],
+					nby = normals[ nb*3 + 1 ],
+					nbz = normals[ nb*3 + 2 ],
+
+					ncx = normals[ nc*3     ],
+					ncy = normals[ nc*3 + 1 ],
+					ncz = normals[ nc*3 + 2 ],
+
+					ndx = normals[ nd*3     ],
+					ndy = normals[ nd*3 + 1 ],
+					ndz = normals[ nd*3 + 2 ];
+
+				scope.faces.push( new THREE.Face3( a, b, d, [
+					new THREE.Vector3( nax, nay, naz ),
+					new THREE.Vector3( nbx, nby, nbz ),
+					new THREE.Vector3( ndx, ndy, ndz )
+				], null, m ) );
+
+				scope.faces.push( new THREE.Face3( b, c, d, [
+					new THREE.Vector3( nbx, nby, nbz ),
+					new THREE.Vector3( ncx, ncy, ncz ),
+					new THREE.Vector3( ndx, ndy, ndz )
+				], null, m ) );
 
 
 			}
 			}
 
 
@@ -681,106 +738,6 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
 
 
 	};
 	};
 
 
-	function vertex ( scope, x, y, z ) {
-
-		scope.vertices.push( new THREE.Vector3( x, y, z ) );
-
-	};
-
-	function f3 ( scope, a, b, c, mi ) {
-
-		scope.faces.push( new THREE.Face3( a, b, c, null, null, mi ) );
-
-	};
-
-	function f4 ( scope, a, b, c, d, mi ) {
-
-		scope.faces.push( new THREE.Face3( a, b, d, null, null, mi ) );
-		scope.faces.push( new THREE.Face3( b, c, d, null, null, mi ) );
-
-	};
-
-	function f3n ( scope, normals, a, b, c, mi, na, nb, nc ) {
-
-		var nax = normals[ na*3     ],
-			nay = normals[ na*3 + 1 ],
-			naz = normals[ na*3 + 2 ],
-
-			nbx = normals[ nb*3     ],
-			nby = normals[ nb*3 + 1 ],
-			nbz = normals[ nb*3 + 2 ],
-
-			ncx = normals[ nc*3     ],
-			ncy = normals[ nc*3 + 1 ],
-			ncz = normals[ nc*3 + 2 ];
-
-		scope.faces.push( new THREE.Face3( a, b, c,
-						  [new THREE.Vector3( nax, nay, naz ),
-						   new THREE.Vector3( nbx, nby, nbz ),
-						   new THREE.Vector3( ncx, ncy, ncz )],
-						  null,
-						  mi ) );
-
-	};
-
-	function f4n ( scope, normals, a, b, c, d, mi, na, nb, nc, nd ) {
-
-		var nax = normals[ na*3     ],
-			nay = normals[ na*3 + 1 ],
-			naz = normals[ na*3 + 2 ],
-
-			nbx = normals[ nb*3     ],
-			nby = normals[ nb*3 + 1 ],
-			nbz = normals[ nb*3 + 2 ],
-
-			ncx = normals[ nc*3     ],
-			ncy = normals[ nc*3 + 1 ],
-			ncz = normals[ nc*3 + 2 ],
-
-			ndx = normals[ nd*3     ],
-			ndy = normals[ nd*3 + 1 ],
-			ndz = normals[ nd*3 + 2 ];
-
-		scope.faces.push( new THREE.Face3( a, b, d, [
-			new THREE.Vector3( nax, nay, naz ),
-			new THREE.Vector3( nbx, nby, nbz ),
-			new THREE.Vector3( ndx, ndy, ndz )
-		], null, mi ) );
-
-		scope.faces.push( new THREE.Face3( b, c, d, [
-			new THREE.Vector3( nbx, nby, nbz ),
-			new THREE.Vector3( ncx, ncy, ncz ),
-			new THREE.Vector3( ndx, ndy, ndz )
-		], null, mi ) );
-
-	};
-
-	function uv3 ( where, u1, v1, u2, v2, u3, v3 ) {
-
-		where.push( [
-			new THREE.Vector2( u1, v1 ),
-			new THREE.Vector2( u2, v2 ),
-			new THREE.Vector2( u3, v3 )
-		] );
-
-	};
-
-	function uv4 ( where, u1, v1, u2, v2, u3, v3, u4, v4 ) {
-
-		where.push( [
-			new THREE.Vector2( u1, v1 ),
-			new THREE.Vector2( u2, v2 ),
-			new THREE.Vector2( u4, v4 )
-		] );
-
-		where.push( [
-			new THREE.Vector2( u2, v2 ),
-			new THREE.Vector2( u3, v3 ),
-			new THREE.Vector2( u4, v4 )
-		] );
-
-	};
-
 	Model.prototype = Object.create( THREE.Geometry.prototype );
 	Model.prototype = Object.create( THREE.Geometry.prototype );
 
 
 	var geometry = new Model( texturePath );
 	var geometry = new Model( texturePath );