@combeenation/3d-viewer 14.0.1-rc1 → 15.0.0
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.
- package/README.md +9 -9
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +51 -62
- package/dist/lib-cjs/index.js +84 -94
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
- package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
- package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js.map +1 -1
- package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
- package/dist/lib-cjs/internal/cloning-helper.js +163 -163
- package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
- package/dist/lib-cjs/internal/device-helper.js +24 -24
- package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
- package/dist/lib-cjs/internal/geometry-helper.js +145 -145
- package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
- package/dist/lib-cjs/internal/metadata-helper.js +50 -50
- package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
- package/dist/lib-cjs/internal/paintable-helper.js +234 -286
- package/dist/lib-cjs/internal/paintable-helper.js.map +1 -1
- package/dist/lib-cjs/internal/svg-helper.d.ts +4 -0
- package/dist/lib-cjs/internal/svg-helper.js +67 -0
- package/dist/lib-cjs/internal/svg-helper.js.map +1 -0
- package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
- package/dist/lib-cjs/internal/tags-helper.js +39 -37
- package/dist/lib-cjs/internal/tags-helper.js.map +1 -1
- package/dist/lib-cjs/internal/texture-parameter-helper.d.ts +37 -0
- package/dist/lib-cjs/internal/texture-parameter-helper.js +287 -0
- package/dist/lib-cjs/internal/texture-parameter-helper.js.map +1 -0
- package/dist/lib-cjs/manager/camera-manager.d.ts +110 -110
- package/dist/lib-cjs/manager/camera-manager.js +209 -206
- package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
- package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
- package/dist/lib-cjs/manager/debug-manager.js +217 -217
- package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
- package/dist/lib-cjs/manager/event-manager.js +71 -71
- package/dist/lib-cjs/manager/gltf-export-manager.d.ts +75 -84
- package/dist/lib-cjs/manager/gltf-export-manager.js +286 -290
- package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
- package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
- package/dist/lib-cjs/manager/material-manager.js +125 -125
- package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
- package/dist/lib-cjs/manager/model-manager.js +382 -382
- package/dist/lib-cjs/manager/parameter-manager.d.ts +228 -210
- package/dist/lib-cjs/manager/parameter-manager.js +573 -514
- package/dist/lib-cjs/manager/parameter-manager.js.map +1 -1
- package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
- package/dist/lib-cjs/manager/scene-manager.js +64 -64
- package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
- package/dist/lib-cjs/manager/texture-manager.js +43 -43
- package/dist/lib-cjs/viewer-error.d.ts +49 -48
- package/dist/lib-cjs/viewer-error.js +61 -60
- package/dist/lib-cjs/viewer-error.js.map +1 -1
- package/dist/lib-cjs/viewer.d.ts +115 -115
- package/dist/lib-cjs/viewer.js +217 -217
- package/dist/lib-cjs/viewer.js.map +1 -1
- package/package.json +94 -91
- package/src/buildinfo.json +3 -3
- package/src/dev.ts +47 -47
- package/src/global-types.d.ts +39 -39
- package/src/index.ts +71 -81
- package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
- package/src/internal/cloning-helper.ts +225 -225
- package/src/internal/device-helper.ts +25 -25
- package/src/internal/geometry-helper.ts +181 -181
- package/src/internal/metadata-helper.ts +63 -63
- package/src/internal/paintable-helper.ts +258 -310
- package/src/internal/svg-helper.ts +52 -0
- package/src/internal/tags-helper.ts +43 -41
- package/src/internal/texture-parameter-helper.ts +353 -0
- package/src/manager/camera-manager.ts +368 -365
- package/src/manager/debug-manager.ts +245 -245
- package/src/manager/event-manager.ts +72 -72
- package/src/manager/gltf-export-manager.ts +356 -357
- package/src/manager/material-manager.ts +135 -135
- package/src/manager/model-manager.ts +458 -458
- package/src/manager/parameter-manager.ts +730 -652
- package/src/manager/scene-manager.ts +101 -101
- package/src/manager/texture-manager.ts +32 -32
- package/src/viewer-error.ts +69 -68
- 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
|
+
}
|
package/src/viewer-error.ts
CHANGED
|
@@ -1,68 +1,69 @@
|
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// we
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
// `
|
|
60
|
-
// `
|
|
61
|
-
// `
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
TextureCouldNotBeParsed: 'TextureCouldNotBeParsed',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export class ViewerError extends Error {
|
|
34
|
+
viewerErrorId: string;
|
|
35
|
+
|
|
36
|
+
constructor(data: ViewerErrorData) {
|
|
37
|
+
// Unfortunately we can't access the custom `viewerErrorId` property when catching global errors in Combeenation so
|
|
38
|
+
// we also have to add the ID to the message itself.
|
|
39
|
+
super(`[${data.id}] ${data.message}`);
|
|
40
|
+
this.viewerErrorId = data.id;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Splits the given error message into a known viewer error id and the message itself.
|
|
45
|
+
*
|
|
46
|
+
* E.g.:
|
|
47
|
+
* Message `[InvalidParameterValue] Some error msg` returns `{ id: 'InvalidParameterValue', msg: 'Some error msg' }`
|
|
48
|
+
*
|
|
49
|
+
* @param message An error message in the form `[KnownErrorId] Some error msg`
|
|
50
|
+
* @returns id = The extracted error id (one of `GlobalViewerErrorIds`) or `undefined` if no valid ID has been found
|
|
51
|
+
* msg = The error message without the prefixed ID. Returns the whole given `message` if it isn't prefixed
|
|
52
|
+
* with a known ID in the correct format.
|
|
53
|
+
*/
|
|
54
|
+
static SplitViewerErrorMsg(message: string): { id: string | undefined; msg: string } {
|
|
55
|
+
const knownIds = Object.values(ViewerErrorIds).join('|');
|
|
56
|
+
|
|
57
|
+
// RegEx:
|
|
58
|
+
// `^` = Start of string
|
|
59
|
+
// `\\[` = Literal `[`
|
|
60
|
+
// `(?<id>abc|xyz|...)` = Named capture group `id` which looks for one of the existing error ids
|
|
61
|
+
// `] ` = Literal `] `
|
|
62
|
+
// `(?<msg>.*)` = Named capture group `msg` which looks for everything after the matched group id
|
|
63
|
+
const result = new RegExp('^\\[(?<id>' + knownIds + ')] (?<msg>.*)').exec(message);
|
|
64
|
+
const id = result?.groups?.id;
|
|
65
|
+
const msg = result?.groups?.msg || message;
|
|
66
|
+
|
|
67
|
+
return { id, msg };
|
|
68
|
+
}
|
|
69
|
+
}
|