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: add KHR_materials_emissive_strength #23867

Merged
merged 2 commits into from
Apr 8, 2022
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
48 changes: 47 additions & 1 deletion examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class GLTFLoader extends Loader {

} );

this.register( function ( parser ) {

return new GLTFMaterialsEmissiveStrengthExtension( parser );

} );

this.register( function ( parser ) {

return new GLTFMaterialsSpecularExtension( parser );
Expand Down Expand Up @@ -453,6 +459,7 @@ const EXTENSIONS = {
KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
EXT_TEXTURE_WEBP: 'EXT_texture_webp',
EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression'
};
Expand Down Expand Up @@ -638,6 +645,45 @@ class GLTFMaterialsUnlitExtension {

}

/**
* Materials Emissive Strength Extension
*
* Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
*/
class GLTFMaterialsEmissiveStrengthExtension {

constructor( parser ) {

this.parser = parser;
this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;

}

extendMaterialParams( materialIndex, materialParams ) {

const parser = this.parser;
const materialDef = parser.json.materials[ materialIndex ];

if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {

return Promise.resolve();

}

const emissiveStrength = materialDef.extensions[this.name].emissiveStrength;

if ( emissiveStrength !== undefined ) {

materialParams.emissiveIntensity = emissiveStrength;

}

return Promise.resolve();

}

}

/**
* Clearcoat Materials Extension
*
Expand Down Expand Up @@ -1733,7 +1779,7 @@ class GLTFMaterialsPbrSpecularGlossinessExtension {
material.aoMapIntensity = 1.0;

material.emissive = materialParams.emissive;
material.emissiveIntensity = 1.0;
material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity;
donmccurdy marked this conversation as resolved.
Show resolved Hide resolved
material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;

material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
Expand Down