Skip to content

Commit

Permalink
Examples: More sRGB usage. (#26119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored May 23, 2023
1 parent 8acb815 commit d732ceb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
35 changes: 25 additions & 10 deletions examples/jsm/loaders/PCDLoader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BufferGeometry,
Color,
FileLoader,
Float32BufferAttribute,
Int32BufferAttribute,
Expand Down Expand Up @@ -232,6 +233,8 @@ class PCDLoader extends Loader {
const intensity = [];
const label = [];

const c = new Color();

// ascii

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

}

const r = ( rgb >> 16 ) & 0x0000ff;
const g = ( rgb >> 8 ) & 0x0000ff;
const b = ( rgb >> 0 ) & 0x0000ff;
color.push( r / 255, g / 255, b / 255 );
const r = ( ( rgb >> 16 ) & 0x0000ff ) / 255;
const g = ( ( rgb >> 8 ) & 0x0000ff ) / 255;
const b = ( ( rgb >> 0 ) & 0x0000ff ) / 255;

c.set( r, g, b ).convertSRGBToLinear();

color.push( c.r, c.g, c.b );

}

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

const rgbIndex = PCDheader.fields.indexOf( 'rgb' );
color.push( dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 2 ) / 255.0 );
color.push( dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 1 ) / 255.0 );
color.push( dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 0 ) / 255.0 );

const r = dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 2 ) / 255.0;
const g = dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 1 ) / 255.0;
const b = dataview.getUint8( ( PCDheader.points * offset.rgb ) + PCDheader.size[ rgbIndex ] * i + 0 ) / 255.0;

c.set( r, g, b ).convertSRGBToLinear();

color.push( c.r, c.g, c.b );

}

Expand Down Expand Up @@ -389,9 +400,13 @@ class PCDLoader extends Loader {

if ( offset.rgb !== undefined ) {

color.push( dataview.getUint8( row + offset.rgb + 2 ) / 255.0 );
color.push( dataview.getUint8( row + offset.rgb + 1 ) / 255.0 );
color.push( dataview.getUint8( row + offset.rgb + 0 ) / 255.0 );
const r = dataview.getUint8( row + offset.rgb + 2 ) / 255.0;
const g = dataview.getUint8( row + offset.rgb + 1 ) / 255.0;
const b = dataview.getUint8( row + offset.rgb + 0 ) / 255.0;

c.set( r, g, b ).convertSRGBToLinear();

color.push( c.r, c.g, c.b );

}

Expand Down
12 changes: 9 additions & 3 deletions examples/jsm/loaders/XYZLoader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BufferGeometry,
Color,
FileLoader,
Float32BufferAttribute,
Loader
Expand Down Expand Up @@ -47,6 +48,7 @@ class XYZLoader extends Loader {

const vertices = [];
const colors = [];
const color = new Color();

for ( let line of lines ) {

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

colors.push( parseFloat( lineValues[ 3 ] ) / 255 );
colors.push( parseFloat( lineValues[ 4 ] ) / 255 );
colors.push( parseFloat( lineValues[ 5 ] ) / 255 );
const r = parseFloat( lineValues[ 3 ] ) / 255;
const g = parseFloat( lineValues[ 4 ] ) / 255;
const b = parseFloat( lineValues[ 5 ] ) / 255;

color.set( r, g, b ).convertSRGBToLinear();

colors.push( color.r, color.g, color.b );

}

Expand Down

0 comments on commit d732ceb

Please sign in to comment.