@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.
Files changed (81) 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 +51 -62
  5. package/dist/lib-cjs/index.js +84 -94
  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/cbn-custom-babylon-loader-plugin.js.map +1 -1
  10. package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
  11. package/dist/lib-cjs/internal/cloning-helper.js +163 -163
  12. package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
  13. package/dist/lib-cjs/internal/device-helper.js +24 -24
  14. package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
  15. package/dist/lib-cjs/internal/geometry-helper.js +145 -145
  16. package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
  17. package/dist/lib-cjs/internal/metadata-helper.js +50 -50
  18. package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
  19. package/dist/lib-cjs/internal/paintable-helper.js +234 -286
  20. package/dist/lib-cjs/internal/paintable-helper.js.map +1 -1
  21. package/dist/lib-cjs/internal/svg-helper.d.ts +4 -0
  22. package/dist/lib-cjs/internal/svg-helper.js +67 -0
  23. package/dist/lib-cjs/internal/svg-helper.js.map +1 -0
  24. package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
  25. package/dist/lib-cjs/internal/tags-helper.js +39 -37
  26. package/dist/lib-cjs/internal/tags-helper.js.map +1 -1
  27. package/dist/lib-cjs/internal/texture-parameter-helper.d.ts +37 -0
  28. package/dist/lib-cjs/internal/texture-parameter-helper.js +287 -0
  29. package/dist/lib-cjs/internal/texture-parameter-helper.js.map +1 -0
  30. package/dist/lib-cjs/manager/camera-manager.d.ts +110 -110
  31. package/dist/lib-cjs/manager/camera-manager.js +209 -206
  32. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  33. package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
  34. package/dist/lib-cjs/manager/debug-manager.js +217 -217
  35. package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
  36. package/dist/lib-cjs/manager/event-manager.js +71 -71
  37. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +75 -84
  38. package/dist/lib-cjs/manager/gltf-export-manager.js +286 -290
  39. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  40. package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
  41. package/dist/lib-cjs/manager/material-manager.js +125 -125
  42. package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
  43. package/dist/lib-cjs/manager/model-manager.js +382 -382
  44. package/dist/lib-cjs/manager/parameter-manager.d.ts +228 -210
  45. package/dist/lib-cjs/manager/parameter-manager.js +573 -514
  46. package/dist/lib-cjs/manager/parameter-manager.js.map +1 -1
  47. package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
  48. package/dist/lib-cjs/manager/scene-manager.js +64 -64
  49. package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
  50. package/dist/lib-cjs/manager/texture-manager.js +43 -43
  51. package/dist/lib-cjs/viewer-error.d.ts +49 -48
  52. package/dist/lib-cjs/viewer-error.js +61 -60
  53. package/dist/lib-cjs/viewer-error.js.map +1 -1
  54. package/dist/lib-cjs/viewer.d.ts +115 -115
  55. package/dist/lib-cjs/viewer.js +217 -217
  56. package/dist/lib-cjs/viewer.js.map +1 -1
  57. package/package.json +94 -91
  58. package/src/buildinfo.json +3 -3
  59. package/src/dev.ts +47 -47
  60. package/src/global-types.d.ts +39 -39
  61. package/src/index.ts +71 -81
  62. package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
  63. package/src/internal/cloning-helper.ts +225 -225
  64. package/src/internal/device-helper.ts +25 -25
  65. package/src/internal/geometry-helper.ts +181 -181
  66. package/src/internal/metadata-helper.ts +63 -63
  67. package/src/internal/paintable-helper.ts +258 -310
  68. package/src/internal/svg-helper.ts +52 -0
  69. package/src/internal/tags-helper.ts +43 -41
  70. package/src/internal/texture-parameter-helper.ts +353 -0
  71. package/src/manager/camera-manager.ts +368 -365
  72. package/src/manager/debug-manager.ts +245 -245
  73. package/src/manager/event-manager.ts +72 -72
  74. package/src/manager/gltf-export-manager.ts +356 -357
  75. package/src/manager/material-manager.ts +135 -135
  76. package/src/manager/model-manager.ts +458 -458
  77. package/src/manager/parameter-manager.ts +730 -652
  78. package/src/manager/scene-manager.ts +101 -101
  79. package/src/manager/texture-manager.ts +32 -32
  80. package/src/viewer-error.ts +69 -68
  81. package/src/viewer.ts +290 -290
@@ -1,135 +1,135 @@
1
- import {
2
- AbstractMesh,
3
- BaseTexture,
4
- Material,
5
- StandardMaterial,
6
- Viewer,
7
- ViewerError,
8
- ViewerErrorIds,
9
- ViewerEvent,
10
- } from '../index';
11
- import {
12
- clearInternalMetadataValue,
13
- getInternalMetadataValue,
14
- setInternalMetadataValue,
15
- } from '../internal/metadata-helper';
16
-
17
- /**
18
- * Manager for material related tasks
19
- */
20
- export class MaterialManager {
21
- /**
22
- * CAUTION: this has to be in sync with the Combeenation backend!
23
- * @internal
24
- */
25
- public static readonly CBN_FALLBACK_MATERIAL_NAME = '$fallback';
26
-
27
- protected _createMaterialPromises: { [materialId: string]: Promise<Material | null> } = {};
28
-
29
- /** @internal */
30
- public constructor(protected viewer: Viewer) {}
31
-
32
- /**
33
- * Assigns material with certain id to desired mesh.\
34
- * Creates the material if not already available (see {@link getOrCreateMaterial}).
35
- */
36
- public async setMaterialOnMesh(materialId: string, mesh: AbstractMesh): Promise<void> {
37
- setInternalMetadataValue(mesh, 'materialToBeSet', materialId);
38
-
39
- const material = await this.getOrCreateMaterial(materialId, mesh);
40
-
41
- // there may have been later "setMaterialOnMesh" calls with faster material creation
42
- // make sure to assign the latest material!
43
- if (getInternalMetadataValue(mesh, 'materialToBeSet') === materialId) {
44
- mesh.material = material;
45
- clearInternalMetadataValue(mesh, 'materialToBeSet');
46
- clearInternalMetadataValue(mesh, 'deferredMaterial');
47
- }
48
- }
49
-
50
- /**
51
- * Returns material with certain id if already available in the scene.\
52
- * If this is not the case material is created from a
53
- * "[Material asset](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset)"
54
- * on the Combeenation server.\
55
- * Waits until textures of material are fully loaded and shader is compiled. In this way "flickering" effects
56
- * will be avoided, since the material would be incomplete without its loaded textures.
57
- *
58
- * @param mesh Required for shader compilation check, can be omitted if this check should not be done.\
59
- * Use {@link setMaterialOnMesh} instead if the material should be applied on the mesh immediately.
60
- */
61
- public async getOrCreateMaterial(materialId: string, mesh?: AbstractMesh): Promise<Material> {
62
- let chosenMaterial: Material | null = this.viewer.scene.materials.find(mat => mat.id === materialId) ?? null;
63
-
64
- if (!chosenMaterial) {
65
- // material not available yet, request it from Combeenation assets
66
- const existingCreationProm = this._createMaterialPromises[materialId];
67
- if (existingCreationProm !== undefined) {
68
- // request is already pending, just wait for the result
69
- chosenMaterial = await existingCreationProm;
70
- } else {
71
- this.viewer.eventManager.fireEvent(ViewerEvent.MaterialCreationStart, materialId);
72
-
73
- // request not pending, call the dedicated function
74
- const newCreationProm = this._createMaterial(materialId, mesh);
75
- // store the promise in a global map, so that subsequent requests can reference it
76
- this._createMaterialPromises[materialId] = newCreationProm;
77
- chosenMaterial = await newCreationProm;
78
-
79
- delete this._createMaterialPromises[materialId];
80
-
81
- const allMaterialsCreated = !Object.entries(this._createMaterialPromises).length;
82
- // signalize event system that material is created now
83
- // also check if there are other material creation processes still pending, as this is an important information
84
- // e.g. for showing load masks
85
- this.viewer.eventManager.fireEvent(ViewerEvent.MaterialCreationEnd, materialId, allMaterialsCreated);
86
- }
87
- }
88
-
89
- return chosenMaterial as Material;
90
- }
91
-
92
- protected async _createMaterial(materialId: string, mesh?: AbstractMesh): Promise<Material> {
93
- if (materialId === MaterialManager.CBN_FALLBACK_MATERIAL_NAME) {
94
- const fallbackMaterial = new StandardMaterial(MaterialManager.CBN_FALLBACK_MATERIAL_NAME, this.viewer.scene);
95
- fallbackMaterial.disableLighting = true;
96
-
97
- return fallbackMaterial;
98
- }
99
-
100
- const materialDefinition = await window.Cbn?.Assets.getMaterial(materialId);
101
- // The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
102
- // `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
103
- // within the material JSON definition
104
- const material = materialDefinition && Material.Parse(materialDefinition, this.viewer.scene, '');
105
-
106
- if (!material) {
107
- throw new ViewerError({
108
- id: ViewerErrorIds.MaterialCouldNotBeParsed,
109
- message: `Material with id "${materialId}" could not be parsed`,
110
- });
111
- }
112
-
113
- await this.viewer.parameterManager.applyParameterValuesToMaterial(material);
114
-
115
- const matReadyProms = [
116
- new Promise<void>(resolve => BaseTexture.WhenAllReady(material.getActiveTextures(), resolve)),
117
- ];
118
-
119
- if (mesh) {
120
- // this promise should only take some time on the first call of the corresponding shader (eg: PBRMaterial shader)
121
- // on each other call of the same material/shader type there should be not be a waiting time, or at maximum one
122
- // frame
123
- // https://forum.babylonjs.com/t/mesh-flickering-when-setting-material-initially/37312
124
- matReadyProms.push(material.forceCompilationAsync(mesh));
125
- }
126
-
127
- // material needs to fulfill 2 criterias before it's ready to use
128
- // - textures need to be "ready" => downloaded
129
- // - dedicated shader needs to be compiled
130
- // if this would not be the case you can see some "flickering" when setting the material
131
- await Promise.all(matReadyProms);
132
-
133
- return material;
134
- }
135
- }
1
+ import {
2
+ AbstractMesh,
3
+ BaseTexture,
4
+ Material,
5
+ StandardMaterial,
6
+ Viewer,
7
+ ViewerError,
8
+ ViewerErrorIds,
9
+ ViewerEvent,
10
+ } from '../index';
11
+ import {
12
+ clearInternalMetadataValue,
13
+ getInternalMetadataValue,
14
+ setInternalMetadataValue,
15
+ } from '../internal/metadata-helper';
16
+
17
+ /**
18
+ * Manager for material related tasks
19
+ */
20
+ export class MaterialManager {
21
+ /**
22
+ * CAUTION: this has to be in sync with the Combeenation backend!
23
+ * @internal
24
+ */
25
+ public static readonly CBN_FALLBACK_MATERIAL_NAME = '$fallback';
26
+
27
+ protected _createMaterialPromises: { [materialId: string]: Promise<Material | null> } = {};
28
+
29
+ /** @internal */
30
+ public constructor(protected viewer: Viewer) {}
31
+
32
+ /**
33
+ * Assigns material with certain id to desired mesh.\
34
+ * Creates the material if not already available (see {@link getOrCreateMaterial}).
35
+ */
36
+ public async setMaterialOnMesh(materialId: string, mesh: AbstractMesh): Promise<void> {
37
+ setInternalMetadataValue(mesh, 'materialToBeSet', materialId);
38
+
39
+ const material = await this.getOrCreateMaterial(materialId, mesh);
40
+
41
+ // there may have been later "setMaterialOnMesh" calls with faster material creation
42
+ // make sure to assign the latest material!
43
+ if (getInternalMetadataValue(mesh, 'materialToBeSet') === materialId) {
44
+ mesh.material = material;
45
+ clearInternalMetadataValue(mesh, 'materialToBeSet');
46
+ clearInternalMetadataValue(mesh, 'deferredMaterial');
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Returns material with certain id if already available in the scene.\
52
+ * If this is not the case material is created from a
53
+ * "[Material asset](https://docs.combeenation.com/docs/howto-create-and-use-babylon-and-material-asset)"
54
+ * on the Combeenation server.\
55
+ * Waits until textures of material are fully loaded and shader is compiled. In this way "flickering" effects
56
+ * will be avoided, since the material would be incomplete without its loaded textures.
57
+ *
58
+ * @param mesh Required for shader compilation check, can be omitted if this check should not be done.\
59
+ * Use {@link setMaterialOnMesh} instead if the material should be applied on the mesh immediately.
60
+ */
61
+ public async getOrCreateMaterial(materialId: string, mesh?: AbstractMesh): Promise<Material> {
62
+ let chosenMaterial: Material | null = this.viewer.scene.materials.find(mat => mat.id === materialId) ?? null;
63
+
64
+ if (!chosenMaterial) {
65
+ // material not available yet, request it from Combeenation assets
66
+ const existingCreationProm = this._createMaterialPromises[materialId];
67
+ if (existingCreationProm !== undefined) {
68
+ // request is already pending, just wait for the result
69
+ chosenMaterial = await existingCreationProm;
70
+ } else {
71
+ this.viewer.eventManager.fireEvent(ViewerEvent.MaterialCreationStart, materialId);
72
+
73
+ // request not pending, call the dedicated function
74
+ const newCreationProm = this._createMaterial(materialId, mesh);
75
+ // store the promise in a global map, so that subsequent requests can reference it
76
+ this._createMaterialPromises[materialId] = newCreationProm;
77
+ chosenMaterial = await newCreationProm;
78
+
79
+ delete this._createMaterialPromises[materialId];
80
+
81
+ const allMaterialsCreated = !Object.entries(this._createMaterialPromises).length;
82
+ // signalize event system that material is created now
83
+ // also check if there are other material creation processes still pending, as this is an important information
84
+ // e.g. for showing load masks
85
+ this.viewer.eventManager.fireEvent(ViewerEvent.MaterialCreationEnd, materialId, allMaterialsCreated);
86
+ }
87
+ }
88
+
89
+ return chosenMaterial as Material;
90
+ }
91
+
92
+ protected async _createMaterial(materialId: string, mesh?: AbstractMesh): Promise<Material> {
93
+ if (materialId === MaterialManager.CBN_FALLBACK_MATERIAL_NAME) {
94
+ const fallbackMaterial = new StandardMaterial(MaterialManager.CBN_FALLBACK_MATERIAL_NAME, this.viewer.scene);
95
+ fallbackMaterial.disableLighting = true;
96
+
97
+ return fallbackMaterial;
98
+ }
99
+
100
+ const materialDefinition = await window.Cbn?.Assets.getMaterial(materialId);
101
+ // The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
102
+ // `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
103
+ // within the material JSON definition
104
+ const material = materialDefinition && Material.Parse(materialDefinition, this.viewer.scene, '');
105
+
106
+ if (!material) {
107
+ throw new ViewerError({
108
+ id: ViewerErrorIds.MaterialCouldNotBeParsed,
109
+ message: `Material with id "${materialId}" could not be parsed`,
110
+ });
111
+ }
112
+
113
+ await this.viewer.parameterManager.applyParameterValuesToMaterial(material);
114
+
115
+ const matReadyProms = [
116
+ new Promise<void>(resolve => BaseTexture.WhenAllReady(material.getActiveTextures(), resolve)),
117
+ ];
118
+
119
+ if (mesh) {
120
+ // this promise should only take some time on the first call of the corresponding shader (eg: PBRMaterial shader)
121
+ // on each other call of the same material/shader type there should be not be a waiting time, or at maximum one
122
+ // frame
123
+ // https://forum.babylonjs.com/t/mesh-flickering-when-setting-material-initially/37312
124
+ matReadyProms.push(material.forceCompilationAsync(mesh));
125
+ }
126
+
127
+ // material needs to fulfill 2 criterias before it's ready to use
128
+ // - textures need to be "ready" => downloaded
129
+ // - dedicated shader needs to be compiled
130
+ // if this would not be the case you can see some "flickering" when setting the material
131
+ await Promise.all(matReadyProms);
132
+
133
+ return material;
134
+ }
135
+ }