@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,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 as string);
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
+ }