@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.
66 lines (63 loc) • 2.21 kB
JavaScript
import { b5 as allocateMat4, b6 as createLightBase, b9 as localMatrixFromDirection, b7 as applyWorldMatrixAccessors, b8 as ObservableVec3 } from './index-By0tcgYN.esm.js';
function createSpotLight(position, direction, angle, exponent, intensity = 1) {
const _localMatrix = allocateMat4();
const { wm, onDirty, lvs } = createLightBase(() => {
return localMatrixFromDirection(light.direction.x, light.direction.y, light.direction.z, light.position.x, light.position.y, light.position.z, _localMatrix);
});
let _angle = angle;
let _cosHalfAngle = Math.cos(angle * 0.5);
const light = applyWorldMatrixAccessors(
{
lightType: "spot",
children: [],
position: new ObservableVec3(position[0], position[1], position[2], onDirty),
direction: new ObservableVec3(direction[0], direction[1], direction[2], onDirty),
angle: 0,
// placeholder — overridden by defineProperty below
exponent,
diffuse: [1, 1, 1],
specular: [1, 1, 1],
intensity,
range: Number.MAX_VALUE,
_writeLightUbo: (data, offset) => {
const o = offset;
const w = light.worldMatrix;
data[o] = w[12];
data[o + 1] = w[13];
data[o + 2] = w[14];
data[o + 3] = 2;
data[o + 4] = light.diffuse[0] * light.intensity;
data[o + 5] = light.diffuse[1] * light.intensity;
data[o + 6] = light.diffuse[2] * light.intensity;
data[o + 7] = light.range;
data[o + 8] = light.specular[0] * light.intensity;
data[o + 9] = light.specular[1] * light.intensity;
data[o + 10] = light.specular[2] * light.intensity;
data[o + 11] = light.exponent;
data[o + 12] = w[8];
data[o + 13] = w[9];
data[o + 14] = w[10];
data[o + 15] = _cosHalfAngle;
}
},
wm,
lvs
);
Object.defineProperty(light, "angle", {
get() {
return _angle;
},
set(v) {
if (v !== _angle) {
_angle = v;
_cosHalfAngle = Math.cos(v * 0.5);
lvs.bump();
}
},
configurable: true,
enumerable: true
});
return light;
}
export { createSpotLight };
//# sourceMappingURL=spot-light-BR3hWdU7.esm.js.map