@combeenation/3d-viewer 18.5.1 → 19.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 (38) 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 +4 -3
  4. package/dist/lib-cjs/index.js +4 -3
  5. package/dist/lib-cjs/index.js.map +1 -1
  6. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +1 -1
  7. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js.map +1 -1
  8. package/dist/lib-cjs/internal/export-helper.js +1 -77
  9. package/dist/lib-cjs/internal/export-helper.js.map +1 -1
  10. package/dist/lib-cjs/manager/export-manager.d.ts +82 -0
  11. package/dist/lib-cjs/manager/export-manager.js +224 -0
  12. package/dist/lib-cjs/manager/export-manager.js.map +1 -0
  13. package/dist/lib-cjs/{helper/decals-helper.d.ts → utils/decal-utils.d.ts} +5 -1
  14. package/dist/lib-cjs/{helper/decals-helper.js → utils/decal-utils.js} +6 -3
  15. package/dist/lib-cjs/utils/decal-utils.js.map +1 -0
  16. package/dist/lib-cjs/utils/node-utils.d.ts +17 -0
  17. package/dist/lib-cjs/utils/node-utils.js +92 -0
  18. package/dist/lib-cjs/utils/node-utils.js.map +1 -0
  19. package/dist/lib-cjs/viewer.d.ts +3 -5
  20. package/dist/lib-cjs/viewer.js +3 -7
  21. package/dist/lib-cjs/viewer.js.map +1 -1
  22. package/package.json +1 -1
  23. package/src/index.ts +4 -3
  24. package/src/internal/cbn-custom-babylon-loader-plugin.ts +2 -2
  25. package/src/internal/export-helper.ts +2 -100
  26. package/src/manager/export-manager.ts +273 -0
  27. package/src/{helper/decals-helper.ts → utils/decal-utils.ts} +6 -1
  28. package/src/utils/node-utils.ts +112 -0
  29. package/src/viewer.ts +5 -11
  30. package/dist/lib-cjs/helper/decals-helper.js.map +0 -1
  31. package/dist/lib-cjs/manager/dxf-export-manager.d.ts +0 -39
  32. package/dist/lib-cjs/manager/dxf-export-manager.js +0 -116
  33. package/dist/lib-cjs/manager/dxf-export-manager.js.map +0 -1
  34. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +0 -54
  35. package/dist/lib-cjs/manager/gltf-export-manager.js +0 -124
  36. package/dist/lib-cjs/manager/gltf-export-manager.js.map +0 -1
  37. package/src/manager/dxf-export-manager.ts +0 -123
  38. package/src/manager/gltf-export-manager.ts +0 -139
@@ -0,0 +1,112 @@
1
+ import { FloatArray, Geometry, Mesh, MorphTarget, MorphTargetManager, VertexBuffer } from '..';
2
+
3
+ export type BakeGeometryOptions = {
4
+ keepTransformation?: boolean;
5
+ };
6
+
7
+ /**
8
+ * Removes transformation data from the mesh and stores it in the geometry, which is called "baking".
9
+ * Also considers the geometry change from morph targets and skeletons.
10
+ *
11
+ * @param settings Optionally avoid baking the transformation, as this only works conveniently if the parent structure
12
+ * is baked as well. Baking morph targets only is a use case when preparing a mesh for CSG operations,
13
+ * which doesn't consider morph targets (yet).
14
+ */
15
+ function bakeGeometryOfMesh(mesh: Mesh, settings?: BakeGeometryOptions): void {
16
+ const { keepTransformation } = settings ?? {};
17
+
18
+ if (!mesh.geometry) {
19
+ // no geometry available, nothing to do
20
+ return;
21
+ }
22
+
23
+ // geometries can be shared across multiple meshes, first make them unique to avoid side-effects
24
+ mesh.makeGeometryUnique();
25
+
26
+ // Babylon.js already provides a function for baking the current skeleton changes into the geometry
27
+ if (mesh.skeleton) {
28
+ mesh.applySkeleton(mesh.skeleton);
29
+ mesh.skeleton = null;
30
+ }
31
+
32
+ // NOTE: in difference to skeletons and transformations there is no baking function for morph targets (yet)
33
+ // however another approach could be to re-apply the position and normals data, as there are nice functions for it
34
+ // - `getPositionData(applySkeleton: boolean = false, applyMorph: boolean = false)`
35
+ // - `getNormalsData(applySkeleton: boolean = false, applyMorph: boolean = false)`
36
+ // you can decide if skeletons and morph targets can be added, which is exactly what we want
37
+ // I'm still hesitant to use it because "tangent" and "UV" kinds are not supported, whereas I'm not sure if it's
38
+ // required
39
+ // => try it out when there is enough time for detailed regression tests!
40
+ const morphTargetManager = mesh.morphTargetManager;
41
+ const geometry = mesh.geometry;
42
+
43
+ if (morphTargetManager?.numTargets) {
44
+ // apply morph target vertices data to mesh geometry
45
+ // mostly only the "PositionKind" is implemented
46
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.PositionKind, morphTargetManager, geometry);
47
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.NormalKind, morphTargetManager, geometry);
48
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.TangentKind, morphTargetManager, geometry);
49
+ _bakeMorphTargetManagerIntoVertices(VertexBuffer.UVKind, morphTargetManager, geometry);
50
+
51
+ // remove morph target manager with all it's morph targets
52
+ mesh.morphTargetManager = null;
53
+ }
54
+
55
+ // bake the transformation data in the mesh geometry, fortunately there is already a help function from Babylon.js
56
+ if (!keepTransformation) {
57
+ mesh.bakeCurrentTransformIntoVertices();
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @param kind morph targets can affect various vertices kinds, whereas "position" is the most common one
63
+ * still other kinds (like normals or tangents) can be affected as well and can be provided on this input
64
+ */
65
+ function _bakeMorphTargetManagerIntoVertices(
66
+ kind: string,
67
+ morphTargetManager: MorphTargetManager,
68
+ geometry: Geometry
69
+ ): void {
70
+ const origVerticesData = geometry.getVerticesData(kind);
71
+ if (!origVerticesData) {
72
+ // no vertices data for this kind availabe on the mesh geometry
73
+ return;
74
+ }
75
+
76
+ let verticesData = [...origVerticesData];
77
+ for (let i = 0; i < morphTargetManager.numTargets; i++) {
78
+ const target = morphTargetManager.getTarget(i);
79
+ const targetVerticesData = _getVerticesDataFromMorphTarget(kind, target);
80
+ if (targetVerticesData) {
81
+ // vertices data of this kind are implemented on the morph target
82
+ // add the influence of this morph target to the vertices data
83
+ // formula is taken from: https://doc.babylonjs.com/features/featuresDeepDive/mesh/morphTargets#basics
84
+ verticesData = verticesData.map(
85
+ (oldVal, idx) => oldVal + (targetVerticesData[idx] - origVerticesData[idx]) * target.influence
86
+ );
87
+ }
88
+ }
89
+
90
+ // apply the updated vertices data
91
+ geometry.setVerticesData(kind, verticesData);
92
+ }
93
+
94
+ function _getVerticesDataFromMorphTarget(kind: string, morphTarget: MorphTarget): FloatArray | null {
95
+ switch (kind) {
96
+ case VertexBuffer.PositionKind:
97
+ return morphTarget.getPositions();
98
+ case VertexBuffer.NormalKind:
99
+ return morphTarget.getNormals();
100
+ case VertexBuffer.TangentKind:
101
+ return morphTarget.getTangents();
102
+ case VertexBuffer.UVKind:
103
+ return morphTarget.getUVs();
104
+ }
105
+
106
+ return null;
107
+ }
108
+
109
+ // export functions under "namespace", so that they can found easier in consuming code
110
+ export const NodeUtils = {
111
+ bakeGeometryOfMesh,
112
+ };
package/src/viewer.ts CHANGED
@@ -6,11 +6,10 @@ import {
6
6
  DebugManager,
7
7
  DefaultSceneSettings,
8
8
  DimensionLineManager,
9
- DxfExportManager,
10
9
  Engine,
11
10
  EngineOptions,
12
11
  EventManager,
13
- GltfExportManager,
12
+ ExportManager,
14
13
  HtmlAnchorManager,
15
14
  MaterialManager,
16
15
  ModelManager,
@@ -85,9 +84,8 @@ export class Viewer {
85
84
  protected _cameraManager!: CameraManager;
86
85
  protected _debugManager!: DebugManager;
87
86
  protected _dimensionLineManager!: DimensionLineManager;
88
- protected _dxfExportManager!: DxfExportManager;
89
87
  protected _eventManager!: EventManager;
90
- protected _gltfExportManager!: GltfExportManager;
88
+ protected _exportManager!: ExportManager;
91
89
  protected _htmlAnchorManager!: HtmlAnchorManager;
92
90
  protected _materialManager!: MaterialManager;
93
91
  protected _modelManager!: ModelManager;
@@ -129,14 +127,11 @@ export class Viewer {
129
127
  get dimensionLineManager(): DimensionLineManager {
130
128
  return this._dimensionLineManager;
131
129
  }
132
- get dxfExportManager(): DxfExportManager {
133
- return this._dxfExportManager;
134
- }
135
130
  get eventManager(): EventManager {
136
131
  return this._eventManager;
137
132
  }
138
- get gltfExportManager(): GltfExportManager {
139
- return this._gltfExportManager;
133
+ get exportManager(): ExportManager {
134
+ return this._exportManager;
140
135
  }
141
136
  get htmlAnchorManager(): HtmlAnchorManager {
142
137
  return this._htmlAnchorManager;
@@ -254,9 +249,8 @@ export class Viewer {
254
249
  this._cameraManager = new CameraManager(this);
255
250
  this._debugManager = new DebugManager(this);
256
251
  this._dimensionLineManager = new DimensionLineManager(this);
257
- this._dxfExportManager = new DxfExportManager(this);
258
252
  this._eventManager = new EventManager(this);
259
- this._gltfExportManager = new GltfExportManager(this);
253
+ this._exportManager = new ExportManager(this);
260
254
  this._htmlAnchorManager = new HtmlAnchorManager(this);
261
255
  this._materialManager = new MaterialManager(this);
262
256
  this._modelManager = new ModelManager(this);
@@ -1 +0,0 @@
1
- {"version":3,"file":"decals-helper.js","sourceRoot":"","sources":["../../../src/helper/decals-helper.ts"],"names":[],"mappings":";;;AAAA,0BAUY;AAEC,QAAA,oBAAoB,GAAG;IAClC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACjB,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,IAAI;IACf,eAAe,EAAE,YAAQ,CAAC,wBAAwB;CACnD,CAAC;AAqDF;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,MAA0B,EAAE,cAA+B,EAAE,UAAU,GAAG,IAAI;;IAC5G,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,cAAc,CAAC,CAAC;IAC3F,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,eAAW,CAAC;YACpB,EAAE,EAAE,kBAAc,CAAC,yBAAyB;YAC5C,OAAO,EAAE,0BAA0B,MAAM,CAAC,IAAI,qBA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O,EAAE;QACxB,MAAM,MAAM,GAAG,MAAA,MAAM,CAAC,MAAM,mCAAI,4BAAoB,CAAC,MAAM,CAAC;QAC5D,6DAA6D;QAC7D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YAC5C,SAAS,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;YACpC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;YAC5C,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;SAC7C;QAED,SAAS,CAAC,eAAe,CAAC,gBAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;KACjE;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAhDD,0CAgDC"}
@@ -1,39 +0,0 @@
1
- import { NodeDescription, Viewer } from '../index';
2
- import { Unit } from 'dxf-writer';
3
- export declare type DxfUnit = Unit;
4
- export declare type DxfExportSettings = {
5
- fileName?: string;
6
- /** List of nodes that should be excluded from the DXF export */
7
- excludeNodes?: NodeDescription[];
8
- /**
9
- * Unit of the 3d model.\
10
- * If a unit is set, CAD tools are able to convert the values from the DXF into the configured unit of the CAD tool.
11
- */
12
- unit?: DxfUnit;
13
- };
14
- /**
15
- * Manager for creating DXF exports of the current viewer scene
16
- */
17
- export declare class DxfExportManager {
18
- protected viewer: Viewer;
19
- /** @internal */
20
- constructor(viewer: Viewer);
21
- /**
22
- * Returns DXF export as `File` for further processing. (e.g upload as Cfgn file)
23
- */
24
- createDxf(settings?: DxfExportSettings): Promise<File>;
25
- /**
26
- * Creates DXF export and downloads the resulting file right away
27
- */
28
- downloadDxf(settings?: DxfExportSettings): Promise<void>;
29
- /**
30
- * Help function for creating a blob with the DXF string, as this is needed for both public interface functions
31
- * (`exportDxf` & `exportDxfToFile`)
32
- */
33
- protected _createDxfBlob(settings?: DxfExportSettings): Promise<Blob>;
34
- /**
35
- * DXF creation process.\
36
- * We go through all vertices of all meshes and create DXF 3d faces accordingly.
37
- */
38
- protected _createDxf(unit?: DxfUnit): string;
39
- }
@@ -1,116 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DxfExportManager = void 0;
16
- const index_1 = require("../index");
17
- const export_helper_1 = require("../internal/export-helper");
18
- const metadata_helper_1 = require("../internal/metadata-helper");
19
- const node_helper_1 = require("../internal/node-helper");
20
- const dxf_writer_1 = __importDefault(require("dxf-writer"));
21
- /**
22
- * Manager for creating DXF exports of the current viewer scene
23
- */
24
- class DxfExportManager {
25
- /** @internal */
26
- constructor(viewer) {
27
- this.viewer = viewer;
28
- }
29
- /**
30
- * Returns DXF export as `File` for further processing. (e.g upload as Cfgn file)
31
- */
32
- createDxf(settings) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const normalizedFileName = (0, export_helper_1.normalizeFileName)(settings === null || settings === void 0 ? void 0 : settings.fileName, 'dxf', 'dxf-export');
35
- const dxfBlob = yield this._createDxfBlob(settings);
36
- const dxfFile = new File([dxfBlob], normalizedFileName, { type: 'application/dxf' });
37
- return dxfFile;
38
- });
39
- }
40
- /**
41
- * Creates DXF export and downloads the resulting file right away
42
- */
43
- downloadDxf(settings) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const normalizedFileName = (0, export_helper_1.normalizeFileName)(settings === null || settings === void 0 ? void 0 : settings.fileName, 'dxf', 'dxf-export');
46
- const dxfBlob = yield this._createDxfBlob(settings);
47
- const url = URL.createObjectURL(dxfBlob);
48
- (0, export_helper_1.downloadFile)(url, normalizedFileName);
49
- URL.revokeObjectURL(url);
50
- });
51
- }
52
- /**
53
- * Help function for creating a blob with the DXF string, as this is needed for both public interface functions
54
- * (`exportDxf` & `exportDxfToFile`)
55
- */
56
- _createDxfBlob(settings) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- // Transformation baking pre process is required for DXF exports, as we take the plain vertex information for the
59
- // DXF conversion, therefore the vertices need to be located in world already
60
- yield (0, export_helper_1.exportPreProcess)(this.viewer, { excludeNodes: settings === null || settings === void 0 ? void 0 : settings.excludeNodes });
61
- const dxfString = this._createDxf(settings === null || settings === void 0 ? void 0 : settings.unit);
62
- yield (0, export_helper_1.exportPostProcess)(this.viewer);
63
- const dxfBlob = new Blob([dxfString], { type: 'application/dxf' });
64
- return dxfBlob;
65
- });
66
- }
67
- /**
68
- * DXF creation process.\
69
- * We go through all vertices of all meshes and create DXF 3d faces accordingly.
70
- */
71
- _createDxf(unit) {
72
- const DXF = new dxf_writer_1.default();
73
- if (unit) {
74
- DXF.setUnits(unit);
75
- }
76
- const meshesToExport = this.viewer.scene.meshes.filter(mesh => (0, metadata_helper_1.getInternalMetadataValue)(mesh, 'exportNode') &&
77
- // NOTE: can't add this criteria in pre export process, as pre export process works recursively and childs of
78
- // transforms nodes or meshes without geometry can still have geometries and therefore be valid for the export
79
- !(0, node_helper_1.nodeMatchesAnyCriteria)(mesh, { hasInvalidBoundingInfo: true }));
80
- meshesToExport.forEach(mesh => {
81
- const positions = mesh.getVerticesData(index_1.VertexBuffer.PositionKind);
82
- const indices = mesh.getIndices();
83
- if (!positions || !indices) {
84
- console.warn(`Can't create DXF export of mesh "${mesh.name}", as there is no vertex data available`);
85
- return;
86
- }
87
- for (let i = 0; i < indices.length; i += 3) {
88
- // A face always consists of 3 vertices.
89
- // First we need to get the indizes of the vertices.
90
- const idx1 = indices[i];
91
- const idx2 = indices[i + 1];
92
- const idx3 = indices[i + 2];
93
- // Now get the x, y, z data of the associated index.
94
- // One index stores 3 vertices, thats why the index is multiplied with 3 before accessing the actual vertex
95
- // position.
96
- // > and z components have dedicated offsets 1 and 2.
97
- // ===============
98
- // Important NOTE:
99
- // ===============
100
- // DXF is right-handed, according to tests in AutoDesk it seems like y and z components are just switched.
101
- // So we use offset 2 for y and offset 1 for z.
102
- const p1 = new index_1.Vector3(positions[idx1 * 3], positions[idx1 * 3 + 2], positions[idx1 * 3 + 1]);
103
- const p2 = new index_1.Vector3(positions[idx2 * 3], positions[idx2 * 3 + 2], positions[idx2 * 3 + 1]);
104
- const p3 = new index_1.Vector3(positions[idx3 * 3], positions[idx3 * 3 + 2], positions[idx3 * 3 + 1]);
105
- // Add a 3D face to the DXF (3DFACE entity).
106
- // The library works with 4 points per face, but we only have 3.
107
- // Using the last point 3 times is fine though.
108
- DXF.drawFace(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, p3.x, p3.y, p3.z);
109
- }
110
- });
111
- const dxfString = DXF.toDxfString();
112
- return dxfString;
113
- }
114
- }
115
- exports.DxfExportManager = DxfExportManager;
116
- //# sourceMappingURL=dxf-export-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dxf-export-manager.js","sourceRoot":"","sources":["../../../src/manager/dxf-export-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oCAA0E;AAC1E,6DAAiH;AACjH,iEAAuE;AACvE,yDAAiE;AACjE,4DAA2C;AAe3C;;GAEG;AACH,MAAa,gBAAgB;IAC3B,gBAAgB;IAChB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,C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AC;QACpC,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AApGD,4CAoGC"}
@@ -1,54 +0,0 @@
1
- import { IExportOptions, NodeDescription, Viewer } from '../index';
2
- /**
3
- * Interface TODOS
4
- * ===============
5
- * - create settings object instead of individual input parameters (optimizeForAR, excludeNodes, fileName)
6
- * - see `DxfExportManager`
7
- * - much more flexible when adding new parameters
8
- * - rename functions to create/download, instead of suffixing "ToFile"
9
- * - also see `DxfExportManager`
10
- *
11
- * Viewer control is directly accessing these functions, so introducing breaking changes here is really annoying, as we
12
- * have to add another version switch in the source code of the viewer control.
13
- * Maybe there is a chance to update the interface when re-creating the viewer control in the new cfgr editor.
14
- */
15
- /**
16
- * Manager for gltf export and augmented reality features
17
- */
18
- export declare class GltfExportManager {
19
- protected viewer: Viewer;
20
- protected _maxTextureSize: number;
21
- /**
22
- * Defines options for the export.
23
- * We don't allow the user to overwrite certain settings, since we rely on properties like `removeNoopRootNodes` to
24
- * stay `true` in order to make the AR export work.
25
- * We could theoretically allow it if AR optimization is not desired, but this may confuse the user.
26
- */
27
- protected static _gltfExportOptions(optimizeForAR: boolean, excludeNodes?: NodeDescription[]): IExportOptions;
28
- /** @internal */
29
- constructor(viewer: Viewer);
30
- /**
31
- * Exports selected nodes to a file.
32
- * @param fileName Optional name of the exported .GLB file.
33
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
34
- * is mostly targeting Apples .usdz format.
35
- * @param excludeNodes Optional list of nodes to be excluded from the export.
36
- */
37
- exportGlb(fileName?: string, optimizeForAR?: boolean, excludeNodes?: NodeDescription[]): Promise<File | undefined>;
38
- /**
39
- * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported seperately.
40
- * @param filename Name of the main (text-based) .GLTF file referring to separate texture files.
41
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
42
- * is mostly targeting Apples .usdz format.
43
- * @param excludeNodes Optional list of nodes to be excluded from the export.
44
- */
45
- exportGltfToFile(fileName: string, optimizeForAR?: boolean, excludeNodes?: NodeDescription[]): Promise<void>;
46
- /**
47
- * Exports selected nodes to GLB. This results in one binary file.
48
- * @param fileName Name of the main (text-based) .GLTF file referring to seperate texture files.
49
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
50
- * is mostly targeting Apples .usdz format.
51
- * @param excludeNodes Optional list of nodes to be excluded from the export.
52
- */
53
- exportGlbToFile(fileName: string, optimizeForAR?: boolean, excludeNodes?: NodeDescription[]): Promise<void>;
54
- }
@@ -1,124 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GltfExportManager = void 0;
13
- const index_1 = require("../index");
14
- const export_helper_1 = require("../internal/export-helper");
15
- const metadata_helper_1 = require("../internal/metadata-helper");
16
- /**
17
- * Interface TODOS
18
- * ===============
19
- * - create settings object instead of individual input parameters (optimizeForAR, excludeNodes, fileName)
20
- * - see `DxfExportManager`
21
- * - much more flexible when adding new parameters
22
- * - rename functions to create/download, instead of suffixing "ToFile"
23
- * - also see `DxfExportManager`
24
- *
25
- * Viewer control is directly accessing these functions, so introducing breaking changes here is really annoying, as we
26
- * have to add another version switch in the source code of the viewer control.
27
- * Maybe there is a chance to update the interface when re-creating the viewer control in the new cfgr editor.
28
- */
29
- /**
30
- * Manager for gltf export and augmented reality features
31
- */
32
- class GltfExportManager {
33
- /** @internal */
34
- constructor(viewer) {
35
- this.viewer = viewer;
36
- // store initial max texture size, so that we can restore it in the post processing
37
- this._maxTextureSize = viewer.engine.getCaps().maxTextureSize;
38
- }
39
- /**
40
- * Defines options for the export.
41
- * We don't allow the user to overwrite certain settings, since we rely on properties like `removeNoopRootNodes` to
42
- * stay `true` in order to make the AR export work.
43
- * We could theoretically allow it if AR optimization is not desired, but this may confuse the user.
44
- */
45
- static _gltfExportOptions(optimizeForAR, excludeNodes) {
46
- return {
47
- shouldExportNode: function (node) {
48
- if (optimizeForAR) {
49
- // we explicitely marked nodes, that should be exported in AR mode
50
- return !!(0, metadata_helper_1.getInternalMetadataValue)(node, 'exportNode');
51
- }
52
- else {
53
- // use the default export node check (enabled state, exclusion list, etc...)
54
- return (0, export_helper_1.isExportableTransformNode)(node, excludeNodes);
55
- }
56
- },
57
- shouldExportAnimation: (animation) => !optimizeForAR,
58
- };
59
- }
60
- /**
61
- * Exports selected nodes to a file.
62
- * @param fileName Optional name of the exported .GLB file.
63
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
64
- * is mostly targeting Apples .usdz format.
65
- * @param excludeNodes Optional list of nodes to be excluded from the export.
66
- */
67
- exportGlb(fileName, optimizeForAR = false, excludeNodes) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- if (optimizeForAR)
70
- yield (0, export_helper_1.exportPreProcess)(this.viewer, { excludeNodes, scaleDownTextures: true });
71
- const glbData = yield index_1.GLTF2Export.GLBAsync(this.viewer.scene, 'dummy', GltfExportManager._gltfExportOptions(optimizeForAR, excludeNodes));
72
- if (optimizeForAR)
73
- yield (0, export_helper_1.exportPostProcess)(this.viewer);
74
- const resBlob = glbData.glTFFiles['dummy.glb'];
75
- // check if result is valid, according to the typings this could also be a string
76
- if (resBlob instanceof Blob) {
77
- const normalizedFileName = (0, export_helper_1.normalizeFileName)(fileName, 'glb', 'glb-export');
78
- return new File([resBlob], normalizedFileName);
79
- }
80
- else {
81
- // result was not a valid blob
82
- return undefined;
83
- }
84
- });
85
- }
86
- /**
87
- * Exports selected nodes to GLTF. This may result in more than one file, since textures are exported seperately.
88
- * @param filename Name of the main (text-based) .GLTF file referring to separate texture files.
89
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
90
- * is mostly targeting Apples .usdz format.
91
- * @param excludeNodes Optional list of nodes to be excluded from the export.
92
- */
93
- exportGltfToFile(fileName, optimizeForAR = false, excludeNodes) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- if (optimizeForAR)
96
- yield (0, export_helper_1.exportPreProcess)(this.viewer, { excludeNodes, scaleDownTextures: true });
97
- const gltf = yield index_1.GLTF2Export.GLTFAsync(this.viewer.scene,
98
- // no need to add .glb, as Babylon.js does that internally
99
- fileName, GltfExportManager._gltfExportOptions(optimizeForAR, excludeNodes));
100
- gltf.downloadFiles();
101
- if (optimizeForAR)
102
- yield (0, export_helper_1.exportPostProcess)(this.viewer);
103
- });
104
- }
105
- /**
106
- * Exports selected nodes to GLB. This results in one binary file.
107
- * @param fileName Name of the main (text-based) .GLTF file referring to seperate texture files.
108
- * @param optimizeForAR Adjusts the exported GLB so that known issues get automatically fixed, this
109
- * is mostly targeting Apples .usdz format.
110
- * @param excludeNodes Optional list of nodes to be excluded from the export.
111
- */
112
- exportGlbToFile(fileName, optimizeForAR = false, excludeNodes) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- if (optimizeForAR)
115
- yield (0, export_helper_1.exportPreProcess)(this.viewer, { excludeNodes, scaleDownTextures: true });
116
- const glb = yield index_1.GLTF2Export.GLBAsync(this.viewer.scene, fileName, GltfExportManager._gltfExportOptions(optimizeForAR, excludeNodes));
117
- glb.downloadFiles();
118
- if (optimizeForAR)
119
- yield (0, export_helper_1.exportPostProcess)(this.viewer);
120
- });
121
- }
122
- }
123
- exports.GltfExportManager = GltfExportManager;
124
- //# sourceMappingURL=gltf-export-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gltf-export-manager.js","sourceRoot":"","sources":["../../../src/manager/gltf-export-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;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AAC,aAAa,EAAE,CAAC;YAEpB,IAAI,aAAa;gBAAE,MAAM,IAAA,iCAAiB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1D,CAAC;KAAA;CACF;AAhHD,8CAgHC"}
@@ -1,123 +0,0 @@
1
- import { NodeDescription, Vector3, VertexBuffer, Viewer } from '../index';
2
- import { downloadFile, exportPostProcess, exportPreProcess, normalizeFileName } from '../internal/export-helper';
3
- import { getInternalMetadataValue } from '../internal/metadata-helper';
4
- import { nodeMatchesAnyCriteria } from '../internal/node-helper';
5
- import DRAWING, { Unit } from 'dxf-writer';
6
-
7
- export type DxfUnit = Unit;
8
-
9
- export type DxfExportSettings = {
10
- fileName?: string;
11
- /** List of nodes that should be excluded from the DXF export */
12
- excludeNodes?: NodeDescription[];
13
- /**
14
- * Unit of the 3d model.\
15
- * If a unit is set, CAD tools are able to convert the values from the DXF into the configured unit of the CAD tool.
16
- */
17
- unit?: DxfUnit;
18
- };
19
-
20
- /**
21
- * Manager for creating DXF exports of the current viewer scene
22
- */
23
- export class DxfExportManager {
24
- /** @internal */
25
- public constructor(protected viewer: Viewer) {}
26
-
27
- /**
28
- * Returns DXF export as `File` for further processing. (e.g upload as Cfgn file)
29
- */
30
- public async createDxf(settings?: DxfExportSettings): Promise<File> {
31
- const normalizedFileName = normalizeFileName(settings?.fileName, 'dxf', 'dxf-export');
32
-
33
- const dxfBlob = await this._createDxfBlob(settings);
34
- const dxfFile = new File([dxfBlob], normalizedFileName, { type: 'application/dxf' });
35
-
36
- return dxfFile;
37
- }
38
-
39
- /**
40
- * Creates DXF export and downloads the resulting file right away
41
- */
42
- public async downloadDxf(settings?: DxfExportSettings): Promise<void> {
43
- const normalizedFileName = normalizeFileName(settings?.fileName, 'dxf', 'dxf-export');
44
-
45
- const dxfBlob = await this._createDxfBlob(settings);
46
-
47
- const url = URL.createObjectURL(dxfBlob);
48
- downloadFile(url, normalizedFileName);
49
- URL.revokeObjectURL(url);
50
- }
51
-
52
- /**
53
- * Help function for creating a blob with the DXF string, as this is needed for both public interface functions
54
- * (`exportDxf` & `exportDxfToFile`)
55
- */
56
- protected async _createDxfBlob(settings?: DxfExportSettings): Promise<Blob> {
57
- // Transformation baking pre process is required for DXF exports, as we take the plain vertex information for the
58
- // DXF conversion, therefore the vertices need to be located in world already
59
- await exportPreProcess(this.viewer, { excludeNodes: settings?.excludeNodes });
60
- const dxfString = this._createDxf(settings?.unit);
61
- await exportPostProcess(this.viewer);
62
-
63
- const dxfBlob = new Blob([dxfString], { type: 'application/dxf' });
64
- return dxfBlob;
65
- }
66
-
67
- /**
68
- * DXF creation process.\
69
- * We go through all vertices of all meshes and create DXF 3d faces accordingly.
70
- */
71
- protected _createDxf(unit?: DxfUnit): string {
72
- const DXF = new DRAWING();
73
- if (unit) {
74
- DXF.setUnits(unit);
75
- }
76
-
77
- const meshesToExport = this.viewer.scene.meshes.filter(
78
- mesh =>
79
- getInternalMetadataValue(mesh, 'exportNode') &&
80
- // NOTE: can't add this criteria in pre export process, as pre export process works recursively and childs of
81
- // transforms nodes or meshes without geometry can still have geometries and therefore be valid for the export
82
- !nodeMatchesAnyCriteria(mesh, { hasInvalidBoundingInfo: true })
83
- );
84
-
85
- meshesToExport.forEach(mesh => {
86
- const positions = mesh.getVerticesData(VertexBuffer.PositionKind);
87
- const indices = mesh.getIndices();
88
- if (!positions || !indices) {
89
- console.warn(`Can't create DXF export of mesh "${mesh.name}", as there is no vertex data available`);
90
- return;
91
- }
92
-
93
- for (let i = 0; i < indices.length; i += 3) {
94
- // A face always consists of 3 vertices.
95
- // First we need to get the indizes of the vertices.
96
- const idx1 = indices[i];
97
- const idx2 = indices[i + 1];
98
- const idx3 = indices[i + 2];
99
-
100
- // Now get the x, y, z data of the associated index.
101
- // One index stores 3 vertices, thats why the index is multiplied with 3 before accessing the actual vertex
102
- // position.
103
- // > and z components have dedicated offsets 1 and 2.
104
- // ===============
105
- // Important NOTE:
106
- // ===============
107
- // DXF is right-handed, according to tests in AutoDesk it seems like y and z components are just switched.
108
- // So we use offset 2 for y and offset 1 for z.
109
- const p1 = new Vector3(positions[idx1 * 3], positions[idx1 * 3 + 2], positions[idx1 * 3 + 1]);
110
- const p2 = new Vector3(positions[idx2 * 3], positions[idx2 * 3 + 2], positions[idx2 * 3 + 1]);
111
- const p3 = new Vector3(positions[idx3 * 3], positions[idx3 * 3 + 2], positions[idx3 * 3 + 1]);
112
-
113
- // Add a 3D face to the DXF (3DFACE entity).
114
- // The library works with 4 points per face, but we only have 3.
115
- // Using the last point 3 times is fine though.
116
- DXF.drawFace(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, p3.x, p3.y, p3.z);
117
- }
118
- });
119
-
120
- const dxfString = DXF.toDxfString();
121
- return dxfString;
122
- }
123
- }