浏览代码

3MFLoader: Better handle face colors.

Mugen87 5 年之前
父节点
当前提交
4b9a508af0
共有 3 个文件被更改,包括 52 次插入36 次删除
  1. 26 18
      examples/js/loaders/3MFLoader.js
  2. 26 18
      examples/jsm/loaders/3MFLoader.js
  3. 二进制
      examples/models/3mf/facecolors.3mf

+ 26 - 18
examples/js/loaders/3MFLoader.js

@@ -937,31 +937,39 @@ THREE.ThreeMFLoader.prototype = Object.assign( Object.create( THREE.Loader.proto
 
 
 				var triangleProperty = triangleProperties[ i ];
 				var triangleProperty = triangleProperties[ i ];
 
 
-				positionData.push( vertices[ ( triangleProperty.v1 * 3 ) + 0 ] );
-				positionData.push( vertices[ ( triangleProperty.v1 * 3 ) + 1 ] );
-				positionData.push( vertices[ ( triangleProperty.v1 * 3 ) + 2 ] );
+				var v1 = triangleProperty.v1;
+				var v2 = triangleProperty.v2;
+				var v3 = triangleProperty.v3;
 
 
-				positionData.push( vertices[ ( triangleProperty.v2 * 3 ) + 0 ] );
-				positionData.push( vertices[ ( triangleProperty.v2 * 3 ) + 1 ] );
-				positionData.push( vertices[ ( triangleProperty.v2 * 3 ) + 2 ] );
+				positionData.push( vertices[ ( v1 * 3 ) + 0 ] );
+				positionData.push( vertices[ ( v1 * 3 ) + 1 ] );
+				positionData.push( vertices[ ( v1 * 3 ) + 2 ] );
 
 
-				positionData.push( vertices[ ( triangleProperty.v3 * 3 ) + 0 ] );
-				positionData.push( vertices[ ( triangleProperty.v3 * 3 ) + 1 ] );
-				positionData.push( vertices[ ( triangleProperty.v3 * 3 ) + 2 ] );
+				positionData.push( vertices[ ( v2 * 3 ) + 0 ] );
+				positionData.push( vertices[ ( v2 * 3 ) + 1 ] );
+				positionData.push( vertices[ ( v2 * 3 ) + 2 ] );
+
+				positionData.push( vertices[ ( v3 * 3 ) + 0 ] );
+				positionData.push( vertices[ ( v3 * 3 ) + 1 ] );
+				positionData.push( vertices[ ( v3 * 3 ) + 2 ] );
 
 
 				//
 				//
 
 
-				colorData.push( colors[ ( triangleProperty.p1 * 3 ) + 0 ] );
-				colorData.push( colors[ ( triangleProperty.p1 * 3 ) + 1 ] );
-				colorData.push( colors[ ( triangleProperty.p1 * 3 ) + 3 ] );
+				var p1 = triangleProperty.p1;
+				var p2 = triangleProperty.p2;
+				var p3 = triangleProperty.p3;
+
+				colorData.push( colors[ ( p1 * 3 ) + 0 ] );
+				colorData.push( colors[ ( p1 * 3 ) + 1 ] );
+				colorData.push( colors[ ( p1 * 3 ) + 3 ] );
 
 
-				colorData.push( colors[ ( triangleProperty.p2 * 3 ) + 0 ] );
-				colorData.push( colors[ ( triangleProperty.p2 * 3 ) + 1 ] );
-				colorData.push( colors[ ( triangleProperty.p2 * 3 ) + 2 ] );
+				colorData.push( colors[ ( ( p2 || p1 ) * 3 ) + 0 ] );
+				colorData.push( colors[ ( ( p2 || p1 ) * 3 ) + 1 ] );
+				colorData.push( colors[ ( ( p2 || p1 ) * 3 ) + 2 ] );
 
 
-				colorData.push( colors[ ( triangleProperty.p3 * 3 ) + 0 ] );
-				colorData.push( colors[ ( triangleProperty.p3 * 3 ) + 1 ] );
-				colorData.push( colors[ ( triangleProperty.p3 * 3 ) + 2 ] );
+				colorData.push( colors[ ( ( p3 || p1 ) * 3 ) + 0 ] );
+				colorData.push( colors[ ( ( p3 || p1 ) * 3 ) + 1 ] );
+				colorData.push( colors[ ( ( p3 || p1 ) * 3 ) + 2 ] );
 
 
 			}
 			}
 
 

+ 26 - 18
examples/jsm/loaders/3MFLoader.js

@@ -960,31 +960,39 @@ ThreeMFLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 
 				var triangleProperty = triangleProperties[ i ];
 				var triangleProperty = triangleProperties[ i ];
 
 
-				positionData.push( vertices[ ( triangleProperty.v1 * 3 ) + 0 ] );
-				positionData.push( vertices[ ( triangleProperty.v1 * 3 ) + 1 ] );
-				positionData.push( vertices[ ( triangleProperty.v1 * 3 ) + 2 ] );
+				var v1 = triangleProperty.v1;
+				var v2 = triangleProperty.v2;
+				var v3 = triangleProperty.v3;
 
 
-				positionData.push( vertices[ ( triangleProperty.v2 * 3 ) + 0 ] );
-				positionData.push( vertices[ ( triangleProperty.v2 * 3 ) + 1 ] );
-				positionData.push( vertices[ ( triangleProperty.v2 * 3 ) + 2 ] );
+				positionData.push( vertices[ ( v1 * 3 ) + 0 ] );
+				positionData.push( vertices[ ( v1 * 3 ) + 1 ] );
+				positionData.push( vertices[ ( v1 * 3 ) + 2 ] );
 
 
-				positionData.push( vertices[ ( triangleProperty.v3 * 3 ) + 0 ] );
-				positionData.push( vertices[ ( triangleProperty.v3 * 3 ) + 1 ] );
-				positionData.push( vertices[ ( triangleProperty.v3 * 3 ) + 2 ] );
+				positionData.push( vertices[ ( v2 * 3 ) + 0 ] );
+				positionData.push( vertices[ ( v2 * 3 ) + 1 ] );
+				positionData.push( vertices[ ( v2 * 3 ) + 2 ] );
+
+				positionData.push( vertices[ ( v3 * 3 ) + 0 ] );
+				positionData.push( vertices[ ( v3 * 3 ) + 1 ] );
+				positionData.push( vertices[ ( v3 * 3 ) + 2 ] );
 
 
 				//
 				//
 
 
-				colorData.push( colors[ ( triangleProperty.p1 * 3 ) + 0 ] );
-				colorData.push( colors[ ( triangleProperty.p1 * 3 ) + 1 ] );
-				colorData.push( colors[ ( triangleProperty.p1 * 3 ) + 3 ] );
+				var p1 = triangleProperty.p1;
+				var p2 = triangleProperty.p2;
+				var p3 = triangleProperty.p3;
+
+				colorData.push( colors[ ( p1 * 3 ) + 0 ] );
+				colorData.push( colors[ ( p1 * 3 ) + 1 ] );
+				colorData.push( colors[ ( p1 * 3 ) + 3 ] );
 
 
-				colorData.push( colors[ ( triangleProperty.p2 * 3 ) + 0 ] );
-				colorData.push( colors[ ( triangleProperty.p2 * 3 ) + 1 ] );
-				colorData.push( colors[ ( triangleProperty.p2 * 3 ) + 2 ] );
+				colorData.push( colors[ ( ( p2 || p1 ) * 3 ) + 0 ] );
+				colorData.push( colors[ ( ( p2 || p1 ) * 3 ) + 1 ] );
+				colorData.push( colors[ ( ( p2 || p1 ) * 3 ) + 2 ] );
 
 
-				colorData.push( colors[ ( triangleProperty.p3 * 3 ) + 0 ] );
-				colorData.push( colors[ ( triangleProperty.p3 * 3 ) + 1 ] );
-				colorData.push( colors[ ( triangleProperty.p3 * 3 ) + 2 ] );
+				colorData.push( colors[ ( ( p3 || p1 ) * 3 ) + 0 ] );
+				colorData.push( colors[ ( ( p3 || p1 ) * 3 ) + 1 ] );
+				colorData.push( colors[ ( ( p3 || p1 ) * 3 ) + 2 ] );
 
 
 			}
 			}
 
 

二进制
examples/models/3mf/facecolors.3mf