From fb6e9893cb504e4de9f81b6aab0f6def3f12e80f Mon Sep 17 00:00:00 2001 From: Felix Herbst Date: Fri, 8 Apr 2022 00:57:49 +0200 Subject: [PATCH 1/2] GLTFLoader: add KHR_materials_emissive_strength --- examples/jsm/loaders/GLTFLoader.js | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index c0d82bcea3ed3e..c5edca0b5a1c26 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -117,6 +117,12 @@ class GLTFLoader extends Loader { } ); + this.register( function ( parser ) { + + return new GLTFMaterialsEmissiveStrengthExtension( parser ); + + } ); + this.register( function ( parser ) { return new GLTFMaterialsSpecularExtension( parser ); @@ -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' }; @@ -638,6 +645,38 @@ 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(); + + } + + materialParams.emissiveIntensity = materialDef.extensions[this.name].emissiveStrength; + return Promise.resolve(); + + } + +} + /** * Clearcoat Materials Extension * @@ -1733,7 +1772,7 @@ class GLTFMaterialsPbrSpecularGlossinessExtension { material.aoMapIntensity = 1.0; material.emissive = materialParams.emissive; - material.emissiveIntensity = 1.0; + material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity; material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap; material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap; From 658e07cf14169a2c80a9a47e02ab05c73f8ce385 Mon Sep 17 00:00:00 2001 From: hybridherbst Date: Fri, 8 Apr 2022 11:25:49 +0200 Subject: [PATCH 2/2] only set emissiveIntensity if emissiveStrength is defined Co-authored-by: Don McCurdy --- examples/jsm/loaders/GLTFLoader.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index c5edca0b5a1c26..c0a70ea251ce41 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -670,7 +670,14 @@ class GLTFMaterialsUnlitExtension { } - materialParams.emissiveIntensity = materialDef.extensions[this.name].emissiveStrength; + const emissiveStrength = materialDef.extensions[this.name].emissiveStrength; + + if ( emissiveStrength !== undefined ) { + + materialParams.emissiveIntensity = emissiveStrength; + + } + return Promise.resolve(); }