@combeenation/3d-viewer 12.1.0 → 12.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@combeenation/3d-viewer",
3
- "version": "12.1.0",
3
+ "version": "12.1.1",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -36,6 +36,7 @@ import { Color3 } from '@babylonjs/core/Maths/math.color';
36
36
  import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
37
37
  import { Mesh } from '@babylonjs/core/Meshes/mesh';
38
38
  import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
39
+ import { Tags } from '@babylonjs/core/Misc/tags';
39
40
  import { has, isArray, isNumber, merge, union } from 'lodash-es';
40
41
 
41
42
  /**
@@ -87,6 +88,12 @@ export class Element extends VariantParameterizable {
87
88
  // we have to create a new clone with the correct source mesh
88
89
  const exchangedInstance = clonedInstance.clone(clonedInstance.name, clonedInstance.parent, true, clonedSource);
89
90
 
91
+ // fix enabled and tags state after cloning
92
+ exchangedInstance.setEnabled(clonedInstance.isEnabled(false));
93
+ if (Tags.HasTags(clonedInstance)) {
94
+ Tags.AddTagsTo(exchangedInstance, Tags.GetTags(clonedInstance, true));
95
+ }
96
+
90
97
  // re-reference the childs of the cloned instance as well
91
98
  const childs = clonedInstance.getChildTransformNodes(true);
92
99
  childs.forEach(child => (child.parent = exchangedInstance));
@@ -116,6 +116,11 @@ const cloneTransformNode = function (
116
116
  // in that case, set the clone's enabled state to the original's state
117
117
  if (node.constructor.name === 'InstancedMesh') {
118
118
  clone.setEnabled(node.isEnabled(false));
119
+
120
+ // tags are not cloned for instanced meshes by default
121
+ if (Tags.HasTags(node)) {
122
+ Tags.AddTagsTo(clone, Tags.GetTags(node, true));
123
+ }
119
124
  }
120
125
  }
121
126
  if (deep) {
@@ -5,6 +5,7 @@ import { ISceneLoaderPlugin } from '@babylonjs/core/Loading/sceneLoader';
5
5
  import { Material } from '@babylonjs/core/Materials/material';
6
6
  import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
7
7
  import { Observer } from '@babylonjs/core/Misc/observable';
8
+ import { Tags } from '@babylonjs/core/Misc/tags';
8
9
  import { AssetContainer } from '@babylonjs/core/assetContainer';
9
10
  //! overload DOM API Node due to name-clash with BJS
10
11
  import { Node as BjsNode } from '@babylonjs/core/node';
@@ -40,6 +41,7 @@ export const getCustomCbnBabylonLoaderPlugin = function (previousLoaderPlugin: I
40
41
  const importedContainer = previousLoaderPlugin.loadAssetContainer(scene, data, rootUrl);
41
42
  //* 3) --- manipulate IMPORTED data
42
43
  addMissingMaterialMetadata(dataParsed, importedContainer);
44
+ reconstructTagsForInstancedMeshes(dataParsed, importedContainer);
43
45
  //* 4) --- return imported data
44
46
  return importedContainer;
45
47
  },
@@ -98,7 +100,7 @@ export const addMissingMaterialMetadata = function (dataParsed: any, container:
98
100
  if (currMeshOriginal.name !== currMeshImported.name) continue;
99
101
  // we're dealing with the original version of the current imported mesh now
100
102
  // first save original material id of the imported babylon or GLB file
101
- injectMetadata(currMeshImported, { [parsedMaterialIdMetadataName]: currMeshOriginal.materialId });
103
+ injectMetadata(currMeshImported, { [parsedMaterialIdMetadataName]: currMeshOriginal.materialId }, false);
102
104
  const materialOnImportedMesh = currMeshImported.material?.id;
103
105
  const materialOnOriginalMesh = currMeshOriginal.materialId;
104
106
  if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh) continue;
@@ -110,6 +112,43 @@ export const addMissingMaterialMetadata = function (dataParsed: any, container:
110
112
  });
111
113
  };
112
114
 
115
+ /**
116
+ * Help function for manipulating tags of instances meshes after parsing.
117
+ * Per default babylon attaches the tags of the source mesh to the instance, **but only** if no tags are set for the
118
+ * instanced mesh. If the instanced mesh has dedicated tags set, the ones from the source mesh are **not** copied over.
119
+ * 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
120
+ * tagging system in the viewer and the Combeenation asset editor as well.
121
+ * This function rejects the default tag import algorithm and just copies the tags of the original parsed node without
122
+ * any parent synchronization.
123
+ *
124
+ * @param dataParsed original data
125
+ * @param container loaded data
126
+ */
127
+ export const reconstructTagsForInstancedMeshes = function (dataParsed: any, container: AssetContainer) {
128
+ container.meshes.forEach(importedMesh => {
129
+ if (importedMesh instanceof InstancedMesh) {
130
+ // remove all tags from the imported mesh if there are some, since these tags are probably coming from the
131
+ // source mesh, if no tags are set there is no need for further operation though
132
+ const importedTags = Tags.GetTags(importedMesh);
133
+ if (importedTags) {
134
+ Tags.RemoveTagsFrom(importedMesh, importedTags);
135
+
136
+ // get tags of parsed instanced mesh and set them on the imported instanced mesh
137
+ const parsedSourceMesh = dataParsed.meshes?.find(
138
+ (parsedMesh: any) => parsedMesh.name === importedMesh.sourceMesh.name
139
+ );
140
+ const parsedInstancedMesh = parsedSourceMesh?.instances.find(
141
+ (parsedMesh: any) => parsedMesh.name === importedMesh.name
142
+ );
143
+ const parsedTags = parsedInstancedMesh?.tags;
144
+ if (parsedTags) {
145
+ Tags.AddTagsTo(importedMesh, parsedTags);
146
+ }
147
+ }
148
+ }
149
+ });
150
+ };
151
+
113
152
  /**
114
153
  * Adds an "onEnabledStateChanged" observer to the given mesh and all its parents:
115
154
  * The added observer (`getMaterialPostLoadObserver`) handles creation of missing materials once the given node is