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

GLTFLoader: Explicitly set r, g, b in setRGB() calls. #26691

Merged
merged 1 commit into from
Sep 4, 2023
Merged
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
14 changes: 8 additions & 6 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class GLTFLightsExtension {

const color = new Color( 0xffffff );

if ( lightDef.color !== undefined ) color.setRGB( ...lightDef.color, LinearSRGBColorSpace );
if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace );

const range = lightDef.range !== undefined ? lightDef.range : 0;

Expand Down Expand Up @@ -665,7 +665,7 @@ class GLTFMaterialsUnlitExtension {

const array = metallicRoughness.baseColorFactor;

materialParams.color.setRGB( ...array, LinearSRGBColorSpace );
materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
Copy link
Collaborator

@donmccurdy donmccurdy Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the spread operations are technically safe, except this one – the other factors do not allow >3 components. For consistency and safety perhaps it's better that we write them all this way though, thanks!

materialParams.opacity = array[ 3 ];

}
Expand Down Expand Up @@ -941,7 +941,8 @@ class GLTFMaterialsSheenExtension {

if ( extension.sheenColorFactor !== undefined ) {

materialParams.sheenColor.setRGB( ...extension.sheenColorFactor, LinearSRGBColorSpace );
const colorFactor = extension.sheenColorFactor;
materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor [ 2 ], LinearSRGBColorSpace );

}

Expand Down Expand Up @@ -1079,7 +1080,7 @@ class GLTFMaterialsVolumeExtension {
materialParams.attenuationDistance = extension.attenuationDistance || Infinity;

const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
materialParams.attenuationColor = new Color().setRGB( ...colorArray, LinearSRGBColorSpace );
materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );

return Promise.all( pending );

Expand Down Expand Up @@ -1182,7 +1183,7 @@ class GLTFMaterialsSpecularExtension {
}

const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
materialParams.specularColor = new Color().setRGB( ...colorArray, LinearSRGBColorSpace );
materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );

if ( extension.specularColorTexture !== undefined ) {

Expand Down Expand Up @@ -3480,7 +3481,8 @@ class GLTFParser {

if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {

materialParams.emissive = new Color().setRGB( ...materialDef.emissiveFactor, LinearSRGBColorSpace );
const emissiveFactor = materialDef.emissiveFactor;
materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace );

}

Expand Down