Browse Source

JSONLoader optimisations.

Mr.doob 12 năm trước cách đây
mục cha
commit
a41c0e1ed0
1 tập tin đã thay đổi với 12 bổ sung18 xóa
  1. 12 18
      src/loaders/JSONLoader.js

+ 12 - 18
src/loaders/JSONLoader.js

@@ -274,13 +274,11 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 
 
 				normalIndex = faces[ offset ++ ] * 3;
 				normalIndex = faces[ offset ++ ] * 3;
 
 
-				normal = new THREE.Vector3();
-
-				normal.x = normals[ normalIndex ++ ];
-				normal.y = normals[ normalIndex ++ ];
-				normal.z = normals[ normalIndex ];
-
-				face.normal = normal;
+				face.normal.set(
+					normals[ normalIndex ++ ],
+					normals[ normalIndex ++ ],
+					normals[ normalIndex ]
+				);
 
 
 			}
 			}
 
 
@@ -290,11 +288,11 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 
 
 					normalIndex = faces[ offset ++ ] * 3;
 					normalIndex = faces[ offset ++ ] * 3;
 
 
-					normal = new THREE.Vector3();
-
-					normal.x = normals[ normalIndex ++ ];
-					normal.y = normals[ normalIndex ++ ];
-					normal.z = normals[ normalIndex ];
+					normal = new THREE.Vector3(
+						normals[ normalIndex ++ ],
+						normals[ normalIndex ++ ],
+						normals[ normalIndex ]
+					);
 
 
 					face.vertexNormals.push( normal );
 					face.vertexNormals.push( normal );
 
 
@@ -306,9 +304,7 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 			if ( hasFaceColor ) {
 			if ( hasFaceColor ) {
 
 
 				colorIndex = faces[ offset ++ ];
 				colorIndex = faces[ offset ++ ];
-
-				color = new THREE.Color( colors[ colorIndex ] );
-				face.color = color;
+				face.color.setHex( colors[ colorIndex ] );
 
 
 			}
 			}
 
 
@@ -318,9 +314,7 @@ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
 				for ( i = 0; i < nVertices; i++ ) {
 				for ( i = 0; i < nVertices; i++ ) {
 
 
 					colorIndex = faces[ offset ++ ];
 					colorIndex = faces[ offset ++ ];
-
-					color = new THREE.Color( colors[ colorIndex ] );
-					face.vertexColors.push( color );
+					face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
 
 
 				}
 				}