소스 검색

PlYLoader: Added support for uvs defined on face level

Mugen87 6 년 전
부모
커밋
b162c11188
1개의 변경된 파일18개의 추가작업 그리고 0개의 파일을 삭제
  1. 18 0
      examples/js/loaders/PLYLoader.js

+ 18 - 0
examples/js/loaders/PLYLoader.js

@@ -236,6 +236,7 @@ THREE.PLYLoader.prototype = {
 				vertices: [],
 				normals: [],
 				uvs: [],
+				faceVertexUvs: [],
 				colors: []
 			};
 
@@ -316,6 +317,13 @@ THREE.PLYLoader.prototype = {
 
 			}
 
+			if ( buffer.faceVertexUvs.length > 0 ) {
+
+				geometry = geometry.toNonIndexed();
+				geometry.addAttribute( 'uv', new THREE.Float32BufferAttribute( buffer.faceVertexUvs, 2 ) );
+
+			}
+
 			geometry.computeBoundingSphere();
 
 			return geometry;
@@ -349,11 +357,20 @@ THREE.PLYLoader.prototype = {
 			} else if ( elementName === 'face' ) {
 
 				var vertex_indices = element.vertex_indices || element.vertex_index; // issue #9338
+				var texcoord = element.texcoord;
 
 				if ( vertex_indices.length === 3 ) {
 
 					buffer.indices.push( vertex_indices[ 0 ], vertex_indices[ 1 ], vertex_indices[ 2 ] );
 
+					if ( texcoord && texcoord.length === 6 ) {
+
+						buffer.faceVertexUvs.push( texcoord[ 0 ], texcoord[ 1 ] );
+						buffer.faceVertexUvs.push( texcoord[ 2 ], texcoord[ 3 ] );
+						buffer.faceVertexUvs.push( texcoord[ 4 ], texcoord[ 5 ] );
+
+					}
+
 				} else if ( vertex_indices.length === 4 ) {
 
 					buffer.indices.push( vertex_indices[ 0 ], vertex_indices[ 1 ], vertex_indices[ 3 ] );
@@ -429,6 +446,7 @@ THREE.PLYLoader.prototype = {
 				vertices: [],
 				normals: [],
 				uvs: [],
+				faceVertexUvs: [],
 				colors: []
 			};