UNPKG

@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/).

797 lines 64 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; 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 _ViewportApi_animationEngine, _ViewportApi_cameras, _ViewportApi_creationControlCenterViewport, _ViewportApi_gltfConverter, _ViewportApi_inputValidator, _ViewportApi_lightScenes, _ViewportApi_logger, _ViewportApi_postProcessing, _ViewportApi_renderingEngine, _ViewportApi_stateEngine, _ViewportApi_systemInfo; Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewportApi = void 0; const sdk_geometry_api_sdk_v2_1 = require("@shapediver/sdk.geometry-api-sdk-v2"); const viewer_api_general_1 = require("@shapediver/viewer.api.general"); const viewer_creation_control_center_viewport_1 = require("@shapediver/viewer.creation-control-center.viewport"); const viewer_data_engine_gltf_converter_1 = require("@shapediver/viewer.data-engine.gltf-converter"); const viewer_rendering_engine_animation_engine_1 = require("@shapediver/viewer.rendering-engine.animation-engine"); const viewer_rendering_engine_camera_engine_1 = require("@shapediver/viewer.rendering-engine.camera-engine"); const viewer_shared_build_data_1 = require("@shapediver/viewer.shared.build-data"); const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree"); const viewer_shared_services_1 = require("@shapediver/viewer.shared.services"); const viewer_shared_types_1 = require("@shapediver/viewer.shared.types"); const gl_matrix_1 = require("gl-matrix"); const QRCode = __importStar(require("qrcode")); const OrthographicCameraApi_1 = require("./camera/OrthographicCameraApi"); const PerspectiveCameraApi_1 = require("./camera/PerspectiveCameraApi"); const LightSceneApi_1 = require("./lights/LightSceneApi"); const PostProcessingApi_1 = require("./PostProcessingApi"); class ViewportApi { // #endregion Properties (11) // #region Constructors (1) constructor(renderingEngine) { // #region Properties (11) _ViewportApi_animationEngine.set(this, viewer_rendering_engine_animation_engine_1.AnimationEngine.instance); _ViewportApi_cameras.set(this, {}); _ViewportApi_creationControlCenterViewport.set(this, viewer_creation_control_center_viewport_1.CreationControlCenterViewport.instance); _ViewportApi_gltfConverter.set(this, viewer_data_engine_gltf_converter_1.GLTFConverter.instance); _ViewportApi_inputValidator.set(this, viewer_shared_services_1.InputValidator.instance); _ViewportApi_lightScenes.set(this, {}); _ViewportApi_logger.set(this, viewer_shared_services_1.Logger.instance); _ViewportApi_postProcessing.set(this, void 0); _ViewportApi_renderingEngine.set(this, void 0); _ViewportApi_stateEngine.set(this, viewer_shared_services_1.StateEngine.instance); _ViewportApi_systemInfo.set(this, viewer_shared_services_1.SystemInfo.instance); __classPrivateFieldSet(this, _ViewportApi_renderingEngine, renderingEngine, "f"); // Whenever a camera is added or removed from the camera engine, this update is called. __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.update = () => { for (const c in __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.cameras) { if (!__classPrivateFieldGet(this, _ViewportApi_cameras, "f")[c]) { if (__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.cameras[c].type === viewer_rendering_engine_camera_engine_1.CAMERA_TYPE.PERSPECTIVE) { __classPrivateFieldGet(this, _ViewportApi_cameras, "f")[c] = new PerspectiveCameraApi_1.PerspectiveCameraApi(this, (__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.cameras[c])); } else { __classPrivateFieldGet(this, _ViewportApi_cameras, "f")[c] = new OrthographicCameraApi_1.OrthographicCameraApi(this, (__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.cameras[c])); } } } for (const c in __classPrivateFieldGet(this, _ViewportApi_cameras, "f")) { if (!__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.cameras[c]) { delete __classPrivateFieldGet(this, _ViewportApi_cameras, "f")[c]; } } }; // We call it once in the beginning to get the current state. __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.update(); // Whenever a camera is added or removed from the camera engine, this update is called. __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.update = () => { for (const l in __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.lightScenes) { if (!__classPrivateFieldGet(this, _ViewportApi_lightScenes, "f")[l]) { __classPrivateFieldGet(this, _ViewportApi_lightScenes, "f")[l] = new LightSceneApi_1.LightSceneApi(this, __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.lightScenes[l]); } } for (const l in __classPrivateFieldGet(this, _ViewportApi_lightScenes, "f")) { if (!__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.lightScenes[l]) { delete __classPrivateFieldGet(this, _ViewportApi_lightScenes, "f")[l]; } } }; // We call it once in the beginning to get the current state. __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.update(); // We create the post processing api __classPrivateFieldSet(this, _ViewportApi_postProcessing, new PostProcessingApi_1.PostProcessingApi(this, __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f")), "f"); } // #endregion Constructors (1) // #region Public Getters And Setters (106) get animations() { return __classPrivateFieldGet(this, _ViewportApi_animationEngine, "f").animations; } get arRotation() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").arRotation; } set arRotation(value) { const scope = "arRotation"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "vec3"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").arRotation = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("arRotation"); } get arScale() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").arScale; } set arScale(value) { const scope = "arScale"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "vec3"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").arScale = gl_matrix_1.vec3.max(gl_matrix_1.vec3.create(), value, gl_matrix_1.vec3.fromValues(0.001, 0.001, 0.001)); __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("arScale"); } get arTranslation() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").arTranslation; } set arTranslation(value) { const scope = "arTranslation"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "vec3"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").arTranslation = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("arTranslation"); } get automaticColorAdjustment() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").automaticColorAdjustment; } set automaticColorAdjustment(value) { const scope = "automaticColorAdjustment"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").automaticColorAdjustment = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("automaticColorAdjustment"); } get automaticResizing() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").automaticResizing; } set automaticResizing(value) { const scope = "automaticResizing"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").automaticResizing = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("automaticResizing"); } get beautyRenderBlendingDuration() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").beautyRenderBlendingDuration; } set beautyRenderBlendingDuration(value) { const scope = "beautyRenderBlendingDuration"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").beautyRenderBlendingDuration = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("beautyRenderBlendingDuration"); } get beautyRenderDelay() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").beautyRenderDelay; } set beautyRenderDelay(value) { const scope = "beautyRenderDelay"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").beautyRenderDelay = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("beautyRenderDelay"); } get camera() { if (!__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.camera) return null; return __classPrivateFieldGet(this, _ViewportApi_cameras, "f")[__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.camera.id]; } get cameras() { return __classPrivateFieldGet(this, _ViewportApi_cameras, "f"); } get canvas() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").canvas; } get clearAlpha() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").clearAlpha; } set clearAlpha(value) { const scope = "clearAlpha"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").clearAlpha = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("clearAlpha"); } get clearColor() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").clearColor; } set clearColor(value) { const scope = "clearColor"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "color"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").clearColor = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("clearColor"); } get contactShadowBlur() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowBlur; } set contactShadowBlur(value) { const scope = "contactShadowBlur"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowBlur = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("contactShadowBlur"); } get contactShadowDarkness() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowDarkness; } set contactShadowDarkness(value) { const scope = "contactShadowDarkness"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowDarkness = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("contactShadowDarkness"); } get contactShadowHeight() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowHeight; } set contactShadowHeight(value) { const scope = "contactShadowHeight"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowHeight = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("contactShadowHeight"); } get contactShadowOpacity() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowOpacity; } set contactShadowOpacity(value) { const scope = "contactShadowOpacity"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowOpacity = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("contactShadowOpacity"); } get contactShadowVisibility() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowVisibility; } set contactShadowVisibility(value) { const scope = "contactShadowVisibility"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").contactShadowVisibility = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("contactShadowVisibility"); } get defaultLineMaterial() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").defaultLineMaterial; } get defaultMaterial() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").defaultMaterial; } get defaultMaterialColor() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").defaultMaterialColor; } set defaultMaterialColor(value) { const scope = "defaultMaterialColor"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "color"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").defaultMaterialColor = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("defaultMaterialColor"); } get defaultPointMaterial() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").defaultPointMaterial; } get enableAR() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").enableAR; } set enableAR(value) { const scope = "enableAR"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").enableAR = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("enableAR"); } get environmentMap() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMap; } set environmentMap(value) { const scope = "environmentMap"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "cubeMap"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMap = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMap"); } get environmentMapAsBackground() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapAsBackground; } set environmentMapAsBackground(value) { const scope = "environmentMapAsBackground"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapAsBackground = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMapAsBackground"); } get environmentMapBlurriness() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapBlurriness; } set environmentMapBlurriness(value) { const scope = "environmentMapBlurriness"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapBlurriness = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMapBlurriness"); } get environmentMapForUnlitMaterials() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapForUnlitMaterials; } set environmentMapForUnlitMaterials(value) { const scope = "environmentMapForUnlitMaterials"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapForUnlitMaterials = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMapForUnlitMaterials"); } get environmentMapIntensity() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapIntensity; } set environmentMapIntensity(value) { const scope = "environmentMapIntensity"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapIntensity = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMapIntensity"); } get environmentMapResolution() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapResolution; } set environmentMapResolution(value) { const scope = "environmentMapResolution"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "string"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapResolution = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMapResolution"); } get environmentMapRotation() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapRotation; } set environmentMapRotation(value) { const scope = "environmentMapRotation"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "quat"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").environmentMapRotation = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("environmentMapRotation"); } get gridColor() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").gridColor; } set gridColor(value) { const scope = "gridColor"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "color"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").gridColor = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("gridColor"); } get gridVisibility() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").gridVisibility; } set gridVisibility(value) { const scope = "gridVisibility"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").gridVisibility = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("gridVisibility"); } get groundPlaneColor() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneColor; } set groundPlaneColor(value) { const scope = "groundPlaneColor"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "color"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneColor = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("groundPlaneColor"); } get groundPlaneShadowColor() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneShadowColor; } set groundPlaneShadowColor(value) { const scope = "groundPlaneShadowColor"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "color"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneShadowColor = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("groundPlaneShadowColor"); } get groundPlaneShadowVisibility() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneShadowVisibility; } set groundPlaneShadowVisibility(value) { const scope = "groundPlaneShadowVisibility"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneShadowVisibility = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("groundPlaneShadowVisibility"); } get groundPlaneVisibility() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneVisibility; } set groundPlaneVisibility(value) { const scope = "groundPlaneVisibility"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").groundPlaneVisibility = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("groundPlaneVisibility"); } get id() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").id; } get isBusy() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").busy; } get lightScene() { if (!__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.lightScene) return null; return __classPrivateFieldGet(this, _ViewportApi_lightScenes, "f")[__classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.lightScene.id]; } get lightScenes() { return __classPrivateFieldGet(this, _ViewportApi_lightScenes, "f"); } get lights() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lights; } set lights(value) { const scope = "lights"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lights = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("lights"); } get loadDefaultCameras() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").loadDefaultCameras; } set loadDefaultCameras(value) { const scope = "loadDefaultCameras"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").loadDefaultCameras = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("loadDefaultCameras"); } get materialOverrideType() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").materialOverrideType; } set materialOverrideType(value) { const scope = "materialOverrideType"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "enum", false, Object.values(viewer_shared_types_1.MATERIAL_TYPE)); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").materialOverrideType = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("materialOverrideType"); } get maximumRenderingSize() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").maximumRenderingSize; } set maximumRenderingSize(value) { const scope = "maximumRenderingSize"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`SessionApi.${scope}`, value, "object"); __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`SessionApi.${scope}`, value.width, "number"); __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`SessionApi.${scope}`, value.height, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").maximumRenderingSize = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("maximumRenderingSize"); } get outputEncoding() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").outputEncoding; } set outputEncoding(value) { const scope = "outputEncoding"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "enum", true, Object.values(viewer_shared_types_1.TEXTURE_ENCODING)); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").outputEncoding = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("outputEncoding"); } get physicallyCorrectLights() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").physicallyCorrectLights; } set physicallyCorrectLights(value) { const scope = "physicallyCorrectLights"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").physicallyCorrectLights = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("physicallyCorrectLights"); } get pointSize() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").pointSize; } set pointSize(value) { const scope = "pointSize"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").pointSize = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("pointSize"); } get postProcessing() { return __classPrivateFieldGet(this, _ViewportApi_postProcessing, "f"); } get postRenderingCallback() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").postRenderingCallback; } set postRenderingCallback(value) { const scope = "postRenderingCallback"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "function", false); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").postRenderingCallback = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("postRenderingCallback"); } get preRenderingCallback() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").preRenderingCallback; } set preRenderingCallback(value) { const scope = "preRenderingCallback"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "function", false); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").preRenderingCallback = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("preRenderingCallback"); } get sessionSettingsId() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").sessionSettingsId; } get sessionSettingsMode() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").sessionSettingsMode; } get shadows() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").shadows; } set shadows(value) { const scope = "shadows"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").shadows = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("shadows"); } get show() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").show; } set show(value) { const scope = "show"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").show = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("show"); } get showStatistics() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").showStatistics; } set showStatistics(value) { const scope = "showStatistics"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").showStatistics = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("showStatistics"); } get softShadows() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").softShadows; } set softShadows(value) { const scope = "softShadows"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "boolean"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").softShadows = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("softShadows"); } get textureEncoding() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").textureEncoding; } set textureEncoding(value) { const scope = "textureEncoding"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "enum", true, Object.values(viewer_shared_types_1.TEXTURE_ENCODING)); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").textureEncoding = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("textureEncoding"); } get threeJsCoreObjects() { return { scene: __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").sceneTreeManager.scene, renderer: __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").renderer, camera: __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraManager.camera, }; } get toneMapping() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").toneMapping; } set toneMapping(value) { const scope = "toneMapping"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "enum", true, Object.values(viewer_shared_types_1.TONE_MAPPING)); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").toneMapping = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("toneMapping"); } get toneMappingExposure() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").toneMappingExposure; } set toneMappingExposure(value) { const scope = "toneMappingExposure"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "number"); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").toneMappingExposure = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("toneMappingExposure"); } get type() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").type; } set type(value) { const scope = "type"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "enum", true, Object.values(viewer_shared_types_1.RENDERER_TYPE)); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").type = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.update("type"); } get visualizeAttributes() { return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").visualizeAttributes; } set visualizeAttributes(value) { const scope = "visualizeAttributes"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, value, "function", false); __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").visualizeAttributes = value; __classPrivateFieldGet(this, _ViewportApi_logger, "f").debug(`ViewportApi.${scope}: ${scope} was set to: ${value}`); this.render(); } // #endregion Public Getters And Setters (106) // #region Public Methods (41) addCanvasEventListener(listener) { const scope = "addCanvasEventListener"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, listener, "object"); return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").domEventEngine.addDomEventListener(listener); } addFlag(flag) { const scope = "addFlag"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, flag, "enum", true, Object.values(viewer_shared_types_1.FLAG_TYPE)); const token = __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").addFlag(flag); return token; } addRestrictedCanvasListenerToken(token) { __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").domEventEngine.addRestrictedListenerToken(token); } applyViewportSettings(settings, sections) { const scope = "applyViewportSettings"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`SessionApi.${scope}`, settings, "object"); __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`SessionApi.${scope}`, sections, "object", false); return __classPrivateFieldGet(this, _ViewportApi_creationControlCenterViewport, "f").applyViewportSettings(this.id, settings, sections); } assignCamera(id) { const scope = "assignCamera"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, id, "string"); const check = __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").cameraEngine.assignCamera(id); this.update("assignCamera"); return check; } assignLightScene(id) { const scope = "assignLightScene"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, id, "string"); const check = __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").lightEngine.assignLightScene(id); this.update("assignLightScene"); return check; } close() { return __awaiter(this, void 0, void 0, function* () { return yield __classPrivateFieldGet(this, _ViewportApi_creationControlCenterViewport, "f").closeViewportEngine(this.id); }); } continueRendering() { __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").continueRendering(); } convert3Dto2D(p) { const scope = "convert3Dto2D"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, p, "vec3"); return __classPrivateFieldGet(this, _ViewportApi_renderingEngine, "f").convert3Dto2D(p); } convertToGlTF() { return __awaiter(this, arguments, void 0, function* (node = viewer_api_general_1.sceneTree.root, convertForAr = false) { const scope = "convertToGlTF"; if (!(node instanceof viewer_shared_node_tree_1.TreeNode)) throw new viewer_shared_services_1.ShapeDiverViewerValidationError(`${scope}: Input could not be validated. ${node} is not of type node.`, node, "node"); this.update("convertToGlTF.start"); const result = yield __classPrivateFieldGet(this, _ViewportApi_gltfConverter, "f").convert(node, convertForAr, this.id); this.update("convertToGlTF.end"); return new Blob([result], { type: "application/octet-stream" }); }); } createArSessionLink(node_1) { return __awaiter(this, arguments, void 0, function* (node, qrCode = true, fallbackUrl) { var _a, _b; const scope = "createArSessionLink"; if (node && !(node instanceof viewer_shared_node_tree_1.TreeNode)) throw new viewer_shared_services_1.ShapeDiverViewerValidationError(`${scope}: Input could not be validated. ${node} is not of type node.`, node, "node"); let sessionEngineId = undefined; for (const s in __classPrivateFieldGet(this, _ViewportApi_stateEngine, "f").sessionEngines) { const state = __classPrivateFieldGet(this, _ViewportApi_stateEngine, "f").sessionEngines[s]; if (state !== undefined && state.canUploadGLTF) { sessionEngineId = s; break; } } if (!sessionEngineId) throw new viewer_shared_services_1.ShapeDiverViewerArError("ViewportApi.createArSessionLink: None of the sessions that are registered are capable of using the AR feature."); const targetNode = node || viewer_api_general_1.sceneTree.root; const scalingMatrix = gl_matrix_1.mat4.fromScaling(gl_matrix_1.mat4.create(), this.arScale); // add scaling matrix to scene tree node targetNode.transformations.push({ id: "ar_scaling", matrix: scalingMatrix, }); // create the gltf this.update("createArSessionLink.start"); const blob = yield __classPrivateFieldGet(this, _ViewportApi_gltfConverter, "f").convert(targetNode, true, this.id); // remove scaling the matrix for (let i = 0; i < targetNode.transformations.length; i++) if (targetNode.transformations[i].id === "ar_scaling") targetNode.transformations.splice(i, 1); this.update("createArSessionLink.end"); const response = yield ((_a = __classPrivateFieldGet(this, _ViewportApi_stateEngine, "f").sessionEngines[sessionEngineId]) === null || _a === void 0 ? void 0 : _a.uploadGLTF(new Blob([blob], { type: "application/octet-stream" }), sdk_geometry_api_sdk_v2_1.QueryGltfConversion.SCENE)); const backends = { sddev3: "https://sddev3.eu-central-1.shapediver.com", sddev2: "https://sddev2.eu-central-1.shapediver.com", sddev: "https://sddev.eu-central-1.shapediver.com", sdtest: "https://sdtest.us-east-1.shapediver.com", sdeuc1: "https://sdeuc1.eu-central-1.shapediver.com", sdr7euc1: "https://sdr7euc1.eu-central-1.shapediver.com", sduse1: "https://model-view.shapediver.com", }; let backendIdentifier = Object.keys(backends).find((key) => { var _a; return backends[key] === ((_a = __classPrivateFieldGet(this, _ViewportApi_stateEngine, "f").sessionEngines[sessionEngineId]) === null || _a === void 0 ? void 0 : _a.modelViewUrl); }); if (!backendIdentifier) { const modelViewUrl = (_b = __classPrivateFieldGet(this, _ViewportApi_stateEngine, "f").sessionEngines[sessionEngineId]) === null || _b === void 0 ? void 0 : _b.modelViewUrl; backendIdentifier = modelViewUrl === null || modelViewUrl === void 0 ? void 0 : modelViewUrl.replace("https://", "").replace(".shapediver.com", ""); } const fallbackQueryParameter = fallbackUrl ? `fb=${encodeURIComponent(fallbackUrl)}&` : ""; if (!response || !response.gltf || !response.gltf.sceneId) throw new viewer_shared_services_1.ShapeDiverViewerArError("ViewportApi.createArSessionLink: There was an unexpected error with the ar scene response. Please contact us if this happens again."); const sceneId = response.gltf.sceneId; const link = `https://viewer.shapediver.com/v3/${viewer_shared_build_data_1.build_data.build_version}/ar.html?${fallbackQueryParameter}b=${encodeURIComponent(backendIdentifier)}&id=${encodeURIComponent(sceneId)}`; if (qrCode === false) { return link; } else { const qrCodeLink = yield new Promise((resolve, reject) => { QRCode.toDataURL(link, (error, url) => { if (error) { reject(error); } else { resolve(url); } }); }); return qrCodeLink; } }); } createLightScene(properties) { const scope = "createLightScene"; __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, properties, "object", false); const prop = Object.assign({}, properties); __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`ViewportApi.${scope}`, prop.name, "string", false); __classPrivateFieldGet(this, _ViewportApi_inputValidator, "f").validateAndError(`Viewp