Przeglądaj źródła

triangulate quads on load, support mesh with no normals

Virtulous 8 lat temu
rodzic
commit
9c9decc7d1
1 zmienionych plików z 25 dodań i 3 usunięć
  1. 25 3
      examples/js/loaders/AssimpLoader.js

+ 25 - 3
examples/js/loaders/AssimpLoader.js

@@ -650,7 +650,7 @@
 				mat = new THREE.MeshLambertMaterial();
 			geometry.setIndex( new THREE.BufferAttribute( new Uint32Array( this.mIndexArray ), 1 ) );
 			geometry.addAttribute( 'position', new THREE.BufferAttribute( this.mVertexBuffer, 3 ) );
-			if ( this.mNormalBuffer.length > 0 )
+			if ( this.mNormalBuffer && this.mNormalBuffer.length > 0 )
 				geometry.addAttribute( 'normal', new THREE.BufferAttribute( this.mNormalBuffer, 3 ) );
 			if ( this.mColorBuffer && this.mColorBuffer.length > 0 )
 				geometry.addAttribute( 'color', new THREE.BufferAttribute( this.mColorBuffer, 4 ) );
@@ -1850,10 +1850,32 @@
 
 					}
 
-					mesh.mIndexArray.push( f.mIndices[ a ] );
+					
 
 				}
 
+				if(f.mNumIndices === 3) {
+
+					mesh.mIndexArray.push( f.mIndices[ 0 ] );
+					mesh.mIndexArray.push( f.mIndices[ 1 ] );
+					mesh.mIndexArray.push( f.mIndices[ 2 ] );
+
+				}
+				else if(f.mNumIndices === 4) {
+
+					mesh.mIndexArray.push( f.mIndices[ 0 ] );
+					mesh.mIndexArray.push( f.mIndices[ 1 ] );
+					mesh.mIndexArray.push( f.mIndices[ 2 ] );
+					mesh.mIndexArray.push( f.mIndices[ 2 ] );
+					mesh.mIndexArray.push( f.mIndices[ 3 ] );
+					mesh.mIndexArray.push( f.mIndices[ 0 ] );
+
+				} else {
+					throw ( new Error( "Sorry, can't currently triangulate polys. Use the triangulate preprocessor in Assimp." ))
+				}
+
+
+
 			}
 
 		}
@@ -2326,4 +2348,4 @@
 
 	THREE.AssimpLoader = AssimpLoader;
 
-} )();
+} )();