Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: More sRGB usage. #26119

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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