@combeenation/3d-viewer 14.0.0 → 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 (65) 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 -62
  5. package/dist/lib-cjs/index.js +94 -94
  6. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
  7. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
  8. package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
  9. package/dist/lib-cjs/internal/cloning-helper.js +163 -163
  10. package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
  11. package/dist/lib-cjs/internal/device-helper.js +24 -24
  12. package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
  13. package/dist/lib-cjs/internal/geometry-helper.js +145 -145
  14. package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
  15. package/dist/lib-cjs/internal/metadata-helper.js +50 -50
  16. package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
  17. package/dist/lib-cjs/internal/paintable-helper.js +286 -286
  18. package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
  19. package/dist/lib-cjs/internal/tags-helper.js +37 -37
  20. package/dist/lib-cjs/manager/camera-manager.d.ts +110 -110
  21. package/dist/lib-cjs/manager/camera-manager.js +206 -206
  22. package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
  23. package/dist/lib-cjs/manager/debug-manager.js +217 -217
  24. package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
  25. package/dist/lib-cjs/manager/event-manager.js +71 -71
  26. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +84 -75
  27. package/dist/lib-cjs/manager/gltf-export-manager.js +290 -278
  28. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  29. package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
  30. package/dist/lib-cjs/manager/material-manager.js +125 -125
  31. package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
  32. package/dist/lib-cjs/manager/model-manager.js +382 -382
  33. package/dist/lib-cjs/manager/parameter-manager.d.ts +210 -210
  34. package/dist/lib-cjs/manager/parameter-manager.js +514 -514
  35. package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
  36. package/dist/lib-cjs/manager/scene-manager.js +64 -64
  37. package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
  38. package/dist/lib-cjs/manager/texture-manager.js +43 -43
  39. package/dist/lib-cjs/viewer-error.d.ts +48 -48
  40. package/dist/lib-cjs/viewer-error.js +60 -60
  41. package/dist/lib-cjs/viewer.d.ts +115 -115
  42. package/dist/lib-cjs/viewer.js +217 -217
  43. package/package.json +91 -91
  44. package/src/buildinfo.json +3 -3
  45. package/src/dev.ts +47 -47
  46. package/src/global-types.d.ts +39 -39
  47. package/src/index.ts +81 -81
  48. package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
  49. package/src/internal/cloning-helper.ts +225 -225
  50. package/src/internal/device-helper.ts +25 -25
  51. package/src/internal/geometry-helper.ts +181 -181
  52. package/src/internal/metadata-helper.ts +63 -63
  53. package/src/internal/paintable-helper.ts +310 -310
  54. package/src/internal/tags-helper.ts +41 -41
  55. package/src/manager/camera-manager.ts +365 -365
  56. package/src/manager/debug-manager.ts +245 -245
  57. package/src/manager/event-manager.ts +72 -72
  58. package/src/manager/gltf-export-manager.ts +357 -341
  59. package/src/manager/material-manager.ts +135 -135
  60. package/src/manager/model-manager.ts +458 -458
  61. package/src/manager/parameter-manager.ts +652 -652
  62. package/src/manager/scene-manager.ts +101 -101
  63. package/src/manager/texture-manager.ts +32 -32
  64. package/src/viewer-error.ts +68 -68
  65. package/src/viewer.ts +290 -290
@@ -1,101 +1,101 @@
1
- import { ArcRotateCamera, CameraManager, Color4, CubeTexture, Vector3, Viewer } from '../index';
2
- import { merge } from 'lodash-es';
3
-
4
- /**
5
- * Settings for creating the default scene
6
- */
7
- export type DefaultSceneSettings = {
8
- backgroundColor: Color4;
9
- camera: {
10
- create: boolean;
11
- initialPosition: {
12
- alpha: number;
13
- beta: number;
14
- radius: number;
15
- target: Vector3;
16
- };
17
- settings: {
18
- minZ: number;
19
- lowerRadiusLimit: number;
20
- wheelPrecision: number;
21
- panningSensibility: number;
22
- };
23
- };
24
- environment: {
25
- create: boolean;
26
- url: string;
27
- intensity: number;
28
- };
29
- };
30
-
31
- /**
32
- * Manager for tasks related to the Babylon.js scene.\
33
- * This contains creating or loading (WIP: Scene Asset) scenes with certain settings for lighting, cameras and
34
- * appearance in genereal.
35
- *
36
- * @internal
37
- */
38
- export class SceneManager {
39
- protected static _DEFAULT_SCENE_NAME = '__defaultScene__';
40
-
41
- // default scene settings
42
- // will be overwritten in the constructor
43
- protected _defaultSceneSettings: DefaultSceneSettings = {
44
- backgroundColor: new Color4(0, 0, 0, 0),
45
- camera: {
46
- create: true,
47
- initialPosition: CameraManager.DEFAULT_CAMERA_POSITION,
48
- settings: {
49
- minZ: 0.1,
50
- lowerRadiusLimit: 2,
51
- wheelPrecision: 100,
52
- panningSensibility: 5000,
53
- },
54
- },
55
-
56
- environment: {
57
- create: true,
58
- url: 'https://assets.babylonjs.com/environments/environmentSpecular.env',
59
- intensity: 1,
60
- },
61
- };
62
-
63
- public constructor(protected viewer: Viewer, defaultSceneSettings?: DeepPartial<DefaultSceneSettings>) {
64
- merge(this._defaultSceneSettings, defaultSceneSettings);
65
- }
66
-
67
- /**
68
- * Creates a camera and minimum lighting, so that the scene is set up good enough to show content.\
69
- * Settings can be overwritten in the constructor.
70
- */
71
- public applyDefaultSettingsToScene(): void {
72
- const cameraSettings = this._defaultSceneSettings.camera;
73
- const envSettings = this._defaultSceneSettings.environment;
74
-
75
- this.viewer.scene.clearColor = this._defaultSceneSettings.backgroundColor;
76
-
77
- // camera
78
- if (cameraSettings.create) {
79
- const camera = new ArcRotateCamera(
80
- `${SceneManager._DEFAULT_SCENE_NAME}.camera`,
81
- cameraSettings.initialPosition.alpha,
82
- cameraSettings.initialPosition.beta,
83
- cameraSettings.initialPosition.radius,
84
- cameraSettings.initialPosition.target,
85
- this.viewer.scene
86
- );
87
- camera.attachControl(this.viewer.engine._workingCanvas, true);
88
- camera.minZ = cameraSettings.settings.minZ;
89
- camera.lowerRadiusLimit = cameraSettings.settings.lowerRadiusLimit;
90
- camera.wheelPrecision = cameraSettings.settings.wheelPrecision;
91
- camera.panningSensibility = cameraSettings.settings.panningSensibility;
92
- }
93
-
94
- // environment
95
- if (envSettings.create) {
96
- const envTexture = CubeTexture.CreateFromPrefilteredData(envSettings.url, this.viewer.scene);
97
- this.viewer.scene.environmentTexture = envTexture;
98
- this.viewer.scene.environmentIntensity = envSettings.intensity;
99
- }
100
- }
101
- }
1
+ import { ArcRotateCamera, CameraManager, Color4, CubeTexture, Vector3, Viewer } from '../index';
2
+ import { merge } from 'lodash-es';
3
+
4
+ /**
5
+ * Settings for creating the default scene
6
+ */
7
+ export type DefaultSceneSettings = {
8
+ backgroundColor: Color4;
9
+ camera: {
10
+ create: boolean;
11
+ initialPosition: {
12
+ alpha: number;
13
+ beta: number;
14
+ radius: number;
15
+ target: Vector3;
16
+ };
17
+ settings: {
18
+ minZ: number;
19
+ lowerRadiusLimit: number;
20
+ wheelPrecision: number;
21
+ panningSensibility: number;
22
+ };
23
+ };
24
+ environment: {
25
+ create: boolean;
26
+ url: string;
27
+ intensity: number;
28
+ };
29
+ };
30
+
31
+ /**
32
+ * Manager for tasks related to the Babylon.js scene.\
33
+ * This contains creating or loading (WIP: Scene Asset) scenes with certain settings for lighting, cameras and
34
+ * appearance in genereal.
35
+ *
36
+ * @internal
37
+ */
38
+ export class SceneManager {
39
+ protected static _DEFAULT_SCENE_NAME = '__defaultScene__';
40
+
41
+ // default scene settings
42
+ // will be overwritten in the constructor
43
+ protected _defaultSceneSettings: DefaultSceneSettings = {
44
+ backgroundColor: new Color4(0, 0, 0, 0),
45
+ camera: {
46
+ create: true,
47
+ initialPosition: CameraManager.DEFAULT_CAMERA_POSITION,
48
+ settings: {
49
+ minZ: 0.1,
50
+ lowerRadiusLimit: 2,
51
+ wheelPrecision: 100,
52
+ panningSensibility: 5000,
53
+ },
54
+ },
55
+
56
+ environment: {
57
+ create: true,
58
+ url: 'https://assets.babylonjs.com/environments/environmentSpecular.env',
59
+ intensity: 1,
60
+ },
61
+ };
62
+
63
+ public constructor(protected viewer: Viewer, defaultSceneSettings?: DeepPartial<DefaultSceneSettings>) {
64
+ merge(this._defaultSceneSettings, defaultSceneSettings);
65
+ }
66
+
67
+ /**
68
+ * Creates a camera and minimum lighting, so that the scene is set up good enough to show content.\
69
+ * Settings can be overwritten in the constructor.
70
+ */
71
+ public applyDefaultSettingsToScene(): void {
72
+ const cameraSettings = this._defaultSceneSettings.camera;
73
+ const envSettings = this._defaultSceneSettings.environment;
74
+
75
+ this.viewer.scene.clearColor = this._defaultSceneSettings.backgroundColor;
76
+
77
+ // camera
78
+ if (cameraSettings.create) {
79
+ const camera = new ArcRotateCamera(
80
+ `${SceneManager._DEFAULT_SCENE_NAME}.camera`,
81
+ cameraSettings.initialPosition.alpha,
82
+ cameraSettings.initialPosition.beta,
83
+ cameraSettings.initialPosition.radius,
84
+ cameraSettings.initialPosition.target,
85
+ this.viewer.scene
86
+ );
87
+ camera.attachControl(this.viewer.engine._workingCanvas, true);
88
+ camera.minZ = cameraSettings.settings.minZ;
89
+ camera.lowerRadiusLimit = cameraSettings.settings.lowerRadiusLimit;
90
+ camera.wheelPrecision = cameraSettings.settings.wheelPrecision;
91
+ camera.panningSensibility = cameraSettings.settings.panningSensibility;
92
+ }
93
+
94
+ // environment
95
+ if (envSettings.create) {
96
+ const envTexture = CubeTexture.CreateFromPrefilteredData(envSettings.url, this.viewer.scene);
97
+ this.viewer.scene.environmentTexture = envTexture;
98
+ this.viewer.scene.environmentIntensity = envSettings.intensity;
99
+ }
100
+ }
101
+ }
@@ -1,32 +1,32 @@
1
- import { BaseTexture, Viewer } from '../index';
2
-
3
- /**
4
- * Manager for texture related tasks, like renaming textures that are based on Combeenation image assets.\
5
- * Doesn't have any public functionalities ATM.
6
- *
7
- * @internal
8
- */
9
- export class TextureManager {
10
- public constructor(protected viewer: Viewer) {
11
- this.viewer.scene.onNewTextureAddedObservable.add(texture => this._onTextureAdded(texture));
12
- }
13
-
14
- protected async _onTextureAdded(texture: BaseTexture): Promise<void> {
15
- // Workaround:
16
- // The texture object is not fully created when the "added observable" is called. E.g. the function
17
- // `onLoadObservable` is not there at that point and the name is not even set.
18
- // More details: https://forum.babylonjs.com/t/basetexture-whenallready-returns-too-early/34501/4
19
- await new Promise(resolve => window.setTimeout(resolve, 0));
20
-
21
- // textures based CBN image assets are hard to analyse in the inspector, since the asset url is set as name
22
- // with this functionality we try to find these CBN image assets and crop the name accordingly
23
- // => see CB-9558
24
- const isUrl = texture.name.startsWith('https://');
25
- const textureQueryString = '?name=';
26
- const indexOfTextureQueryParam = texture.name.lastIndexOf(textureQueryString);
27
-
28
- if (isUrl && indexOfTextureQueryParam > -1) {
29
- texture.name = texture.name.substring(indexOfTextureQueryParam + textureQueryString.length);
30
- }
31
- }
32
- }
1
+ import { BaseTexture, Viewer } from '../index';
2
+
3
+ /**
4
+ * Manager for texture related tasks, like renaming textures that are based on Combeenation image assets.\
5
+ * Doesn't have any public functionalities ATM.
6
+ *
7
+ * @internal
8
+ */
9
+ export class TextureManager {
10
+ public constructor(protected viewer: Viewer) {
11
+ this.viewer.scene.onNewTextureAddedObservable.add(texture => this._onTextureAdded(texture));
12
+ }
13
+
14
+ protected async _onTextureAdded(texture: BaseTexture): Promise<void> {
15
+ // Workaround:
16
+ // The texture object is not fully created when the "added observable" is called. E.g. the function
17
+ // `onLoadObservable` is not there at that point and the name is not even set.
18
+ // More details: https://forum.babylonjs.com/t/basetexture-whenallready-returns-too-early/34501/4
19
+ await new Promise(resolve => window.setTimeout(resolve, 0));
20
+
21
+ // textures based CBN image assets are hard to analyse in the inspector, since the asset url is set as name
22
+ // with this functionality we try to find these CBN image assets and crop the name accordingly
23
+ // => see CB-9558
24
+ const isUrl = texture.name.startsWith('https://');
25
+ const textureQueryString = '?name=';
26
+ const indexOfTextureQueryParam = texture.name.lastIndexOf(textureQueryString);
27
+
28
+ if (isUrl && indexOfTextureQueryParam > -1) {
29
+ texture.name = texture.name.substring(indexOfTextureQueryParam + textureQueryString.length);
30
+ }
31
+ }
32
+ }
@@ -1,68 +1,68 @@
1
- /**
2
- * Combeenation configurators are explicitly catching and handling some specific errors thrown by the viewer.
3
- * We use this custom error class which adds a unique ID to each error so that we can safely distinguish the different
4
- * errors without having to look at the thrown text.
5
- */
6
-
7
- type ViewerErrorData = {
8
- /** One of `GlobalViewerErrorIds` */
9
- id: string;
10
- message: string;
11
- };
12
-
13
- /**
14
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15
- * !!! Note: Combeenation viewer ctrl needs to be adjusted, whenever changing existing keys here. !!!
16
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17
- *
18
- * IDs here shall only include "word characters" (`/w` in RegEx) as `GetViewerErrorIdFromMsg` wouldn't work correctly
19
- * otherwise.
20
- * @internal
21
- */
22
- export const ViewerErrorIds = {
23
- InvalidParameterValue: 'InvalidParameterValue',
24
- ModelNotRegistered: 'ModelNotRegistered',
25
- ModelAlreadyExists: 'ModelAlreadyExists',
26
- ModelIsNotAClone: 'ModelIsNotAClone',
27
- AssetLoadingFailed: 'AssetLoadingFailed',
28
- MaterialCouldNotBeParsed: 'MaterialCouldNotBeParsed',
29
- };
30
-
31
- /** @internal */
32
- export class ViewerError extends Error {
33
- viewerErrorId: string;
34
-
35
- constructor(data: ViewerErrorData) {
36
- // Unfortunately we can't access the custom `viewerErrorId` property when catching global errors in Combeenation so
37
- // we also have to add the ID to the message itself.
38
- super(`[${data.id}] ${data.message}`);
39
- this.viewerErrorId = data.id;
40
- }
41
-
42
- /**
43
- * Splits the given error message into a known viewer error id and the message itself.
44
- *
45
- * E.g.:
46
- * Message `[InvalidParameterValue] Some error msg` returns `{ id: 'InvalidParameterValue', msg: 'Some error msg' }`
47
- *
48
- * @param message An error message in the form `[KnownErrorId] Some error msg`
49
- * @returns id = The extracted error id (one of `GlobalViewerErrorIds`) or `undefined` if no valid ID has been found
50
- * msg = The error message without the prefixed ID. Returns the whole given `message` if it isn't prefixed
51
- * with a known ID in the correct format.
52
- */
53
- static SplitViewerErrorMsg(message: string): { id: string | undefined; msg: string } {
54
- const knownIds = Object.values(ViewerErrorIds).join('|');
55
-
56
- // RegEx:
57
- // `^` = Start of string
58
- // `\\[` = Literal `[`
59
- // `(?<id>abc|xyz|...)` = Named capture group `id` which looks for one of the existing error ids
60
- // `] ` = Literal `] `
61
- // `(?<msg>.*)` = Named capture group `msg` which looks for everything after the matched group id
62
- const result = new RegExp('^\\[(?<id>' + knownIds + ')] (?<msg>.*)').exec(message);
63
- const id = result?.groups?.id;
64
- const msg = result?.groups?.msg || message;
65
-
66
- return { id, msg };
67
- }
68
- }
1
+ /**
2
+ * Combeenation configurators are explicitly catching and handling some specific errors thrown by the viewer.
3
+ * We use this custom error class which adds a unique ID to each error so that we can safely distinguish the different
4
+ * errors without having to look at the thrown text.
5
+ */
6
+
7
+ type ViewerErrorData = {
8
+ /** One of `GlobalViewerErrorIds` */
9
+ id: string;
10
+ message: string;
11
+ };
12
+
13
+ /**
14
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15
+ * !!! Note: Combeenation viewer ctrl needs to be adjusted, whenever changing existing keys here. !!!
16
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17
+ *
18
+ * IDs here shall only include "word characters" (`/w` in RegEx) as `GetViewerErrorIdFromMsg` wouldn't work correctly
19
+ * otherwise.
20
+ * @internal
21
+ */
22
+ export const ViewerErrorIds = {
23
+ InvalidParameterValue: 'InvalidParameterValue',
24
+ ModelNotRegistered: 'ModelNotRegistered',
25
+ ModelAlreadyExists: 'ModelAlreadyExists',
26
+ ModelIsNotAClone: 'ModelIsNotAClone',
27
+ AssetLoadingFailed: 'AssetLoadingFailed',
28
+ MaterialCouldNotBeParsed: 'MaterialCouldNotBeParsed',
29
+ };
30
+
31
+ /** @internal */
32
+ export class ViewerError extends Error {
33
+ viewerErrorId: string;
34
+
35
+ constructor(data: ViewerErrorData) {
36
+ // Unfortunately we can't access the custom `viewerErrorId` property when catching global errors in Combeenation so
37
+ // we also have to add the ID to the message itself.
38
+ super(`[${data.id}] ${data.message}`);
39
+ this.viewerErrorId = data.id;
40
+ }
41
+
42
+ /**
43
+ * Splits the given error message into a known viewer error id and the message itself.
44
+ *
45
+ * E.g.:
46
+ * Message `[InvalidParameterValue] Some error msg` returns `{ id: 'InvalidParameterValue', msg: 'Some error msg' }`
47
+ *
48
+ * @param message An error message in the form `[KnownErrorId] Some error msg`
49
+ * @returns id = The extracted error id (one of `GlobalViewerErrorIds`) or `undefined` if no valid ID has been found
50
+ * msg = The error message without the prefixed ID. Returns the whole given `message` if it isn't prefixed
51
+ * with a known ID in the correct format.
52
+ */
53
+ static SplitViewerErrorMsg(message: string): { id: string | undefined; msg: string } {
54
+ const knownIds = Object.values(ViewerErrorIds).join('|');
55
+
56
+ // RegEx:
57
+ // `^` = Start of string
58
+ // `\\[` = Literal `[`
59
+ // `(?<id>abc|xyz|...)` = Named capture group `id` which looks for one of the existing error ids
60
+ // `] ` = Literal `] `
61
+ // `(?<msg>.*)` = Named capture group `msg` which looks for everything after the matched group id
62
+ const result = new RegExp('^\\[(?<id>' + knownIds + ')] (?<msg>.*)').exec(message);
63
+ const id = result?.groups?.id;
64
+ const msg = result?.groups?.msg || message;
65
+
66
+ return { id, msg };
67
+ }
68
+ }