@combeenation/3d-viewer 12.4.1 → 13.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/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +63 -63
- package/dist/lib-cjs/index.js +81 -114
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.d.ts +10 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js +124 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js.map +1 -0
- package/dist/lib-cjs/internal/cloningHelper.d.ts +19 -0
- package/dist/lib-cjs/internal/cloningHelper.js +165 -0
- package/dist/lib-cjs/internal/cloningHelper.js.map +1 -0
- package/dist/lib-cjs/internal/deviceHelper.d.ts +9 -0
- package/dist/lib-cjs/{api/util → internal}/deviceHelper.js +6 -10
- package/dist/lib-cjs/internal/deviceHelper.js.map +1 -0
- package/dist/lib-cjs/internal/geometryHelper.d.ts +21 -0
- package/dist/lib-cjs/{api/util → internal}/geometryHelper.js +57 -24
- package/dist/lib-cjs/internal/geometryHelper.js.map +1 -0
- package/dist/lib-cjs/internal/metadataHelper.d.ts +26 -0
- package/dist/lib-cjs/internal/metadataHelper.js +51 -0
- package/dist/lib-cjs/internal/metadataHelper.js.map +1 -0
- package/dist/lib-cjs/internal/paintableHelper.d.ts +40 -0
- package/dist/lib-cjs/internal/paintableHelper.js +287 -0
- package/dist/lib-cjs/internal/paintableHelper.js.map +1 -0
- package/dist/lib-cjs/internal/tagsHelper.d.ts +12 -0
- package/dist/lib-cjs/internal/tagsHelper.js +38 -0
- package/dist/lib-cjs/internal/tagsHelper.js.map +1 -0
- package/dist/lib-cjs/manager/cameraManager.d.ts +51 -0
- package/dist/lib-cjs/manager/cameraManager.js +154 -0
- package/dist/lib-cjs/manager/cameraManager.js.map +1 -0
- package/dist/lib-cjs/manager/debugManager.d.ts +60 -0
- package/dist/lib-cjs/manager/debugManager.js +218 -0
- package/dist/lib-cjs/manager/debugManager.js.map +1 -0
- package/dist/lib-cjs/manager/eventManager.d.ts +52 -0
- package/dist/lib-cjs/manager/eventManager.js +72 -0
- package/dist/lib-cjs/manager/eventManager.js.map +1 -0
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.d.ts +29 -34
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.js +99 -120
- package/dist/lib-cjs/manager/gltfExportManager.js.map +1 -0
- package/dist/lib-cjs/manager/materialManager.d.ts +35 -0
- package/dist/lib-cjs/manager/materialManager.js +126 -0
- package/dist/lib-cjs/manager/materialManager.js.map +1 -0
- package/dist/lib-cjs/manager/modelManager.d.ts +145 -0
- package/dist/lib-cjs/manager/modelManager.js +381 -0
- package/dist/lib-cjs/manager/modelManager.js.map +1 -0
- package/dist/lib-cjs/manager/parameterManager.d.ts +210 -0
- package/dist/lib-cjs/manager/parameterManager.js +515 -0
- package/dist/lib-cjs/manager/parameterManager.js.map +1 -0
- package/dist/lib-cjs/manager/sceneManager.d.ts +45 -0
- package/dist/lib-cjs/manager/sceneManager.js +65 -0
- package/dist/lib-cjs/manager/sceneManager.js.map +1 -0
- package/dist/lib-cjs/manager/screenshotManager.d.ts +36 -0
- package/dist/lib-cjs/manager/screenshotManager.js +40 -0
- package/dist/lib-cjs/manager/screenshotManager.js.map +1 -0
- package/dist/lib-cjs/manager/textureManager.d.ts +12 -0
- package/dist/lib-cjs/manager/textureManager.js +44 -0
- package/dist/lib-cjs/manager/textureManager.js.map +1 -0
- package/dist/lib-cjs/viewer.d.ts +117 -0
- package/dist/lib-cjs/viewer.js +222 -0
- package/dist/lib-cjs/viewer.js.map +1 -0
- package/dist/lib-cjs/{api/classes/viewerError.d.ts → viewerError.d.ts} +6 -1
- package/dist/lib-cjs/{api/classes/viewerError.js → viewerError.js} +6 -1
- package/dist/lib-cjs/viewerError.js.map +1 -0
- package/package.json +10 -11
- package/src/dev.ts +14 -37
- package/src/{types.d.ts → globalTypes.d.ts} +8 -18
- package/src/index.ts +79 -113
- package/src/internal/cbnCustomBabylonLoaderPlugin.ts +149 -0
- package/src/internal/cloningHelper.ts +225 -0
- package/src/internal/deviceHelper.ts +25 -0
- package/src/{api/util → internal}/geometryHelper.ts +63 -24
- package/src/internal/metadataHelper.ts +63 -0
- package/src/internal/paintableHelper.ts +310 -0
- package/src/internal/tagsHelper.ts +41 -0
- package/src/manager/cameraManager.ts +236 -0
- package/src/manager/debugManager.ts +245 -0
- package/src/manager/eventManager.ts +72 -0
- package/src/{api/manager → manager}/gltfExportManager.ts +132 -125
- package/src/manager/materialManager.ts +135 -0
- package/src/manager/modelManager.ts +456 -0
- package/src/manager/parameterManager.ts +652 -0
- package/src/manager/sceneManager.ts +101 -0
- package/src/manager/screenshotManager.ts +59 -0
- package/src/manager/textureManager.ts +32 -0
- package/src/viewer.ts +296 -0
- package/src/{api/classes/viewerError.ts → viewerError.ts} +6 -1
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +0 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +0 -3
- package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +0 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +0 -167
- package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -1
- package/dist/lib-cjs/api/classes/element.d.ts +0 -153
- package/dist/lib-cjs/api/classes/element.js +0 -703
- package/dist/lib-cjs/api/classes/element.js.map +0 -1
- package/dist/lib-cjs/api/classes/event.d.ts +0 -401
- package/dist/lib-cjs/api/classes/event.js +0 -425
- package/dist/lib-cjs/api/classes/event.js.map +0 -1
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +0 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +0 -50
- package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -1
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +0 -7
- package/dist/lib-cjs/api/classes/fuzzyMap.js +0 -22
- package/dist/lib-cjs/api/classes/fuzzyMap.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +0 -410
- package/dist/lib-cjs/api/classes/parameter.js +0 -643
- package/dist/lib-cjs/api/classes/parameter.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +0 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +0 -73
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +0 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +0 -103
- package/dist/lib-cjs/api/classes/parameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +0 -45
- package/dist/lib-cjs/api/classes/placementAnimation.js +0 -177
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +0 -261
- package/dist/lib-cjs/api/classes/variant.js +0 -873
- package/dist/lib-cjs/api/classes/variant.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +0 -53
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -126
- package/dist/lib-cjs/api/classes/variantInstance.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +0 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +0 -87
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +0 -215
- package/dist/lib-cjs/api/classes/viewer.js +0 -709
- package/dist/lib-cjs/api/classes/viewer.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerError.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +0 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +0 -345
- package/dist/lib-cjs/api/classes/viewerLight.js.map +0 -1
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +0 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +0 -12
- package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +0 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +0 -228
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +0 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +0 -30
- package/dist/lib-cjs/api/manager/animationManager.js +0 -127
- package/dist/lib-cjs/api/manager/animationManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +0 -33
- package/dist/lib-cjs/api/manager/sceneManager.js +0 -129
- package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/tagManager.d.ts +0 -118
- package/dist/lib-cjs/api/manager/tagManager.js +0 -531
- package/dist/lib-cjs/api/manager/tagManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +0 -22
- package/dist/lib-cjs/api/manager/textureLoadManager.js +0 -108
- package/dist/lib-cjs/api/manager/textureLoadManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +0 -106
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +0 -291
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -1
- package/dist/lib-cjs/api/store/specStorage.d.ts +0 -32
- package/dist/lib-cjs/api/store/specStorage.js +0 -66
- package/dist/lib-cjs/api/store/specStorage.js.map +0 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +0 -238
- package/dist/lib-cjs/api/util/babylonHelper.js +0 -826
- package/dist/lib-cjs/api/util/babylonHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/debugHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/debugHelper.js +0 -94
- package/dist/lib-cjs/api/util/debugHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/deviceHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/deviceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/geometryHelper.d.ts +0 -17
- package/dist/lib-cjs/api/util/geometryHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +0 -490
- package/dist/lib-cjs/api/util/globalTypes.js +0 -2
- package/dist/lib-cjs/api/util/globalTypes.js.map +0 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/resourceHelper.js +0 -215
- package/dist/lib-cjs/api/util/resourceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +0 -229
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +0 -13
- package/dist/lib-cjs/api/util/stringHelper.js +0 -33
- package/dist/lib-cjs/api/util/stringHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/structureHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/structureHelper.js +0 -58
- package/dist/lib-cjs/api/util/structureHelper.js.map +0 -1
- package/src/api/classes/animationInterface.ts +0 -10
- package/src/api/classes/dottedPath.ts +0 -181
- package/src/api/classes/element.ts +0 -766
- package/src/api/classes/event.ts +0 -457
- package/src/api/classes/eventBroadcaster.ts +0 -52
- package/src/api/classes/fuzzyMap.ts +0 -21
- package/src/api/classes/parameter.ts +0 -686
- package/src/api/classes/parameterObservable.ts +0 -73
- package/src/api/classes/parameterizable.ts +0 -87
- package/src/api/classes/placementAnimation.ts +0 -162
- package/src/api/classes/variant.ts +0 -965
- package/src/api/classes/variantInstance.ts +0 -123
- package/src/api/classes/variantParameterizable.ts +0 -83
- package/src/api/classes/viewer.ts +0 -751
- package/src/api/classes/viewerLight.ts +0 -335
- package/src/api/internal/debugViewer.ts +0 -90
- package/src/api/internal/lensRendering.ts +0 -9
- package/src/api/internal/sceneSetup.ts +0 -208
- package/src/api/manager/animationManager.ts +0 -143
- package/src/api/manager/sceneManager.ts +0 -134
- package/src/api/manager/tagManager.ts +0 -572
- package/src/api/manager/textureLoadManager.ts +0 -107
- package/src/api/manager/variantInstanceManager.ts +0 -306
- package/src/api/store/specStorage.ts +0 -68
- package/src/api/util/babylonHelper.ts +0 -915
- package/src/api/util/debugHelper.ts +0 -121
- package/src/api/util/deviceHelper.ts +0 -31
- package/src/api/util/globalTypes.ts +0 -566
- package/src/api/util/resourceHelper.ts +0 -201
- package/src/api/util/sceneLoaderHelper.ts +0 -247
- package/src/api/util/stringHelper.ts +0 -30
- package/src/api/util/structureHelper.ts +0 -62
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IScreenshotSize, ScreenshotTools, Viewer } from '../index';
|
|
2
|
+
|
|
3
|
+
// NOTE: this module will be reworked in the near future (CB-8789)
|
|
4
|
+
|
|
5
|
+
export type ScreenshotSettings = {
|
|
6
|
+
/** Defaults to canvas width & height */
|
|
7
|
+
size?: IScreenshotSize;
|
|
8
|
+
/**
|
|
9
|
+
* Default `image/png`
|
|
10
|
+
*
|
|
11
|
+
* **Info regarding JPEG:** \
|
|
12
|
+
* Use mimeType `image/jpeg` (**not** `image/jpg`) when creating jpeg's. \
|
|
13
|
+
* Also ensure that the viewer scenes `clearColor` has an alpha value of `1` as jpeg's don't
|
|
14
|
+
* support transparency. Otherwise background will always be black for jpeg's.
|
|
15
|
+
*/
|
|
16
|
+
mimeType?: string;
|
|
17
|
+
/** Default `1` */
|
|
18
|
+
samples?: number;
|
|
19
|
+
/** Default `false` */
|
|
20
|
+
antialiasing?: boolean;
|
|
21
|
+
/** NOTE: after update to Babylon.js V6: if file name is given, the screenshot image will be downloaded and the base64
|
|
22
|
+
* string will NOT be returned! */
|
|
23
|
+
fileName?: string;
|
|
24
|
+
/** Default `false` */
|
|
25
|
+
renderSprites?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Manager for tasks related to screenshots
|
|
30
|
+
*/
|
|
31
|
+
export class ScreenshotManager {
|
|
32
|
+
/** @internal */
|
|
33
|
+
public constructor(protected viewer: Viewer) {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Takes a sceenshot the the current scene.\
|
|
37
|
+
* The result is a string containing a base64 encoded image.
|
|
38
|
+
*/
|
|
39
|
+
public async takeScreenshot(settings?: ScreenshotSettings): Promise<string> {
|
|
40
|
+
// in combination with a render target, we need to refresh the scene manually to get the latest view
|
|
41
|
+
this.viewer.scene.render();
|
|
42
|
+
|
|
43
|
+
const size = settings?.size ?? { width: this.viewer.canvas.clientWidth, height: this.viewer.canvas.clientHeight };
|
|
44
|
+
|
|
45
|
+
const imageStr = await ScreenshotTools.CreateScreenshotUsingRenderTargetAsync(
|
|
46
|
+
this.viewer.engine,
|
|
47
|
+
// mark as non-nullable as we wouldn't come this far if no camera is active anyway
|
|
48
|
+
this.viewer.scene.activeCamera!,
|
|
49
|
+
size,
|
|
50
|
+
settings?.mimeType,
|
|
51
|
+
settings?.samples,
|
|
52
|
+
settings?.antialiasing,
|
|
53
|
+
settings?.fileName,
|
|
54
|
+
settings?.renderSprites
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return imageStr;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
package/src/viewer.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import buildInfo from './buildinfo.json';
|
|
2
|
+
import * as Index from './index';
|
|
3
|
+
import {
|
|
4
|
+
BoundingInfo,
|
|
5
|
+
CameraManager,
|
|
6
|
+
DebugManager,
|
|
7
|
+
DefaultSceneSettings,
|
|
8
|
+
Engine,
|
|
9
|
+
EngineOptions,
|
|
10
|
+
EventManager,
|
|
11
|
+
GltfExportManager,
|
|
12
|
+
MaterialManager,
|
|
13
|
+
ModelManager,
|
|
14
|
+
ParameterManager,
|
|
15
|
+
ParameterSubject,
|
|
16
|
+
Scene,
|
|
17
|
+
SceneManager,
|
|
18
|
+
ScreenshotManager,
|
|
19
|
+
TextureManager,
|
|
20
|
+
TransformNode,
|
|
21
|
+
Vector3,
|
|
22
|
+
} from './index';
|
|
23
|
+
import { registerCustomCbnBabylonLoaderPlugin } from './internal/cbnCustomBabylonLoaderPlugin';
|
|
24
|
+
import { getIsScaledDownDevice } from './internal/deviceHelper';
|
|
25
|
+
import { isNodeExcluded } from './internal/geometryHelper';
|
|
26
|
+
import { cloneDeep, merge } from 'lodash-es';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Use this to define geometry to be excluded from autofocus, GLB export, etc.
|
|
30
|
+
*/
|
|
31
|
+
export type ExcludedGeometry = TransformNode | ParameterSubject;
|
|
32
|
+
export type ExcludedGeometryList = ExcludedGeometry[];
|
|
33
|
+
|
|
34
|
+
export type LimitTextureSizeConfig = {
|
|
35
|
+
size: 512 | 1024;
|
|
36
|
+
devices: 'iPhone' | 'all';
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type ViewerSettings = {
|
|
40
|
+
antialiasing: boolean;
|
|
41
|
+
engineOptions: EngineOptions;
|
|
42
|
+
/**
|
|
43
|
+
* Important for visual quality on iOS devices, this setting will set the hardware scaling proportional to the devices
|
|
44
|
+
* pixel ratio
|
|
45
|
+
*/
|
|
46
|
+
adaptToDeviceRatio: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Possibility to limit the size of textures when getting loaded by the engine.\
|
|
49
|
+
* Activating this feature potentially saves a lot of memory and can be used to avoid crashes when loading expensive
|
|
50
|
+
* models on weaker devices.\
|
|
51
|
+
* In praxis this has been an issue with iPhones a lot, therefore it's possible to activate this feature for iPhones
|
|
52
|
+
* only as well.
|
|
53
|
+
*/
|
|
54
|
+
limitTextureSize: LimitTextureSizeConfig | false;
|
|
55
|
+
/**
|
|
56
|
+
* See this forum entry for description of parallel shader compilition effect:
|
|
57
|
+
* https://forum.babylonjs.com/t/scene-flickering-when-turning-off-light/48733.\
|
|
58
|
+
* Parallel shading compilition generally improves the speed of material compilition and helps when switching
|
|
59
|
+
* materials while objects are moving (eg: animations).\
|
|
60
|
+
* Deactivating parallel shading compilition is benefitial when switching lights and materials in static scenarios.\
|
|
61
|
+
* It's activated by default due to compatibility reasons but can be overwritten with this flag.
|
|
62
|
+
*/
|
|
63
|
+
useParallelShaderCompile: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This is the entry point into the application.\
|
|
68
|
+
* Create an instance to set up the viewer on your canvas.
|
|
69
|
+
* ```js
|
|
70
|
+
* const canvas = document.getElementById('babylon-canvas');
|
|
71
|
+
* const viewer = Viewer(canvas, viewerSettings, defaultSceneSettings);
|
|
72
|
+
* ```
|
|
73
|
+
* Use "manager" sub classes for interacting with the Babylon.js engine.
|
|
74
|
+
* (e.g. `modelManager` for loading models into the scene)
|
|
75
|
+
*/
|
|
76
|
+
export class Viewer {
|
|
77
|
+
static readonly version = buildInfo.version;
|
|
78
|
+
|
|
79
|
+
// NOTE: "non-null assertion operator" is used since these variables are not initialized in the constructor itself
|
|
80
|
+
// but in a help function (`_init`) inside the constructor
|
|
81
|
+
protected _scene!: Scene;
|
|
82
|
+
|
|
83
|
+
protected _cameraManager!: CameraManager;
|
|
84
|
+
protected _debugManager!: DebugManager;
|
|
85
|
+
protected _eventManager!: EventManager;
|
|
86
|
+
protected _gltfExportManager!: GltfExportManager;
|
|
87
|
+
protected _materialManager!: MaterialManager;
|
|
88
|
+
protected _modelManager!: ModelManager;
|
|
89
|
+
protected _parameterManager!: ParameterManager;
|
|
90
|
+
protected _sceneManager!: SceneManager;
|
|
91
|
+
protected _screenshotManager!: ScreenshotManager;
|
|
92
|
+
protected _textureManager!: TextureManager;
|
|
93
|
+
|
|
94
|
+
// default viewer settings
|
|
95
|
+
// will be overwritten in the viewer constructor
|
|
96
|
+
protected _viewerSettings: ViewerSettings = {
|
|
97
|
+
antialiasing: true,
|
|
98
|
+
engineOptions: {
|
|
99
|
+
preserveDrawingBuffer: true,
|
|
100
|
+
stencil: true,
|
|
101
|
+
xrCompatible: false,
|
|
102
|
+
},
|
|
103
|
+
adaptToDeviceRatio: true,
|
|
104
|
+
limitTextureSize: {
|
|
105
|
+
devices: 'iPhone',
|
|
106
|
+
size: 1024,
|
|
107
|
+
},
|
|
108
|
+
useParallelShaderCompile: true,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
protected _isRenderLoopPaused: boolean = false;
|
|
112
|
+
|
|
113
|
+
get scene(): Scene {
|
|
114
|
+
return this._scene;
|
|
115
|
+
}
|
|
116
|
+
get engine(): Engine {
|
|
117
|
+
return this.scene.getEngine();
|
|
118
|
+
}
|
|
119
|
+
get cameraManager(): CameraManager {
|
|
120
|
+
return this._cameraManager;
|
|
121
|
+
}
|
|
122
|
+
get debugManager(): DebugManager {
|
|
123
|
+
return this._debugManager;
|
|
124
|
+
}
|
|
125
|
+
get eventManager(): EventManager {
|
|
126
|
+
return this._eventManager;
|
|
127
|
+
}
|
|
128
|
+
get gltfExportManager(): GltfExportManager {
|
|
129
|
+
return this._gltfExportManager;
|
|
130
|
+
}
|
|
131
|
+
get materialManager(): MaterialManager {
|
|
132
|
+
return this._materialManager;
|
|
133
|
+
}
|
|
134
|
+
get modelManager(): ModelManager {
|
|
135
|
+
return this._modelManager;
|
|
136
|
+
}
|
|
137
|
+
get parameterManager(): ParameterManager {
|
|
138
|
+
return this._parameterManager;
|
|
139
|
+
}
|
|
140
|
+
/** @internal */
|
|
141
|
+
get sceneManager(): SceneManager {
|
|
142
|
+
return this._sceneManager;
|
|
143
|
+
}
|
|
144
|
+
get screenshotManager(): ScreenshotManager {
|
|
145
|
+
return this._screenshotManager;
|
|
146
|
+
}
|
|
147
|
+
/** @internal */
|
|
148
|
+
get textureManager(): TextureManager {
|
|
149
|
+
return this._textureManager;
|
|
150
|
+
}
|
|
151
|
+
get viewerSettings(): ViewerSettings {
|
|
152
|
+
return this._viewerSettings;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns all modules which are exported by the viewers index file.\
|
|
157
|
+
* Needed by the [Combeenation viewer control](https://docs.combeenation.com/docs/3d-viewer-control) in situations where the viewer is injected from external code.\
|
|
158
|
+
* See [Combeenation docs](https://docs.combeenation.com/docs/3d-viewer-control-with-custom-js) for more details.
|
|
159
|
+
*/
|
|
160
|
+
public static getAllViewerModules(): typeof Index {
|
|
161
|
+
return Index;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param viewerSettings Can be overwritten to tweak settings for the Babylon.js engine or viewer internal
|
|
166
|
+
* functionalities like "texture downscaling mode"
|
|
167
|
+
* @param defaultSceneSettings Can be overwritten to tweak settings for the automatically create Babylon.js scene.\
|
|
168
|
+
* This scene contains a camera and an environment per default.
|
|
169
|
+
*/
|
|
170
|
+
public constructor(
|
|
171
|
+
public readonly canvas: HTMLCanvasElement,
|
|
172
|
+
viewerSettings?: DeepPartial<ViewerSettings>,
|
|
173
|
+
defaultSceneSettings?: DeepPartial<DefaultSceneSettings>
|
|
174
|
+
) {
|
|
175
|
+
merge(this._viewerSettings, viewerSettings);
|
|
176
|
+
this._init(defaultSceneSettings);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Pause rendering can be usefull when doing internal scene processings that should not be visible to the user,
|
|
181
|
+
* e.g. cloning meshes for gltf export
|
|
182
|
+
*/
|
|
183
|
+
public pauseRendering(): void {
|
|
184
|
+
this._isRenderLoopPaused = true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Resume render loop when paused by {@link pauseRendering} function
|
|
189
|
+
*/
|
|
190
|
+
public resumeRendering(): void {
|
|
191
|
+
this._isRenderLoopPaused = false;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Destroys this viewer instance and disposes Babylon.js engine and all scene content
|
|
196
|
+
*/
|
|
197
|
+
public destroy(): void {
|
|
198
|
+
this.eventManager.removeAllListeners();
|
|
199
|
+
this.engine.dispose();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Calculates size of the current scene.\
|
|
204
|
+
* Only takes meshes into considerations that:
|
|
205
|
+
* - are visible
|
|
206
|
+
* - are not excluded by "excludeGeometry" parameter
|
|
207
|
+
* - do not have an infinite distance (like sky boxes)
|
|
208
|
+
*/
|
|
209
|
+
public calculateBoundingInfo(excludeGeometry?: ExcludedGeometryList): BoundingInfo {
|
|
210
|
+
// CB-6062: workaround for BoundingBox not respecting render loop
|
|
211
|
+
this.scene.render();
|
|
212
|
+
|
|
213
|
+
const { max, min } = this.scene.meshes
|
|
214
|
+
.filter(mesh => {
|
|
215
|
+
const isEnabled = mesh.isEnabled();
|
|
216
|
+
// ignore meshes with invalid bounding infos
|
|
217
|
+
const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
|
|
218
|
+
// ignore meshes with infinite distance, typically these are sky boxes
|
|
219
|
+
const hasInfiniteDistance = mesh.infiniteDistance;
|
|
220
|
+
// ignore excluded meshes
|
|
221
|
+
const isExcluded = excludeGeometry ? isNodeExcluded(mesh, excludeGeometry) : false;
|
|
222
|
+
return isEnabled && hasValidBBoxInfo && !hasInfiniteDistance && !isExcluded;
|
|
223
|
+
})
|
|
224
|
+
.reduce(
|
|
225
|
+
(accBBoxMinMax, curMesh, idx) => {
|
|
226
|
+
curMesh.refreshBoundingInfo(true, true);
|
|
227
|
+
const bBox = curMesh.getBoundingInfo().boundingBox;
|
|
228
|
+
// use the first entry in the array as default value and get the resulting maximum/minimum values
|
|
229
|
+
const max = idx === 0 ? bBox.maximumWorld : Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
|
|
230
|
+
const min = idx === 0 ? bBox.minimumWorld : Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
|
|
231
|
+
return { max, min };
|
|
232
|
+
},
|
|
233
|
+
{ max: new Vector3(), min: new Vector3() }
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const boundingInfo = new BoundingInfo(min, max);
|
|
237
|
+
return boundingInfo;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Set up viewer (engine and scene) and initialize all managers
|
|
242
|
+
*/
|
|
243
|
+
protected _init(defaultSceneSettings?: DeepPartial<DefaultSceneSettings>): void {
|
|
244
|
+
// we use a custom plugin for ".babylon" files to be able to lazy load materials that were cropped by the CBN
|
|
245
|
+
// asset manager
|
|
246
|
+
registerCustomCbnBabylonLoaderPlugin();
|
|
247
|
+
|
|
248
|
+
const engine = new Engine(
|
|
249
|
+
this.canvas,
|
|
250
|
+
this._viewerSettings.antialiasing,
|
|
251
|
+
cloneDeep(this._viewerSettings.engineOptions),
|
|
252
|
+
this._viewerSettings.adaptToDeviceRatio
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const isScaledDownDevice = getIsScaledDownDevice(this._viewerSettings.limitTextureSize);
|
|
256
|
+
if (this._viewerSettings.limitTextureSize && isScaledDownDevice) {
|
|
257
|
+
engine.getCaps().maxTextureSize = this._viewerSettings.limitTextureSize.size;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (this._viewerSettings.useParallelShaderCompile === false) {
|
|
261
|
+
engine.getCaps().parallelShaderCompile = undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
this._scene = new Scene(engine);
|
|
265
|
+
|
|
266
|
+
// NOTE: order of manage seems to be a bit counter intuitive as it's sorted alphabetically
|
|
267
|
+
// semantically one would start with scene manager, etc...
|
|
268
|
+
// still this is a good test as the order of manager constructors should not matter
|
|
269
|
+
this._cameraManager = new CameraManager(this);
|
|
270
|
+
this._debugManager = new DebugManager(this);
|
|
271
|
+
this._eventManager = new EventManager(this);
|
|
272
|
+
this._gltfExportManager = new GltfExportManager(this);
|
|
273
|
+
this._materialManager = new MaterialManager(this);
|
|
274
|
+
this._modelManager = new ModelManager(this);
|
|
275
|
+
this._parameterManager = new ParameterManager(this);
|
|
276
|
+
this._sceneManager = new SceneManager(this, defaultSceneSettings);
|
|
277
|
+
this._screenshotManager = new ScreenshotManager(this);
|
|
278
|
+
this._textureManager = new TextureManager(this);
|
|
279
|
+
|
|
280
|
+
// creates black cube
|
|
281
|
+
// this model is not based on an URL and can be targeted by the Combeenation backend as fallback model
|
|
282
|
+
this._modelManager.createFallbackModel();
|
|
283
|
+
|
|
284
|
+
// NOTE: ATM creating the default scene required, as otherwise no camera would be available and the first render
|
|
285
|
+
// call would already throw
|
|
286
|
+
this._sceneManager.applyDefaultSettingsToScene();
|
|
287
|
+
|
|
288
|
+
this._debugManager.registerAutofocusStartListener();
|
|
289
|
+
|
|
290
|
+
engine.runRenderLoop(() => {
|
|
291
|
+
if (!this._isRenderLoopPaused) {
|
|
292
|
+
this.scene.render();
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -17,13 +17,18 @@ type ViewerErrorData = {
|
|
|
17
17
|
*
|
|
18
18
|
* IDs here shall only include "word characters" (`/w` in RegEx) as `GetViewerErrorIdFromMsg` wouldn't work correctly
|
|
19
19
|
* otherwise.
|
|
20
|
+
* @internal
|
|
20
21
|
*/
|
|
21
22
|
export const ViewerErrorIds = {
|
|
22
23
|
InvalidParameterValue: 'InvalidParameterValue',
|
|
23
|
-
|
|
24
|
+
ModelNotRegistered: 'ModelNotRegistered',
|
|
25
|
+
ModelAlreadyExists: 'ModelAlreadyExists',
|
|
26
|
+
ModelIsNotAClone: 'ModelIsNotAClone',
|
|
24
27
|
AssetLoadingFailed: 'AssetLoadingFailed',
|
|
28
|
+
MaterialCouldNotBeParsed: 'MaterialCouldNotBeParsed',
|
|
25
29
|
};
|
|
26
30
|
|
|
31
|
+
/** @internal */
|
|
27
32
|
export class ViewerError extends Error {
|
|
28
33
|
viewerErrorId: string;
|
|
29
34
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"animationInterface.js","sourceRoot":"","sources":["../../../../src/api/classes/animationInterface.ts"],"names":[],"mappings":""}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
export declare class DottedPath {
|
|
2
|
-
static DELIMITER: string;
|
|
3
|
-
static SAFE_CHAR: string;
|
|
4
|
-
parts: string[];
|
|
5
|
-
/**
|
|
6
|
-
* Magic factory function that creates a DottedPath based on the argument type.
|
|
7
|
-
*/
|
|
8
|
-
static create(dottedPath?: DottedPathArgument): DottedPath;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a DottedPath from a string.
|
|
11
|
-
* Allows patterns with unsafe characters wrapped in apostrophes or quotes.
|
|
12
|
-
* E.g. "part1.part2.'part.3'.part_4"
|
|
13
|
-
*/
|
|
14
|
-
static createFromPath(path: string): DottedPath;
|
|
15
|
-
/**
|
|
16
|
-
* Creates a DottedPath from a string list.
|
|
17
|
-
*/
|
|
18
|
-
static createFromParts(parts: string[]): DottedPath;
|
|
19
|
-
/**
|
|
20
|
-
* Creates an empty DottedPath.
|
|
21
|
-
*/
|
|
22
|
-
static createEmpty(): DottedPath;
|
|
23
|
-
/**
|
|
24
|
-
* Sanitizes given part: replaces all characters like {@link DottedPath.DELIMITER}
|
|
25
|
-
* with a "safe" character like {@link DottedPath.SAFE_CHAR}.
|
|
26
|
-
* (i) Does not trim whitespace.
|
|
27
|
-
*/
|
|
28
|
-
static sanitizePart(part: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* Constructor
|
|
31
|
-
*/
|
|
32
|
-
private constructor();
|
|
33
|
-
/**
|
|
34
|
-
* The path.
|
|
35
|
-
* (i) Does not return an empty dot for no path.
|
|
36
|
-
*/
|
|
37
|
-
get path(): string;
|
|
38
|
-
/**
|
|
39
|
-
* The first part.
|
|
40
|
-
*/
|
|
41
|
-
get firstPart(): string | null;
|
|
42
|
-
/**
|
|
43
|
-
* The last part.
|
|
44
|
-
*/
|
|
45
|
-
get lastPart(): string | null;
|
|
46
|
-
/**
|
|
47
|
-
* Gets the tokens to each leaf of the DottedPath tree.
|
|
48
|
-
* E.g. "part1.part2.part_3" will return an array like
|
|
49
|
-
* ["part1", "part1.part2", "part1.part2.part_3"]
|
|
50
|
-
*/
|
|
51
|
-
get leafTokens(): string[];
|
|
52
|
-
/**
|
|
53
|
-
* Removes the first part and returns it.
|
|
54
|
-
*/
|
|
55
|
-
shiftPart(): string | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Adds part to the beginning of parts list.
|
|
58
|
-
*/
|
|
59
|
-
unshiftPart(part: string, duplicateCheck?: boolean): DottedPath;
|
|
60
|
-
/**
|
|
61
|
-
* Adds part to the end of parts list.
|
|
62
|
-
* (i) Does not add a part if the last char already is the delimiter or if an empty string was passed.
|
|
63
|
-
*/
|
|
64
|
-
addPart(part: string, duplicateCheck?: boolean): DottedPath;
|
|
65
|
-
/**
|
|
66
|
-
* Adds multiple parts to the end of parts list.
|
|
67
|
-
*/
|
|
68
|
-
addParts(parts: string[], duplicateCheck?: boolean): DottedPath;
|
|
69
|
-
/**
|
|
70
|
-
* Removes the last part and returns it.
|
|
71
|
-
*/
|
|
72
|
-
popPart(): string | undefined;
|
|
73
|
-
toString(): string;
|
|
74
|
-
valueOf(): string;
|
|
75
|
-
/**
|
|
76
|
-
* Clones the DottedPath.
|
|
77
|
-
*/
|
|
78
|
-
clone(): DottedPath;
|
|
79
|
-
}
|