Skip to content

Commit dc8f729

Browse files
authored
PLYExporter: convert vertex colors to srgb before export (#23399)
1 parent 11833d7 commit dc8f729

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

examples/jsm/exporters/PLYExporter.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Matrix3,
3-
Vector3
3+
Vector3,
4+
Color
45
} from 'three';
56

67
/**
@@ -112,6 +113,7 @@ class PLYExporter {
112113

113114
} );
114115

116+
const tempColor = new Color();
115117
const includeIndices = excludeAttributes.indexOf( 'index' ) === - 1;
116118
includeNormals = includeNormals && excludeAttributes.indexOf( 'normal' ) === - 1;
117119
includeColors = includeColors && excludeAttributes.indexOf( 'color' ) === - 1;
@@ -305,13 +307,17 @@ class PLYExporter {
305307

306308
if ( colors != null ) {
307309

308-
output.setUint8( vOffset, Math.floor( colors.getX( i ) * 255 ) );
310+
tempColor
311+
.fromBufferAttribute( colors, i )
312+
.convertLinearToSRGB();
313+
314+
output.setUint8( vOffset, Math.floor( tempColor.r * 255 ) );
309315
vOffset += 1;
310316

311-
output.setUint8( vOffset, Math.floor( colors.getY( i ) * 255 ) );
317+
output.setUint8( vOffset, Math.floor( tempColor.g * 255 ) );
312318
vOffset += 1;
313319

314-
output.setUint8( vOffset, Math.floor( colors.getZ( i ) * 255 ) );
320+
output.setUint8( vOffset, Math.floor( tempColor.b * 255 ) );
315321
vOffset += 1;
316322

317323
} else {
@@ -464,10 +470,14 @@ class PLYExporter {
464470

465471
if ( colors != null ) {
466472

473+
tempColor
474+
.fromBufferAttribute( colors, i )
475+
.convertLinearToSRGB();
476+
467477
line += ' ' +
468-
Math.floor( colors.getX( i ) * 255 ) + ' ' +
469-
Math.floor( colors.getY( i ) * 255 ) + ' ' +
470-
Math.floor( colors.getZ( i ) * 255 );
478+
Math.floor( tempColor.r * 255 ) + ' ' +
479+
Math.floor( tempColor.g * 255 ) + ' ' +
480+
Math.floor( tempColor.b * 255 );
471481

472482
} else {
473483

0 commit comments

Comments
 (0)