浏览代码

PLYExporter: convert vertex colors to srgb before export (#23399)

Garrett Johnson 3 年之前
父节点
当前提交
dc8f72996a
共有 1 个文件被更改,包括 17 次插入7 次删除
  1. 17 7
      examples/jsm/exporters/PLYExporter.js

+ 17 - 7
examples/jsm/exporters/PLYExporter.js

@@ -1,6 +1,7 @@
 import {
 	Matrix3,
-	Vector3
+	Vector3,
+	Color
 } from 'three';
 
 /**
@@ -112,6 +113,7 @@ class PLYExporter {
 
 		} );
 
+		const tempColor = new Color();
 		const includeIndices = excludeAttributes.indexOf( 'index' ) === - 1;
 		includeNormals = includeNormals && excludeAttributes.indexOf( 'normal' ) === - 1;
 		includeColors = includeColors && excludeAttributes.indexOf( 'color' ) === - 1;
@@ -305,13 +307,17 @@ class PLYExporter {
 
 						if ( colors != null ) {
 
-							output.setUint8( vOffset, Math.floor( colors.getX( i ) * 255 ) );
+							tempColor
+								.fromBufferAttribute( colors, i )
+								.convertLinearToSRGB();
+
+							output.setUint8( vOffset, Math.floor( tempColor.r * 255 ) );
 							vOffset += 1;
 
-							output.setUint8( vOffset, Math.floor( colors.getY( i ) * 255 ) );
+							output.setUint8( vOffset, Math.floor( tempColor.g * 255 ) );
 							vOffset += 1;
 
-							output.setUint8( vOffset, Math.floor( colors.getZ( i ) * 255 ) );
+							output.setUint8( vOffset, Math.floor( tempColor.b * 255 ) );
 							vOffset += 1;
 
 						} else {
@@ -464,10 +470,14 @@ class PLYExporter {
 
 						if ( colors != null ) {
 
+							tempColor
+								.fromBufferAttribute( colors, i )
+								.convertLinearToSRGB();
+
 							line += ' ' +
-								Math.floor( colors.getX( i ) * 255 ) + ' ' +
-								Math.floor( colors.getY( i ) * 255 ) + ' ' +
-								Math.floor( colors.getZ( i ) * 255 );
+								Math.floor( tempColor.r * 255 ) + ' ' +
+								Math.floor( tempColor.g * 255 ) + ' ' +
+								Math.floor( tempColor.b * 255 );
 
 						} else {