forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
loaders/src/glTF/2.0/Extensions/KHR_materials_emissive_strength.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Nullable } from "babylonjs/types"; | ||
import { PBRMaterial } from "babylonjs/Materials/PBR/pbrMaterial"; | ||
import { Material } from "babylonjs/Materials/material"; | ||
|
||
import { IMaterial } from "../glTFLoaderInterfaces"; | ||
import { IGLTFLoaderExtension } from "../glTFLoaderExtension"; | ||
import { GLTFLoader } from "../glTFLoader"; | ||
import { IKHRMaterialsEmissiveStrength } from 'babylonjs-gltf2interface'; | ||
|
||
const NAME = "KHR_materials_emissive_strength"; | ||
|
||
/** | ||
* [Experimental Spec](https://github.com/KhronosGroup/glTF/pull/1994) | ||
*/ | ||
export class KHR_materials_emissive_strength implements IGLTFLoaderExtension { | ||
/** | ||
* The name of this extension. | ||
*/ | ||
public readonly name = NAME; | ||
|
||
/** | ||
* Defines whether this extension is enabled. | ||
*/ | ||
public enabled: boolean; | ||
|
||
/** | ||
* Defines a number that determines the order the extensions are applied. | ||
*/ | ||
public order = 170; | ||
|
||
private _loader: GLTFLoader; | ||
|
||
/** @hidden */ | ||
constructor(loader: GLTFLoader) { | ||
this._loader = loader; | ||
this.enabled = this._loader.isExtensionUsed(NAME); | ||
} | ||
|
||
/** @hidden */ | ||
public dispose() { | ||
(this._loader as any) = null; | ||
} | ||
|
||
/** @hidden */ | ||
public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> { | ||
return GLTFLoader.LoadExtensionAsync<IKHRMaterialsEmissiveStrength>(context, material, this.name, (extensionContext, extension) => { | ||
const promises = new Array<Promise<any>>(); | ||
promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial)); | ||
promises.push(this._loadEmissivePropertiesAsync(extensionContext, extension, babylonMaterial)); | ||
return Promise.all(promises).then(() => { }); | ||
}); | ||
} | ||
|
||
private _loadEmissivePropertiesAsync(context: string, properties: IKHRMaterialsEmissiveStrength, babylonMaterial: Material): Promise<void> { | ||
if (!(babylonMaterial instanceof PBRMaterial)) { | ||
throw new Error(`${context}: Material type not supported`); | ||
} | ||
|
||
if (properties.emissiveStrength !== undefined) { | ||
babylonMaterial.emissiveColor.scaleToRef(properties.emissiveStrength, babylonMaterial.emissiveColor); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
GLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_emissive_strength(loader)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters