-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1003.07365fe51405362eed1f.bundle.js
More file actions
258 lines (258 loc) · 12.3 KB
/
1003.07365fe51405362eed1f.bundle.js
File metadata and controls
258 lines (258 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
"use strict";
(self.webpackChunkmetapress = self.webpackChunkmetapress || []).push([
[1003], {
91003: (e, t, i) => {
i.r(t), i.d(t, {
default: () => l
});
var s = i(69584),
r = i(48830),
a = i(62977),
n = i(84362),
o = i(25108);
class l {
id = "core.misc.tools.optimize_glb_imports";
name = "Optimize GLB Imports";
description = "Allows the user to optimize their .glb files for better performance.";
requires = ["entities"];
texture = 2048;
strength = 0;
error = 8e-4;
async optimizeGLTF(e, t, i, l) {
this.texture = i, this.strength = t, this.error = l, this.requireExtensionsSet = new Set;
const c = {
KHR_materials_ior: n.S8,
KHR_materials_emissive_strength: n.SE,
KHR_draco_mesh_compression: n.r7,
EXT_mesh_gpu_instancing: n.Fb,
KHR_lights_punctual: n.bO,
KHR_texture_transform: n.c7,
KHR_texture_basisu: n.S3,
KHR_mesh_quantization: n.to,
KHR_materials_unlit: n.oN,
KHR_materials_clearcoat: n.X4,
KHR_materials_sheen: n.V$,
KHR_materials_specular: n.UW,
KHR_materials_transmission: n.y1,
KHR_materials_volume: n.Wh,
KHR_materials_anisotropy: n.HN,
KHR_materials_pbrSpecularGlossiness: n.z4,
KHR_materials_variants: n.vC,
KHR_xmp_json_ld: n.FC,
KHR_materials_iridescence: n.Gq,
EXT_texture_webp: n.oh,
EXT_texture_avif: n.t4,
EXT_meshopt_compression: n.XD
},
g = new m(s.Yd.Verbosity.WARN);
let p = (new s.AH).setLogger(g);
try {
let i, s = await this.readFileAsUint8Array(e);
try {
await p.readBinary(s)
} catch (l) {
if (o.log("Failed to read binary: ", l), l.message.includes("Missing required extension")) {
const e = g.extractExtensionName(l.message);
e && g.missingExtensions.add(e)
}({
io: p,
document: i
} = await this.SetupMissingExtensions(g, c, p, i, s))
}
i = await p.readBinary(s), ({
io: p,
document: i
} = await this.SetupMissingExtensions(g, c, p, i, s));
try {
await i.transform((0, r.LV)(), (0, r.Qs)())
} catch (e) {
o.log("Error during transformation, trying fallback approach:", e), await i.transform((0, r.Qs)())
}
try {
await this.processTextures(i, this.texture)
} catch (l) {
o.log("Failed to process textures: ", l)
}
await i.transform((0, r.xH)(), (0, r.v_)(), (0, r.sr)(), (0, r.uC)({
tolerance: 5e-7
}), (0, r.og)({
simplifier: a.BC,
ratio: t,
error: l
}), (0, r.VJ)());
const n = await p.writeBinary(i),
m = new Blob([n], {
type: "model/gltf-binary"
});
return new File([m], e.name, {
type: m.type,
lastModified: (new Date).getTime()
})
} catch (l) {
o.error("Failed to optimize: ", l, "Returning original file")
}
}
async SetupMissingExtensions(e, t, i, r, a) {
const n = e.getMissingExtensions(),
o = [];
return n.forEach((e => {
t[e] && o.push(t[e])
})), o.length > 0 && (i = (new s.AH).setLogger(e).registerExtensions(o), r = await i.readBinary(a)), {
io: i,
document: r
}
}
backfaceCulling(e) {
return t => {
for (const i of t.getRoot().listMaterials()) i.setDoubleSided(!e.cull)
}
}
readFileAsUint8Array(e) {
return new Promise(((t, i) => {
const s = new FileReader;
s.onload = () => {
const e = s.result,
i = new Uint8Array(e);
t(i)
}, s.onerror = i, s.readAsArrayBuffer(e)
}))
}
async processTextures(e, t) {
const i = e.getRoot();
for (const e of i.listTextures()) {
let i = e.getImage();
if (i) try {
let s = new Blob([i], {
type: e.getMimeType()
}),
r = await this.resizeImageToOriginalFormat(s, t, t, e.getMimeType()),
a = await this.convertAndResizeImage(s, t, t),
n = await this.getSmallestBlob([s, r, a]);
if (n === s) continue;
const o = await this.blobToUint8Array(n);
e.setImage(o), n === a && e.setMimeType("image/webp")
} catch (e) {
o.error("Failed to convert and resize image: ", e)
}
}
}
async getSmallestBlob(e) {
let t = 1 / 0,
i = null;
for (const s of e) {
const e = s.size;
e >= t || (t = e, i = s)
}
return i
}
async blobToUint8Array(e) {
const t = await e.arrayBuffer();
return new Uint8Array(t)
}
async convertAndResizeImage(e, t, i) {
return new Promise(((s, r) => {
const a = new Image;
a.onload = () => {
const e = document.createElement("canvas");
e.width = t, e.height = i, e.getContext("2d").drawImage(a, 0, 0, t, i), e.toBlob((e => s(e)), "image/webp", 1)
}, a.onerror = r, a.src = URL.createObjectURL(new Blob([e]))
}))
}
async resizeImageToOriginalFormat(e, t, i, s) {
return new Promise(((r, a) => {
const n = new Image;
n.onload = () => {
const e = document.createElement("canvas");
e.width = t, e.height = i, e.getContext("2d").drawImage(n, 0, 0, t, i), e.toBlob((e => r(e)), s, 1)
}, n.onerror = a, n.src = URL.createObjectURL(new Blob([e]))
}))
}
$upload_getFileOptimizationStages = () => [{
id: "optimize_glb_imports.optimize.glb",
name: "Optimize GLB Model",
filter: e => e.name.toLowerCase().endsWith(".glb"),
settings: [{
type: "header",
id: "optimize.glb.header",
name: "3D Model Optimization"
}, {
type: "description",
id: "optimize.glb.decription",
name: "Optimize your 3D model for better performance."
}, {
type: "select",
id: "optimize.glb.texture",
name: "Texture Size",
placeholder: "2048",
values: [512, 1024, 2048, 4096],
labels: ["small(512)", "Medium(1024)", "Big(2048)", "Very Big(4096)"],
value: 2048,
help: "Select the maximum size of the textures in the model."
}, {
type: "select",
id: "optimize.glb.strength",
name: "Strength",
placeholder: "0.0",
values: [0, 5e-9, 5e-5, .005],
labels: ["None", "Low", "Medium", "High"],
value: 0,
help: "Select the strength of mesh the optimization"
}],
execute: async (e, t) => {
let i = e.settings.filter((e => "optimize.glb.texture" === e.id))[0].value,
s = e.settings.filter((e => "optimize.glb.strength" === e.id))[0].value;
return await this.optimizeGLTF(t, 0, i, s)
}
}, {
id: "optimize_glb_imports.optimize.img",
name: "Optimize Image",
filter: e => e.name.toLowerCase().endsWith(".png") || e.name.toLowerCase().endsWith(".jpg") || e.name.toLowerCase().endsWith(".jpeg") || e.name.toLowerCase().endsWith(".webp"),
settings: [{
type: "header",
id: "optimize.img.header",
name: "Image Optimization"
}, {
type: "description",
id: "optimize.img.decription",
name: "Optimize your image for better performance."
}, {
type: "select",
id: "optimize.img.size",
name: "Image Size",
placeholder: "2048",
values: [512, 1024, 2048, 4096],
labels: ["small(512)", "Medium(1024)", "Big(2048)", "Very Big(4096)"],
value: 2048,
help: "Select the maximum size of the image."
}],
execute: async (e, t) => {
let i = e.settings.filter((e => "optimize.img.size" === e.id))[0].value,
s = t.type,
r = await this.resizeImageToOriginalFormat(t, i, i, s);
return o.log("Image", r, t), new File([r], t.name, {
type: r.type,
lastModified: (new Date).getTime()
})
}
}]
}
class m extends s.Yd {
constructor(e) {
super(e), this.missingExtensions = new Set
}
warn(e) {
if (!e.includes("Missing optional extension")) return;
const t = this.extractExtensionName(e);
this.missingExtensions.add(t)
}
extractExtensionName(e) {
const t = e.match(/"([^"]+)"/);
return t ? t[1] : null
}
getMissingExtensions() {
return this.missingExtensions
}
}
}
}
]);