UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

115 lines (111 loc) 5.21 kB
import { V as Vector3, bs as DirectionalLight, aL as Light, i as Color3, bo as unregisterGLTFExtension, bp as registerGLTFExtension } from './index-MZPybX0H.esm.js'; import { P as PointLight } from './pointLight.pure-CmWfCM4F.esm.js'; import { S as SpotLight } from './spotLight.pure-CRdZC6Ci.esm.js'; import { A as ArrayItem, b as GLTFLoader } from './glTFLoader.pure-BaIedO7s.esm.js'; import './morphTargetManager-CK7B3gaT.esm.js'; import './bone.pure-CjsCww39.esm.js'; import './skeleton-D7Sw58cv.esm.js'; import './assetContainer-Bm0vsreJ.esm.js'; import './objectModelMapping-De5EKNEZ.esm.js'; const NAME = "KHR_lights_punctual"; /** * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual/README.md) */ // eslint-disable-next-line @typescript-eslint/naming-convention class KHR_lights { /** * @internal */ constructor(loader) { /** * The name of this extension. */ this.name = NAME; this._loader = loader; this.enabled = this._loader.isExtensionUsed(NAME); } /** @internal */ dispose() { this._loader = null; delete this._lights; } /** @internal */ onLoading() { const extensions = this._loader.gltf.extensions; if (extensions && extensions[this.name]) { const extension = extensions[this.name]; this._lights = extension.lights; ArrayItem.Assign(this._lights); } } /** * @internal */ // eslint-disable-next-line no-restricted-syntax loadNodeAsync(context, node, assign) { return GLTFLoader.LoadExtensionAsync(context, node, this.name, async (extensionContext, extension) => { this._loader._allMaterialsDirtyRequired = true; return await this._loader.loadNodeAsync(context, node, (babylonMesh) => { let babylonLight; const light = ArrayItem.Get(extensionContext, this._lights, extension.light); const name = light.name || babylonMesh.name; this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer; switch (light.type) { case "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */: { const babylonDirectionalLight = new DirectionalLight(name, Vector3.Backward(), this._loader.babylonScene); babylonDirectionalLight.position.setAll(0); babylonLight = babylonDirectionalLight; break; } case "point" /* KHRLightsPunctual_LightType.POINT */: { babylonLight = new PointLight(name, Vector3.Zero(), this._loader.babylonScene); break; } case "spot" /* KHRLightsPunctual_LightType.SPOT */: { const babylonSpotLight = new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene); babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2; babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2; babylonLight = babylonSpotLight; break; } default: { this._loader.babylonScene._blockEntityCollection = false; throw new Error(`${extensionContext}: Invalid light type (${light.type})`); } } babylonLight._parentContainer = this._loader._assetContainer; this._loader.babylonScene._blockEntityCollection = false; light._babylonLight = babylonLight; babylonLight.falloffType = Light.FALLOFF_GLTF; babylonLight.diffuse = light.color ? Color3.FromArray(light.color) : Color3.White(); babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity; babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range; babylonLight.parent = babylonMesh; this._loader._babylonLights.push(babylonLight); GLTFLoader.AddPointerMetadata(babylonLight, extensionContext); assign(babylonMesh); }); }); } } let _Registered = false; /** * Registers the KHR_lights glTF loader extension. * Safe to call multiple times; only the first call has an effect. */ // eslint-disable-next-line @typescript-eslint/naming-convention function RegisterKHR_lights() { if (_Registered) { return; } _Registered = true; unregisterGLTFExtension(NAME); registerGLTFExtension(NAME, true, (loader) => new KHR_lights(loader)); } /** * Re-exports the pure implementation and applies the runtime registration side effect. * Import "./KHR_lights_punctual.pure" for tree-shakeable, side-effect-free usage. */ RegisterKHR_lights(); export { KHR_lights, RegisterKHR_lights }; //# sourceMappingURL=KHR_lights_punctual-CbIDdy1X.esm.js.map