@babylonjs/loaders 6.27.1 → 6.28.1
Sign up to get free protection for your applications and to get access to all the features.
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +1 -0
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +1 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +2 -0
- package/glTF/2.0/glTFLoader.js +13 -1
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +1 -1
- package/glTF/glTFValidation.js +2 -2
- package/glTF/glTFValidation.js.map +1 -1
- package/package.json +3 -3
@@ -38,6 +38,7 @@ export class EXT_lights_image_based {
|
|
38
38
|
*/
|
39
39
|
loadSceneAsync(context, scene) {
|
40
40
|
return GLTFLoader.LoadExtensionAsync(context, scene, this.name, (extensionContext, extension) => {
|
41
|
+
this._loader._allMaterialsDirtyRequired = true;
|
41
42
|
const promises = new Array();
|
42
43
|
promises.push(this._loader.loadSceneAsync(context, scene));
|
43
44
|
this._loader.logOpen(`${extensionContext}`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qDAAuC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AAE5D,OAAO,EAAE,cAAc,EAAE,6DAA+C;AAKxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAWtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAc/B;;OAEG;IACH,YAAY,MAAkB;QAhB9B;;WAEG;QACa,SAAI,GAAG,I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0BAA0B,EAAE,CAAC,CAAC;iBACrF;gBAED,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,uCAAuC,CAAC,CAAC;iBACtE;gBAED,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBACtF,kBAAkB,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAEjD,kBAAkB,CAAC,qCAAqC,EAAE,CAAC;gBAC3D,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAElF,qFAAqF;gBACrF,MAAM,kBAAkB,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACzF,OAAO,cAAc,CAAC,eAAe,CAAC,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"core/Maths/math.vector\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport type { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport type { IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @internal */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(\r\n this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(\r\n this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Scalar.Log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_lights_image_based(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qDAAuC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AAE5D,OAAO,EAAE,cAAc,EAAE,6DAA+C;AAKxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAWtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAc/B;;OAEG;IACH,YAAY,MAAkB;QAhB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAcxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC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AAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,uCAAuC,CAAC,CAAC;iBACtE;gBAED,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBACtF,kBAAkB,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAEjD,kBAAkB,CAAC,qCAAqC,EAAE,CAAC;gBAC3D,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAElF,qFAAqF;gBACrF,MAAM,kBAAkB,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACzF,OAAO,cAAc,CAAC,eAAe,CAAC,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"core/Maths/math.vector\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport type { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport type { IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @internal */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(\r\n this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(\r\n this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Scalar.Log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new EXT_lights_image_based(loader));\r\n"]}
|
@@ -41,6 +41,7 @@ export class KHR_lights {
|
|
41
41
|
*/
|
42
42
|
loadNodeAsync(context, node, assign) {
|
43
43
|
return GLTFLoader.LoadExtensionAsync(context, node, this.name, (extensionContext, extension) => {
|
44
|
+
this._loader._allMaterialsDirtyRequired = true;
|
44
45
|
return this._loader.loadNodeAsync(context, node, (babylonMesh) => {
|
45
46
|
let babylonLight;
|
46
47
|
const light = ArrayItem.Get(extensionContext, this._lights, extension.light);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAChE,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,SAAS,EAAE,4CAA8B;AAClD,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAO1C,OAAO,EAAE,UAAU,EAAE,SA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,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { PointLight } from \"core/Lights/pointLight\";\r\nimport { SpotLight } from \"core/Lights/spotLight\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\n\r\nimport type { IKHRLightsPunctual_LightReference } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { INode, IKHRLightsPunctual_Light } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /** hidden */\r\n private _loader: GLTFLoader;\r\n private _lights?: IKHRLightsPunctual_Light[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as any;\r\n this._lights = extension.lights;\r\n ArrayItem.Assign(this._lights);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRLightsPunctual_LightReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n return this._loader.loadNodeAsync(context, node, (babylonMesh) => {\r\n let babylonLight: Light;\r\n\r\n const light = ArrayItem.Get(extensionContext, this._lights, extension.light);\r\n const name = light.name || babylonMesh.name;\r\n\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n\r\n switch (light.type) {\r\n case KHRLightsPunctual_LightType.DIRECTIONAL: {\r\n const babylonDirectionalLight = new DirectionalLight(name, Vector3.Backward(), this._loader.babylonScene);\r\n babylonDirectionalLight.position.setAll(0);\r\n babylonLight = babylonDirectionalLight;\r\n break;\r\n }\r\n case KHRLightsPunctual_LightType.POINT: {\r\n babylonLight = new PointLight(name, Vector3.Zero(), this._loader.babylonScene);\r\n break;\r\n }\r\n case KHRLightsPunctual_LightType.SPOT: {\r\n const babylonSpotLight = new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene);\r\n babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;\r\n babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;\r\n babylonLight = babylonSpotLight;\r\n break;\r\n }\r\n default: {\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n throw new Error(`${extensionContext}: Invalid light type (${light.type})`);\r\n }\r\n }\r\n\r\n babylonLight._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n light._babylonLight = babylonLight;\r\n\r\n babylonLight.falloffType = Light.FALLOFF_GLTF;\r\n babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();\r\n babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;\r\n babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;\r\n babylonLight.parent = babylonMesh;\r\n\r\n this._loader._babylonLights.push(babylonLight);\r\n\r\n GLTFLoader.AddPointerMetadata(babylonLight, extensionContext);\r\n\r\n assign(babylonMesh);\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_lights(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAChE,OAAO,EAAE,UAAU,EAAE,6CAA+B;AACpD,OAAO,EAAE,SAAS,EAAE,4CAA8B;AAClD,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAO1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,UAAU;IAenB;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,gBAAgB;IACT,SAAS;QACZ,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI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AAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBACpF,YAAY,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;gBAC5E,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC/E,YAAY,CAAC,MAAM,GAAG,WAAW,CAAC;gBAElC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAE/C,UAAU,CAAC,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;gBAE9D,MAAM,CAAC,WAAW,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { PointLight } from \"core/Lights/pointLight\";\r\nimport { SpotLight } from \"core/Lights/spotLight\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\n\r\nimport type { IKHRLightsPunctual_LightReference } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { INode, IKHRLightsPunctual_Light } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /** hidden */\r\n private _loader: GLTFLoader;\r\n private _lights?: IKHRLightsPunctual_Light[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as any;\r\n this._lights = extension.lights;\r\n ArrayItem.Assign(this._lights);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRLightsPunctual_LightReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n return this._loader.loadNodeAsync(context, node, (babylonMesh) => {\r\n let babylonLight: Light;\r\n\r\n const light = ArrayItem.Get(extensionContext, this._lights, extension.light);\r\n const name = light.name || babylonMesh.name;\r\n\r\n this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;\r\n\r\n switch (light.type) {\r\n case KHRLightsPunctual_LightType.DIRECTIONAL: {\r\n const babylonDirectionalLight = new DirectionalLight(name, Vector3.Backward(), this._loader.babylonScene);\r\n babylonDirectionalLight.position.setAll(0);\r\n babylonLight = babylonDirectionalLight;\r\n break;\r\n }\r\n case KHRLightsPunctual_LightType.POINT: {\r\n babylonLight = new PointLight(name, Vector3.Zero(), this._loader.babylonScene);\r\n break;\r\n }\r\n case KHRLightsPunctual_LightType.SPOT: {\r\n const babylonSpotLight = new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene);\r\n babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;\r\n babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;\r\n babylonLight = babylonSpotLight;\r\n break;\r\n }\r\n default: {\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n throw new Error(`${extensionContext}: Invalid light type (${light.type})`);\r\n }\r\n }\r\n\r\n babylonLight._parentContainer = this._loader._assetContainer;\r\n this._loader.babylonScene._blockEntityCollection = false;\r\n light._babylonLight = babylonLight;\r\n\r\n babylonLight.falloffType = Light.FALLOFF_GLTF;\r\n babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White();\r\n babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;\r\n babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;\r\n babylonLight.parent = babylonMesh;\r\n\r\n this._loader._babylonLights.push(babylonLight);\r\n\r\n GLTFLoader.AddPointerMetadata(babylonLight, extensionContext);\r\n\r\n assign(babylonMesh);\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_lights(loader));\r\n"]}
|
package/glTF/2.0/glTFLoader.d.ts
CHANGED
@@ -68,6 +68,8 @@ export declare class GLTFLoader implements IGLTFLoader {
|
|
68
68
|
_babylonLights: Light[];
|
69
69
|
/** @internal */
|
70
70
|
_disableInstancedMesh: number;
|
71
|
+
/** @internal */
|
72
|
+
_allMaterialsDirtyRequired: boolean;
|
71
73
|
private readonly _parent;
|
72
74
|
private readonly _extensions;
|
73
75
|
private _disposed;
|
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -160,6 +160,8 @@ export class GLTFLoader {
|
|
160
160
|
this._babylonLights = [];
|
161
161
|
/** @internal */
|
162
162
|
this._disableInstancedMesh = 0;
|
163
|
+
/** @internal */
|
164
|
+
this._allMaterialsDirtyRequired = false;
|
163
165
|
this._extensions = new Array();
|
164
166
|
this._disposed = false;
|
165
167
|
this._rootUrl = null;
|
@@ -244,6 +246,7 @@ export class GLTFLoader {
|
|
244
246
|
this._rootUrl = rootUrl;
|
245
247
|
this._uniqueRootUrl = !rootUrl.startsWith("file:") && fileName ? rootUrl : `${rootUrl}${Date.now()}/`;
|
246
248
|
this._fileName = fileName;
|
249
|
+
this._allMaterialsDirtyRequired = false;
|
247
250
|
this._loadExtensions();
|
248
251
|
this._checkExtensions();
|
249
252
|
const loadingToReadyCounterName = `${GLTFLoaderState[GLTFLoaderState.LOADING]} => ${GLTFLoaderState[GLTFLoaderState.READY]}`;
|
@@ -274,7 +277,16 @@ export class GLTFLoader {
|
|
274
277
|
}
|
275
278
|
}
|
276
279
|
// Restore the blocking of material dirty.
|
277
|
-
this.
|
280
|
+
if (this._allMaterialsDirtyRequired) {
|
281
|
+
// This can happen if we add a light for instance as it will impact the whole scene.
|
282
|
+
// This automatically resets everything if needed.
|
283
|
+
this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
|
284
|
+
}
|
285
|
+
else {
|
286
|
+
// By default a newly created material is dirty so there is no need to flag the full scene as dirty.
|
287
|
+
// For perf reasons, we then bypass blockMaterialDirtyMechanism as this would "dirty" the entire scene.
|
288
|
+
this._babylonScene._forceBlockMaterialDirtyMechanism(oldBlockMaterialDirtyMechanism);
|
289
|
+
}
|
278
290
|
if (this._parent.compileMaterials) {
|
279
291
|
promises.push(this._compileMaterialsAsync());
|
280
292
|
}
|