@combeenation/3d-viewer 9.0.2-alpha2 → 9.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/manager/gltfExportManager.d.ts +11 -8
- package/dist/lib-cjs/api/manager/gltfExportManager.js +23 -21
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +5 -0
- 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/manager/gltfExportManager.ts +35 -21
- package/src/api/util/globalTypes.ts +5 -0
package/package.json
CHANGED
|
@@ -34,17 +34,22 @@ export class GltfExportManager {
|
|
|
34
34
|
* Exports selected nodes to a file.
|
|
35
35
|
* @param filename optional name of the exported .GLB file.
|
|
36
36
|
* @param exportOptions export options to be merged with default options.\
|
|
37
|
-
* `exportOptions.exchangeRefractionMaterials`
|
|
37
|
+
* `exportOptions.exchangeRefractionMaterials` and `exportOptions.limitTextureSize`
|
|
38
|
+
* default to `true` if not given.
|
|
38
39
|
* @param optimizeForAR adjusts the exported GLB so that known AR issues get fixed automatically
|
|
39
40
|
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
40
41
|
*/
|
|
41
42
|
public async exportGlb(
|
|
42
43
|
filename = 'glb-export.glb',
|
|
43
|
-
{ exchangeRefractionMaterials = true, ...exportOptions }: IExportOptionsExtended = {},
|
|
44
|
+
{ exchangeRefractionMaterials = true, limitTextureSize = true, ...exportOptions }: IExportOptionsExtended = {},
|
|
44
45
|
optimizeForAR: boolean = false,
|
|
45
46
|
excluded?: ExcludedGeometryList
|
|
46
47
|
): Promise<File | undefined> {
|
|
47
|
-
const { scene, sceneCopied } = await this.exportPreProcess(
|
|
48
|
+
const { scene, sceneCopied } = await this.exportPreProcess(
|
|
49
|
+
exchangeRefractionMaterials,
|
|
50
|
+
limitTextureSize,
|
|
51
|
+
optimizeForAR
|
|
52
|
+
);
|
|
48
53
|
const glbData = await GLTF2Export.GLBAsync(scene, 'dummy', this.gltfExportOptions(exportOptions, excluded));
|
|
49
54
|
this.exportPostProcess(scene, sceneCopied);
|
|
50
55
|
|
|
@@ -65,17 +70,22 @@ export class GltfExportManager {
|
|
|
65
70
|
* Exports selected nodes to GLTF. This may result in more than one file, since textures are exported separately.
|
|
66
71
|
* @param filename name of the main (text-based) .GLTF file referring to separate texture files.
|
|
67
72
|
* @param exportOptions export options to be merged with default options.\
|
|
68
|
-
* `exportOptions.exchangeRefractionMaterials`
|
|
73
|
+
* `exportOptions.exchangeRefractionMaterials` and `exportOptions.limitTextureSize`
|
|
74
|
+
* default to `true` if not given.
|
|
69
75
|
* @param optimizeForAR adjusts the exported GLB so that known AR issues get fixed automatically
|
|
70
76
|
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
71
77
|
*/
|
|
72
78
|
public async exportGltfToFile(
|
|
73
79
|
filename: string,
|
|
74
|
-
{ exchangeRefractionMaterials = true, ...exportOptions }: IExportOptionsExtended = {},
|
|
80
|
+
{ exchangeRefractionMaterials = true, limitTextureSize = true, ...exportOptions }: IExportOptionsExtended = {},
|
|
75
81
|
optimizeForAR: boolean = false,
|
|
76
82
|
excluded?: ExcludedGeometryList
|
|
77
83
|
) {
|
|
78
|
-
const { scene, sceneCopied } = await this.exportPreProcess(
|
|
84
|
+
const { scene, sceneCopied } = await this.exportPreProcess(
|
|
85
|
+
exchangeRefractionMaterials,
|
|
86
|
+
limitTextureSize,
|
|
87
|
+
optimizeForAR
|
|
88
|
+
);
|
|
79
89
|
const gltf = await GLTF2Export.GLTFAsync(scene, filename, this.gltfExportOptions(exportOptions, excluded));
|
|
80
90
|
gltf.downloadFiles();
|
|
81
91
|
this.exportPostProcess(scene, sceneCopied);
|
|
@@ -85,17 +95,22 @@ export class GltfExportManager {
|
|
|
85
95
|
* Exports selected nodes to GLB. This results in one binary file.
|
|
86
96
|
* @param filename name of the .GLB file.
|
|
87
97
|
* @param exportOptions export options to be merged with default options.\
|
|
88
|
-
* `exportOptions.exchangeRefractionMaterials`
|
|
98
|
+
* `exportOptions.exchangeRefractionMaterials` and `exportOptions.limitTextureSize`
|
|
99
|
+
* default to `true` if not given.
|
|
89
100
|
* @param optimizeForAR adjusts the exported GLB so that known AR issues get fixed automatically
|
|
90
101
|
* @param excluded optional list of geometry (meshes, elements, variants, variantInstances) to be excluded from export
|
|
91
102
|
*/
|
|
92
103
|
public async exportGlbToFile(
|
|
93
104
|
filename: string,
|
|
94
|
-
{ exchangeRefractionMaterials = true, ...exportOptions }: IExportOptionsExtended = {},
|
|
105
|
+
{ exchangeRefractionMaterials = true, limitTextureSize = true, ...exportOptions }: IExportOptionsExtended = {},
|
|
95
106
|
optimizeForAR: boolean = false,
|
|
96
107
|
excluded?: ExcludedGeometryList
|
|
97
108
|
) {
|
|
98
|
-
const { scene, sceneCopied } = await this.exportPreProcess(
|
|
109
|
+
const { scene, sceneCopied } = await this.exportPreProcess(
|
|
110
|
+
exchangeRefractionMaterials,
|
|
111
|
+
limitTextureSize,
|
|
112
|
+
optimizeForAR
|
|
113
|
+
);
|
|
99
114
|
const glb = await GLTF2Export.GLBAsync(scene, filename, this.gltfExportOptions(exportOptions, excluded));
|
|
100
115
|
glb.downloadFiles();
|
|
101
116
|
this.exportPostProcess(scene, sceneCopied);
|
|
@@ -130,15 +145,16 @@ export class GltfExportManager {
|
|
|
130
145
|
*/
|
|
131
146
|
protected async exportPreProcess(
|
|
132
147
|
exchangeRefractionMaterials: boolean,
|
|
148
|
+
limitTextureSize: boolean,
|
|
133
149
|
optimizeForAR: boolean
|
|
134
150
|
): Promise<{ scene: Scene; sceneCopied: boolean }> {
|
|
135
|
-
if (!exchangeRefractionMaterials && !optimizeForAR) {
|
|
151
|
+
if (!exchangeRefractionMaterials && !optimizeForAR && !limitTextureSize) {
|
|
136
152
|
// no need to copy the scene if no adjustments have to be made
|
|
137
153
|
return { scene: this.viewer.scene, sceneCopied: false };
|
|
138
154
|
}
|
|
139
155
|
|
|
140
156
|
// copy the scene for the GLB export improvements, so that the original viewer scene remains untouched
|
|
141
|
-
const copiedScene = await this.copyViewerScene();
|
|
157
|
+
const copiedScene = await this.copyViewerScene(limitTextureSize);
|
|
142
158
|
|
|
143
159
|
if (exchangeRefractionMaterials) {
|
|
144
160
|
this.exchangeRefractionMaterials(copiedScene);
|
|
@@ -156,7 +172,7 @@ export class GltfExportManager {
|
|
|
156
172
|
* Create a copy of the viewer scene, which can be further processed and optimized for the GLB export.
|
|
157
173
|
* There is no "scene.clone" function, therefore the scene is serialized and loaded again to achieve this result.
|
|
158
174
|
*/
|
|
159
|
-
protected async copyViewerScene(): Promise<Scene> {
|
|
175
|
+
protected async copyViewerScene(limitTextureSize: boolean): Promise<Scene> {
|
|
160
176
|
// required by the scene serializer
|
|
161
177
|
await import(/* webpackChunkName: "physicsenginecomponent" */ '@babylonjs/core/Physics/physicsEngineComponent');
|
|
162
178
|
|
|
@@ -173,11 +189,14 @@ export class GltfExportManager {
|
|
|
173
189
|
this.restoreMetadataOfAllNodes(metadataArr);
|
|
174
190
|
|
|
175
191
|
// load the scene into an invisible "dummy" canvas
|
|
176
|
-
const
|
|
177
|
-
const engine = new Engine(
|
|
192
|
+
const dummyCanvas = document.createElement('canvas');
|
|
193
|
+
const engine = new Engine(dummyCanvas);
|
|
178
194
|
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
if (limitTextureSize) {
|
|
196
|
+
// according to some tests iOS devices break when exporting a scene with textures above 1024
|
|
197
|
+
// this only affects the scene clone for the export
|
|
198
|
+
engine.getCaps().maxTextureSize = 1024;
|
|
199
|
+
}
|
|
181
200
|
|
|
182
201
|
SceneLoader.ShowLoadingScreen = false;
|
|
183
202
|
const newScene = await SceneLoader.LoadAsync('', 'data:' + JSON.stringify(serializedScene), engine);
|
|
@@ -185,11 +204,6 @@ export class GltfExportManager {
|
|
|
185
204
|
// events
|
|
186
205
|
newScene.doNotHandleCursors = true;
|
|
187
206
|
|
|
188
|
-
console.log('old scene');
|
|
189
|
-
this.viewer.scene.textures.map(texture => console.log(texture._texture?.width));
|
|
190
|
-
console.log('new scene');
|
|
191
|
-
newScene.textures.map(texture => console.log(texture._texture?.width));
|
|
192
|
-
|
|
193
207
|
return newScene;
|
|
194
208
|
}
|
|
195
209
|
|
|
@@ -480,6 +480,11 @@ interface IExportOptionsExtended extends IExportOptions {
|
|
|
480
480
|
* mode settings.
|
|
481
481
|
*/
|
|
482
482
|
exchangeRefractionMaterials?: boolean;
|
|
483
|
+
/**
|
|
484
|
+
* iOS devices crash when exporting textures which are larger than 1024.\
|
|
485
|
+
* If this flag is set, then all textures will be limited to a maximum texture size of 1024.
|
|
486
|
+
*/
|
|
487
|
+
limitTextureSize?: boolean;
|
|
483
488
|
}
|
|
484
489
|
|
|
485
490
|
type SpecGenerationData = {
|