@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,159 +1,159 @@
1
- import { AssetContainer, ISceneLoaderPlugin, InstancedMesh, Scene, SceneLoader } from '../index';
2
- import { cloneMorphTargetManager } from './cloning-helper';
3
- import { setInternalMetadataValue } from './metadata-helper';
4
- import { deleteAllTags, getTags, setTagsAsString } from './tags-helper';
5
- import { isArray, isString } from 'lodash-es';
6
-
7
- /**
8
- * Create and return a custom loader plugin to be registered with SceneLoader, that allows
9
- * us to run our own code against the input data before using the standard procedure to
10
- * import.
11
- * The main use case is to mark missing material in meshes, which will get loaded on demand at the first time the
12
- * dedicated mesh gets visible.
13
- * This is the case if the babylon file is a Combeenation "3d asset" which comes without materials, as the materials
14
- * are defined as "material assets".
15
- */
16
- export function registerCustomCbnBabylonLoaderPlugin(): void {
17
- // get original plugin for babylon files
18
- // we only want to manipulate Combeenation 3d assets, which are represented as babylon files
19
- // the plugin is not used for GLB files, "local" babylon are also not really affected by this plugin
20
- const previousLoaderPlugin = SceneLoader.GetPluginForExtension('.babylon') as ISceneLoaderPlugin;
21
-
22
- const customLoader: ISceneLoaderPlugin = {
23
- name: 'cbnCustomBabylonLoader',
24
- extensions: '.babylon',
25
- importMesh: previousLoaderPlugin.importMesh,
26
- load: previousLoaderPlugin.load,
27
- loadAssetContainer: function (scene, data, rootUrl, onError) {
28
- // temporarily remove all morph target managers from scene before loading the model to avoid clashes with existing
29
- // unique ids => see CB-9928
30
- // NOTE: morph target managers still exist on the dedicated mesh when getting removed from the scene, only
31
- // `scene.getMorphTargetManagerById` is affected, which is used internally in the `loadAssetContainer` function
32
- const curMorphTargetManagers = scene.morphTargetManagers;
33
- scene.morphTargetManagers = [];
34
-
35
- const dataParsed = JSON.parse(data);
36
- const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
37
-
38
- _addMissingMaterialMetadata(dataParsed, importedContainer);
39
- _reconstructTagsForInstancedMeshes(dataParsed, importedContainer);
40
- _unifyMorphTargetManagerIds(importedContainer, scene);
41
-
42
- // restore existing morph target managers
43
- scene.morphTargetManagers.push(...curMorphTargetManagers);
44
-
45
- return importedContainer;
46
- },
47
- };
48
-
49
- SceneLoader.RegisterPlugin(customLoader);
50
- }
51
-
52
- type InstanceData = {
53
- name: string;
54
- tags?: string;
55
- };
56
-
57
- function _isMeshInstanceData(data: any): data is InstanceData {
58
- const hasName = isString(data.name);
59
- const hasValidTags = !data.tags || isString(data.tags);
60
- return hasName && hasValidTags;
61
- }
62
-
63
- type MeshData = {
64
- name: string;
65
- materialId?: string;
66
- instances?: unknown[];
67
- };
68
-
69
- function _isMeshData(data: any): data is MeshData {
70
- const hasName = isString(data.name);
71
- const hasValidMaterialId = !data.materialId || isString(data.materialId);
72
-
73
- return hasName && hasValidMaterialId;
74
- }
75
-
76
- type DataWithMeshes = { meshes: unknown[] };
77
-
78
- function _isDataWithMeshes(data: any): data is DataWithMeshes {
79
- return data && isArray(data.meshes);
80
- }
81
-
82
- /**
83
- * Internal function that compares the original meshes on a .babylon file with what was loaded,
84
- * and tags missing materials with respective metadata on respective meshes.
85
- * @param dataParsed original data
86
- * @param container loaded data
87
- */
88
- function _addMissingMaterialMetadata(dataParsed: unknown, container: AssetContainer): void {
89
- if (!_isDataWithMeshes(dataParsed)) return;
90
-
91
- const validatedMeshes = dataParsed.meshes.filter(_isMeshData);
92
-
93
- container.meshes.forEach(importedMesh => {
94
- const parsedMesh = validatedMeshes.find(mesh => mesh.name === importedMesh.name);
95
-
96
- const materialOnImportedMesh = importedMesh.material?.id;
97
- const materialOnOriginalMesh = parsedMesh?.materialId;
98
-
99
- if (materialOnOriginalMesh && materialOnImportedMesh !== materialOnOriginalMesh) {
100
- window.Cbn?.Assets.assertMaterialExists(materialOnOriginalMesh);
101
- setInternalMetadataValue(importedMesh, 'deferredMaterial', materialOnOriginalMesh);
102
- }
103
- });
104
- }
105
-
106
- /**
107
- * Help function for manipulating tags of instances meshes after parsing.
108
- * Per default babylon attaches the tags of the source mesh to the instance, **but only** if no tags are set for the
109
- * instanced mesh. If the instanced mesh has dedicated tags set, the ones from the source mesh are **not** copied over.
110
- * In this case it's not possible to have tags on the source mesh but not on the instance, which is a problem with our
111
- * tagging system in the viewer and the Combeenation asset editor as well.
112
- * This function rejects the default tag import algorithm and just copies the tags of the original parsed node without
113
- * any parent synchronization.
114
- *
115
- * @param dataParsed original data
116
- * @param container loaded data
117
- */
118
- function _reconstructTagsForInstancedMeshes(dataParsed: unknown, container: AssetContainer): void {
119
- if (!_isDataWithMeshes(dataParsed)) return;
120
-
121
- const validatedMeshes = dataParsed.meshes.filter(_isMeshData);
122
-
123
- container.meshes.forEach(importedMesh => {
124
- if (importedMesh instanceof InstancedMesh) {
125
- // remove all tags from the imported mesh if there are some, since these tags are probably coming from the
126
- // source mesh, if no tags are set there is no need for further operation though
127
- const hasTags = getTags(importedMesh);
128
- if (hasTags) {
129
- deleteAllTags(importedMesh);
130
-
131
- // get tags of parsed instanced mesh and set them on the imported instanced mesh
132
- const parsedSourceMesh = validatedMeshes.find(mesh => mesh.name === importedMesh.sourceMesh.name);
133
- const validatedSourceMeshInstances = parsedSourceMesh?.instances?.filter(_isMeshInstanceData);
134
- const parsedInstancedMesh = validatedSourceMeshInstances?.find(mesh => mesh.name === importedMesh.name);
135
- const parsedTags = parsedInstancedMesh?.tags;
136
- if (parsedTags) {
137
- setTagsAsString(importedMesh, parsedTags);
138
- }
139
- }
140
- }
141
- });
142
- }
143
-
144
- /**
145
- * Morph target managers from different assets may receive the same id, which leads to erroneous morph target
146
- * assignments. We can't change the id, but we can create a clone which then creates a new unique id.
147
- */
148
- function _unifyMorphTargetManagerIds(container: AssetContainer, scene: Scene): void {
149
- [...container.morphTargetManagers].forEach(sourceMTM => {
150
- const clonedMTM = cloneMorphTargetManager(sourceMTM, container);
151
-
152
- // clone function adds morph target manager to scene right, which we don't want here as we are only loading the
153
- // asset container
154
- scene.removeMorphTargetManager(clonedMTM);
155
-
156
- // original morph target manager with bad id is not needed anymore and can be disposed
157
- sourceMTM.dispose();
158
- });
159
- }
1
+ import { AssetContainer, ISceneLoaderPlugin, InstancedMesh, Scene, SceneLoader } from '../index';
2
+ import { cloneMorphTargetManager } from './cloning-helper';
3
+ import { setInternalMetadataValue } from './metadata-helper';
4
+ import { deleteAllTags, getTags, setTagsAsString } from './tags-helper';
5
+ import { isArray, isString } from 'lodash-es';
6
+
7
+ /**
8
+ * Create and return a custom loader plugin to be registered with SceneLoader, that allows
9
+ * us to run our own code against the input data before using the standard procedure to
10
+ * import.
11
+ * The main use case is to mark missing material in meshes, which will get loaded on demand at the first time the
12
+ * dedicated mesh gets visible.
13
+ * This is the case if the babylon file is a Combeenation "3d asset" which comes without materials, as the materials
14
+ * are defined as "material assets".
15
+ */
16
+ export function registerCustomCbnBabylonLoaderPlugin(): void {
17
+ // get original plugin for babylon files
18
+ // we only want to manipulate Combeenation 3d assets, which are represented as babylon files
19
+ // the plugin is not used for GLB files, "local" babylon are also not really affected by this plugin
20
+ const previousLoaderPlugin = SceneLoader.GetPluginForExtension('.babylon') as ISceneLoaderPlugin;
21
+
22
+ const customLoader: ISceneLoaderPlugin = {
23
+ name: 'cbnCustomBabylonLoader',
24
+ extensions: '.babylon',
25
+ importMesh: previousLoaderPlugin.importMesh,
26
+ load: previousLoaderPlugin.load,
27
+ loadAssetContainer: function (scene, data, rootUrl, onError) {
28
+ // temporarily remove all morph target managers from scene before loading the model to avoid clashes with existing
29
+ // unique ids => see CB-9928
30
+ // NOTE: morph target managers still exist on the dedicated mesh when getting removed from the scene, only
31
+ // `scene.getMorphTargetManagerById` is affected, which is used internally in the `loadAssetContainer` function
32
+ const curMorphTargetManagers = scene.morphTargetManagers;
33
+ scene.morphTargetManagers = [];
34
+
35
+ const dataParsed = JSON.parse(data);
36
+ const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
37
+
38
+ _addMissingMaterialMetadata(dataParsed, importedContainer);
39
+ _reconstructTagsForInstancedMeshes(dataParsed, importedContainer);
40
+ _unifyMorphTargetManagerIds(importedContainer, scene);
41
+
42
+ // restore existing morph target managers
43
+ scene.morphTargetManagers.push(...curMorphTargetManagers);
44
+
45
+ return importedContainer;
46
+ },
47
+ };
48
+
49
+ SceneLoader.RegisterPlugin(customLoader);
50
+ }
51
+
52
+ type InstanceData = {
53
+ name: string;
54
+ tags?: string;
55
+ };
56
+
57
+ function _isMeshInstanceData(data: any): data is InstanceData {
58
+ const hasName = isString(data.name);
59
+ const hasValidTags = !data.tags || isString(data.tags);
60
+ return hasName && hasValidTags;
61
+ }
62
+
63
+ type MeshData = {
64
+ name: string;
65
+ materialId?: string;
66
+ instances?: unknown[];
67
+ };
68
+
69
+ function _isMeshData(data: any): data is MeshData {
70
+ const hasName = isString(data.name);
71
+ const hasValidMaterialId = !data.materialId || isString(data.materialId);
72
+
73
+ return hasName && hasValidMaterialId;
74
+ }
75
+
76
+ type DataWithMeshes = { meshes: unknown[] };
77
+
78
+ function _isDataWithMeshes(data: any): data is DataWithMeshes {
79
+ return data && isArray(data.meshes);
80
+ }
81
+
82
+ /**
83
+ * Internal function that compares the original meshes on a .babylon file with what was loaded,
84
+ * and tags missing materials with respective metadata on respective meshes.
85
+ * @param dataParsed original data
86
+ * @param container loaded data
87
+ */
88
+ function _addMissingMaterialMetadata(dataParsed: unknown, container: AssetContainer): void {
89
+ if (!_isDataWithMeshes(dataParsed)) return;
90
+
91
+ const validatedMeshes = dataParsed.meshes.filter(_isMeshData);
92
+
93
+ container.meshes.forEach(importedMesh => {
94
+ const parsedMesh = validatedMeshes.find(mesh => mesh.name === importedMesh.name);
95
+
96
+ const materialOnImportedMesh = importedMesh.material?.id;
97
+ const materialOnOriginalMesh = parsedMesh?.materialId;
98
+
99
+ if (materialOnOriginalMesh && materialOnImportedMesh !== materialOnOriginalMesh) {
100
+ window.Cbn?.Assets.assertMaterialExists(materialOnOriginalMesh);
101
+ setInternalMetadataValue(importedMesh, 'deferredMaterial', materialOnOriginalMesh);
102
+ }
103
+ });
104
+ }
105
+
106
+ /**
107
+ * Help function for manipulating tags of instances meshes after parsing.
108
+ * Per default babylon attaches the tags of the source mesh to the instance, **but only** if no tags are set for the
109
+ * instanced mesh. If the instanced mesh has dedicated tags set, the ones from the source mesh are **not** copied over.
110
+ * In this case it's not possible to have tags on the source mesh but not on the instance, which is a problem with our
111
+ * tagging system in the viewer and the Combeenation asset editor as well.
112
+ * This function rejects the default tag import algorithm and just copies the tags of the original parsed node without
113
+ * any parent synchronization.
114
+ *
115
+ * @param dataParsed original data
116
+ * @param container loaded data
117
+ */
118
+ function _reconstructTagsForInstancedMeshes(dataParsed: unknown, container: AssetContainer): void {
119
+ if (!_isDataWithMeshes(dataParsed)) return;
120
+
121
+ const validatedMeshes = dataParsed.meshes.filter(_isMeshData);
122
+
123
+ container.meshes.forEach(importedMesh => {
124
+ if (importedMesh instanceof InstancedMesh) {
125
+ // remove all tags from the imported mesh if there are some, since these tags are probably coming from the
126
+ // source mesh, if no tags are set there is no need for further operation though
127
+ const hasTags = getTags(importedMesh);
128
+ if (hasTags) {
129
+ deleteAllTags(importedMesh);
130
+
131
+ // get tags of parsed instanced mesh and set them on the imported instanced mesh
132
+ const parsedSourceMesh = validatedMeshes.find(mesh => mesh.name === importedMesh.sourceMesh.name);
133
+ const validatedSourceMeshInstances = parsedSourceMesh?.instances?.filter(_isMeshInstanceData);
134
+ const parsedInstancedMesh = validatedSourceMeshInstances?.find(mesh => mesh.name === importedMesh.name);
135
+ const parsedTags = parsedInstancedMesh?.tags;
136
+ if (parsedTags) {
137
+ setTagsAsString(importedMesh, parsedTags);
138
+ }
139
+ }
140
+ }
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Morph target managers from different assets may receive the same id, which leads to erroneous morph target
146
+ * assignments. We can't change the id, but we can create a clone which then creates a new unique id.
147
+ */
148
+ function _unifyMorphTargetManagerIds(container: AssetContainer, scene: Scene): void {
149
+ [...container.morphTargetManagers].forEach(sourceMTM => {
150
+ const clonedMTM = cloneMorphTargetManager(sourceMTM, container);
151
+
152
+ // clone function adds morph target manager to scene right, which we don't want here as we are only loading the
153
+ // asset container
154
+ scene.removeMorphTargetManager(clonedMTM);
155
+
156
+ // original morph target manager with bad id is not needed anymore and can be disposed
157
+ sourceMTM.dispose();
158
+ });
159
+ }