-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5414.4031eef599a696f81f7c.bundle.js
More file actions
636 lines (636 loc) · 41.3 KB
/
5414.4031eef599a696f81f7c.bundle.js
File metadata and controls
636 lines (636 loc) · 41.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
"use strict";
(self.webpackChunkmetapress = self.webpackChunkmetapress || []).push([
[5414], {
47660: (e, t, i) => {
i.d(t, {
Z: () => r
});
var n = i(6147);
class r extends n.Z {
get settings() {
return [...super.settings, {
type: "file",
id: "url",
name: "Source",
help: "The model to render."
}]
}
modelInfo = {};animationClips = [];async onLoad() {
let e = await metapress.assets.load("mesh", this.entity.url, !0);
this.object = e.scene, this.animationClips = e.animations || [], this.modelInfo = e.userData || {}
}
}
},
6147: (e, t, i) => {
i.d(t, {
Z: () => r
});
var n = i(4028);
class r {
get settings() {
return [{
type: "checkbox",
id: "hidden",
name: "Hidden",
help: "If enabled, the object will not be visible."
}]
}
static showBoundingBoxes = !1;
static wireframeMode = !1;
_lastEntityWireframe = void 0;
container = new THREE.Object3D;
object = null;
entity = {};
hideLock = new n.Z;
hasLoaded = !1;
wireframeState = {};
async onLoad() {}
afterLoad() {
if (!this.object?.isObject3D) throw new Error("The renderer must create an Object3D instance when subclassing Object3DRenderer.");
this.container.entityRenderer = this, this.container.add(this.object), metapress.renderer.scene.add(this.container), this.applyTransforms(), this._lastUrl = this.entity.url, this._lastEntityWireframe = this.entity.wireframe
}
onUnload() {}
afterUnload() {
this.container?.removeFromParent(), this.container = null, this.applyParent()
}
onEntityUpdated() {
this._lastUrl != this.entity.url && metapress.entities.reload(this.entity.id);
for (let e of metapress.entities.renderers) e != this && e.container?.isObject3D && e.applyParent && e.applyParent(!0);
this.entity.wireframe != this._lastEntityWireframe && (this._lastEntityWireframe = this.entity.wireframe, this.container.traverse((e => {
e.isMesh && e.material && (e.material.wireframe = this.entity.wireframe ?? !1, this.wireframeState[e.uuid] = e.material.wireframe)
}))), this.onRender()
}
onRender() {
this._lastTransformUpdate != this.entity.lastModified && (this._lastTransformUpdate = this.entity.lastModified, this.applyTransforms()), this.applyHideLock(), this.applyBoundingBox(), this.applyWireframe()
}
applyTransforms() {
this.object && (this.entity.x = parseFloat(this.entity.x) || 0, this.entity.y = parseFloat(this.entity.y) || 0, this.entity.z = parseFloat(this.entity.z) || 0, this.entity.scaleX = parseFloat(this.entity.scaleX) || 1, this.entity.scaleY = parseFloat(this.entity.scaleY) || 1, this.entity.scaleZ = parseFloat(this.entity.scaleZ) || 1, this.entity.quatX = parseFloat(this.entity.quatX) || 0, this.entity.quatY = parseFloat(this.entity.quatY) || 0, this.entity.quatZ = parseFloat(this.entity.quatZ) || 0, this.entity.quatW = parseFloat(this.entity.quatW) || 0, this.entity.extra_offset_x = parseFloat(this.entity.extra_offset_x) || 0, this.entity.extra_offset_y = parseFloat(this.entity.extra_offset_y) || 0, this.entity.extra_offset_z = parseFloat(this.entity.extra_offset_z) || 0, this.entity.extra_scale_x = parseFloat(this.entity.extra_scale_x) || 1, this.entity.extra_scale_y = parseFloat(this.entity.extra_scale_y) || 1, this.entity.extra_scale_z = parseFloat(this.entity.extra_scale_z) || 1, this.entity.extra_rotation_x = parseFloat(this.entity.extra_rotation_x) || 0, this.entity.extra_rotation_y = parseFloat(this.entity.extra_rotation_y) || 0, this.entity.extra_rotation_z = parseFloat(this.entity.extra_rotation_z) || 0, this.container.position.set(this.entity.x, this.entity.y, this.entity.z), this.container.scale.set(this.entity.scaleX, this.entity.scaleY, this.entity.scaleZ), this.entity.quatX || this.entity.quatY || this.entity.quatZ || this.entity.quatW ? this.container.quaternion.set(this.entity.quatX, this.entity.quatY, this.entity.quatZ, this.entity.quatW) : this.container.quaternion.set(0, 0, 0, 1), this.object.position.set(this.entity.extra_offset_x, this.entity.extra_offset_y, this.entity.extra_offset_z), this.object.scale.set(this.entity.extra_scale_x, this.entity.extra_scale_y, this.entity.extra_scale_z), this.object.rotation.set(this.entity.extra_rotation_x, this.entity.extra_rotation_y, this.entity.extra_rotation_z))
}
applyHideLock() {
let e = !this.entity.hidden && !this.hideLock.isAcquired;
this.container.visible && !e ? this.container.visible = !1 : !this.container.visible && e && (this.container.visible = !0)
}
applyBoundingBox() {
this.boundingBoxHelper?.update();
let e = r.showBoundingBoxes && this.container.visible;
!e && this.boundingBoxHelper ? (this.boundingBoxHelper.removeFromParent(), this.boundingBoxHelper.dispose(), this.boundingBoxHelper = null) : e && !this.boundingBoxHelper && (this.boundingBoxHelper = new THREE.BoxHelper(this.container, 16777215), metapress.renderer.scene.add(this.boundingBoxHelper))
}
applyWireframe() {
this._lastWireframeMode != r.wireframeMode && (this._lastWireframeMode = r.wireframeMode, this.container.traverse((e => {
e.isMesh && e.material && (this.hasLoaded || (this.wireframeState[e.uuid] = !!e.material.wireframe), e.material.wireframe = !!r.wireframeMode || (this.wireframeState[e.uuid] ?? !1))
})), this.hasLoaded = !0)
}
applyParent(e) {
if (!e && !this.parentHideLock && void 0 !== this._lastParent && this._lastParent != this.entity.parent) return;
if (this._lastParent = this.entity.parent || "", !e)
for (let e of metapress.entities.renderers) e != this && e.container?.isObject3D && e.applyParent && e.applyParent(!0);
if (!this.entity.parent) return this.parentHideLock?.(), this.parentHideLock = null, void(this.container && this.container.parent != metapress.renderer.scene && (this.container.removeFromParent(), metapress.renderer.scene.add(this.container)));
let t = metapress.entities.getRenderer(this.entity.parent);
t?.object?.isObject3D ? (this.parentHideLock?.(), this.parentHideLock = null, this.container.parent != t.container && (this.container.removeFromParent(), t.container.add(this.container))) : this.parentHideLock || (this.parentHideLock = this.hideLock.acquire())
}
}
},
65414: (e, t, i) => {
i.r(t), i.d(t, {
default: () => f
});
class n {
name = "Face movement direction";
hidden = !0;
entity = null;
renderer = null;
isOwner = !1;
onLoad() {
if (!this.renderer.object?.isObject3D) throw new Error(`Not supported on entity of type '${this.entity.type}'`);
this.currentAngle = this.renderer.container.rotation.y, this.targetAngle = this.currentAngle, this.oldPosition.copy(this.renderer.container.position), this.isOwner = !this.entity.owner || this.entity.owner == metapress.instanceID
}
oldPosition = new THREE.Vector3;
direction = new THREE.Vector3;
v3a = new THREE.Vector3;
v3b = new THREE.Vector3;
quatA = new THREE.Quaternion;
beforeRender() {
if (this.isOwner) {
if (Math.abs(this.oldPosition.x - this.renderer.container.position.x) > .001 || Math.abs(this.oldPosition.z - this.renderer.container.position.z) > .001) {
this.v3a.copy(this.renderer.container.position).sub(this.oldPosition).normalize(), this.targetAngle = -Math.atan2(this.v3a.z, this.v3a.x) + Math.PI / 2;
let e = 2 * Math.PI;
for (; Math.abs(this.targetAngle - this.currentAngle) > e / 2;) this.targetAngle += this.targetAngle > this.currentAngle ? -e : e;
this.oldPosition.copy(this.renderer.container.position)
}
Math.abs(this.currentAngle - this.targetAngle) > 1e-4 && (this.currentAngle = THREE.MathUtils.damp(this.currentAngle, this.targetAngle, 5, metapress.renderer.delta), this.quatA.setFromAxisAngle(THREE.Object3D.DEFAULT_UP, this.currentAngle), this.entity.quatX = this.quatA.x, this.entity.quatY = this.quatA.y, this.entity.quatZ = this.quatA.z, this.entity.quatW = this.quatA.w, this.entity.lastModified = Date.now())
}
}
}
var r = i(25108);
class a {
name = "Material";
description = "Modifies object material.";
icon = i(5143);
provides = ["material"];
get settings() {
let e = [{
type: "file",
id: "url",
name: "Image",
allowClear: !0,
help: "The image to render.",
onRemove: () => this.removeImage(!0)
}, {
type: "select",
id: "transparencyMode",
name: "Transparency",
values: ["", "alpha", "clip"],
labels: ["None", "Alpha Blend", "Alpha Clip"],
help: "In Alpha Blend mode, full transparency is supported but the render order is changed, which may cause visual glitches. In Alpha Clip mode, only on/off transparency is supported but the render order is unchanged."
}, {
type: "select",
id: "shaderMode",
name: "Shading Type",
values: ["standard", "basic"],
labels: ["Standard (Default)", "Basic"],
help: "Shading type to be used on this object."
}];
return this.entity?.url && "" !== this.entity?.url && (e = e.concat([{
type: "number",
id: "tileX",
name: "Repeat X",
help: "Amount of times to repeat the image on the X axis."
}, {
type: "number",
id: "tileY",
name: "Repeat Y",
help: "Amount of times to repeat the image on the Y axis."
}, {
type: "checkbox",
id: "mirrorX",
name: "Mirrored Repeat X",
help: "Mirror the repeats of the image on the X axis."
}, {
type: "checkbox",
id: "mirrorY",
name: "Mirrored Repeat Y",
help: "Mirror the repeats of the image on the Y axis"
}])), e
}
entity = null;
renderer = null;
onLoad() {
if (!this.renderer.object?.isObject3D) throw new Error(`Not supported on entity of type '${this.entity.type}'`);
this.applyChanges(), this.updateMaterial()
}
onEntityEdited() {
this.applyChanges()
}
applyChanges() {
for (let e in this.entity)
if (e.startsWith("replaceMaterial:")) try {
this.applyChangesFor(e)
} catch (e) {
r.warn("[MetaPress > MaterialModifier] Error: ", e)
}
}
applyChangesFor(e) {
let t = e.substring(16),
i = this.renderer.object.getObjectByName(t);
if (!i) throw new Error(`Mesh not found: ${t}`);
let n = this.entity[e];
if (i._materialReplacerLastValue == n) return;
i._materialReplacerLastValue = n;
let r = n,
a = "",
s = r.indexOf(":");
if (-1 != s && (a = n.substring(s + 1).trim(), r = n.substring(0, s).trim()), "color" == r) "basic" == this.entity.shaderMode ? i.material = new THREE.MeshBasicMaterial({
color: a
}) : i.material = new THREE.MeshStandardMaterial({
color: a
});
else {
if ("image" != r) throw new Error(`Unknown material type '${r}'`);
{
let e = (new THREE.TextureLoader).load(a);
e.flipY = !1, e.colorSpace = THREE.SRGBColorSpace, "basic" == this.entity.shaderMode ? i.material = new THREE.MeshBasicMaterial({
map: e
}) : i.material = new THREE.MeshStandardMaterial({
map: e
})
}
}
}
onEntityUpdated() {
this._lastTransparencyMode == this.entity.transparencyMode && this._lastColor == this.entity.color && this._lastOpacity == this.entity.opacity && this._lastAlphaClip == this.entity.alphaClip && this._lastEntityUrl == this.entity.url && this._lastShaderMode == this.entity.shaderMode && this._lastMirrorX == this.entity.mirrorX && this._lastMirrorY == this.entity.mirrorY && this._lastTileX == this.entity.tileX && this._lastTileY == this.entity.tileY || this.updateMaterial()
}
removeImage(e) {
e && metapress.entities.update(this.entity.id, {
url: null
}), this.renderer.object.material.map = null, this.renderer.object.material.color = new THREE.Color(16777215)
}
updateMaterial() {
if (!this.renderer.object) return;
let e = "basic" === this.entity.shaderMode ? THREE.MeshBasicMaterial : THREE.MeshStandardMaterial,
t = this.renderer.object.material.type !== e.name,
i = this.renderer.object.material.map;
this.entity.url && this.entity.url !== this._lastTextureUrl && (i = (new THREE.TextureLoader).load(this.entity.url), i.colorSpace = THREE.SRGBColorSpace, this._lastTextureUrl = this.entity.url), i && (i.wrapS = this.entity.mirrorX ? THREE.MirroredRepeatWrapping : THREE.RepeatWrapping, i.wrapT = this.entity.mirrorY ? THREE.MirroredRepeatWrapping : THREE.RepeatWrapping, i.repeat.set(this.entity.tileX || 1, this.entity.tileY || 1), i.needsUpdate = !0), t || !this.renderer.object.material.map ? this.renderer.object.material = new e({
color: this.entity.color ? new THREE.Color(this.entity.color) : "#FFFFFF",
side: THREE.DoubleSide,
map: i,
transparent: "alpha" === this.entity.transparencyMode,
opacity: this.entity.opacity || 1,
alphaTest: "clip" === this.entity.transparencyMode ? this.entity.alphaClip || .5 : .01
}) : (this.renderer.object.material.map = i, this.renderer.object.material.color.set(this.entity.color ? new THREE.Color(this.entity.color) : "#FFFFFF"), this.renderer.object.material.transparent = "alpha" === this.entity.transparencyMode, this.renderer.object.material.opacity = this.entity.opacity || 1, this.renderer.object.material.alphaTest = "clip" === this.entity.transparencyMode ? this.entity.alphaClip || .5 : .01), this._lastTransparencyMode = this.entity.transparencyMode, this._lastColor = this.entity.color, this._lastOpacity = this.entity.opacity, this._lastAlphaClip = this.entity.alphaClip, this._lastEntityUrl = this.entity.url, this._lastShaderMode = this.entity.shaderMode, this._lastMirrorX = this.entity.mirrorX, this._lastMirrorY = this.entity.mirrorY, this._lastTileX = this.entity.tileX, this._lastTileY = this.entity.tileY
}
}
var s = i(47660),
o = i(6147),
h = i(99477);
class l extends o.Z {
get settings() {
return [...super.settings]
}
async onLoad() {
let e = null;
if ("cube" == this.entity.type) e = new h.BoxGeometry(1, 1, 1);
else if ("plane" == this.entity.type) e = new h.PlaneGeometry(1, 1);
else if ("circle" == this.entity.type) e = new h.CircleGeometry(.5, 32);
else if ("cylinder" == this.entity.type) e = new h.CylinderGeometry(.5, .5, 1, 32);
else {
if ("sphere" != this.entity.type) throw new Error("Unknown shape type: " + this.entity.type);
e = new h.SphereGeometry(.5)
}
let t = null;
t = "basic" == this.entity.shaderMode ? new h.MeshBasicMaterial({
side: h.DoubleSide
}) : new h.MeshStandardMaterial({
side: h.DoubleSide
}), this.object = new h.Mesh(e, t)
}
}
class d {
name = "Transform smoothing";
hidden = !0;
entity = null;
renderer = null;
onLoad() {
if (!this.renderer.object?.isObject3D) throw new Error(`Not supported on entity of type '${this.entity.type}'`);
this.currentPosition = this.renderer.container.position.clone(), this.targetPosition = this.renderer.container.position.clone(), this.currentQuaternion = this.renderer.container.quaternion.clone(), this.targetQuaternion = this.renderer.container.quaternion.clone(), this.isOwner = this.entity.owner == metapress.instanceID
}
beforeRender() {
this.isOwner || (this.preparePosition(), this.prepareOrientation())
}
onRender() {
this.isOwner || (this.smoothPosition(), this.smoothOrientation())
}
preparePosition() {
let e = Date.now();
this.entity.x == this._x && this.entity.y == this._y && this.entity.z == this._z || (this._x = this.entity.x || 0, this._y = this.entity.y || 0, this._z = this.entity.z || 0, this.positionUpdatedAt = e, this.currentPosition.copy(this.renderer.container.position), this.targetPosition.set(this.entity.x || 0, this.entity.y || 0, this.entity.z || 0))
}
smoothPosition() {
let e = Date.now() - this.positionUpdatedAt,
t = THREE.MathUtils.clamp(e / 250, 0, 1);
t >= 1 ? this.renderer.container.position.copy(this.targetPosition) : (this._v3a || (this._v3a = new THREE.Vector3), this._v3a.lerpVectors(this.currentPosition, this.targetPosition, t), this.renderer.container.position.copy(this._v3a))
}
prepareOrientation() {
if (!(this.entity.quatX || this.entity.quatY || this.entity.quatZ || this.entity.quatW)) return;
let e = Date.now();
this.entity.quatX == this._quatX && this.entity.quatY == this._quatY && this.entity.quatZ == this._quatZ && this.entity.quatW == this._quatW || (this._quatX = this.entity.quatX, this._quatY = this.entity.quatY, this._quatZ = this.entity.quatZ, this._quatW = this.entity.quatW, this.quaternionUpdatedAt = e, this.currentQuaternion.copy(this.renderer.container.quaternion), this.targetQuaternion.set(this.entity.quatX || 0, this.entity.quatY || 0, this.entity.quatZ || 0, this.entity.quatW || 0))
}
smoothOrientation() {
if (!(this.entity.quatX || this.entity.quatY || this.entity.quatZ || this.entity.quatW)) return;
let e = Date.now() - this.quaternionUpdatedAt,
t = THREE.MathUtils.clamp(e / 250, 0, 1);
t >= 1 ? this.renderer.container.quaternion.copy(this.targetQuaternion) : (this._quatA || (this._quatA = new THREE.Quaternion), this._quatA.slerpQuaternions(this.currentQuaternion, this.targetQuaternion, t), this.renderer.container.quaternion.copy(this._quatA))
}
}
var c = i(1217),
p = i(20452);
class y extends o.Z {
async onLoad() {
this.object = new h.Group
}
}
class u {
name = "ShaderToy Material";
description = "Modifies object material.";
icon = i(5143);
provides = ["material"];
get settings() {
return [{
type: "description",
name: "Renders a ShaderToy compatible shader as this object's material."
}, {
type: "select",
id: "shadertoy_transparencyMode",
name: "Transparency Mode",
help: "The transparency mode to use.",
values: ["none", "alpha-channel", "brightness"],
labels: ["None", "Alpha Channel", "Color Brightness"]
}, {
type: "textarea",
id: "shadertoy_code",
name: "Shader Code",
help: "Specify the ShaderToy shader code."
}, ...[0, 1, 2, 3].map((e => [{
type: "header",
name: `iChannel${e}`
}, {
type: "select",
id: `shadertoy_iChannel${e}_type`,
name: "Type",
values: ["none", "texture", "framebuffer"],
labels: ["None", "Texture", "Frame Buffer"]
}, "texture" == this.entity?.[`shadertoy_iChannel${e}_type`] ? [{
type: "file",
id: `shadertoy_iChannel${e}_texture`,
name: "Texture File",
help: "The texture file to use."
}] : []])).flat(2)]
}
entity = null;
renderer = null;
async onLoad() {
if (!this.renderer.object?.geometry) throw new Error("Not supported on solid shape entities, eg. cube, sphere, plane etc.");
await this.onEntityUpdated()
}
async onEntityUpdated() {
metapress.entities.didSettingsChange(this) && await this.updateMaterial()
}
async updateMaterial() {
let e = {},
t = [];
for (let i = 0; i < 4; i++) {
let n = this.createChannel(i, t);
n && (e[`iChannel${i}`] = {
value: n
})
}
this.renderer.object.material = new m({
shader: this.entity.shadertoy_code,
transparencyMode: this.entity.shadertoy_transparencyMode,
uniforms: e,
onBeforeRender: (e, i, n, r, a, s) => {
t.forEach((t => t(e, i, n, r, a, s)))
}
})
}
createChannel(e, t) {
return "texture" == this.entity[`shadertoy_iChannel${e}_type`] ? this.createChannelTexture(e) : "framebuffer" == this.entity[`shadertoy_iChannel${e}_type`] ? this.createChannelFramebuffer(e, t) : void 0
}
createChannelTexture(e) {
let t = this.entity[`shadertoy_iChannel${e}_texture`];
if (t) return (new h.TextureLoader).load(t)
}
createChannelFramebuffer(e, t) {
let i = new h.Vector2;
metapress.renderer.glrenderer.getSize(i);
let n = new h.FramebufferTexture(i.x, i.y);
n.type = h.HalfFloatType;
let r = new h.Vector2(0, 0);
return t.push(((e, t, i, a, s, o) => {
e.copyFramebufferToTexture(r, n, 0)
})), n
}
$renderer_onResize() {
this.updateMaterial()
}
}
class m extends h.ShaderMaterial {
constructor(e) {
let t = {
...e
};
delete t.shader, delete t.transparencyMode, delete t.onBeforeRender, /#define\s+METAPRESS_DEPTH_WRITE_DISABLED/.test(e.shader) && (e.depthWrite = !1), super({
side: h.DoubleSide,
...t,
transparent: "alpha-channel" == e.transparencyMode || "brightness" == e.transparencyMode,
defines: {
...e.defines,
TRANSPARENCY_MODE_ALPHA_CHANNEL: "alpha-channel" == e.transparencyMode ? 1 : 0,
TRANSPARENCY_MODE_BRIGHTNESS: "brightness" == e.transparencyMode ? 1 : 0
},
uniforms: {
...e.uniforms,
iTime: {
value: 0
},
iTimeDelta: {
value: 0
},
iTimeGlobal: {
value: 0
},
iFrame: {
value: 0
},
iResolution: {
value: new h.Vector2(1024, 1024)
},
iScreenResolution: {
value: new h.Vector2(1024, 1024)
},
iMouse: {
value: new h.Vector4
},
iDiffuse: {
value: null
},
iDepth: {
value: null
}
},
vertexShader: `\n \n // THREE.js's shader code\n #include <common>\n #include <fog_pars_vertex>\n \n // Uniforms we add automatically\n uniform vec2 iResolution;\n uniform vec2 iScreenResolution;\n uniform float iTime;\n uniform float iTimeDelta;\n uniform float iTimeGlobal;\n uniform int iFrame;\n uniform vec4 iMouse;\n ${e.uniforms?.iChannel0?"uniform sampler2D iChannel0;":""}\n ${e.uniforms?.iChannel1?"uniform sampler2D iChannel1;":""}\n ${e.uniforms?.iChannel2?"uniform sampler2D iChannel2;":""}\n ${e.uniforms?.iChannel3?"uniform sampler2D iChannel3;":""}\n \n // Stuff to pass to the fragment shader\n varying vec3 vNormal;\n varying vec2 vUv;\n varying vec3 vPosition;\n varying vec4 vWorldPosition;\n varying vec3 vCameraPosition;\n\n // Main code\n void main() {\n\n // Pass values to fragment shader\n vNormal = normal;\n vUv = uv;\n vPosition = position;\n vWorldPosition = modelMatrix * vec4(position, 1.0);\n vCameraPosition = cameraPosition;\n\n // THREE.js code\n #include <begin_vertex>\n #include <project_vertex>\n #include <fog_vertex>\n\n }\n\n `,
fragmentShader: `\n\n // THREE.js's shader code\n #include <common>\n #include <fog_pars_fragment>\n #include <packing>\n \n // Uniforms we add automatically\n uniform vec2 iResolution;\n uniform vec2 iScreenResolution;\n uniform float iTime;\n uniform float iTimeDelta;\n uniform float iTimeGlobal;\n uniform int iFrame;\n uniform vec4 iMouse;\n ${e.uniforms?.iChannel0?"uniform sampler2D iChannel0;":""}\n ${e.uniforms?.iChannel1?"uniform sampler2D iChannel1;":""}\n ${e.uniforms?.iChannel2?"uniform sampler2D iChannel2;":""}\n ${e.uniforms?.iChannel3?"uniform sampler2D iChannel3;":""}\n \n // Stuff we received from the vertex shader\n varying vec3 vNormal;\n varying vec2 vUv;\n varying vec3 vPosition;\n varying vec4 vWorldPosition;\n varying vec3 vCameraPosition;\n\n // ShaderToy code provides the mainImage() function\n ${e.shader}\n\n // Main entry point\n void main() {\n\n // Call mainImage() in the provided shader\n mainImage(gl_FragColor, vUv * 1024.0);\n\n // Safety check on the returned values from the shader. Without this it can cause the entire scene to flicker.\n gl_FragColor = clamp(gl_FragColor, 0.0, 999.0);\n\n // Check transparency mode\n #if TRANSPARENCY_MODE_ALPHA_CHANNEL\n\n // In alpha channel mode, use the alpha channel as transparency and discard colors too close to 0 opacity, to help\n // prevent issues with z-fighting in certain situations\n if (gl_FragColor.a < 0.01) \n discard;\n\n #elif TRANSPARENCY_MODE_BRIGHTNESS\n\n // In brightness mode, use the brightness of the color as transparency. Reduce it a bit as well to hide cutoff parts.\n gl_FragColor.a = clamp((gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0, 0.0, 1.0);\n if (gl_FragColor.a < 0.01) \n discard;\n\n #else\n\n // In no transparency mode, set to fully opaque. This should already be the case, but just in case the\n // shader messed with the alpha value we set it back.\n gl_FragColor.a = 1.0;\n\n #endif\n\n // Done, do THREE.js shader code now\n #include <fog_fragment>\n\n }\n \n `
}), this._params = e, this.clock = new h.Clock
}
onBeforeRender(e, t, i, n, r, a) {
this._params.onBeforeRender?.(e, t, i, n, r, a), this.uniforms.iTimeDelta.value = this.clock.getDelta(), this.uniforms.iTime.value = this.clock.elapsedTime, this.uniforms.iTimeGlobal.value = this.clock.elapsedTime, e.getDrawingBufferSize(this.uniforms.iScreenResolution.value), this.uniforms.iDiffuse.value = metapress.renderer.diffuseCopyPass?.texture, this.uniforms.iDepth.value = metapress.renderer.depthCopyPass?.texture, super.onBeforeRender(e, t, i, n, r, a)
}
}
class f extends EventTarget {
id = "core.render.builtin-objects";
name = "Built-in Objects";
description = "Provides a set of built-in objects and modifiers.";
version = "1.0.0";
requires = ["assets", "renderer"];
provides = ["builtinObjects", "render:group", "render:mesh", "render:cube", "render:circle", "render:cylinder", "render:plane", "render:sphere", "modifier:transform-smoothing", "modifier:materials", "modifier:face-movement-direction", "modifier:shadertoy"];
Object3DRenderer = o.Z;
createRenderer(e) {
return "mesh" == e ? new s.Z : "group" == e ? new y : new l
}
createModifier(e) {
return "transform-smoothing" == e ? new d : "materials" == e ? new a : "face-movement-direction" == e ? new n : "shadertoy" == e ? new u : void 0
}
async $prepareEntityForFile(e) {
if ([".glb", ".fbx"].find((t => e.name.toLowerCase().endsWith(t)))) return {
type: "mesh",
url: "$URL"
};
if ([".png", ".jpg", ".jpeg", ".gif", ".webp"].find((t => e.name.toLowerCase().endsWith(t)))) {
let t = await new Promise(((t, i) => {
let n = new Image;
n.src = URL.createObjectURL(e), n.onload = () => t(n), n.onerror = () => i(new Error("unable to load image."))
})),
i = document.createElement("canvas");
i.width = 32, i.height = 32;
let n = i.getContext("2d");
n.drawImage(t, 0, 0, 32, 32);
let r = n.getImageData(0, 0, 32, 32),
a = !1;
for (let e = 0; e < r.data.length; e += 4)
if (255 != r.data[e + 3]) {
a = !0;
break
} return {
type: "plane",
scaleX: t.width / t.height,
"modifier:materials": !0,
shaderMode: "basic",
transparencyMode: a ? "alpha" : "",
url: "$URL"
}
}
}
$loadAsset(e) {
return "mesh" == e.type && ".glb" == e.extension ? this.loadGLB(e) : "mesh" == e.type && ".fbx" == e.extension ? this.loadFBX(e) : void 0
}
async loadGLB(e) {
let t = new c.E,
i = await t.loadAsync(e.url);
return i.scene.traverse((e => {
e.isMesh && e.geometry?.attributes?.uv1 && (e.material.emissiveMap?.name.toLowerCase().includes("use_as_lightmap") && (e.material.lightMap = e.material.emissiveMap, e.material.lightMapIntensity = e.material.emissiveIntensity, e.material.emissiveMap = null, e.material.emissiveIntensity = 0), e.material.aoMap && (e.material.aoMap.channel = 1), e.material.lightMap && (e.material.lightMap.channel = 1))
})), i.userData = {
...i.userData,
isGLTF: !0,
isGLB: !0
}, i
}
async loadFBX(e) {
let t = await (new p.y).loadAsync(e.url);
return {
animations: t.animations || [],
cameras: [],
scene: t,
scenes: [t],
userData: {
...t.userData,
isFBX: !0
}
}
}
$getDebugMenuOptions = () => [{
id: "core.objects.boundingBoxes",
section: "Rendering",
name: "Bounding boxes: " + (o.Z.showBoundingBoxes ? "On" : "Off"),
action: () => o.Z.showBoundingBoxes = !o.Z.showBoundingBoxes
}, {
id: "core.objects.wireframe",
section: "Rendering",
name: "Wireframe: " + (o.Z.wireframeMode ? "On" : "Off"),
action: () => o.Z.wireframeMode = !o.Z.wireframeMode
}];
$editor_getAddableEntities = () => [{
id: "metapress.shape.circle",
name: "Add Circle",
icon: i(41598),
section: "builtin",
action: e => metapress.editor.createEntityNearby({
type: "circle",
"modifier:materials": !0
})
}, {
id: "metapress.shape.cylinder",
name: "Add Cylinder",
icon: i(5461),
section: "builtin",
action: e => metapress.editor.createEntityNearby({
type: "cylinder",
"modifier:materials": !0
})
}, {
id: "metapress.shape.cube",
name: "Add Cube",
icon: i(90371),
section: "builtin",
action: e => metapress.editor.createEntityNearby({
type: "cube",
"modifier:materials": !0
})
}, {
id: "metapress.shape.plane",
name: "Add Plane",
icon: i(26192),
section: "builtin",
action: e => metapress.editor.createEntityNearby({
type: "plane",
"modifier:materials": !0
})
}, {
id: "metapress.shape.region",
name: "Add Region",
description: "Regions are 3D volumes that can be used for adjusting the skybox, lighting etc when a user is inside the volume.",
icon: i(26247),
section: "builtin",
action: e => metapress.editor.createEntityNearby({
type: "region",
"modifier:materials": !0
})
}, {
id: "metapress.shape.sphere",
name: "Add Sphere",
icon: i(34949),
section: "builtin",
action: e => metapress.editor.createEntityNearby({
type: "sphere",
"modifier:materials": !0
})
}]
}
},
4028: (e, t, i) => {
i.d(t, {
Z: () => n
});
class n {
_counter = 0;
get isUnlocked() {
return 0 == this._counter
}
get isLocked() {
return this._counter > 0
}
get isAcquired() {
return this._counter > 0
}
lock() {
this._counter += 1;
let e = !1;
return () => {
e || (e = !0, this._counter = Math.max(0, this._counter - 1))
}
}
acquire() {
return this.lock()
}
}
},
5143: (e, t, i) => {
e.exports = i.p + "mp-core/texture.5890236f46b2b8ebaca6.svg"
},
41598: (e, t, i) => {
e.exports = i.p + "mp-core/object-circle.f7abe3405d346872969c.svg"
},
90371: (e, t, i) => {
e.exports = i.p + "mp-core/object-cube.28f5b6d5b3236e38a354.svg"
},
5461: (e, t, i) => {
e.exports = i.p + "mp-core/object-cylinder.8ba97d22a2f697c6e15f.svg"
},
26192: (e, t, i) => {
e.exports = i.p + "mp-core/object-plane.12f4b034648a5127c7b9.svg"
},
26247: (e, t, i) => {
e.exports = i.p + "mp-core/object-region.9d3d97740123301db48b.svg"
},
34949: (e, t, i) => {
e.exports = i.p + "mp-core/object-sphere.76ed3af0e9e4df404a93.svg"
}
}
]);