@combeenation/3d-viewer 18.2.0 → 18.4.0-beta1

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 (36) hide show
  1. package/dist/lib-cjs/buildinfo.json +1 -1
  2. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  3. package/dist/lib-cjs/index.d.ts +1 -0
  4. package/dist/lib-cjs/index.js +1 -0
  5. package/dist/lib-cjs/index.js.map +1 -1
  6. package/dist/lib-cjs/internal/export-helper.d.ts +34 -0
  7. package/dist/lib-cjs/internal/export-helper.js +306 -0
  8. package/dist/lib-cjs/internal/export-helper.js.map +1 -0
  9. package/dist/lib-cjs/internal/node-helper.js +2 -2
  10. package/dist/lib-cjs/internal/node-helper.js.map +1 -1
  11. package/dist/lib-cjs/manager/camera-manager.js +2 -6
  12. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  13. package/dist/lib-cjs/manager/dxf-export-manager.d.ts +39 -0
  14. package/dist/lib-cjs/manager/dxf-export-manager.js +116 -0
  15. package/dist/lib-cjs/manager/dxf-export-manager.js.map +1 -0
  16. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +19 -39
  17. package/dist/lib-cjs/manager/gltf-export-manager.js +38 -179
  18. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  19. package/dist/lib-cjs/manager/html-anchor-manager.js +7 -2
  20. package/dist/lib-cjs/manager/html-anchor-manager.js.map +1 -1
  21. package/dist/lib-cjs/viewer.d.ts +3 -1
  22. package/dist/lib-cjs/viewer.js +4 -0
  23. package/dist/lib-cjs/viewer.js.map +1 -1
  24. package/package.json +13 -12
  25. package/src/index.ts +1 -0
  26. package/src/internal/export-helper.ts +378 -0
  27. package/src/internal/node-helper.ts +2 -2
  28. package/src/manager/camera-manager.ts +2 -6
  29. package/src/manager/dxf-export-manager.ts +123 -0
  30. package/src/manager/gltf-export-manager.ts +38 -231
  31. package/src/manager/html-anchor-manager.ts +8 -2
  32. package/src/viewer.ts +6 -0
  33. package/dist/lib-cjs/internal/geometry-helper.d.ts +0 -14
  34. package/dist/lib-cjs/internal/geometry-helper.js +0 -114
  35. package/dist/lib-cjs/internal/geometry-helper.js.map +0 -1
  36. package/src/internal/geometry-helper.ts +0 -144
@@ -1,144 +0,0 @@
1
- import {
2
- FloatArray,
3
- Geometry,
4
- InstancedMesh,
5
- Mesh,
6
- MorphTarget,
7
- MorphTargetManager,
8
- TransformNode,
9
- Vector3,
10
- VertexBuffer,
11
- } from '../index';
12
- import { cloneInternalMetadata } from './metadata-helper';
13
-
14
- /**
15
- * Creates a "standard" mesh from an instanced mesh, by cloning the source mesh and applying transformation data
16
- */
17
- export function createMeshFromInstancedMesh(
18
- instancedMesh: InstancedMesh,
19
- newName: string,
20
- clonedParent: TransformNode | null
21
- ): Mesh {
22
- // first create a clone of the source mesh
23
- const newMesh = instancedMesh.sourceMesh.clone(newName, clonedParent, true);
24
- cloneInternalMetadata(instancedMesh.sourceMesh, newMesh);
25
- // apply the transformation data, it's important to create clones of the transformations to not touch the original
26
- // transformation when applying changes (eg: geometry baking)
27
- newMesh.position = instancedMesh.position.clone();
28
- newMesh.rotation = instancedMesh.rotation.clone();
29
- newMesh.scaling = instancedMesh.scaling.clone();
30
-
31
- // rotation quaternion is optional
32
- if (instancedMesh.rotationQuaternion) {
33
- newMesh.rotationQuaternion = instancedMesh.rotationQuaternion.clone();
34
- }
35
-
36
- // also sync the enabled state from the original instanced mesh
37
- newMesh.setEnabled(instancedMesh.isEnabled(false));
38
-
39
- return newMesh;
40
- }
41
-
42
- /**
43
- * Removes transformation data from the mesh and stores it in the geometry, which is called "baking".
44
- * Also considers the geometry change from morph targets.
45
- */
46
- export function bakeGeometryOfMesh(mesh: Mesh): void {
47
- if (!mesh.geometry) {
48
- // no geometry available, nothing to do
49
- return;
50
- }
51
-
52
- // geometries can be shared across multiple meshes, first make them unique to avoid side-effects
53
- mesh.makeGeometryUnique();
54
-
55
- // Babylon.js already provides a function for baking the current skeleton changes into the geometry
56
- if (mesh.skeleton) {
57
- mesh.applySkeleton(mesh.skeleton);
58
- mesh.skeleton = null;
59
- }
60
-
61
- // NOTE: in difference to skeletons and transformations there is no baking function for morph targets (yet)
62
- // however another approach could be to re-apply the position and normals data, as there are nice functions for it
63
- // - `getPositionData(applySkeleton: boolean = false, applyMorph: boolean = false)`
64
- // - `getNormalsData(applySkeleton: boolean = false, applyMorph: boolean = false)`
65
- // you can decide if skeletons and morph targets can be added, which is exactly what we want
66
- // I'm still hesitant to use it because "tangent" and "UV" kinds are not supported, whereas I'm not sure if it's
67
- // required
68
- // => try it out when there is enough time for detailed regression tests!
69
- const morphTargetManager = mesh.morphTargetManager;
70
- const geometry = mesh.geometry;
71
-
72
- if (morphTargetManager?.numTargets) {
73
- // apply morph target vertices data to mesh geometry
74
- // mostly only the "PositionKind" is implemented
75
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.PositionKind, morphTargetManager, geometry);
76
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.NormalKind, morphTargetManager, geometry);
77
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.TangentKind, morphTargetManager, geometry);
78
- _bakeMorphTargetManagerIntoVertices(VertexBuffer.UVKind, morphTargetManager, geometry);
79
-
80
- // remove morph target manager with all it's morph targets
81
- mesh.morphTargetManager = null;
82
- }
83
-
84
- // bake the transformation data in the mesh geometry, fortunately there is already a help function from Babylon.js
85
- mesh.bakeCurrentTransformIntoVertices();
86
- }
87
-
88
- /**
89
- * Resets transformation to initial state
90
- */
91
- export function resetTransformation(node: TransformNode): void {
92
- node.position = new Vector3(0, 0, 0);
93
- node.rotation = new Vector3(0, 0, 0);
94
- node.rotationQuaternion = null;
95
- node.scaling = new Vector3(1, 1, 1);
96
- }
97
-
98
- /**
99
- * @param kind morph targets can affect various vertices kinds, whereas "position" is the most common one
100
- * still other kinds (like normals or tangents) can be affected as well and can be provided on this input
101
- */
102
- function _bakeMorphTargetManagerIntoVertices(
103
- kind: string,
104
- morphTargetManager: MorphTargetManager,
105
- geometry: Geometry
106
- ): void {
107
- const origVerticesData = geometry.getVerticesData(kind);
108
- if (!origVerticesData) {
109
- // no vertices data for this kind availabe on the mesh geometry
110
- return;
111
- }
112
-
113
- let verticesData = [...origVerticesData];
114
- for (let i = 0; i < morphTargetManager.numTargets; i++) {
115
- const target = morphTargetManager.getTarget(i);
116
- const targetVerticesData = _getVerticesDataFromMorphTarget(kind, target);
117
- if (targetVerticesData) {
118
- // vertices data of this kind are implemented on the morph target
119
- // add the influence of this morph target to the vertices data
120
- // formula is taken from: https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets#basics
121
- verticesData = verticesData.map(
122
- (oldVal, idx) => oldVal + (targetVerticesData[idx] - origVerticesData[idx]) * target.influence
123
- );
124
- }
125
- }
126
-
127
- // apply the updated vertices data
128
- geometry.setVerticesData(kind, verticesData);
129
- }
130
-
131
- function _getVerticesDataFromMorphTarget(kind: string, morphTarget: MorphTarget): FloatArray | null {
132
- switch (kind) {
133
- case VertexBuffer.PositionKind:
134
- return morphTarget.getPositions();
135
- case VertexBuffer.NormalKind:
136
- return morphTarget.getNormals();
137
- case VertexBuffer.TangentKind:
138
- return morphTarget.getTangents();
139
- case VertexBuffer.UVKind:
140
- return morphTarget.getUVs();
141
- }
142
-
143
- return null;
144
- }