Skip to content

Commit d732ceb

Browse files
authored
Examples: More sRGB usage. (#26119)
1 parent 8acb815 commit d732ceb

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

examples/jsm/loaders/PCDLoader.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
BufferGeometry,
3+
Color,
34
FileLoader,
45
Float32BufferAttribute,
56
Int32BufferAttribute,
@@ -232,6 +233,8 @@ class PCDLoader extends Loader {
232233
const intensity = [];
233234
const label = [];
234235

236+
const c = new Color();
237+
235238
// ascii
236239

237240
if ( PCDheader.data === 'ascii' ) {
@@ -272,10 +275,13 @@ class PCDLoader extends Loader {
272275

273276
}
274277

275-
const r = ( rgb >> 16 ) & 0x0000ff;
276-
const g = ( rgb >> 8 ) & 0x0000ff;
277-
const b = ( rgb >> 0 ) & 0x0000ff;
278-
color.push( r / 255, g / 255, b / 255 );
278+
const r = ( ( rgb >> 16 ) & 0x0000ff ) / 255;
279+
const g = ( ( rgb >> 8 ) & 0x0000ff ) / 255;
280+
const b = ( ( rgb >> 0 ) & 0x0000ff ) / 255;
281+
282+
c.set( r, g, b ).convertSRGBToLinear();
283+
284+
color.push( c.r, c.g, c.b );
279285

280286
}
281287

@@ -335,9 +341,14 @@ class PCDLoader extends Loader {
335341
if ( offset.rgb !== undefined ) {
336342

337343
const rgbIndex = PCDheader.fields.indexOf( 'rgb' );
338-
color.push( dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 2 ) / 255.0 );
339-
color.push( dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 1 ) / 255.0 );
340-
color.push( dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 0 ) / 255.0 );
344+
345+
const r = dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 2 ) / 255.0;
346+
const g = dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 1 ) / 255.0;
347+
const b = dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 0 ) / 255.0;
348+
349+
c.set( r, g, b ).convertSRGBToLinear();
350+
351+
color.push( c.r, c.g, c.b );
341352

342353
}
343354

@@ -389,9 +400,13 @@ class PCDLoader extends Loader {
389400

390401
if ( offset.rgb !== undefined ) {
391402

392-
color.push( dataview.getUint8( row + offset.rgb + 2 ) / 255.0 );
393-
color.push( dataview.getUint8( row + offset.rgb + 1 ) / 255.0 );
394-
color.push( dataview.getUint8( row + offset.rgb + 0 ) / 255.0 );
403+
const r = dataview.getUint8( row + offset.rgb + 2 ) / 255.0;
404+
const g = dataview.getUint8( row + offset.rgb + 1 ) / 255.0;
405+
const b = dataview.getUint8( row + offset.rgb + 0 ) / 255.0;
406+
407+
c.set( r, g, b ).convertSRGBToLinear();
408+
409+
color.push( c.r, c.g, c.b );
395410

396411
}
397412

examples/jsm/loaders/XYZLoader.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
BufferGeometry,
3+
Color,
34
FileLoader,
45
Float32BufferAttribute,
56
Loader
@@ -47,6 +48,7 @@ class XYZLoader extends Loader {
4748

4849
const vertices = [];
4950
const colors = [];
51+
const color = new Color();
5052

5153
for ( let line of lines ) {
5254

@@ -74,9 +76,13 @@ class XYZLoader extends Loader {
7476
vertices.push( parseFloat( lineValues[ 1 ] ) );
7577
vertices.push( parseFloat( lineValues[ 2 ] ) );
7678

77-
colors.push( parseFloat( lineValues[ 3 ] ) / 255 );
78-
colors.push( parseFloat( lineValues[ 4 ] ) / 255 );
79-
colors.push( parseFloat( lineValues[ 5 ] ) / 255 );
79+
const r = parseFloat( lineValues[ 3 ] ) / 255;
80+
const g = parseFloat( lineValues[ 4 ] ) / 255;
81+
const b = parseFloat( lineValues[ 5 ] ) / 255;
82+
83+
color.set( r, g, b ).convertSRGBToLinear();
84+
85+
colors.push( color.r, color.g, color.b );
8086

8187
}
8288

0 commit comments

Comments
 (0)