@combeenation/3d-viewer 12.0.0-alpha2 → 12.0.0-alpha4

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.0.0-alpha2",
3
+ "version": "12.0.0-alpha4",
4
4
  "description": "Combeenation 3D Viewer",
5
5
  "homepage": "https://github.com/Combeenation/3d-viewer#readme",
6
6
  "bugs": {
@@ -1,4 +1,4 @@
1
- import { Node as BjsNode, Color3, InstancedMesh, PBRMaterial } from '../../index';
1
+ import { Node as BjsNode, Color3, InstancedMesh, PBRMaterial, Vector3 } from '../../index';
2
2
  import { Viewer } from '../classes/viewer';
3
3
  import { injectMetadata } from '../util/babylonHelper';
4
4
  import { bakeGeometryOfMesh, createMeshFromInstancedMesh, resetTransformation } from '../util/geometryHelper';
@@ -13,6 +13,7 @@ export class GltfExportManager {
13
13
  deleteAfterExport: 'deleteAfterExport',
14
14
  exchangeMaterialWith: 'exchangeMaterialWith',
15
15
  };
16
+ protected static readonly _EXPORT_ROOT_NAME = '__export_root__';
16
17
 
17
18
  protected constructor(protected viewer: Viewer) {}
18
19
 
@@ -59,13 +60,24 @@ export class GltfExportManager {
59
60
  }
60
61
 
61
62
  protected async _exportPreProcess(excluded?: ExcludedGeometryList): Promise<void> {
63
+ this.viewer.pauseRendering();
64
+
62
65
  // handle materials
63
66
  this.viewer.scene.materials
64
67
  .filter(material => this._shouldReplaceMaterial(material))
65
68
  .forEach(material => this._createRefractionMaterialReplacement(material as PBRMaterial));
66
69
 
70
+ const exportRootNode = new TransformNode(GltfExportManager._EXPORT_ROOT_NAME, this.viewer.scene);
71
+ exportRootNode.scaling = new Vector3(-1, 1, 1);
72
+ injectMetadata(exportRootNode!, {
73
+ [GltfExportManager._METADATA_PROPS.exportNode]: true,
74
+ [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true,
75
+ });
76
+
67
77
  // handle nodes
68
- this.viewer.scene.rootNodes.forEach(rootNode => this._prepareNodeForExport(rootNode, null, excluded));
78
+ this.viewer.scene.rootNodes
79
+ .filter(rootNode => rootNode.name !== GltfExportManager._EXPORT_ROOT_NAME)
80
+ .forEach(rootNode => this._prepareNodeForExport(rootNode, exportRootNode, excluded));
69
81
 
70
82
  // bake transformation of all meshes, so that no negative scalings are left
71
83
  // it's important that this is done AFTER instanced meshes have been converted (_prepareNodeForExport)
@@ -75,8 +87,12 @@ export class GltfExportManager {
75
87
 
76
88
  // reset transformation of all "TransformNodes", which couldn't be handled by the geometry baking algorithm
77
89
  // it's important that this is done AFTER all geometries have been baked
78
- this.viewer.scene.transformNodes
79
- .filter(node => !!node.metadata?.[GltfExportManager._METADATA_PROPS.exportNode])
90
+ [...this.viewer.scene.transformNodes, ...this.viewer.scene.meshes]
91
+ .filter(
92
+ node =>
93
+ !!node.metadata?.[GltfExportManager._METADATA_PROPS.exportNode] &&
94
+ node.name !== GltfExportManager._EXPORT_ROOT_NAME
95
+ )
80
96
  .forEach(node => resetTransformation(node as TransformNode));
81
97
  }
82
98
 
@@ -89,6 +105,8 @@ export class GltfExportManager {
89
105
  this.viewer.scene.materials
90
106
  .filter(mat => !!mat.metadata?.[GltfExportManager._METADATA_PROPS.deleteAfterExport])
91
107
  .forEach(material => material.dispose(false, false));
108
+
109
+ this.viewer.resumeRendering();
92
110
  }
93
111
 
94
112
  protected _gltfExportOptions(): IExportOptions {
@@ -96,18 +114,10 @@ export class GltfExportManager {
96
114
  shouldExportNode: function (node: BjsNode) {
97
115
  return !!node.metadata?.[GltfExportManager._METADATA_PROPS.exportNode];
98
116
  },
99
- // keep root node(s)
100
- // this seems to be important due to the geometry baking and transformation resetting stuff
101
- // => root node would have no transformation anymore, which seems to be problematic for the import
102
- removeNoopRootNodes: false,
103
117
  };
104
118
  }
105
119
 
106
- protected _prepareNodeForExport(
107
- node: BjsNode,
108
- clonedParent: Nullable<TransformNode>,
109
- excluded?: ExcludedGeometryList
110
- ) {
120
+ protected _prepareNodeForExport(node: BjsNode, clonedParent: TransformNode, excluded?: ExcludedGeometryList) {
111
121
  if (!this._shouldExportNode(node, excluded)) {
112
122
  return;
113
123
  }
@@ -176,12 +186,12 @@ export class GltfExportManager {
176
186
  /**
177
187
  * Create an export-friendly replacement material for a material using refraction.
178
188
  */
179
- protected _createRefractionMaterialReplacement(material: PBRMaterial): PBRMaterial {
189
+ protected _createRefractionMaterialReplacement(material: PBRMaterial) {
180
190
  const newName = `${material.name}_clone`;
181
- // change material according to https://www.notion.so/combeenation/Glas-materials-don-t-look-glasy-after-export-d5fda2c6515e4420a8772744d3e6b460
182
- const clonedMaterial = material.clone(newName); // clone material
191
+
192
+ const clonedMaterial = material.clone(newName);
183
193
  clonedMaterial.refractionTexture = null;
184
- clonedMaterial.metallicReflectanceTexture = null; // is this the correct one for metallic roughness?
194
+ clonedMaterial.metallicReflectanceTexture = null;
185
195
  clonedMaterial.alpha = 0.7;
186
196
  clonedMaterial.albedoColor = new Color3(0.3, 0.3, 0.3);
187
197
  clonedMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
@@ -190,7 +200,5 @@ export class GltfExportManager {
190
200
 
191
201
  injectMetadata(material, { [GltfExportManager._METADATA_PROPS.exchangeMaterialWith]: newName });
192
202
  injectMetadata(clonedMaterial, { [GltfExportManager._METADATA_PROPS.deleteAfterExport]: true });
193
-
194
- return clonedMaterial;
195
203
  }
196
204
  }