@combeenation/3d-viewer 13.0.1 → 14.0.1-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +9 -9
  2. package/dist/lib-cjs/buildinfo.json +3 -3
  3. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  4. package/dist/lib-cjs/index.d.ts +62 -63
  5. package/dist/lib-cjs/index.js +94 -95
  6. package/dist/lib-cjs/index.js.map +1 -1
  7. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
  8. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
  9. package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
  10. package/dist/lib-cjs/internal/cloning-helper.js +163 -163
  11. package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
  12. package/dist/lib-cjs/internal/device-helper.js +24 -24
  13. package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
  14. package/dist/lib-cjs/internal/geometry-helper.js +145 -145
  15. package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
  16. package/dist/lib-cjs/internal/metadata-helper.js +50 -50
  17. package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
  18. package/dist/lib-cjs/internal/paintable-helper.js +286 -286
  19. package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
  20. package/dist/lib-cjs/internal/tags-helper.js +37 -37
  21. package/dist/lib-cjs/manager/camera-manager.d.ts +110 -51
  22. package/dist/lib-cjs/manager/camera-manager.js +206 -153
  23. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  24. package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
  25. package/dist/lib-cjs/manager/debug-manager.js +217 -217
  26. package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
  27. package/dist/lib-cjs/manager/event-manager.js +71 -71
  28. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +84 -75
  29. package/dist/lib-cjs/manager/gltf-export-manager.js +290 -278
  30. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  31. package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
  32. package/dist/lib-cjs/manager/material-manager.js +125 -125
  33. package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
  34. package/dist/lib-cjs/manager/model-manager.js +382 -382
  35. package/dist/lib-cjs/manager/parameter-manager.d.ts +210 -210
  36. package/dist/lib-cjs/manager/parameter-manager.js +514 -514
  37. package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
  38. package/dist/lib-cjs/manager/scene-manager.js +64 -64
  39. package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
  40. package/dist/lib-cjs/manager/texture-manager.js +43 -43
  41. package/dist/lib-cjs/viewer-error.d.ts +48 -48
  42. package/dist/lib-cjs/viewer-error.js +60 -60
  43. package/dist/lib-cjs/viewer.d.ts +115 -117
  44. package/dist/lib-cjs/viewer.js +217 -221
  45. package/dist/lib-cjs/viewer.js.map +1 -1
  46. package/package.json +91 -91
  47. package/src/buildinfo.json +3 -3
  48. package/src/dev.ts +47 -47
  49. package/src/global-types.d.ts +39 -39
  50. package/src/index.ts +81 -82
  51. package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
  52. package/src/internal/cloning-helper.ts +225 -225
  53. package/src/internal/device-helper.ts +25 -25
  54. package/src/internal/geometry-helper.ts +181 -181
  55. package/src/internal/metadata-helper.ts +63 -63
  56. package/src/internal/paintable-helper.ts +310 -310
  57. package/src/internal/tags-helper.ts +41 -41
  58. package/src/manager/camera-manager.ts +365 -236
  59. package/src/manager/debug-manager.ts +245 -245
  60. package/src/manager/event-manager.ts +72 -72
  61. package/src/manager/gltf-export-manager.ts +357 -341
  62. package/src/manager/material-manager.ts +135 -135
  63. package/src/manager/model-manager.ts +458 -458
  64. package/src/manager/parameter-manager.ts +652 -652
  65. package/src/manager/scene-manager.ts +101 -101
  66. package/src/manager/texture-manager.ts +32 -32
  67. package/src/viewer-error.ts +68 -68
  68. package/src/viewer.ts +290 -296
  69. package/dist/lib-cjs/manager/screenshot-manager.d.ts +0 -36
  70. package/dist/lib-cjs/manager/screenshot-manager.js +0 -40
  71. package/dist/lib-cjs/manager/screenshot-manager.js.map +0 -1
  72. package/src/manager/screenshot-manager.ts +0 -59
@@ -1,38 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cloneTags = exports.setTagsAsString = exports.deleteAllTags = exports.setTags = exports.getTags = exports.hasTag = void 0;
4
- const tags_1 = require("@babylonjs/core/Misc/tags");
5
- function hasTag(object, tag) {
6
- return tags_1.Tags.MatchesQuery(object, tag);
7
- }
8
- exports.hasTag = hasTag;
9
- function getTags(object) {
10
- var _a;
11
- const tagsObject = (_a = tags_1.Tags.GetTags(object, false)) !== null && _a !== void 0 ? _a : {};
12
- const tags = Object.keys(tagsObject);
13
- return tags;
14
- }
15
- exports.getTags = getTags;
16
- function setTags(object, tags) {
17
- const tagsString = tags.join(' ');
18
- tags_1.Tags.AddTagsTo(object, tagsString);
19
- }
20
- exports.setTags = setTags;
21
- function deleteAllTags(object) {
22
- const curTags = tags_1.Tags.GetTags(object);
23
- if (curTags) {
24
- tags_1.Tags.RemoveTagsFrom(object, curTags);
25
- }
26
- }
27
- exports.deleteAllTags = deleteAllTags;
28
- function setTagsAsString(object, tagsString) {
29
- tags_1.Tags.AddTagsTo(object, tagsString);
30
- }
31
- exports.setTagsAsString = setTagsAsString;
32
- function cloneTags(sourceObject, destinationObject) {
33
- if (tags_1.Tags.HasTags(sourceObject)) {
34
- tags_1.Tags.AddTagsTo(destinationObject, tags_1.Tags.GetTags(sourceObject, true));
35
- }
36
- }
37
- exports.cloneTags = cloneTags;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneTags = exports.setTagsAsString = exports.deleteAllTags = exports.setTags = exports.getTags = exports.hasTag = void 0;
4
+ const tags_1 = require("@babylonjs/core/Misc/tags");
5
+ function hasTag(object, tag) {
6
+ return tags_1.Tags.MatchesQuery(object, tag);
7
+ }
8
+ exports.hasTag = hasTag;
9
+ function getTags(object) {
10
+ var _a;
11
+ const tagsObject = (_a = tags_1.Tags.GetTags(object, false)) !== null && _a !== void 0 ? _a : {};
12
+ const tags = Object.keys(tagsObject);
13
+ return tags;
14
+ }
15
+ exports.getTags = getTags;
16
+ function setTags(object, tags) {
17
+ const tagsString = tags.join(' ');
18
+ tags_1.Tags.AddTagsTo(object, tagsString);
19
+ }
20
+ exports.setTags = setTags;
21
+ function deleteAllTags(object) {
22
+ const curTags = tags_1.Tags.GetTags(object);
23
+ if (curTags) {
24
+ tags_1.Tags.RemoveTagsFrom(object, curTags);
25
+ }
26
+ }
27
+ exports.deleteAllTags = deleteAllTags;
28
+ function setTagsAsString(object, tagsString) {
29
+ tags_1.Tags.AddTagsTo(object, tagsString);
30
+ }
31
+ exports.setTagsAsString = setTagsAsString;
32
+ function cloneTags(sourceObject, destinationObject) {
33
+ if (tags_1.Tags.HasTags(sourceObject)) {
34
+ tags_1.Tags.AddTagsTo(destinationObject, tags_1.Tags.GetTags(sourceObject, true));
35
+ }
36
+ }
37
+ exports.cloneTags = cloneTags;
38
38
  //# sourceMappingURL=tags-helper.js.map
@@ -1,51 +1,110 @@
1
- import { AnimationGroup, ArcRotateCamera, ExcludedGeometryList, Vector3, Viewer } from '../index';
2
- export declare type CameraPosition = {
3
- alpha: number;
4
- beta: number;
5
- radius: number;
6
- target: Vector3;
7
- };
8
- export declare type AutofocusSettings = {
9
- /** Can be used to customize the margins shown around the 3d model. Defaults to 1. */
10
- radiusFactor?: number;
11
- adjustWheelPrecision?: boolean;
12
- adjustPanningSensibility?: boolean;
13
- adjustPinchPrecision?: boolean;
14
- /** Desired horizontal camera angle, this won't be overwritten by the autofocus function */
15
- alpha?: number;
16
- /** Desired vertical camera angle, this won't be overwritten by the autofocus function */
17
- beta?: number;
18
- /** Optional list of geometry to be excluded from consideration */
19
- exclude?: ExcludedGeometryList;
20
- durationMs?: number;
21
- };
22
- /**
23
- * Manager for camera related tasks
24
- */
25
- export declare class CameraManager {
26
- protected viewer: Viewer;
27
- static readonly CAMERA_ANIMATION_NAME = "__cameraAnimation__";
28
- /** @internal */
29
- static readonly DEFAULT_CAMERA_POSITION: CameraPosition;
30
- protected static readonly _AUTOFOCUS_CONSTANTS: {
31
- minZ: number;
32
- wheelPrecision: number;
33
- panningSensibility: number;
34
- pinchPrecision: number;
35
- };
36
- protected static readonly _DEFAULT_AUTOFOCUS_RADIUS_FACTOR = 1;
37
- protected static readonly _DEFAULT_CAM_SPEED_MS = 250;
38
- /** @internal */
39
- constructor(viewer: Viewer);
40
- /**
41
- * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
42
- */
43
- autofocusActiveCamera(settings?: AutofocusSettings): Promise<void>;
44
- /**
45
- * Moves the active camera smoothly to certain position
46
- *
47
- * @param durationMs defaults to 250ms if unset, use 0 for instant movement
48
- */
49
- moveActiveCameraTo(position: CameraPosition, durationMs?: number): Promise<void>;
50
- protected static _addCameraAnimationToGroup(targetProperty: string, from: number | Vector3, to: number | Vector3, framesPerSec: number, dataType: number, animationGroup: AnimationGroup, activeCamera: ArcRotateCamera): void;
51
- }
1
+ import { AnimationGroup, ArcRotateCamera, BoundingSphere, ExcludedGeometryList, Vector3, Viewer } from '../index';
2
+ export declare type CameraPosition = {
3
+ alpha: number;
4
+ beta: number;
5
+ radius: number;
6
+ target: Vector3;
7
+ };
8
+ export declare type AutofocusSettings = {
9
+ /** Can be used to customize the margins shown around the 3d model. Defaults to 1. */
10
+ radiusFactor?: number;
11
+ adjustWheelPrecision?: boolean;
12
+ adjustPanningSensibility?: boolean;
13
+ adjustPinchPrecision?: boolean;
14
+ /** Desired horizontal camera angle, this won't be overwritten by the autofocus function */
15
+ alpha?: number;
16
+ /** Desired vertical camera angle, this won't be overwritten by the autofocus function */
17
+ beta?: number;
18
+ /** Optional list of geometry to be excluded from consideration */
19
+ exclude?: ExcludedGeometryList;
20
+ durationMs?: number;
21
+ };
22
+ export declare type ScreenshotSettings = {
23
+ /** Width of the final screenshot image, defaults to canvas width */
24
+ width?: number;
25
+ /** Height of the final screenshot image, defaults to canvas height */
26
+ height?: number;
27
+ /** Camera alpha angle used for the screenshot, defaults to alpha angle of currently active camera */
28
+ alpha?: number;
29
+ /** Camera beta angle used for the screenshot, defaults to beta angle of currently active camera */
30
+ beta?: number;
31
+ /**
32
+ * Camera radius used for the screenshot, default value depends on `autofocusScene` flag:
33
+ * - `true`: radius is calculated automatically so that the whole current scene content is visible
34
+ * - `false`: radius of currently active camera is used
35
+ */
36
+ radius?: number;
37
+ /**
38
+ * Camera target used for the screenshot, default value depends on `autofocusScene` flag:
39
+ * - `true`: center of the current scene content is set as camera target
40
+ * - `false`: target of currently active camera is used
41
+ */
42
+ target?: Vector3;
43
+ /** Used to scale the calculated radius if `radius` property is not set and `autofocusScene` mode is active */
44
+ radiusFactor?: number;
45
+ /** Can be used to automatically calculate camera `radius` and `target`, if these 2 settings are not defined
46
+ * explicitely */
47
+ autofocusScene?: boolean;
48
+ /** Optional list of geometry to be excluded from consideration */
49
+ exclude?: ExcludedGeometryList;
50
+ /**
51
+ * "MIME type" of the returned screenshot image, defaults to `image/png`
52
+ *
53
+ * **Info regarding JPEG:** \
54
+ * Use mimeType `image/jpeg` (**not** `image/jpg`) when creating jpeg's. \
55
+ * Also ensure that the viewer scenes `clearColor` has an alpha value of `1` as jpeg's don't
56
+ * support transparency. Otherwise background will always be black for jpeg's.
57
+ */
58
+ mimeType?: string;
59
+ /** If file name is given, the screenshot image will be downloaded and the base64 string will NOT be returned! */
60
+ fileName?: string;
61
+ /** Expert settings to tweak the screenshot image, see [Babylon.js](https://doc.babylonjs.com/typedoc/functions/BABYLON.CreateScreenshotUsingRenderTarget) docs for further information */
62
+ samples?: number;
63
+ /** Expert settings to tweak the screenshot image, see [Babylon.js](https://doc.babylonjs.com/typedoc/functions/BABYLON.CreateScreenshotUsingRenderTarget) docs for further information */
64
+ antialiasing?: boolean;
65
+ /** Expert settings to tweak the screenshot image, see [Babylon.js](https://doc.babylonjs.com/typedoc/functions/BABYLON.CreateScreenshotUsingRenderTarget) docs for further information */
66
+ renderSprites?: boolean;
67
+ /** Expert settings to tweak the screenshot image, see [Babylon.js](https://doc.babylonjs.com/typedoc/functions/BABYLON.CreateScreenshotUsingRenderTarget) docs for further information */
68
+ enableStencilBuffer?: boolean;
69
+ /** Expert settings to tweak the screenshot image, see [Babylon.js](https://doc.babylonjs.com/typedoc/functions/BABYLON.CreateScreenshotUsingRenderTarget) docs for further information */
70
+ useLayerMask?: boolean;
71
+ /** Expert settings to tweak the screenshot image, see [Babylon.js](https://doc.babylonjs.com/typedoc/functions/BABYLON.CreateScreenshotUsingRenderTarget) docs for further information */
72
+ quality?: number;
73
+ };
74
+ /**
75
+ * Manager for camera related tasks
76
+ */
77
+ export declare class CameraManager {
78
+ protected viewer: Viewer;
79
+ static readonly CAMERA_ANIMATION_NAME = "__cameraAnimation__";
80
+ /** @internal */
81
+ static readonly DEFAULT_CAMERA_POSITION: CameraPosition;
82
+ protected static readonly _AUTOFOCUS_CONSTANTS: {
83
+ minZ: number;
84
+ wheelPrecision: number;
85
+ panningSensibility: number;
86
+ pinchPrecision: number;
87
+ };
88
+ protected static readonly _DEFAULT_AUTOFOCUS_RADIUS_FACTOR = 1;
89
+ protected static readonly _DEFAULT_CAM_SPEED_MS = 250;
90
+ protected static readonly _SCREENSHOT_CAMERA_NAME = "__screenshotCamera__";
91
+ /** @internal */
92
+ constructor(viewer: Viewer);
93
+ /**
94
+ * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
95
+ */
96
+ autofocusActiveCamera(settings?: AutofocusSettings): Promise<void>;
97
+ /**
98
+ * Moves the active camera smoothly to certain position
99
+ *
100
+ * @param durationMs defaults to 250ms if unset, use 0 for instant movement
101
+ */
102
+ moveActiveCameraTo(position: CameraPosition, durationMs?: number): Promise<void>;
103
+ /**
104
+ * Takes a sceenshot the the current scene.\
105
+ * The result is a string containing a base64 encoded image.
106
+ */
107
+ createScreenshot(settings?: ScreenshotSettings): Promise<string>;
108
+ protected static _addCameraAnimationToGroup(targetProperty: string, from: number | Vector3, to: number | Vector3, framesPerSec: number, dataType: number, animationGroup: AnimationGroup, activeCamera: ArcRotateCamera): void;
109
+ protected _getAutofocusZoomingDistance(boundingSphere: BoundingSphere, camera: ArcRotateCamera): number;
110
+ }
@@ -1,154 +1,207 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CameraManager = void 0;
13
- const index_1 = require("../index");
14
- /**
15
- * Manager for camera related tasks
16
- */
17
- class CameraManager {
18
- /** @internal */
19
- constructor(viewer) {
20
- this.viewer = viewer;
21
- }
22
- /**
23
- * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
24
- */
25
- autofocusActiveCamera(settings) {
26
- var _a, _b, _c;
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const activeCamera = this.viewer.scene.activeCamera;
29
- if (!(activeCamera instanceof index_1.ArcRotateCamera)) {
30
- throw new Error(`Camera type "${activeCamera === null || activeCamera === void 0 ? void 0 : activeCamera.getClassName()}" is not implemented for "autofocusActiveCamera".`);
31
- }
32
- // get bounding box of all visible meshes, this is the base for the autofocus algorithm
33
- const boundingInfo = this.viewer.calculateBoundingInfo(settings === null || settings === void 0 ? void 0 : settings.exclude);
34
- // optionally show bounding sphere for debugging purpose
35
- this.viewer.eventManager.fireEvent(index_1.ViewerEvent.AutofocusStart, boundingInfo.boundingSphere);
36
- const radius = boundingInfo.boundingSphere.radius;
37
- const center = boundingInfo.boundingSphere.center;
38
- // set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
39
- activeCamera.lowerRadiusLimit = radius;
40
- // additional settings
41
- // constants for division are taken directly from Babylon.js repository
42
- activeCamera.minZ = Math.min(radius / CameraManager._AUTOFOCUS_CONSTANTS.minZ, 1);
43
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
44
- activeCamera.wheelPrecision = CameraManager._AUTOFOCUS_CONSTANTS.wheelPrecision / radius;
45
- }
46
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
47
- activeCamera.panningSensibility = CameraManager._AUTOFOCUS_CONSTANTS.panningSensibility / radius;
48
- }
49
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
50
- activeCamera.pinchPrecision = CameraManager._AUTOFOCUS_CONSTANTS.pinchPrecision / radius;
51
- }
52
- const radiusFactor = (_a = settings === null || settings === void 0 ? void 0 : settings.radiusFactor) !== null && _a !== void 0 ? _a : CameraManager._DEFAULT_AUTOFOCUS_RADIUS_FACTOR;
53
- const alpha = (_b = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _b !== void 0 ? _b : CameraManager.DEFAULT_CAMERA_POSITION.alpha;
54
- const beta = (_c = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _c !== void 0 ? _c : CameraManager.DEFAULT_CAMERA_POSITION.beta;
55
- // calculation is taken from Babylon.js repository, which on their side took it from this SO post:
56
- // http://stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene
57
- // there's a good sketch which explains the calculation quite a bit
58
- const aspectRatio = this.viewer.engine.getAspectRatio(activeCamera);
59
- const frustumSlopeY = Math.tan(activeCamera.fov / 2);
60
- const frustumSlopeX = frustumSlopeY * aspectRatio;
61
- const distanceForHorizontalFrustum = radius * Math.sqrt(1 + 1 / (frustumSlopeX * frustumSlopeX));
62
- const distanceForVerticalFrustum = radius * Math.sqrt(1 + 1 / (frustumSlopeY * frustumSlopeY));
63
- const distance = Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum);
64
- const newCameraPosition = {
65
- alpha: alpha,
66
- beta: beta,
67
- radius: distance * radiusFactor,
68
- target: center,
69
- };
70
- yield this.moveActiveCameraTo(newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.durationMs);
71
- });
72
- }
73
- /**
74
- * Moves the active camera smoothly to certain position
75
- *
76
- * @param durationMs defaults to 250ms if unset, use 0 for instant movement
77
- */
78
- moveActiveCameraTo(position, durationMs = CameraManager._DEFAULT_CAM_SPEED_MS) {
79
- var _a, _b, _c, _d;
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const activeCamera = this.viewer.scene.activeCamera;
82
- if (!(activeCamera instanceof index_1.ArcRotateCamera)) {
83
- throw new Error(`Camera type "${activeCamera === null || activeCamera === void 0 ? void 0 : activeCamera.getClassName()}" is not implemented yet for "moveActiveCameraTo".`);
84
- }
85
- if (durationMs === 0) {
86
- // instant movement without animation
87
- activeCamera.alpha = (_a = position.alpha) !== null && _a !== void 0 ? _a : activeCamera.alpha;
88
- activeCamera.beta = (_b = position.beta) !== null && _b !== void 0 ? _b : activeCamera.beta;
89
- activeCamera.radius = (_c = position.radius) !== null && _c !== void 0 ? _c : activeCamera.radius;
90
- activeCamera.target = (_d = position.target) !== null && _d !== void 0 ? _d : activeCamera.target;
91
- }
92
- const framesPerSec = 100;
93
- const animationGroup = new index_1.AnimationGroup(CameraManager.CAMERA_ANIMATION_NAME, this.viewer.scene);
94
- if (position.alpha !== undefined) {
95
- // transform the target's alpha value into the same turn as the current camera position to avoid movements
96
- // > 360 degrees
97
- const alphaGap = activeCamera.alpha - position.alpha;
98
- const cntTurns = Math.round(alphaGap / (2 * Math.PI));
99
- const targetAlpha = position.alpha + 2 * Math.PI * cntTurns;
100
- CameraManager._addCameraAnimationToGroup('alpha', activeCamera.alpha, targetAlpha, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
101
- }
102
- if (position.beta !== undefined) {
103
- CameraManager._addCameraAnimationToGroup('beta', activeCamera.beta, position.beta, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
104
- }
105
- if (position.radius !== undefined) {
106
- CameraManager._addCameraAnimationToGroup('radius', activeCamera.radius, position.radius, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
107
- }
108
- if (position.target !== undefined) {
109
- CameraManager._addCameraAnimationToGroup('target', activeCamera.target, position.target, framesPerSec, index_1.Animation.ANIMATIONTYPE_VECTOR3, animationGroup, activeCamera);
110
- }
111
- // animation is created for 1 second (100 frames), adjust speed ratio according to desired movement time
112
- const speedRatio = 1000 / durationMs;
113
- return new Promise(resolve => {
114
- animationGroup.onAnimationGroupEndObservable.addOnce(() => {
115
- animationGroup.dispose();
116
- resolve();
117
- });
118
- animationGroup.start(false, speedRatio, 0, 100);
119
- });
120
- });
121
- }
122
- static _addCameraAnimationToGroup(targetProperty, from, to, framesPerSec, dataType, animationGroup, activeCamera) {
123
- const alphaAnimation = new index_1.Animation(targetProperty, targetProperty, framesPerSec, dataType, index_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
124
- alphaAnimation.setKeys([
125
- {
126
- frame: 0,
127
- value: from,
128
- },
129
- {
130
- frame: 100,
131
- value: to,
132
- },
133
- ]);
134
- animationGroup.addTargetedAnimation(alphaAnimation, activeCamera);
135
- }
136
- }
137
- exports.CameraManager = CameraManager;
138
- CameraManager.CAMERA_ANIMATION_NAME = '__cameraAnimation__';
139
- /** @internal */
140
- CameraManager.DEFAULT_CAMERA_POSITION = {
141
- alpha: (45 * Math.PI) / 180,
142
- beta: (75 * Math.PI) / 180,
143
- radius: 1,
144
- target: new index_1.Vector3(0, 0, 0),
145
- };
146
- CameraManager._AUTOFOCUS_CONSTANTS = {
147
- minZ: 100,
148
- wheelPrecision: 100,
149
- panningSensibility: 2500,
150
- pinchPrecision: 200,
151
- };
152
- CameraManager._DEFAULT_AUTOFOCUS_RADIUS_FACTOR = 1;
153
- CameraManager._DEFAULT_CAM_SPEED_MS = 250;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CameraManager = void 0;
13
+ const index_1 = require("../index");
14
+ const geometry_helper_1 = require("../internal/geometry-helper");
15
+ /**
16
+ * Manager for camera related tasks
17
+ */
18
+ class CameraManager {
19
+ /** @internal */
20
+ constructor(viewer) {
21
+ this.viewer = viewer;
22
+ }
23
+ /**
24
+ * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
25
+ */
26
+ autofocusActiveCamera(settings) {
27
+ var _a, _b, _c;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const activeCamera = this.viewer.scene.activeCamera;
30
+ if (!(activeCamera instanceof index_1.ArcRotateCamera)) {
31
+ throw new Error(`Camera type "${activeCamera === null || activeCamera === void 0 ? void 0 : activeCamera.getClassName()}" is not implemented for "autofocusActiveCamera".`);
32
+ }
33
+ // get bounding box of all visible meshes, this is the base for the autofocus algorithm
34
+ const boundingInfo = this.viewer.calculateBoundingInfo(settings === null || settings === void 0 ? void 0 : settings.exclude);
35
+ // optionally show bounding sphere for debugging purpose
36
+ this.viewer.eventManager.fireEvent(index_1.ViewerEvent.AutofocusStart, boundingInfo.boundingSphere);
37
+ const distance = this._getAutofocusZoomingDistance(boundingInfo.boundingSphere, activeCamera);
38
+ const radius = boundingInfo.boundingSphere.radius;
39
+ const center = boundingInfo.boundingSphere.center;
40
+ // set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
41
+ activeCamera.lowerRadiusLimit = radius;
42
+ // additional settings
43
+ // constants for division are taken directly from Babylon.js repository
44
+ activeCamera.minZ = Math.min(radius / CameraManager._AUTOFOCUS_CONSTANTS.minZ, 1);
45
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
46
+ activeCamera.wheelPrecision = CameraManager._AUTOFOCUS_CONSTANTS.wheelPrecision / radius;
47
+ }
48
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
49
+ activeCamera.panningSensibility = CameraManager._AUTOFOCUS_CONSTANTS.panningSensibility / radius;
50
+ }
51
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
52
+ activeCamera.pinchPrecision = CameraManager._AUTOFOCUS_CONSTANTS.pinchPrecision / radius;
53
+ }
54
+ const radiusFactor = (_a = settings === null || settings === void 0 ? void 0 : settings.radiusFactor) !== null && _a !== void 0 ? _a : CameraManager._DEFAULT_AUTOFOCUS_RADIUS_FACTOR;
55
+ const alpha = (_b = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _b !== void 0 ? _b : CameraManager.DEFAULT_CAMERA_POSITION.alpha;
56
+ const beta = (_c = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _c !== void 0 ? _c : CameraManager.DEFAULT_CAMERA_POSITION.beta;
57
+ const newCameraPosition = {
58
+ alpha: alpha,
59
+ beta: beta,
60
+ radius: distance * radiusFactor,
61
+ target: center,
62
+ };
63
+ yield this.moveActiveCameraTo(newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.durationMs);
64
+ });
65
+ }
66
+ /**
67
+ * Moves the active camera smoothly to certain position
68
+ *
69
+ * @param durationMs defaults to 250ms if unset, use 0 for instant movement
70
+ */
71
+ moveActiveCameraTo(position, durationMs = CameraManager._DEFAULT_CAM_SPEED_MS) {
72
+ var _a, _b, _c, _d;
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const activeCamera = this.viewer.scene.activeCamera;
75
+ if (!(activeCamera instanceof index_1.ArcRotateCamera)) {
76
+ throw new Error(`Camera type "${activeCamera === null || activeCamera === void 0 ? void 0 : activeCamera.getClassName()}" is not implemented yet for "moveActiveCameraTo".`);
77
+ }
78
+ if (durationMs === 0) {
79
+ // instant movement without animation
80
+ activeCamera.alpha = (_a = position.alpha) !== null && _a !== void 0 ? _a : activeCamera.alpha;
81
+ activeCamera.beta = (_b = position.beta) !== null && _b !== void 0 ? _b : activeCamera.beta;
82
+ activeCamera.radius = (_c = position.radius) !== null && _c !== void 0 ? _c : activeCamera.radius;
83
+ activeCamera.target = (_d = position.target) !== null && _d !== void 0 ? _d : activeCamera.target;
84
+ }
85
+ const framesPerSec = 100;
86
+ const animationGroup = new index_1.AnimationGroup(CameraManager.CAMERA_ANIMATION_NAME, this.viewer.scene);
87
+ if (position.alpha !== undefined) {
88
+ // transform the target's alpha value into the same turn as the current camera position to avoid movements
89
+ // > 360 degrees
90
+ const alphaGap = activeCamera.alpha - position.alpha;
91
+ const cntTurns = Math.round(alphaGap / (2 * Math.PI));
92
+ const targetAlpha = position.alpha + 2 * Math.PI * cntTurns;
93
+ CameraManager._addCameraAnimationToGroup('alpha', activeCamera.alpha, targetAlpha, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
94
+ }
95
+ if (position.beta !== undefined) {
96
+ CameraManager._addCameraAnimationToGroup('beta', activeCamera.beta, position.beta, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
97
+ }
98
+ if (position.radius !== undefined) {
99
+ CameraManager._addCameraAnimationToGroup('radius', activeCamera.radius, position.radius, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
100
+ }
101
+ if (position.target !== undefined) {
102
+ CameraManager._addCameraAnimationToGroup('target', activeCamera.target, position.target, framesPerSec, index_1.Animation.ANIMATIONTYPE_VECTOR3, animationGroup, activeCamera);
103
+ }
104
+ // animation is created for 1 second (100 frames), adjust speed ratio according to desired movement time
105
+ const speedRatio = 1000 / durationMs;
106
+ return new Promise(resolve => {
107
+ animationGroup.onAnimationGroupEndObservable.addOnce(() => {
108
+ animationGroup.dispose();
109
+ resolve();
110
+ });
111
+ animationGroup.start(false, speedRatio, 0, 100);
112
+ });
113
+ });
114
+ }
115
+ /**
116
+ * Takes a sceenshot the the current scene.\
117
+ * The result is a string containing a base64 encoded image.
118
+ */
119
+ createScreenshot(settings) {
120
+ var _a, _b;
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const screenshotCam = (_a = this.viewer.scene.activeCamera) === null || _a === void 0 ? void 0 : _a.clone(CameraManager._SCREENSHOT_CAMERA_NAME);
123
+ const boundingInfo = (settings === null || settings === void 0 ? void 0 : settings.autofocusScene) ? this.viewer.calculateBoundingInfo(settings.exclude) : undefined;
124
+ if ((settings === null || settings === void 0 ? void 0 : settings.alpha) !== undefined) {
125
+ screenshotCam.alpha = settings.alpha;
126
+ }
127
+ if ((settings === null || settings === void 0 ? void 0 : settings.beta) !== undefined) {
128
+ screenshotCam.beta = settings.beta;
129
+ }
130
+ if ((settings === null || settings === void 0 ? void 0 : settings.radius) !== undefined) {
131
+ screenshotCam.radius = settings.radius;
132
+ }
133
+ else if (boundingInfo) {
134
+ // zoom out to have full scene in view if requested by `autofocusScene` flag
135
+ const distance = this._getAutofocusZoomingDistance(boundingInfo.boundingSphere, screenshotCam);
136
+ const radiusFactor = (_b = settings === null || settings === void 0 ? void 0 : settings.radiusFactor) !== null && _b !== void 0 ? _b : 1;
137
+ screenshotCam.radius = distance * radiusFactor;
138
+ }
139
+ // `cloneAlphaBetaRadius` has to be set to true, otherwise these values get adapted by setting the new target
140
+ // this would also be the case when setting `screenshotCam.target` directly
141
+ if ((settings === null || settings === void 0 ? void 0 : settings.target) !== undefined) {
142
+ screenshotCam.setTarget(settings.target, undefined, undefined, true);
143
+ }
144
+ else if (boundingInfo) {
145
+ screenshotCam.setTarget(boundingInfo.boundingSphere.center, undefined, undefined, true);
146
+ }
147
+ // don't expose internal props of `IScreenshotSize` in the API (yet), as it gets rather confusing and it shouldn't
148
+ // be necessary in the first place
149
+ // also let Babylon.js do all the fallback handling for missing properties
150
+ const size = { width: settings === null || settings === void 0 ? void 0 : settings.width, height: settings === null || settings === void 0 ? void 0 : settings.height };
151
+ // for some reason the `customizeTexture` property is not exposed in the async version of this function, therefore
152
+ // we create the promise here manually
153
+ const imageStr = yield new Promise(resolve => {
154
+ index_1.ScreenshotTools.CreateScreenshotUsingRenderTarget(this.viewer.engine, screenshotCam, size, (data) => resolve(data), settings === null || settings === void 0 ? void 0 : settings.mimeType, settings === null || settings === void 0 ? void 0 : settings.samples, settings === null || settings === void 0 ? void 0 : settings.antialiasing, settings === null || settings === void 0 ? void 0 : settings.fileName, settings === null || settings === void 0 ? void 0 : settings.renderSprites, settings === null || settings === void 0 ? void 0 : settings.enableStencilBuffer, settings === null || settings === void 0 ? void 0 : settings.useLayerMask, settings === null || settings === void 0 ? void 0 : settings.quality, texture => {
155
+ texture.renderList = this.viewer.scene.meshes.filter(mesh => !(settings === null || settings === void 0 ? void 0 : settings.exclude) || !(0, geometry_helper_1.isNodeExcluded)(mesh, settings.exclude));
156
+ });
157
+ });
158
+ screenshotCam.dispose();
159
+ return imageStr;
160
+ });
161
+ }
162
+ static _addCameraAnimationToGroup(targetProperty, from, to, framesPerSec, dataType, animationGroup, activeCamera) {
163
+ const alphaAnimation = new index_1.Animation(targetProperty, targetProperty, framesPerSec, dataType, index_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
164
+ alphaAnimation.setKeys([
165
+ {
166
+ frame: 0,
167
+ value: from,
168
+ },
169
+ {
170
+ frame: 100,
171
+ value: to,
172
+ },
173
+ ]);
174
+ animationGroup.addTargetedAnimation(alphaAnimation, activeCamera);
175
+ }
176
+ _getAutofocusZoomingDistance(boundingSphere, camera) {
177
+ // calculation is taken from Babylon.js repository, which on their side took it from this SO post:
178
+ // http://stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene
179
+ // there's a good sketch which explains the calculation quite a bit
180
+ const aspectRatio = this.viewer.engine.getAspectRatio(camera);
181
+ const frustumSlopeY = Math.tan(camera.fov / 2);
182
+ const frustumSlopeX = frustumSlopeY * aspectRatio;
183
+ const distanceForHorizontalFrustum = boundingSphere.radius * Math.sqrt(1 + 1 / (frustumSlopeX * frustumSlopeX));
184
+ const distanceForVerticalFrustum = boundingSphere.radius * Math.sqrt(1 + 1 / (frustumSlopeY * frustumSlopeY));
185
+ const distance = Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum);
186
+ return distance;
187
+ }
188
+ }
189
+ exports.CameraManager = CameraManager;
190
+ CameraManager.CAMERA_ANIMATION_NAME = '__cameraAnimation__';
191
+ /** @internal */
192
+ CameraManager.DEFAULT_CAMERA_POSITION = {
193
+ alpha: (45 * Math.PI) / 180,
194
+ beta: (75 * Math.PI) / 180,
195
+ radius: 1,
196
+ target: new index_1.Vector3(0, 0, 0),
197
+ };
198
+ CameraManager._AUTOFOCUS_CONSTANTS = {
199
+ minZ: 100,
200
+ wheelPrecision: 100,
201
+ panningSensibility: 2500,
202
+ pinchPrecision: 200,
203
+ };
204
+ CameraManager._DEFAULT_AUTOFOCUS_RADIUS_FACTOR = 1;
205
+ CameraManager._DEFAULT_CAM_SPEED_MS = 250;
206
+ CameraManager._SCREENSHOT_CAMERA_NAME = '__screenshotCamera__';
154
207
  //# sourceMappingURL=camera-manager.js.map