Selaa lähdekoodia

OBJLoader: Only add attributes if necessary.

Mugen87 5 vuotta sitten
vanhempi
commit
c467d7891d
2 muutettua tiedostoa jossa 18 lisäystä ja 14 poistoa
  1. 9 7
      examples/js/loaders/OBJLoader.js
  2. 9 7
      examples/jsm/loaders/OBJLoader.js

+ 9 - 7
examples/js/loaders/OBJLoader.js

@@ -62,7 +62,9 @@ THREE.OBJLoader = ( function () {
 						vertices: [],
 						normals: [],
 						colors: [],
-						uvs: []
+						uvs: [],
+						hasNormalIndices: false,
+						hasUVIndices: false
 					},
 					materials: [],
 					smooth: true,
@@ -340,6 +342,8 @@ THREE.OBJLoader = ( function () {
 
 					this.addNormal( ia, ib, ic );
 
+					this.object.geometry.hasNormalIndices = true;
+
 				}	else {
 
 					this.addFaceNormal( ia, ib, ic );
@@ -358,6 +362,8 @@ THREE.OBJLoader = ( function () {
 
 					this.addUV( ia, ib, ic );
 
+					this.object.geometry.hasUVIndices = true;
+
 				} else {
 
 					// add placeholder values (for inconsistent face definitions)
@@ -705,14 +711,10 @@ THREE.OBJLoader = ( function () {
 
 				buffergeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( geometry.vertices, 3 ) );
 
-				if ( geometry.normals.length > 0 ) {
+				if ( geometry.hasNormalIndices === true ) {
 
 					buffergeometry.setAttribute( 'normal', new THREE.Float32BufferAttribute( geometry.normals, 3 ) );
 
-				} else {
-
-					buffergeometry.computeVertexNormals();
-
 				}
 
 				if ( geometry.colors.length > 0 ) {
@@ -722,7 +724,7 @@ THREE.OBJLoader = ( function () {
 
 				}
 
-				if ( geometry.uvs.length > 0 ) {
+				if ( geometry.hasUVIndices === true ) {
 
 					buffergeometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( geometry.uvs, 2 ) );
 

+ 9 - 7
examples/jsm/loaders/OBJLoader.js

@@ -78,7 +78,9 @@ var OBJLoader = ( function () {
 						vertices: [],
 						normals: [],
 						colors: [],
-						uvs: []
+						uvs: [],
+						hasNormalIndices: false,
+						hasUVIndices: false
 					},
 					materials: [],
 					smooth: true,
@@ -356,6 +358,8 @@ var OBJLoader = ( function () {
 
 					this.addNormal( ia, ib, ic );
 
+					this.object.geometry.hasNormalIndices = true;
+
 				}	else {
 
 					this.addFaceNormal( ia, ib, ic );
@@ -374,6 +378,8 @@ var OBJLoader = ( function () {
 
 					this.addUV( ia, ib, ic );
 
+					this.object.geometry.hasUVIndices = true;
+
 				} else {
 
 					// add placeholder values (for inconsistent face definitions)
@@ -721,14 +727,10 @@ var OBJLoader = ( function () {
 
 				buffergeometry.setAttribute( 'position', new Float32BufferAttribute( geometry.vertices, 3 ) );
 
-				if ( geometry.normals.length > 0 ) {
+				if ( geometry.hasNormalIndices === true ) {
 
 					buffergeometry.setAttribute( 'normal', new Float32BufferAttribute( geometry.normals, 3 ) );
 
-				} else {
-
-					buffergeometry.computeVertexNormals();
-
 				}
 
 				if ( geometry.colors.length > 0 ) {
@@ -738,7 +740,7 @@ var OBJLoader = ( function () {
 
 				}
 
-				if ( geometry.uvs.length > 0 ) {
+				if ( geometry.hasUVIndices === true ) {
 
 					buffergeometry.setAttribute( 'uv', new Float32BufferAttribute( geometry.uvs, 2 ) );