@combeenation/3d-viewer 12.0.2 → 12.1.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.
- package/dist/lib-cjs/api/classes/element.js +29 -0
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.js +1 -5
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/geometryHelper.js +13 -0
- package/dist/lib-cjs/api/util/geometryHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +1 -0
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +4 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/api/classes/element.ts +35 -0
- package/src/api/util/babylonHelper.ts +1 -5
- package/src/api/util/geometryHelper.ts +14 -0
- package/src/api/util/sceneLoaderHelper.ts +3 -0
package/package.json
CHANGED
|
@@ -71,6 +71,41 @@ export class Element extends VariantParameterizable {
|
|
|
71
71
|
};
|
|
72
72
|
return cloneTransformNode(node, nodeNamingStrategy, this.filterNode.bind(this), true);
|
|
73
73
|
});
|
|
74
|
+
|
|
75
|
+
// when cloning an instanced mesh the source mesh is still referencing to the source of the original mesh
|
|
76
|
+
// this is wrong, as we want to reference the cloned source
|
|
77
|
+
// this can only be done after the cloning process of the whole tree is finished, as we can't be sure if all
|
|
78
|
+
// instanced meshes or all sources meshes are cloning prior
|
|
79
|
+
const reassignSourceMesh = (node: TransformNode) => {
|
|
80
|
+
if (node.constructor.name === 'InstancedMesh') {
|
|
81
|
+
// find the cloned instance and source mesh
|
|
82
|
+
const clonedInstance = node as InstancedMesh;
|
|
83
|
+
const originalInstance = clonedInstance.metadata.cloneSource as InstancedMesh;
|
|
84
|
+
const originalSource = originalInstance.sourceMesh;
|
|
85
|
+
const clonedSource = originalSource.metadata.cloneTarget;
|
|
86
|
+
// it's not possible to just exchange the source mesh => readonly property
|
|
87
|
+
// we have to create a new clone with the correct source mesh
|
|
88
|
+
const exchangedInstance = clonedInstance.clone(clonedInstance.name, clonedInstance.parent, true, clonedSource);
|
|
89
|
+
|
|
90
|
+
// re-reference the childs of the cloned instance as well
|
|
91
|
+
const childs = clonedInstance.getChildTransformNodes(true);
|
|
92
|
+
childs.forEach(child => (child.parent = exchangedInstance));
|
|
93
|
+
|
|
94
|
+
// old instance mesh is not needed anymore and can be disposed
|
|
95
|
+
clonedInstance.dispose();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// recurse into childs
|
|
99
|
+
const children = node.getChildTransformNodes(true);
|
|
100
|
+
children.forEach(reassignSourceMesh);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
nodes.forEach(node => {
|
|
104
|
+
if (node) {
|
|
105
|
+
reassignSourceMesh(node);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
74
109
|
this.nodes = nodes.filter(node => !!node) as TransformNode[];
|
|
75
110
|
this._dottedNodes = mapToDottedNodes<TransformNode>(this.nodes, node => node instanceof TransformNode);
|
|
76
111
|
variant.broadcastEvent(Event.ELEMENT_NODES_CLONED, this);
|
|
@@ -110,17 +110,13 @@ const cloneTransformNode = function (
|
|
|
110
110
|
clone.id = newName;
|
|
111
111
|
clone.metadata = cloneDeep(node.metadata);
|
|
112
112
|
injectMetadata(clone, { cloneSource: node }, false);
|
|
113
|
+
injectMetadata(node, { cloneTarget: clone }, false);
|
|
113
114
|
// if the cloned node is of type InstancedMesh, due to a bug(?),
|
|
114
115
|
// the InstancedMesh.isEnabled state may have changed after cloning.
|
|
115
116
|
// in that case, set the clone's enabled state to the original's state
|
|
116
117
|
if (node.constructor.name === 'InstancedMesh') {
|
|
117
118
|
clone.setEnabled(node.isEnabled(false));
|
|
118
119
|
}
|
|
119
|
-
// copying tags is a temporary workaround, as it doesn't work for TransformNodes ATM
|
|
120
|
-
// see https://forum.babylonjs.com/t/transformnode-clone-doesnt-contain-original-tags/38429/1
|
|
121
|
-
if (Tags?.HasTags(node)) {
|
|
122
|
-
Tags.AddTagsTo(clone, Tags.GetTags(node, true));
|
|
123
|
-
}
|
|
124
120
|
}
|
|
125
121
|
if (deep) {
|
|
126
122
|
const children = node.getChildTransformNodes(true);
|
|
@@ -48,6 +48,20 @@ const bakeGeometryOfMesh = function (mesh: Mesh) {
|
|
|
48
48
|
// geometries can be shared across multiple meshes, first make them unique to avoid side-effects
|
|
49
49
|
mesh.makeGeometryUnique();
|
|
50
50
|
|
|
51
|
+
// Babylon.js already provides a function for baking the current skeleton changes into the geometry
|
|
52
|
+
if (mesh.skeleton) {
|
|
53
|
+
mesh.applySkeleton(mesh.skeleton);
|
|
54
|
+
mesh.skeleton = null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// NOTE: in difference to skeletons and transformations there is no baking function for morph targets (yet)
|
|
58
|
+
// however another approach could be to re-apply the position and normals data, as there are nice functions for it
|
|
59
|
+
// - `getPositionData(applySkeleton: boolean = false, applyMorph: boolean = false)`
|
|
60
|
+
// - `getNormalsData(applySkeleton: boolean = false, applyMorph: boolean = false)`
|
|
61
|
+
// you can decide if skeletons and morph targets can be added, which is exactly what we want
|
|
62
|
+
// I'm still hesitant to use it because "tangent" and "UV" kinds are not supported, whereas I'm not sure if it's
|
|
63
|
+
// required
|
|
64
|
+
// => try it out when there is enough time for detailed regression tests!
|
|
51
65
|
const morphTargetManager = mesh.morphTargetManager;
|
|
52
66
|
const geometry = mesh.geometry;
|
|
53
67
|
|
|
@@ -18,6 +18,7 @@ const enableObserverMap: {
|
|
|
18
18
|
} = {};
|
|
19
19
|
|
|
20
20
|
export const missingMaterialMetadataName = 'missingMaterial';
|
|
21
|
+
export const parsedMaterialIdMetadataName = 'parsedMaterialId';
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Create and return a custom loader plugin to be registered with SceneLoader, that allows
|
|
@@ -96,6 +97,8 @@ export const addMissingMaterialMetadata = function (dataParsed: any, container:
|
|
|
96
97
|
for (const currMeshOriginal of dataParsed.meshes) {
|
|
97
98
|
if (currMeshOriginal.name !== currMeshImported.name) continue;
|
|
98
99
|
// we're dealing with the original version of the current imported mesh now
|
|
100
|
+
// first save original material id of the imported babylon or GLB file
|
|
101
|
+
injectMetadata(currMeshImported, { [parsedMaterialIdMetadataName]: currMeshOriginal.materialId });
|
|
99
102
|
const materialOnImportedMesh = currMeshImported.material?.id;
|
|
100
103
|
const materialOnOriginalMesh = currMeshOriginal.materialId;
|
|
101
104
|
if (!materialOnOriginalMesh || materialOnImportedMesh === materialOnOriginalMesh) continue;
|