@shapediver/viewer.viewport
Version:
This is the npm package for the ShapeDiver Viewer Viewport API. For more information on ShapeDiver, please visit our [homepage](https://shapediver.com/).
172 lines • 14.9 kB
JavaScript
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _LightSceneApi_inputValidator, _LightSceneApi_lightScene, _LightSceneApi_lights, _LightSceneApi_logger, _LightSceneApi_viewportApi;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LightSceneApi = void 0;
const viewer_rendering_engine_light_engine_1 = require("@shapediver/viewer.rendering-engine.light-engine");
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
const AmbientLightApi_1 = require("./types/AmbientLightApi");
const DirectionalLightApi_1 = require("./types/DirectionalLightApi");
const HemisphereLightApi_1 = require("./types/HemisphereLightApi");
const PointLightApi_1 = require("./types/PointLightApi");
const SpotLightApi_1 = require("./types/SpotLightApi");
class LightSceneApi {
// #endregion Properties (5)
// #region Constructors (1)
constructor(viewportApi, lightScene) {
// #region Properties (5)
_LightSceneApi_inputValidator.set(this, viewer_shared_services_1.InputValidator.instance);
_LightSceneApi_lightScene.set(this, void 0);
_LightSceneApi_lights.set(this, {});
_LightSceneApi_logger.set(this, viewer_shared_services_1.Logger.instance);
_LightSceneApi_viewportApi.set(this, void 0);
__classPrivateFieldSet(this, _LightSceneApi_viewportApi, viewportApi, "f");
__classPrivateFieldSet(this, _LightSceneApi_lightScene, lightScene, "f");
// Whenever a light is added or removed from the light scene, this update is called.
__classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").update = () => {
for (const l in __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights) {
if (!__classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l]) {
switch (__classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l].type) {
case viewer_rendering_engine_light_engine_1.LIGHT_TYPE.AMBIENT:
__classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l] = new AmbientLightApi_1.AmbientLightApi(__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f"), __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l]);
break;
case viewer_rendering_engine_light_engine_1.LIGHT_TYPE.DIRECTIONAL:
__classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l] = new DirectionalLightApi_1.DirectionalLightApi(__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f"), __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l]);
break;
case viewer_rendering_engine_light_engine_1.LIGHT_TYPE.HEMISPHERE:
__classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l] = new HemisphereLightApi_1.HemisphereLightApi(__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f"), __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l]);
break;
case viewer_rendering_engine_light_engine_1.LIGHT_TYPE.POINT:
__classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l] = new PointLightApi_1.PointLightApi(__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f"), __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l]);
break;
case viewer_rendering_engine_light_engine_1.LIGHT_TYPE.SPOT:
__classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l] = new SpotLightApi_1.SpotLightApi(__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f"), __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l]);
break;
default:
}
}
}
for (const l in __classPrivateFieldGet(this, _LightSceneApi_lights, "f")) {
if (!__classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").lights[l]) {
delete __classPrivateFieldGet(this, _LightSceneApi_lights, "f")[l];
}
}
};
// We call it once in the beginning to get the current state.
__classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").update();
}
// #endregion Constructors (1)
// #region Public Getters And Setters (5)
get id() {
return __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").id;
}
get lights() {
return __classPrivateFieldGet(this, _LightSceneApi_lights, "f");
}
get name() {
return __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").name;
}
set name(value) {
const scope = "name";
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, value, "string", false);
__classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").name = value;
__classPrivateFieldGet(this, _LightSceneApi_logger, "f").debug(`LightSceneApi.${scope}: ${scope} was set to: ${value}`);
}
get node() {
return __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").node;
}
// #endregion Public Getters And Setters (5)
// #region Public Methods (6)
addAmbientLight(properties) {
const scope = "addAmbientLight";
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, properties, "object", false);
const prop = Object.assign({}, properties);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.color, "color", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.intensity, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.id, "string", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.name, "string", false);
const light = __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").addAmbientLight(properties);
__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f").update();
return __classPrivateFieldGet(this, _LightSceneApi_lights, "f")[light.id];
}
addDirectionalLight(properties) {
const scope = "addDirectionalLight";
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, properties, "object", false);
const prop = Object.assign({}, properties);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.color, "color", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.intensity, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.direction, "vec3", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.castShadow, "boolean", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.shadowMapResolution, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.shadowMapBias, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.id, "string", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.name, "string", false);
const light = __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").addDirectionalLight(properties);
__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f").update();
return __classPrivateFieldGet(this, _LightSceneApi_lights, "f")[light.id];
}
addHemisphereLight(properties) {
const scope = "addHemisphereLight";
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, properties, "object", false);
const prop = Object.assign({}, properties);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.color, "color", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.intensity, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.groundColor, "color", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.id, "string", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.name, "string", false);
const light = __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").addHemisphereLight(properties);
__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f").update();
return __classPrivateFieldGet(this, _LightSceneApi_lights, "f")[light.id];
}
addPointLight(properties) {
const scope = "addPointLight";
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, properties, "object", false);
const prop = Object.assign({}, properties);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.color, "color", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.intensity, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.position, "vec3", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.distance, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.decay, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.id, "string", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.name, "string", false);
const light = __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").addPointLight(properties);
__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f").update();
return __classPrivateFieldGet(this, _LightSceneApi_lights, "f")[light.id];
}
addSpotLight(properties) {
const scope = "addSpotLight";
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, properties, "object", false);
const prop = Object.assign({}, properties);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.color, "color", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.intensity, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.position, "vec3", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.target, "vec3", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.distance, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.decay, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.angle, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.penumbra, "number", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.id, "string", false);
__classPrivateFieldGet(this, _LightSceneApi_inputValidator, "f").validateAndError(`LightSceneApi.${scope}`, prop.name, "string", false);
const light = __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").addSpotLight(properties);
__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f").update();
return __classPrivateFieldGet(this, _LightSceneApi_lights, "f")[light.id];
}
removeLight(id) {
const check = __classPrivateFieldGet(this, _LightSceneApi_lightScene, "f").removeLight(id);
__classPrivateFieldGet(this, _LightSceneApi_viewportApi, "f").update();
return check;
}
}
exports.LightSceneApi = LightSceneApi;
_LightSceneApi_inputValidator = new WeakMap(), _LightSceneApi_lightScene = new WeakMap(), _LightSceneApi_lights = new WeakMap(), _LightSceneApi_logger = new WeakMap(), _LightSceneApi_viewportApi = new WeakMap();
//# sourceMappingURL=LightSceneApi.js.map