@combeenation/3d-viewer 6.1.0 → 6.2.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 (97) hide show
  1. package/README.md +111 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
  6. package/dist/lib-cjs/api/classes/element.d.ts +149 -149
  7. package/dist/lib-cjs/api/classes/element.js +669 -669
  8. package/dist/lib-cjs/api/classes/event.d.ts +342 -342
  9. package/dist/lib-cjs/api/classes/event.js +365 -365
  10. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  11. package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
  12. package/dist/lib-cjs/api/classes/parameter.d.ts +339 -339
  13. package/dist/lib-cjs/api/classes/parameter.js +464 -464
  14. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  15. package/dist/lib-cjs/api/classes/parameterObservable.js +97 -97
  16. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  17. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  18. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  19. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  20. package/dist/lib-cjs/api/classes/variant.d.ts +238 -234
  21. package/dist/lib-cjs/api/classes/variant.js +841 -828
  22. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  23. package/dist/lib-cjs/api/classes/variantInstance.d.ts +44 -44
  24. package/dist/lib-cjs/api/classes/variantInstance.js +105 -105
  25. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  26. package/dist/lib-cjs/api/classes/variantParameterizable.js +88 -88
  27. package/dist/lib-cjs/api/classes/viewer.d.ts +192 -187
  28. package/dist/lib-cjs/api/classes/viewer.js +639 -594
  29. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  31. package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
  32. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  33. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  34. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
  35. package/dist/lib-cjs/api/internal/sceneSetup.js +226 -226
  36. package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
  37. package/dist/lib-cjs/api/manager/animationManager.js +126 -126
  38. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +78 -78
  39. package/dist/lib-cjs/api/manager/gltfExportManager.js +241 -241
  40. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
  41. package/dist/lib-cjs/api/manager/sceneManager.js +130 -130
  42. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
  43. package/dist/lib-cjs/api/manager/textureLoadManager.js +97 -97
  44. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
  45. package/dist/lib-cjs/api/manager/variantInstanceManager.js +260 -260
  46. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  47. package/dist/lib-cjs/api/store/specStorage.js +50 -50
  48. package/dist/lib-cjs/api/util/babylonHelper.d.ts +187 -187
  49. package/dist/lib-cjs/api/util/babylonHelper.js +596 -596
  50. package/dist/lib-cjs/api/util/globalTypes.d.ts +387 -383
  51. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  52. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  53. package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
  54. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +42 -42
  55. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +139 -139
  56. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  57. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  58. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  59. package/dist/lib-cjs/api/util/structureHelper.js +48 -48
  60. package/dist/lib-cjs/buildinfo.json +3 -3
  61. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  62. package/dist/lib-cjs/index.d.ts +51 -51
  63. package/dist/lib-cjs/index.js +110 -110
  64. package/package.json +81 -81
  65. package/src/api/classes/animationInterface.ts +10 -10
  66. package/src/api/classes/dottedPath.ts +181 -181
  67. package/src/api/classes/element.ts +717 -717
  68. package/src/api/classes/event.ts +385 -385
  69. package/src/api/classes/eventBroadcaster.ts +52 -52
  70. package/src/api/classes/parameter.ts +497 -497
  71. package/src/api/classes/parameterObservable.ts +100 -100
  72. package/src/api/classes/parameterizable.ts +87 -87
  73. package/src/api/classes/placementAnimation.ts +162 -162
  74. package/src/api/classes/variant.ts +910 -896
  75. package/src/api/classes/variantInstance.ts +97 -97
  76. package/src/api/classes/variantParameterizable.ts +85 -85
  77. package/src/api/classes/viewer.ts +720 -672
  78. package/src/api/classes/viewerLight.ts +339 -339
  79. package/src/api/internal/debugViewer.ts +90 -90
  80. package/src/api/internal/lensRendering.ts +9 -9
  81. package/src/api/internal/sceneSetup.ts +205 -205
  82. package/src/api/manager/animationManager.ts +143 -143
  83. package/src/api/manager/gltfExportManager.ts +236 -236
  84. package/src/api/manager/sceneManager.ts +132 -132
  85. package/src/api/manager/textureLoadManager.ts +95 -95
  86. package/src/api/manager/variantInstanceManager.ts +265 -265
  87. package/src/api/store/specStorage.ts +51 -51
  88. package/src/api/util/babylonHelper.ts +663 -663
  89. package/src/api/util/globalTypes.ts +437 -432
  90. package/src/api/util/resourceHelper.ts +191 -191
  91. package/src/api/util/sceneLoaderHelper.ts +137 -137
  92. package/src/api/util/stringHelper.ts +23 -23
  93. package/src/api/util/structureHelper.ts +49 -49
  94. package/src/buildinfo.json +3 -3
  95. package/src/dev.ts +61 -61
  96. package/src/index.ts +96 -96
  97. package/src/types.d.ts +28 -28
@@ -1,137 +1,137 @@
1
- import { injectNodeMetadata } from './babylonHelper';
2
- import { ISceneLoaderPlugin } from '@babylonjs/core/Loading/sceneLoader';
3
- import { Material } from '@babylonjs/core/Materials/material';
4
- import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
5
- import { AssetContainer } from '@babylonjs/core/assetContainer';
6
- //! overload DOM API Node due to name-clash with BJS
7
- import { Node as BjsNode } from '@babylonjs/core/node';
8
- import { Scene } from '@babylonjs/core/scene';
9
- import { Nullable } from '@babylonjs/core/types';
10
- import has from 'lodash-es/has';
11
-
12
- export const missingMaterialMetadataName = 'missingMaterial';
13
-
14
- /**
15
- * Create and return a custom loader plugin to be registered with SceneLoader, that allows
16
- * us to run our own code against the input data before using the standard procedure to
17
- * import.
18
- * @param previousLoaderPlugin the actual loader that's executed after manipulating the input data
19
- * @returns Custom loader plugin to be registered with SceneLoader.RegisterPlugin()
20
- */
21
- export const getCustomCbnBabylonLoaderPlugin = function (previousLoaderPlugin: ISceneLoaderPlugin): ISceneLoaderPlugin {
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
- //* 1) --- manipulate ORIGINAL data
29
- const dataParsed = JSON.parse(data);
30
- //* 2) --- call default (non-custom) loading method
31
- const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
32
- //* 3) --- manipulate IMPORTED data
33
- addMissingMaterialMetadata(dataParsed, importedContainer);
34
- //* 4) --- return imported data
35
- return importedContainer;
36
- },
37
- };
38
- return customLoader;
39
- };
40
-
41
- /**
42
- * Return an observer to be applied to meshes in order to post-load missing materials
43
- * upon set enabled/visible.
44
- * @param targetMeshOrInstance AbstractMesh the observer will be applied to
45
- * @param concerningMesh Mesh to look for missing materials on, and create/apply to (when found).
46
- * @returns observer
47
- */
48
- export const getMaterialPostLoadObserver = function (targetMeshOrInstance: AbstractMesh, concerningMesh: Mesh) {
49
- return (eventData: any, eventState: any) => {
50
- const hasBeenEnabled = concerningMesh.isEnabled(true);
51
- const materialMissing = has(concerningMesh.metadata, missingMaterialMetadataName);
52
- if (!hasBeenEnabled || !materialMissing) return;
53
- // get id of missing material
54
- const missingMatId = concerningMesh.metadata[missingMaterialMetadataName];
55
- // try to find material on the scene
56
- const existingMat = concerningMesh.getScene().getMaterialById(missingMatId);
57
- // assign either existing material or freshly created one
58
- concerningMesh.material = existingMat || createMaterialFromCbnAssets(missingMatId, concerningMesh.getScene());
59
- // since the material is there now, we do not need the related metadata tag anymore
60
- delete concerningMesh.metadata[missingMaterialMetadataName];
61
- };
62
- };
63
-
64
- /**
65
- * Internal function that compares the original meshes on a .babylon file with what was loaded,
66
- * and tags missing materials with respective metadata on respective meshes.
67
- * @param dataParsed original data
68
- * @param container loaded data
69
- */
70
- export const addMissingMaterialMetadata = function (dataParsed: any, container: AssetContainer) {
71
- container.meshes.forEach(currMeshImported => {
72
- for (const currMeshOriginal of dataParsed.meshes) {
73
- if (currMeshOriginal.name !== currMeshImported.name) continue;
74
- // we're dealing with the original version of the current imported mesh now
75
- const materialOnImportedMesh = currMeshImported.material?.id;
76
- const materialOnOriginalMesh = currMeshOriginal.materialId;
77
- if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh) continue;
78
- // if we're here, the imported mesh has different material than original one
79
- window.Cbn?.Assets.assertMaterialExists(materialOnOriginalMesh);
80
- injectNodeMetadata(currMeshImported, { [missingMaterialMetadataName]: materialOnOriginalMesh }, false);
81
- break;
82
- }
83
- });
84
- };
85
-
86
- /**
87
- * Adds an "onEnabledStateChanged" observer to the given mesh and all its parents:
88
- * The added observer (`getMaterialPostLoadObserver`) handles creation of missing materials once the given node is
89
- * enabled.
90
- */
91
- export const addMissingMaterialObserver = function (node: BjsNode) {
92
- // set the concerning node, i.e. the node the observer should check for missing material.
93
- // for instanced meshes, we want the sourcemesh here.
94
- const concerningNode = node instanceof InstancedMesh ? node.sourceMesh : (node as Mesh);
95
-
96
- // observer is pointless if concerning node has no missing material
97
- if (!has(concerningNode.metadata, missingMaterialMetadataName)) return;
98
-
99
- // for each of our AbstractMeshes, set an observer on the AbstractMesh itself and all of its parents.
100
- let currNode: Nullable<BjsNode> = node;
101
- while (currNode) {
102
- // Note HAR: Using `addOnce` could be wrong in certain situations.
103
- // E.g.:
104
- // * 2 meshes `parentMesh` & `parentMesh.concerningMesh`
105
- // * `concerningMesh` is having the missing material flag
106
- // * Both `parentMesh` & `concerningMesh` are disabled
107
- // * `parentMesh` is enabled -> material should **not** be created as `concerningMesh` is still disabled
108
- // * `parentMesh` is disabled
109
- // * `concerningMesh` is enabled -> material should **not** be created as `concerningMesh` is still invisible
110
- // because its `parentMesh` is ATM disabled
111
- // * `parentMesh` & `concerningMesh` are both enable
112
- // -> material should be created as `concerningMesh` is now actually visible but it isn't, as all observers were
113
- // only fired once 🔥
114
- //
115
- // However: Using `add` instead of `addOnce` requires rather complicated manual clean up work...
116
-
117
- // add observer. needed only once per node, hence addOnce()
118
- node.onEnabledStateChangedObservable.addOnce(getMaterialPostLoadObserver(currNode as AbstractMesh, concerningNode));
119
- // console.log('## observer set on: ' + meshOrInstance.name);
120
- currNode = currNode.parent;
121
- }
122
- };
123
-
124
- /**
125
- * Look up the provided materials (see library import) and create and return one if found.
126
- * @param materialId BabylonJs material-id. E.g. 'concrete".
127
- * @param scene BabylonJs scene
128
- * @returns PBRMaterial | null
129
- */
130
- export const createMaterialFromCbnAssets = function (materialId: string, scene: Scene): Material | null {
131
- const materialDefinition = window.Cbn?.Assets.getMaterial(materialId);
132
- // The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
133
- // `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
134
- // within the material JSON definition
135
- const material = materialDefinition && Material.Parse(materialDefinition, scene, '');
136
- return material || null;
137
- };
1
+ import { injectNodeMetadata } from './babylonHelper';
2
+ import { ISceneLoaderPlugin } from '@babylonjs/core/Loading/sceneLoader';
3
+ import { Material } from '@babylonjs/core/Materials/material';
4
+ import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
5
+ import { AssetContainer } from '@babylonjs/core/assetContainer';
6
+ //! overload DOM API Node due to name-clash with BJS
7
+ import { Node as BjsNode } from '@babylonjs/core/node';
8
+ import { Scene } from '@babylonjs/core/scene';
9
+ import { Nullable } from '@babylonjs/core/types';
10
+ import has from 'lodash-es/has';
11
+
12
+ export const missingMaterialMetadataName = 'missingMaterial';
13
+
14
+ /**
15
+ * Create and return a custom loader plugin to be registered with SceneLoader, that allows
16
+ * us to run our own code against the input data before using the standard procedure to
17
+ * import.
18
+ * @param previousLoaderPlugin the actual loader that's executed after manipulating the input data
19
+ * @returns Custom loader plugin to be registered with SceneLoader.RegisterPlugin()
20
+ */
21
+ export const getCustomCbnBabylonLoaderPlugin = function (previousLoaderPlugin: ISceneLoaderPlugin): ISceneLoaderPlugin {
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
+ //* 1) --- manipulate ORIGINAL data
29
+ const dataParsed = JSON.parse(data);
30
+ //* 2) --- call default (non-custom) loading method
31
+ const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
32
+ //* 3) --- manipulate IMPORTED data
33
+ addMissingMaterialMetadata(dataParsed, importedContainer);
34
+ //* 4) --- return imported data
35
+ return importedContainer;
36
+ },
37
+ };
38
+ return customLoader;
39
+ };
40
+
41
+ /**
42
+ * Return an observer to be applied to meshes in order to post-load missing materials
43
+ * upon set enabled/visible.
44
+ * @param targetMeshOrInstance AbstractMesh the observer will be applied to
45
+ * @param concerningMesh Mesh to look for missing materials on, and create/apply to (when found).
46
+ * @returns observer
47
+ */
48
+ export const getMaterialPostLoadObserver = function (targetMeshOrInstance: AbstractMesh, concerningMesh: Mesh) {
49
+ return (eventData: any, eventState: any) => {
50
+ const hasBeenEnabled = concerningMesh.isEnabled(true);
51
+ const materialMissing = has(concerningMesh.metadata, missingMaterialMetadataName);
52
+ if (!hasBeenEnabled || !materialMissing) return;
53
+ // get id of missing material
54
+ const missingMatId = concerningMesh.metadata[missingMaterialMetadataName];
55
+ // try to find material on the scene
56
+ const existingMat = concerningMesh.getScene().getMaterialById(missingMatId);
57
+ // assign either existing material or freshly created one
58
+ concerningMesh.material = existingMat || createMaterialFromCbnAssets(missingMatId, concerningMesh.getScene());
59
+ // since the material is there now, we do not need the related metadata tag anymore
60
+ delete concerningMesh.metadata[missingMaterialMetadataName];
61
+ };
62
+ };
63
+
64
+ /**
65
+ * Internal function that compares the original meshes on a .babylon file with what was loaded,
66
+ * and tags missing materials with respective metadata on respective meshes.
67
+ * @param dataParsed original data
68
+ * @param container loaded data
69
+ */
70
+ export const addMissingMaterialMetadata = function (dataParsed: any, container: AssetContainer) {
71
+ container.meshes.forEach(currMeshImported => {
72
+ for (const currMeshOriginal of dataParsed.meshes) {
73
+ if (currMeshOriginal.name !== currMeshImported.name) continue;
74
+ // we're dealing with the original version of the current imported mesh now
75
+ const materialOnImportedMesh = currMeshImported.material?.id;
76
+ const materialOnOriginalMesh = currMeshOriginal.materialId;
77
+ if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh) continue;
78
+ // if we're here, the imported mesh has different material than original one
79
+ window.Cbn?.Assets.assertMaterialExists(materialOnOriginalMesh);
80
+ injectNodeMetadata(currMeshImported, { [missingMaterialMetadataName]: materialOnOriginalMesh }, false);
81
+ break;
82
+ }
83
+ });
84
+ };
85
+
86
+ /**
87
+ * Adds an "onEnabledStateChanged" observer to the given mesh and all its parents:
88
+ * The added observer (`getMaterialPostLoadObserver`) handles creation of missing materials once the given node is
89
+ * enabled.
90
+ */
91
+ export const addMissingMaterialObserver = function (node: BjsNode) {
92
+ // set the concerning node, i.e. the node the observer should check for missing material.
93
+ // for instanced meshes, we want the sourcemesh here.
94
+ const concerningNode = node instanceof InstancedMesh ? node.sourceMesh : (node as Mesh);
95
+
96
+ // observer is pointless if concerning node has no missing material
97
+ if (!has(concerningNode.metadata, missingMaterialMetadataName)) return;
98
+
99
+ // for each of our AbstractMeshes, set an observer on the AbstractMesh itself and all of its parents.
100
+ let currNode: Nullable<BjsNode> = node;
101
+ while (currNode) {
102
+ // Note HAR: Using `addOnce` could be wrong in certain situations.
103
+ // E.g.:
104
+ // * 2 meshes `parentMesh` & `parentMesh.concerningMesh`
105
+ // * `concerningMesh` is having the missing material flag
106
+ // * Both `parentMesh` & `concerningMesh` are disabled
107
+ // * `parentMesh` is enabled -> material should **not** be created as `concerningMesh` is still disabled
108
+ // * `parentMesh` is disabled
109
+ // * `concerningMesh` is enabled -> material should **not** be created as `concerningMesh` is still invisible
110
+ // because its `parentMesh` is ATM disabled
111
+ // * `parentMesh` & `concerningMesh` are both enable
112
+ // -> material should be created as `concerningMesh` is now actually visible but it isn't, as all observers were
113
+ // only fired once 🔥
114
+ //
115
+ // However: Using `add` instead of `addOnce` requires rather complicated manual clean up work...
116
+
117
+ // add observer. needed only once per node, hence addOnce()
118
+ node.onEnabledStateChangedObservable.addOnce(getMaterialPostLoadObserver(currNode as AbstractMesh, concerningNode));
119
+ // console.log('## observer set on: ' + meshOrInstance.name);
120
+ currNode = currNode.parent;
121
+ }
122
+ };
123
+
124
+ /**
125
+ * Look up the provided materials (see library import) and create and return one if found.
126
+ * @param materialId BabylonJs material-id. E.g. 'concrete".
127
+ * @param scene BabylonJs scene
128
+ * @returns PBRMaterial | null
129
+ */
130
+ export const createMaterialFromCbnAssets = function (materialId: string, scene: Scene): Material | null {
131
+ const materialDefinition = window.Cbn?.Assets.getMaterial(materialId);
132
+ // The generic `Material.Parse` actually returns a more specific material like `BABYLON.StandardMaterial`,
133
+ // `BABYLON.PBRMaterial` or stuff like `BABYLON.PBRMetallicRoughnessMaterial` etc. based on the given `customType`
134
+ // within the material JSON definition
135
+ const material = materialDefinition && Material.Parse(materialDefinition, scene, '');
136
+ return material || null;
137
+ };
@@ -1,23 +1,23 @@
1
- /**
2
- * Creates a random uuidv4.
3
- */
4
- const uuidv4 = function () {
5
- return ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => {
6
- const cNum = parseInt(c);
7
- return (cNum ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (cNum / 4)))).toString(16);
8
- });
9
- };
10
-
11
- /**
12
- * Converts a string from camel case to snake case.
13
- */
14
- const camelToSnakeCase = function (str: string): string {
15
- return str
16
- .replace(/([A-Z])/g, ' $1')
17
- .trim()
18
- .split(' ')
19
- .join('_')
20
- .toLowerCase();
21
- };
22
-
23
- export { uuidv4, camelToSnakeCase };
1
+ /**
2
+ * Creates a random uuidv4.
3
+ */
4
+ const uuidv4 = function () {
5
+ return ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => {
6
+ const cNum = parseInt(c);
7
+ return (cNum ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (cNum / 4)))).toString(16);
8
+ });
9
+ };
10
+
11
+ /**
12
+ * Converts a string from camel case to snake case.
13
+ */
14
+ const camelToSnakeCase = function (str: string): string {
15
+ return str
16
+ .replace(/([A-Z])/g, ' $1')
17
+ .trim()
18
+ .split(' ')
19
+ .join('_')
20
+ .toLowerCase();
21
+ };
22
+
23
+ export { uuidv4, camelToSnakeCase };
@@ -1,49 +1,49 @@
1
- import { Element } from '../classes/element';
2
- import { Variant } from '../classes/variant';
3
- import { VariantInstance } from '../classes/variantInstance';
4
- import { Mesh } from '@babylonjs/core/Meshes/mesh';
5
-
6
- /**
7
- * Find out if a mesh is part of a list of excluded geometry
8
- * @param mesh BJS mesh
9
- * @param list list of excluded geometry
10
- * @returns boolean based on whether mesh (or one of its parents) was found in list
11
- */
12
- const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometryList): boolean {
13
- const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
14
- return inputMesh.uniqueId === meshToCheck.uniqueId;
15
- };
16
- const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
17
- return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
18
- };
19
- const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
20
- return inputVariant.elements.some(el => checkElement(el, meshToCheck));
21
- };
22
- const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
23
- return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
24
- };
25
- const check = (geometryToExclude: ExcludedGeometry, mesh: Mesh) => {
26
- if (geometryToExclude instanceof VariantInstance) {
27
- return checkVariantInstance(geometryToExclude, mesh);
28
- }
29
- if (geometryToExclude instanceof Variant) {
30
- return checkVariant(geometryToExclude, mesh);
31
- }
32
- if (geometryToExclude instanceof Element) {
33
- return checkElement(geometryToExclude, mesh);
34
- }
35
- if (geometryToExclude instanceof Mesh) {
36
- return checkMesh(geometryToExclude, mesh);
37
- }
38
- return false;
39
- };
40
-
41
- let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
42
- if (!isExcluded && mesh.parent instanceof Mesh) {
43
- isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
44
- }
45
-
46
- return isExcluded;
47
- };
48
-
49
- export { isMeshIncludedInExclusionList };
1
+ import { Element } from '../classes/element';
2
+ import { Variant } from '../classes/variant';
3
+ import { VariantInstance } from '../classes/variantInstance';
4
+ import { Mesh } from '@babylonjs/core/Meshes/mesh';
5
+
6
+ /**
7
+ * Find out if a mesh is part of a list of excluded geometry
8
+ * @param mesh BJS mesh
9
+ * @param list list of excluded geometry
10
+ * @returns boolean based on whether mesh (or one of its parents) was found in list
11
+ */
12
+ const isMeshIncludedInExclusionList = function (mesh: Mesh, list: ExcludedGeometryList): boolean {
13
+ const checkMesh = (inputMesh: Mesh, meshToCheck: Mesh) => {
14
+ return inputMesh.uniqueId === meshToCheck.uniqueId;
15
+ };
16
+ const checkElement = (inputEl: Element, meshToCheck: Mesh) => {
17
+ return inputEl.meshesFlat.some(m => checkMesh(m, meshToCheck));
18
+ };
19
+ const checkVariant = (inputVariant: Variant, meshToCheck: Mesh) => {
20
+ return inputVariant.elements.some(el => checkElement(el, meshToCheck));
21
+ };
22
+ const checkVariantInstance = (inputVarInst: VariantInstance, meshToCheck: Mesh) => {
23
+ return inputVarInst.variant.elements.some(el => checkElement(el, meshToCheck));
24
+ };
25
+ const check = (geometryToExclude: ExcludedGeometry, mesh: Mesh) => {
26
+ if (geometryToExclude instanceof VariantInstance) {
27
+ return checkVariantInstance(geometryToExclude, mesh);
28
+ }
29
+ if (geometryToExclude instanceof Variant) {
30
+ return checkVariant(geometryToExclude, mesh);
31
+ }
32
+ if (geometryToExclude instanceof Element) {
33
+ return checkElement(geometryToExclude, mesh);
34
+ }
35
+ if (geometryToExclude instanceof Mesh) {
36
+ return checkMesh(geometryToExclude, mesh);
37
+ }
38
+ return false;
39
+ };
40
+
41
+ let isExcluded = list.some(geometryToExclude => check(geometryToExclude, mesh));
42
+ if (!isExcluded && mesh.parent instanceof Mesh) {
43
+ isExcluded = isMeshIncludedInExclusionList(mesh.parent, list);
44
+ }
45
+
46
+ return isExcluded;
47
+ };
48
+
49
+ export { isMeshIncludedInExclusionList };
@@ -1,3 +1,3 @@
1
- {
2
- "version": "@VERSION@"
3
- }
1
+ {
2
+ "version": "@VERSION@"
3
+ }
package/src/dev.ts CHANGED
@@ -1,61 +1,61 @@
1
- import { Emitter, Event, Viewer } from '.';
2
- import {
3
- afterBootstrap,
4
- beforeBootstrap,
5
- createSpec,
6
- createUIelements,
7
- getMaterial,
8
- mockMaterials,
9
- } from '../assets/index';
10
- import { set } from 'lodash-es';
11
-
12
- const loadingElement = document.getElementById('loading') as HTMLDivElement;
13
-
14
- Emitter.on(Event.BOOTSTRAP_START, () => {
15
- Emitter.on(Event.LOADING_START, () => {
16
- loadingElement!.style.display = 'block';
17
- });
18
- Emitter.on(Event.VARIANT_CREATED, () => {
19
- loadingElement!.style.display = 'none';
20
- });
21
- });
22
-
23
- document.addEventListener('DOMContentLoaded', main);
24
-
25
- window.Cbn = {
26
- Assets: {
27
- getMaterial(materialId: string) {
28
- const material = getMaterial(materialId);
29
- if (material) return material;
30
-
31
- // Fallback to random mock material
32
- return mockMaterials[Math.floor(Math.random() * mockMaterials.length)];
33
- },
34
- assertMaterialExists(materialId: string): boolean {
35
- return true;
36
- },
37
- },
38
- };
39
-
40
- async function main() {
41
- const viewer = await bootstrapViewer();
42
- // "Export" for console testing...
43
- set(window, 'viewer', viewer);
44
- }
45
-
46
- async function bootstrapViewer() {
47
- const canvas = document.getElementById('babylon-canvas') as HTMLCanvasElement;
48
- if (!canvas) {
49
- throw new Error('Missing "canvas" element');
50
- }
51
- const viewer = new Viewer(canvas, createSpec());
52
- await beforeBootstrap(viewer);
53
- try {
54
- await viewer.bootstrap();
55
- } catch (e) {
56
- console.error(e);
57
- }
58
- await afterBootstrap(viewer);
59
- await createUIelements(viewer);
60
- return viewer;
61
- }
1
+ import { Emitter, Event, Viewer } from '.';
2
+ import {
3
+ afterBootstrap,
4
+ beforeBootstrap,
5
+ createSpec,
6
+ createUIelements,
7
+ getMaterial,
8
+ mockMaterials,
9
+ } from '../assets/index';
10
+ import { set } from 'lodash-es';
11
+
12
+ const loadingElement = document.getElementById('loading') as HTMLDivElement;
13
+
14
+ Emitter.on(Event.BOOTSTRAP_START, () => {
15
+ Emitter.on(Event.LOADING_START, () => {
16
+ loadingElement!.style.display = 'block';
17
+ });
18
+ Emitter.on(Event.VARIANT_CREATED, () => {
19
+ loadingElement!.style.display = 'none';
20
+ });
21
+ });
22
+
23
+ document.addEventListener('DOMContentLoaded', main);
24
+
25
+ window.Cbn = {
26
+ Assets: {
27
+ getMaterial(materialId: string) {
28
+ const material = getMaterial(materialId);
29
+ if (material) return material;
30
+
31
+ // Fallback to random mock material
32
+ return mockMaterials[Math.floor(Math.random() * mockMaterials.length)];
33
+ },
34
+ assertMaterialExists(materialId: string): boolean {
35
+ return true;
36
+ },
37
+ },
38
+ };
39
+
40
+ async function main() {
41
+ const viewer = await bootstrapViewer();
42
+ // "Export" for console testing...
43
+ set(window, 'viewer', viewer);
44
+ }
45
+
46
+ async function bootstrapViewer() {
47
+ const canvas = document.getElementById('babylon-canvas') as HTMLCanvasElement;
48
+ if (!canvas) {
49
+ throw new Error('Missing "canvas" element');
50
+ }
51
+ const viewer = new Viewer(canvas, createSpec());
52
+ await beforeBootstrap(viewer);
53
+ try {
54
+ await viewer.bootstrap();
55
+ } catch (e) {
56
+ console.error(e);
57
+ }
58
+ await afterBootstrap(viewer);
59
+ await createUIelements(viewer);
60
+ return viewer;
61
+ }