Преглед изворни кода

PLYLoader: Add support for files with face color definitions. (#26014)

* automatically convert mask color to vertex color

automatically convert mask color to vertex color,because the ply format includes mesh and point clouds

* refactor PLYLoader.js

* Update PLYLoader.js

---------

Co-authored-by: Michael Herzog <[email protected]>
Sindre Yang пре 2 година
родитељ
комит
a14dd2223c
1 измењених фајлова са 20 додато и 8 уклоњено
  1. 20 8
      examples/jsm/loaders/PLYLoader.js

+ 20 - 8
examples/jsm/loaders/PLYLoader.js

@@ -287,6 +287,7 @@ class PLYLoader extends Loader {
 			  uvs: [],
 			  uvs: [],
 			  faceVertexUvs: [],
 			  faceVertexUvs: [],
 			  colors: [],
 			  colors: [],
+			  faceVertexColors: []
 			};
 			};
 
 
 			for ( const customProperty of Object.keys( scope.customPropertyMapping ) ) {
 			for ( const customProperty of Object.keys( scope.customPropertyMapping ) ) {
@@ -407,16 +408,12 @@ class PLYLoader extends Loader {
 
 
 			}
 			}
 
 
-			if ( buffer.colors.length > 0 ) {
-
-				geometry.setAttribute( 'color', new Float32BufferAttribute( buffer.colors, 3 ) );
-
-			}
-
-			if ( buffer.faceVertexUvs.length > 0 ) {
+			if ( buffer.faceVertexUvs.length > 0 || buffer.faceVertexColors.length > 0 ) {
 
 
 				geometry = geometry.toNonIndexed();
 				geometry = geometry.toNonIndexed();
-				geometry.setAttribute( 'uv', new Float32BufferAttribute( buffer.faceVertexUvs, 2 ) );
+
+				if ( buffer.faceVertexUvs.length > 0 ) geometry.setAttribute( 'uv', new Float32BufferAttribute( buffer.faceVertexUvs, 2 ) );
+				if ( buffer.faceVertexColors.length > 0 ) geometry.setAttribute( 'color', new Float32BufferAttribute( buffer.faceVertexColors, 3 ) );
 
 
 			}
 			}
 
 
@@ -508,6 +505,21 @@ class PLYLoader extends Loader {
 
 
 				}
 				}
 
 
+				// face colors
+
+				if ( cacheEntry.attrR !== null && cacheEntry.attrG !== null && cacheEntry.attrB !== null ) {
+
+					_color.setRGB(
+						element[ cacheEntry.attrR ] / 255.0,
+						element[ cacheEntry.attrG ] / 255.0,
+						element[ cacheEntry.attrB ] / 255.0
+					).convertSRGBToLinear();
+					buffer.faceVertexColors.push( _color.r, _color.g, _color.b );
+					buffer.faceVertexColors.push( _color.r, _color.g, _color.b );
+					buffer.faceVertexColors.push( _color.r, _color.g, _color.b );
+
+				}
+
 			}
 			}
 
 
 		}
 		}