@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.
107 lines (103 loc) • 4.68 kB
JavaScript
import { V as Vector3, aL as Light, i as Color3, m as Texture, bo as unregisterGLTFExtension, bp as registerGLTFExtension } from './index-MZPybX0H.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 = "EXT_lights_ies";
/**
* [Specification](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Vendor/EXT_lights_ies)
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
class EXT_lights_ies {
/**
* @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
// 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;
let babylonSpotLight;
let light;
const transformNode = await this._loader.loadNodeAsync(context, node, (babylonMesh) => {
light = ArrayItem.Get(extensionContext, this._lights, extension.light);
const name = light.name || babylonMesh.name;
this._loader.babylonScene._blockEntityCollection = !!this._loader._assetContainer;
babylonSpotLight = new SpotLight(name, Vector3.Zero(), Vector3.Backward(), 0, 1, this._loader.babylonScene);
babylonSpotLight.angle = Math.PI / 2;
babylonSpotLight.innerAngle = 0;
babylonSpotLight._parentContainer = this._loader._assetContainer;
this._loader.babylonScene._blockEntityCollection = false;
light._babylonLight = babylonSpotLight;
babylonSpotLight.falloffType = Light.FALLOFF_GLTF;
babylonSpotLight.diffuse = extension.color ? Color3.FromArray(extension.color) : Color3.White();
babylonSpotLight.intensity = extension.multiplier || 1;
babylonSpotLight.range = Number.MAX_VALUE;
babylonSpotLight.parent = babylonMesh;
this._loader._babylonLights.push(babylonSpotLight);
GLTFLoader.AddPointerMetadata(babylonSpotLight, extensionContext);
assign(babylonMesh);
});
// Load the profile
let bufferData;
if (light.uri) {
bufferData = await this._loader.loadUriAsync(context, light, light.uri);
}
else {
const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, light.bufferView);
bufferData = await this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);
}
babylonSpotLight.iesProfileTexture = new Texture(babylonSpotLight.name + "_iesProfile", this._loader.babylonScene, true, false, undefined, null, null, bufferData, true, undefined, undefined, undefined, undefined, ".ies");
return transformNode;
});
}
}
let _Registered = false;
/**
* Registers the EXT_lights_ies glTF loader extension.
* Safe to call multiple times; only the first call has an effect.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function RegisterEXT_lights_ies() {
if (_Registered) {
return;
}
_Registered = true;
unregisterGLTFExtension(NAME);
registerGLTFExtension(NAME, true, (loader) => new EXT_lights_ies(loader));
}
/**
* Re-exports the pure implementation and applies the runtime registration side effect.
* Import "./EXT_lights_ies.pure" for tree-shakeable, side-effect-free usage.
*/
RegisterEXT_lights_ies();
export { EXT_lights_ies, RegisterEXT_lights_ies };
//# sourceMappingURL=EXT_lights_ies-C3cWZJnT.esm.js.map