lecodes-cli 0.1.1 → 0.1.2

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.
@@ -0,0 +1,1395 @@
1
+ // ../worker/src/components/Component.ts
2
+ var Component = class {
3
+ onAssign(entityId) {
4
+ }
5
+ entity;
6
+ channels;
7
+ };
8
+
9
+ // ../worker/src/fetch.ts
10
+ var FetchResponseImpl = class {
11
+ _id;
12
+ status;
13
+ constructor(_id, status) {
14
+ this.status = status;
15
+ this._id = _id;
16
+ }
17
+ json() {
18
+ return _creatorUtils.fetchToJson(this._id);
19
+ }
20
+ text() {
21
+ return _creatorUtils.fetchToText(this._id);
22
+ }
23
+ dispose() {
24
+ _creatorUtils.disposeFetch(this._id);
25
+ }
26
+ };
27
+ var fetch2 = (url, fetchOptions = {}) => {
28
+ return new Promise((res, rej) => {
29
+ _creatorUtils.fetch(url, fetchOptions, (systemId, statusCode) => {
30
+ res(new FetchResponseImpl(systemId, statusCode));
31
+ }, rej);
32
+ });
33
+ };
34
+ var fetchLocal = (path) => {
35
+ return new FetchResponseImpl(_creatorUtils.fetchLocal(path), 200);
36
+ };
37
+ var FormData = class {
38
+ _entries = [];
39
+ append(name, value, filename) {
40
+ this._entries.push([name, value, filename ?? (typeof value === "object" ? value.name : void 0)]);
41
+ }
42
+ delete(name) {
43
+ const index = this._entries.findIndex((i) => i[0] === name);
44
+ if (index >= 0) {
45
+ this._entries.splice(index);
46
+ }
47
+ }
48
+ };
49
+ var File = class {
50
+ _id;
51
+ name;
52
+ size;
53
+ constructor(_id, name, size) {
54
+ this._id = _id;
55
+ this.name = name;
56
+ this.size = size;
57
+ }
58
+ };
59
+
60
+ // ../worker/src/Texture.ts
61
+ var Texture = class _Texture {
62
+ _id;
63
+ /** Defines how the texture is wrapped horizontally and corresponds to U in UV mapping. */
64
+ wrapS = 1;
65
+ /** Defines how the texture is wrapped vertically and corresponds to V in UV mapping. */
66
+ wrapT = 1;
67
+ width;
68
+ height;
69
+ constructor(width, height, externalId) {
70
+ this.width = width;
71
+ this.height = height;
72
+ this._id = externalId;
73
+ }
74
+ static load(urlOrResponse) {
75
+ if (typeof urlOrResponse === "string") {
76
+ return fetch(urlOrResponse, { useOnce: true }).then((resp) => {
77
+ if (resp.status >= 400) {
78
+ return Promise.reject(new Error(`Failed to fetch texture from ${urlOrResponse}. HTTP code: ${resp.status}`));
79
+ } else {
80
+ return _Texture.load(resp);
81
+ }
82
+ });
83
+ } else {
84
+ return new Promise((res, rej) => {
85
+ _creator.createTexture(urlOrResponse._id, (id, width, height) => {
86
+ res(new _Texture(width, height, id));
87
+ }, rej);
88
+ });
89
+ }
90
+ }
91
+ // static getInternalId(texture: Texture): number {
92
+ // return texture._id
93
+ // }
94
+ };
95
+
96
+ // ../worker/src/Material.ts
97
+ function set(target, key, newValue) {
98
+ target[key] = newValue;
99
+ if (typeof newValue === "string") {
100
+ if (newValue.length > 7) {
101
+ _creator.setUniformRgba(this._id, key, parseInt(newValue.slice(1), 16));
102
+ } else {
103
+ _creator.setUniformRgb(this._id, key, parseInt(newValue.slice(1), 16));
104
+ }
105
+ } else if (typeof newValue === "number") {
106
+ _creator.setUniformFloat(this._id, key, newValue);
107
+ } else if (typeof newValue === "boolean") {
108
+ _creator.setUniformBoolean(this._id, key, newValue);
109
+ } else if (newValue instanceof Texture) {
110
+ _creator.setUniformTexture(this._id, key, newValue._id, newValue.wrapS, newValue.wrapT);
111
+ } else if (newValue instanceof Float32Array) {
112
+ _creator.setUniformArray(this._id, key, newValue);
113
+ } else if (Array.isArray(newValue)) {
114
+ _creator.setUniformArray(this._id, key, Float32Array.of(...newValue));
115
+ } else if (typeof newValue === null) {
116
+ _creator.setUniformNull(this._id, key);
117
+ }
118
+ return true;
119
+ }
120
+ function get(target, key) {
121
+ return target[key];
122
+ }
123
+ var Material = class _Material {
124
+ _id;
125
+ // private _onlyClone: boolean = false
126
+ shader;
127
+ _uniforms = {};
128
+ uniforms;
129
+ constructor(shader) {
130
+ if (typeof shader === "number") {
131
+ this.shader = "unknown";
132
+ this._id = shader;
133
+ } else {
134
+ this.shader = shader;
135
+ this._id = _creator.createMaterial(shader._id);
136
+ }
137
+ this.uniforms = new Proxy(this._uniforms, {
138
+ set: set.bind(this),
139
+ get: get.bind(this)
140
+ });
141
+ }
142
+ clone() {
143
+ return new _Material(this.shader);
144
+ }
145
+ static load(url) {
146
+ return fetch(url, { useOnce: true }).then((resp) => {
147
+ if (resp.status >= 400) {
148
+ return Promise.reject(new Error(`Failed to fetch shader from ${url}. HTTP code: ${resp.status}`));
149
+ } else {
150
+ return new _Material(resp);
151
+ }
152
+ });
153
+ }
154
+ // static setOnlyClone(material: Material, value: boolean): void {
155
+ // material._onlyClone = value
156
+ // }
157
+ // static isOnlyClone(material: Material): boolean {
158
+ // return material._onlyClone
159
+ // }
160
+ static getInternalId(material) {
161
+ return material._id;
162
+ }
163
+ };
164
+ var LitMaterial = class extends Material {
165
+ constructor(options) {
166
+ super({ _id: _creatorUtils.fetchLocal("lit.filamat") });
167
+ if (options?.map) {
168
+ this.map = options.map;
169
+ }
170
+ if (options?.color) {
171
+ this.color = this.color;
172
+ }
173
+ }
174
+ set color(value) {
175
+ this.uniforms.color = value;
176
+ }
177
+ get color() {
178
+ return this.uniforms.color;
179
+ }
180
+ set map(value) {
181
+ if (value === null) {
182
+ this.uniforms.useBaseColorMap = false;
183
+ } else {
184
+ this.uniforms.baseColorMap = value;
185
+ this.uniforms.useBaseColorMap = true;
186
+ }
187
+ }
188
+ get map() {
189
+ return this.uniforms.map;
190
+ }
191
+ };
192
+ var UnlitMaterial = class extends Material {
193
+ constructor(options) {
194
+ super({ _id: _creatorUtils.fetchLocal("unlit.filamat") });
195
+ if (options?.map) {
196
+ this.map = options.map;
197
+ }
198
+ if (options?.color) {
199
+ this.color = this.color;
200
+ }
201
+ }
202
+ set color(value) {
203
+ this.uniforms.baseColor = value;
204
+ }
205
+ get color() {
206
+ return this.uniforms.baseColor;
207
+ }
208
+ set map(value) {
209
+ if (value === null) {
210
+ this.uniforms.useBaseColorMap = false;
211
+ } else {
212
+ this.uniforms.baseColorMap = value;
213
+ this.uniforms.useBaseColorMap = true;
214
+ }
215
+ }
216
+ get map() {
217
+ return this.uniforms.map;
218
+ }
219
+ };
220
+ var VideoMaterial = class extends Material {
221
+ constructor(map) {
222
+ super({ _id: _creatorUtils.fetchLocal("video.filamat") });
223
+ if (map) {
224
+ this.map = map;
225
+ }
226
+ }
227
+ set map(value) {
228
+ this.uniforms.baseColorMap = value;
229
+ }
230
+ get map() {
231
+ return this.uniforms.baseColorMap;
232
+ }
233
+ };
234
+ var ShadowMaterial = class extends Material {
235
+ constructor(color) {
236
+ super({ _id: _creatorUtils.fetchLocal("shadow.filamat") });
237
+ if (color) {
238
+ this.color = color;
239
+ } else {
240
+ this.color = "#000000aa";
241
+ }
242
+ }
243
+ set color(value) {
244
+ this.uniforms.color = value;
245
+ }
246
+ get color() {
247
+ return this.uniforms.color;
248
+ }
249
+ };
250
+
251
+ // ../worker/src/primitives/MeshGeometry.ts
252
+ var MeshGeometry = class {
253
+ vertices;
254
+ normals;
255
+ indices;
256
+ uv;
257
+ _meshType = 0;
258
+ constructor(vertices, normals, indices, uv) {
259
+ this.vertices = vertices;
260
+ this.normals = normals;
261
+ this.indices = indices;
262
+ this.uv = uv;
263
+ }
264
+ translate(x, y, z) {
265
+ for (let i = 0; i < this.vertices.length; i += 3) {
266
+ this.vertices[i] = x + this.vertices[i];
267
+ this.vertices[i + 1] = y + this.vertices[i + 1];
268
+ this.vertices[i + 2] = z + this.vertices[i + 2];
269
+ }
270
+ return this;
271
+ }
272
+ scale(x, y, z) {
273
+ for (let i = 0; i < this.vertices.length; i += 3) {
274
+ this.vertices[i] = x * this.vertices[i];
275
+ this.vertices[i + 1] = y * this.vertices[i + 1];
276
+ this.vertices[i + 2] = z * this.vertices[i + 2];
277
+ }
278
+ return this;
279
+ }
280
+ scaleUV(x, y) {
281
+ for (let i = 0; i < this.uv.length; i += 2) {
282
+ this.uv[i] = x * this.uv[i];
283
+ this.uv[i + 1] = y * this.uv[i + 1];
284
+ }
285
+ return this;
286
+ }
287
+ set meshType(type) {
288
+ if (type === "triangles") {
289
+ this._meshType = 0;
290
+ } else if (type === "edges") {
291
+ this._meshType = 1;
292
+ } else if (type === "vertices") {
293
+ this._meshType = 2;
294
+ }
295
+ }
296
+ };
297
+
298
+ // ../worker/src/primitives/cube.ts
299
+ var createCubeGeometry = () => {
300
+ const vertices = new Float32Array(6 * 4 * 3);
301
+ const normals = new Float32Array(6 * 4 * 3);
302
+ const uv = new Float32Array(6 * 4 * 3);
303
+ const indices = new Uint16Array(6 * 6);
304
+ let cnt = 0;
305
+ let indicesCnt = 0;
306
+ const sides = [-0.5, 0.5];
307
+ for (let i = 0; i < 6; i++) {
308
+ const s = cnt;
309
+ const side = i % 2 == 0 ? -0.5 : 0.5;
310
+ for (let a of sides) {
311
+ for (let b of sides) {
312
+ uv.set([a + 0.5, b + 0.5], cnt * 2);
313
+ if (i == 0 || i == 1) {
314
+ vertices.set([side, b, -a], cnt * 3);
315
+ normals.set([side * 2, 0, 0], cnt * 3);
316
+ }
317
+ if (i == 2 || i == 3) {
318
+ vertices.set([a, side, -b], cnt * 3);
319
+ normals.set([0, side * 2, 0], cnt * 3);
320
+ }
321
+ if (i == 4 || i == 5) {
322
+ vertices.set([a, b, side], cnt * 3);
323
+ normals.set([0, 0, side * 2], cnt * 3);
324
+ }
325
+ cnt++;
326
+ }
327
+ }
328
+ let s1 = s + 1;
329
+ let s2 = s + 2;
330
+ let s3 = s + 3;
331
+ if (i % 2 == 0) {
332
+ indices.set([s, s1, s2, s3, s2, s1], indicesCnt);
333
+ } else {
334
+ indices.set([s2, s1, s, s1, s2, s3], indicesCnt);
335
+ }
336
+ indicesCnt += 6;
337
+ }
338
+ return new MeshGeometry(vertices, normals, indices, uv);
339
+ };
340
+
341
+ // ../worker/src/primitives/cylinder.ts
342
+ var createCylinderGeometry = (options = {}) => {
343
+ const { edges = 32, smooth = true, radius = 0.5, radiusTop = radius, radiusBottom = radius } = options;
344
+ const verticesCount = edges * 4 + (edges + 1) * 2;
345
+ const vertices = new Float32Array(verticesCount * 3);
346
+ const normals = new Float32Array(verticesCount * 3);
347
+ const uv = new Float32Array(verticesCount * 2);
348
+ const indices = new Uint16Array(edges * 6 + edges * 6);
349
+ const sides = [-0.5, 0.5];
350
+ let cnt = 0;
351
+ let indicesCnt = 0;
352
+ for (let i = 0; i < edges; i++) {
353
+ const s = cnt;
354
+ const normalX = Math.cos((i + 0.5) / edges * Math.PI * 2);
355
+ const normalY = Math.sin((i + 0.5) / edges * Math.PI * 2);
356
+ for (let j = 0; j < 2; j++) {
357
+ const x = Math.cos((i + j) / edges * Math.PI * 2);
358
+ const y = Math.sin((i + j) / edges * Math.PI * 2);
359
+ for (let side of sides) {
360
+ if (side > 0) {
361
+ vertices.set([x * radiusTop, side, y * radiusTop], cnt * 3);
362
+ } else {
363
+ vertices.set([x * radiusBottom, side, y * radiusBottom], cnt * 3);
364
+ }
365
+ if (smooth) {
366
+ normals.set([x, 0, y], cnt * 3);
367
+ } else {
368
+ normals.set([normalX, 0, normalY], cnt * 3);
369
+ }
370
+ uv.set([(i + j) / edges, side + 0.5], cnt * 2);
371
+ cnt++;
372
+ }
373
+ }
374
+ let s1 = s + 1;
375
+ let s2 = (s + 2) % (edges * 4);
376
+ let s3 = (s + 3) % (edges * 4);
377
+ indices.set([s, s1, s2, s3, s2, s1], indicesCnt);
378
+ indicesCnt += 6;
379
+ }
380
+ for (let side of sides) {
381
+ let center = cnt;
382
+ vertices.set([0, side, 0], cnt * 3);
383
+ normals.set([0, side * 2, 0], cnt * 3);
384
+ cnt++;
385
+ for (let i = 0; i < edges; i++) {
386
+ const x = Math.cos(i / edges * Math.PI * 2);
387
+ const y = Math.sin(i / edges * Math.PI * 2);
388
+ if (side > 0) {
389
+ vertices.set([x * radiusTop, side, y * radiusTop], cnt * 3);
390
+ } else {
391
+ vertices.set([x * radiusBottom, side, y * radiusBottom], cnt * 3);
392
+ }
393
+ normals.set([0, side * 2, 0], cnt * 3);
394
+ if (side < 0) {
395
+ indices.set([center, center + i + 1, center + 1 + (i + 1) % edges], indicesCnt);
396
+ } else {
397
+ indices.set([center + 1 + (i + 1) % edges, center + i + 1, center], indicesCnt);
398
+ }
399
+ indicesCnt += 3;
400
+ cnt++;
401
+ }
402
+ }
403
+ return new MeshGeometry(vertices, normals, indices, uv);
404
+ };
405
+
406
+ // ../worker/src/primitives/plane.ts
407
+ import * as vec3Op from "gl-matrix/vec3";
408
+ var createPlaneGeometry = (options = {}) => {
409
+ const { normal = Float32Array.of(0, 0, 1) } = options;
410
+ const vertices = new Float32Array(4 * 3);
411
+ const normals = new Float32Array(4 * 3);
412
+ const uvs = new Float32Array(4 * 2);
413
+ const sides = [-0.5, 0.5];
414
+ let cnt = 0;
415
+ let upVector;
416
+ let rightVec;
417
+ if (normal[1] === 0 && normal[2] === 0) {
418
+ upVector = Float32Array.of(0, 1, 0);
419
+ rightVec = Float32Array.of(0, 0, normal[0]);
420
+ } else if (normal[0] === 0 && normal[2] === 0) {
421
+ upVector = Float32Array.of(0, 0, 1);
422
+ rightVec = Float32Array.of(normal[1], 0, 0);
423
+ } else if (normal[0] === 0 && normal[1] === 0) {
424
+ upVector = Float32Array.of(0, 1, 0);
425
+ rightVec = Float32Array.of(normal[2], 0, 0);
426
+ } else {
427
+ const tempVec = Math.abs(normal[0]) < 0.5 ? Float32Array.of(1, 0, 0) : Float32Array.of(0, 0, 1);
428
+ upVector = vec3Op.cross(tempVec, tempVec, normal);
429
+ rightVec = vec3Op.cross(new Float32Array(3), upVector, normal);
430
+ }
431
+ for (let a of sides) {
432
+ for (let b of sides) {
433
+ normals.set(normal, cnt * 3);
434
+ uvs.set([a + 0.5, b + 0.5], cnt * 2);
435
+ vertices.set([
436
+ rightVec[0] * a + upVector[0] * b,
437
+ rightVec[1] * a + upVector[1] * b,
438
+ rightVec[2] * a + upVector[2] * b
439
+ ], cnt * 3);
440
+ cnt++;
441
+ }
442
+ }
443
+ const indices = new Uint16Array([2, 1, 0, 1, 2, 3]);
444
+ return new MeshGeometry(vertices, normals, indices, uvs);
445
+ };
446
+
447
+ // ../worker/src/primitives/sphere.ts
448
+ var createSphereGeometry = (options = {}) => {
449
+ const { radius = 0.5, widthSegments = 32, heightSegments = 32 } = options;
450
+ const verticesCount = (widthSegments + 1) * (heightSegments - 1) + widthSegments * 2;
451
+ const vertices = new Float32Array(verticesCount * 3);
452
+ const normals = new Float32Array(verticesCount * 3);
453
+ const uvs = new Float32Array(verticesCount * 2);
454
+ const indices = new Uint16Array(widthSegments * (heightSegments - 2) * 6 + widthSegments * 3 * 2);
455
+ const phiStart = 0;
456
+ const phiLength = Math.PI * 2;
457
+ const thetaStart = 0;
458
+ const thetaLength = Math.PI;
459
+ let uOffset = 0;
460
+ let vertexCnt = 0;
461
+ let indicesCnt = 0;
462
+ for (let iy = 1; iy < heightSegments; iy++) {
463
+ const v = iy / heightSegments;
464
+ for (let ix = 0; ix <= widthSegments; ix++) {
465
+ const u = ix / widthSegments;
466
+ const point = [
467
+ -Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength),
468
+ Math.cos(thetaStart + v * thetaLength),
469
+ Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength)
470
+ ];
471
+ vertices.set([point[0] * radius, point[1] * radius, point[2] * radius], vertexCnt * 3);
472
+ normals.set(point, vertexCnt * 3);
473
+ uvs.set([u + uOffset, 1 - v], vertexCnt * 2);
474
+ if (iy > 1 && ix > 0) {
475
+ const s = vertexCnt - 1;
476
+ const s1 = vertexCnt - (widthSegments + 1) - 1;
477
+ const s2 = s + 1;
478
+ const s3 = s1 + 1;
479
+ indices.set([s2, s1, s, s1, s2, s3], indicesCnt);
480
+ indicesCnt += 6;
481
+ }
482
+ vertexCnt++;
483
+ }
484
+ }
485
+ const sides = [-radius, radius];
486
+ const circleStart2 = vertexCnt - (widthSegments + 1);
487
+ for (let side of sides) {
488
+ const circleStart = side > 0 ? 0 : circleStart2;
489
+ for (let ix = 0; ix < widthSegments; ix++) {
490
+ const u = (ix + 0.5) / widthSegments;
491
+ vertices.set([0, side, 0], vertexCnt * 3);
492
+ normals.set([0, side < 0 ? -1 : 1, 0], vertexCnt * 3);
493
+ uvs.set([u + uOffset, side < 0 ? 0 : 1], vertexCnt * 2);
494
+ const s = circleStart + ix;
495
+ const s1 = s + 1;
496
+ if (side > 0) {
497
+ indices.set([s, s1, vertexCnt], indicesCnt);
498
+ } else {
499
+ indices.set([vertexCnt, s1, s], indicesCnt);
500
+ }
501
+ indicesCnt += 3;
502
+ vertexCnt++;
503
+ }
504
+ }
505
+ return new MeshGeometry(vertices, normals, indices, uvs);
506
+ };
507
+
508
+ // ../worker/src/components/Mesh.ts
509
+ var assignMaterial = (mesh, material, index) => {
510
+ if (!mesh["_materials"]) {
511
+ if (index === 0) {
512
+ mesh["_materials"] = [material];
513
+ } else {
514
+ mesh["_materials"] = [];
515
+ mesh["_materials"][index] = material;
516
+ }
517
+ } else {
518
+ mesh["_materials"][index] = material;
519
+ }
520
+ };
521
+ var Mesh = class _Mesh extends Component {
522
+ name = "mesh";
523
+ _materials;
524
+ _geometry;
525
+ _culling = true;
526
+ constructor(geometry, material) {
527
+ super();
528
+ this._geometry = geometry;
529
+ if (material) {
530
+ this._materials = [material];
531
+ }
532
+ }
533
+ getMaterial(index) {
534
+ const existsMaterial = this._materials?.[index];
535
+ if (existsMaterial) {
536
+ return existsMaterial;
537
+ }
538
+ const materialId = _creator.getMaterial(this.entity._id, index);
539
+ if (materialId === 0) return null;
540
+ const mat = new Material(materialId);
541
+ assignMaterial(this, mat, index);
542
+ return mat;
543
+ }
544
+ setMaterial(material, index) {
545
+ assignMaterial(this, material, index);
546
+ if (this.entity) {
547
+ _creator.setMaterial(this.entity._id, Material.getInternalId(material), index);
548
+ }
549
+ }
550
+ clone() {
551
+ const mesh = new _Mesh(this._geometry);
552
+ mesh._materials = this._materials ? [...this._materials] : void 0;
553
+ return mesh;
554
+ }
555
+ get material() {
556
+ return this.getMaterial(0);
557
+ }
558
+ set material(material) {
559
+ this.setMaterial(material, 0);
560
+ }
561
+ // static createCube(): Mesh
562
+ // static createCylinder(radius = 0.5, edges = 32, smooth: boolean = true): Mesh {
563
+ // return new Mesh(createCylinder(radius, edges, smooth))
564
+ // }
565
+ // static createSphere(radius = 0.5, widthSegments = 32, heightSegments = 16): Mesh {
566
+ // return new Mesh(createSphere(radius, widthSegments, heightSegments))
567
+ // }
568
+ // static createPlane(normal?: ReadonlyVec3): Mesh {
569
+ // return new Mesh(createPlane(normal))
570
+ // }
571
+ // static createEmpty(): Mesh {
572
+ // const mesh = new Mesh()
573
+ // return mesh
574
+ // }
575
+ onAssign(entityId) {
576
+ if (this._geometry) {
577
+ if (!this._materials) {
578
+ this._materials = [new UnlitMaterial()];
579
+ }
580
+ _creator.setMesh(
581
+ entityId,
582
+ Material.getInternalId(this._materials[0]),
583
+ this._geometry.vertices,
584
+ this._geometry.normals,
585
+ this._geometry.indices,
586
+ this._geometry.uv,
587
+ this._geometry._meshType
588
+ );
589
+ if (this._culling !== true) {
590
+ _creator.setCulling(entityId, this._culling);
591
+ }
592
+ }
593
+ }
594
+ get culling() {
595
+ return this._culling;
596
+ }
597
+ get geometry() {
598
+ return this._geometry;
599
+ }
600
+ set culling(culling) {
601
+ this._culling = culling;
602
+ if (this.entity) {
603
+ _creator.setCulling(this.entity._id, this._culling);
604
+ }
605
+ }
606
+ set castShadows(value) {
607
+ _creator.setCastShadows(this.entity._id, value);
608
+ }
609
+ set receiveShadows(value) {
610
+ _creator.setReceiveShadows(this.entity._id, value);
611
+ }
612
+ // setMeshType(meshType: "triangles" | "vertices" | "edges"): this {
613
+ // if (this._geometry) {
614
+ // this._geometry.meshType = meshType
615
+ // }
616
+ // return this
617
+ // }
618
+ };
619
+ var createCubeMesh = (mat) => new Mesh(createCubeGeometry(), mat);
620
+ var createCylinderMesh = (options = {}) => {
621
+ return new Mesh(createCylinderGeometry(options), options.material);
622
+ };
623
+ var createPlaneMesh = (options = {}) => {
624
+ return new Mesh(createPlaneGeometry(options), options.material);
625
+ };
626
+ var createSphereMesh = (options = {}) => {
627
+ return new Mesh(createSphereGeometry(options), options.material);
628
+ };
629
+
630
+ // ../worker/src/utils/transform.ts
631
+ import * as mat4Op from "gl-matrix/mat4";
632
+ var getPosition = (mat) => {
633
+ return Float32Array.of(mat[12], mat[13], mat[14]);
634
+ };
635
+ var getScale = (mat) => {
636
+ const m11 = mat[0];
637
+ const m12 = mat[1];
638
+ const m13 = mat[2];
639
+ const m21 = mat[4];
640
+ const m22 = mat[5];
641
+ const m23 = mat[6];
642
+ const m31 = mat[8];
643
+ const m32 = mat[9];
644
+ const m33 = mat[10];
645
+ return Float32Array.of(Math.hypot(m11, m12, m13), Math.hypot(m21, m22, m23), Math.hypot(m31, m32, m33));
646
+ };
647
+ var getQuaternion = (mat, scale) => {
648
+ const is1 = 1 / scale[0];
649
+ const is2 = 1 / scale[1];
650
+ const is3 = 1 / scale[2];
651
+ const sm11 = mat[0] * is1;
652
+ const sm12 = mat[1] * is2;
653
+ const sm13 = mat[2] * is3;
654
+ const sm21 = mat[4] * is1;
655
+ const sm22 = mat[5] * is2;
656
+ const sm23 = mat[6] * is3;
657
+ const sm31 = mat[8] * is1;
658
+ const sm32 = mat[9] * is2;
659
+ const sm33 = mat[10] * is3;
660
+ const trace = sm11 + sm22 + sm33;
661
+ let S = 0;
662
+ if (trace > 0) {
663
+ S = Math.sqrt(trace + 1) * 2;
664
+ return Float32Array.of(
665
+ (sm23 - sm32) / S,
666
+ (sm31 - sm13) / S,
667
+ (sm12 - sm21) / S,
668
+ 0.25 * S
669
+ );
670
+ } else if (sm11 > sm22 && sm11 > sm33) {
671
+ S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
672
+ return Float32Array.of(
673
+ 0.25 * S,
674
+ (sm12 + sm21) / S,
675
+ (sm31 + sm13) / S,
676
+ (sm23 - sm32) / S
677
+ );
678
+ } else if (sm22 > sm33) {
679
+ S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
680
+ return Float32Array.of(
681
+ (sm12 + sm21) / S,
682
+ 0.25 * S,
683
+ (sm23 + sm32) / S,
684
+ (sm31 - sm13) / S
685
+ );
686
+ } else {
687
+ S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
688
+ return Float32Array.of(
689
+ (sm31 + sm13) / S,
690
+ (sm23 + sm32) / S,
691
+ 0.25 * S,
692
+ (sm12 - sm21) / S
693
+ );
694
+ }
695
+ };
696
+ var getEulerAngles = (mat, order = "YXZ") => {
697
+ let x = 0, y = 0, z = 0;
698
+ const m11 = mat[0], m12 = mat[1], m13 = mat[2];
699
+ const m21 = mat[4], m22 = mat[5], m23 = mat[6];
700
+ const m31 = mat[8], m32 = mat[9], m33 = mat[10];
701
+ switch (order) {
702
+ case "XYZ":
703
+ y = Math.asin(Math.min(Math.max(m13, -1), 1));
704
+ if (Math.abs(m13) < 0.9999999) {
705
+ x = Math.atan2(-m23, m33);
706
+ z = Math.atan2(-m12, m11);
707
+ } else {
708
+ x = Math.atan2(m32, m22);
709
+ z = 0;
710
+ }
711
+ break;
712
+ case "YXZ":
713
+ x = Math.asin(-Math.min(Math.max(m23, -1), 1));
714
+ if (Math.abs(m23) < 0.9999999) {
715
+ y = Math.atan2(m13, m33);
716
+ z = Math.atan2(m21, m22);
717
+ } else {
718
+ y = Math.atan2(-m31, m11);
719
+ z = 0;
720
+ }
721
+ break;
722
+ case "ZXY":
723
+ x = Math.asin(Math.min(Math.max(m32, -1), 1));
724
+ if (Math.abs(m32) < 0.9999999) {
725
+ y = Math.atan2(-m31, m33);
726
+ z = Math.atan2(-m12, m22);
727
+ } else {
728
+ y = 0;
729
+ z = Math.atan2(m21, m11);
730
+ }
731
+ break;
732
+ case "ZYX":
733
+ y = Math.asin(-Math.min(Math.max(m31, -1), 1));
734
+ if (Math.abs(m31) < 0.9999999) {
735
+ x = Math.atan2(m32, m33);
736
+ z = Math.atan2(m21, m11);
737
+ } else {
738
+ x = 0;
739
+ z = Math.atan2(-m12, m22);
740
+ }
741
+ break;
742
+ case "YZX":
743
+ z = Math.asin(Math.min(Math.max(m21, -1), 1));
744
+ if (Math.abs(m21) < 0.9999999) {
745
+ x = Math.atan2(-m23, m22);
746
+ y = Math.atan2(-m31, m11);
747
+ } else {
748
+ x = 0;
749
+ y = Math.atan2(m13, m33);
750
+ }
751
+ break;
752
+ case "XZY":
753
+ z = Math.asin(-Math.min(Math.max(m12, -1), 1));
754
+ if (Math.abs(m12) < 0.9999999) {
755
+ x = Math.atan2(m32, m22);
756
+ y = Math.atan2(m13, m11);
757
+ } else {
758
+ x = Math.atan2(-m23, m33);
759
+ y = 0;
760
+ }
761
+ break;
762
+ default:
763
+ throw new Error(`Unknown rotation order: ${order}`);
764
+ }
765
+ return Float32Array.of(x * RAD2DEG, y * RAD2DEG, z * RAD2DEG);
766
+ };
767
+ function vec3Cross(out, a, b) {
768
+ var ax = a[0], ay = a[1], az = a[2];
769
+ var bx = b[0], by = b[1], bz = b[2];
770
+ out[0] = ay * bz - az * by;
771
+ out[1] = az * bx - ax * bz;
772
+ out[2] = ax * by - ay * bx;
773
+ return out;
774
+ }
775
+ function normalizeInPlace(a) {
776
+ let len = Math.hypot(a[0], a[1], a[2]);
777
+ if (len > 0) {
778
+ len = 1 / len;
779
+ }
780
+ a[0] *= len;
781
+ a[1] *= len;
782
+ a[2] *= len;
783
+ return a;
784
+ }
785
+
786
+ // ../worker/src/utils/clone.ts
787
+ var cloneDeep = (obj) => {
788
+ if (typeof obj !== "object" || obj === null) return obj;
789
+ if (Array.isArray(obj)) {
790
+ return [...obj.map(cloneDeep)];
791
+ }
792
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, cloneDeep(value)]));
793
+ };
794
+
795
+ // ../worker/src/Entity.ts
796
+ var entityMap = /* @__PURE__ */ new Map();
797
+ var getEntityById = (entityId) => {
798
+ return entityMap.get(entityId) ?? new Entity(entityId);
799
+ };
800
+ var Entity = class Entity2 {
801
+ _id;
802
+ _matrix;
803
+ _lastSync = 0;
804
+ _worldMatrix;
805
+ _scale;
806
+ // private _components?: ComponentConstructor<Component>[]
807
+ constructor(...components) {
808
+ if (typeof components[0] === "number") {
809
+ this._id = components.shift();
810
+ if (_creator.hasMesh(this._id)) {
811
+ this.addComponent(new Mesh());
812
+ }
813
+ } else {
814
+ this._id = _creator.createEntity();
815
+ }
816
+ entityMap.set(this._id, this);
817
+ for (let component of components) {
818
+ this.addComponent(component);
819
+ }
820
+ }
821
+ // Name methods
822
+ get name() {
823
+ return _creator.getName(this._id);
824
+ }
825
+ set name(value) {
826
+ _creator.setName(this._id, value);
827
+ }
828
+ // Visible methods
829
+ get visible() {
830
+ return _creator.isVisible(this._id);
831
+ }
832
+ set visible(value) {
833
+ _creator.setVisible(this._id, value);
834
+ }
835
+ // Component methods
836
+ addComponent(component) {
837
+ component.entity = this;
838
+ this[component.name] = component;
839
+ const proto = Object.getPrototypeOf(component);
840
+ if (!proto.name) {
841
+ proto.name = component.name;
842
+ }
843
+ component["onAssign"](this._id);
844
+ return this;
845
+ }
846
+ setData(data) {
847
+ return Object.assign(this, data);
848
+ }
849
+ hasComponent(component) {
850
+ const name = component.prototype.name;
851
+ if (!name) return false;
852
+ return name in this;
853
+ }
854
+ _listeners = {};
855
+ _onListenerAdded;
856
+ addEventListener(channel, callback) {
857
+ if (!this._listeners[channel]) {
858
+ this._onListenerAdded?.[channel]?.();
859
+ this._listeners[channel] = [callback];
860
+ } else {
861
+ this._listeners[channel].push(callback);
862
+ }
863
+ }
864
+ removeEventListener(channel, callback) {
865
+ if (!this._listeners[channel]) return;
866
+ const index = this._listeners[channel].indexOf(callback);
867
+ if (index >= 0) {
868
+ this._listeners[channel].splice(index, 1);
869
+ }
870
+ }
871
+ // Transform methods
872
+ get children() {
873
+ return _creator.getChildren(this._id).map((entityId) => getEntityById(entityId));
874
+ }
875
+ get childCount() {
876
+ return _creator.getChildCount(this._id);
877
+ }
878
+ getChild(index) {
879
+ const entity = _creator.getChild(this._id, index);
880
+ if (entity === 0) return null;
881
+ return getEntityById(entity);
882
+ }
883
+ get parent() {
884
+ const entityId = _creator.getParent(this._id);
885
+ if (entityId === 0) return null;
886
+ return getEntityById(entityId);
887
+ }
888
+ get matrix() {
889
+ if (!this._matrix) {
890
+ this._matrix = new Float32Array(16);
891
+ }
892
+ if (this._lastSync === 0 || Date.now() - this._lastSync > 10) {
893
+ _creator.getMatrix(this._id, this._matrix);
894
+ delete this._scale;
895
+ this._lastSync = Date.now();
896
+ }
897
+ return this._matrix;
898
+ }
899
+ set matrix(matrix) {
900
+ this._matrix = matrix;
901
+ _creator.setMatrix(this._id, matrix);
902
+ }
903
+ get worldMatrix() {
904
+ if (this.parent === null) {
905
+ return this.matrix;
906
+ }
907
+ if (!this._worldMatrix) {
908
+ this._worldMatrix = new Float32Array(16);
909
+ }
910
+ _creator.getWorldMatrix(this._id, this._worldMatrix);
911
+ return this._worldMatrix;
912
+ }
913
+ set worldMatrix(matrix) {
914
+ if (this.parent === null) {
915
+ this.matrix = matrix;
916
+ } else {
917
+ this._lastSync = 0;
918
+ _creator.setWorldMatrix(this._id, matrix);
919
+ }
920
+ }
921
+ get worldMatrixInverse() {
922
+ const mat = new Float32Array(16);
923
+ _creator.getWorldMatrix(this._id, mat);
924
+ return mat;
925
+ }
926
+ get position() {
927
+ return getPosition(this.matrix);
928
+ }
929
+ get quaternion() {
930
+ return getQuaternion(this.matrix, this.scale);
931
+ }
932
+ get eulerAngles() {
933
+ return getEulerAngles(this.matrix);
934
+ }
935
+ get scale() {
936
+ if (this._lastSync === 0 || !this._scale) {
937
+ this._scale = getScale(this.matrix);
938
+ }
939
+ return this._scale;
940
+ }
941
+ /** Get forward direction in global space */
942
+ get forward() {
943
+ const vec = new Float32Array(3);
944
+ _creator.getWorldDirection(this._id, 2, vec);
945
+ vec[0] = -vec[0];
946
+ vec[1] = -vec[1];
947
+ vec[2] = -vec[2];
948
+ return vec;
949
+ }
950
+ /** Get position in global space */
951
+ get worldPosition() {
952
+ const vec = new Float32Array(3);
953
+ _creator.getWorldPosition(this._id, vec);
954
+ return vec;
955
+ }
956
+ get worldQuaternion() {
957
+ return getQuaternion(this.worldMatrix, this.worldScale);
958
+ }
959
+ get worldScale() {
960
+ return getScale(this.worldMatrix);
961
+ }
962
+ get worldEulerAngles() {
963
+ return getEulerAngles(this.worldMatrix);
964
+ }
965
+ set position(val) {
966
+ this._lastSync = 0;
967
+ _creator.setPosition(this._id, val[0], val[1], val[2]);
968
+ }
969
+ set quaternion(val) {
970
+ this._lastSync = 0;
971
+ _creator.setQuaternion(this._id, val[0], val[1], val[2], val[3]);
972
+ }
973
+ set eulerAngles(val) {
974
+ this._lastSync = 0;
975
+ _creator.setEulerAngles(this._id, val[0], val[1], val[2], 0);
976
+ }
977
+ set scale(val) {
978
+ this._lastSync = 0;
979
+ _creator.setScale(this._id, val[0], val[1], val[2]);
980
+ }
981
+ addChildren(...entities) {
982
+ for (let child of entities) {
983
+ _creator.setParent(child._id, this._id, false);
984
+ }
985
+ }
986
+ setParent(parent, worldPositionStays = false) {
987
+ if (parent === null) {
988
+ _creator.setParentNull(this._id, worldPositionStays);
989
+ } else {
990
+ _creator.setParent(this._id, parent._id, worldPositionStays);
991
+ }
992
+ if (worldPositionStays) {
993
+ this._lastSync = 0;
994
+ }
995
+ }
996
+ traverse(callback) {
997
+ callback(this);
998
+ _creator.traverse(this._id, (entityId) => {
999
+ callback(getEntityById(entityId));
1000
+ });
1001
+ }
1002
+ static dispatchEvent(entity, event) {
1003
+ if (!entity._listeners) return;
1004
+ const _listener = entity._listeners[event.type];
1005
+ if (!_listener) return;
1006
+ for (let listener of _listener) {
1007
+ listener(event);
1008
+ if (event.defaultPrevented) return;
1009
+ }
1010
+ }
1011
+ static dispatch(entity, channel, ...args) {
1012
+ if (!entity._listeners) return;
1013
+ const _listener = entity._listeners[channel];
1014
+ if (!_listener) return;
1015
+ for (let listener of _listener) {
1016
+ listener(...args);
1017
+ }
1018
+ }
1019
+ clone() {
1020
+ const newEntity = new Entity2(_creator.cloneEntity(this._id));
1021
+ for (let key in this) {
1022
+ if (key in newEntity) continue;
1023
+ const data = this[key];
1024
+ if (data instanceof Component) {
1025
+ const clone2 = "clone" in data ? data.clone() : new data.constructor();
1026
+ newEntity.addComponent(clone2);
1027
+ } else {
1028
+ newEntity[key] = cloneDeep(data);
1029
+ }
1030
+ }
1031
+ return newEntity;
1032
+ }
1033
+ };
1034
+
1035
+ // ../worker/src/Ray.ts
1036
+ import * as vec3Op2 from "gl-matrix/vec3";
1037
+ var Ray = class {
1038
+ origin;
1039
+ dir;
1040
+ /**
1041
+ * @param origin - The start point of the ray.
1042
+ * @param dir - The direction of the ray (need not be normalised).
1043
+ */
1044
+ constructor(origin, dir) {
1045
+ this.origin = vec3Op2.clone(origin);
1046
+ this.dir = vec3Op2.clone(dir);
1047
+ }
1048
+ /**
1049
+ * Evaluate the ray at parameter `t`.
1050
+ * @returns The world-space point `origin + t * dir`.
1051
+ */
1052
+ getPoint(t) {
1053
+ return vec3Op2.scaleAndAdd(vec3Op2.create(), this.origin, this.dir, t);
1054
+ }
1055
+ toString() {
1056
+ const [ox, oy, oz] = this.origin;
1057
+ const [dx, dy, dz] = this.dir;
1058
+ return `Ray(origin=[${ox.toFixed(4)}, ${oy.toFixed(4)}, ${oz.toFixed(4)}], dir=[${dx.toFixed(4)}, ${dy.toFixed(4)}, ${dz.toFixed(4)}])`;
1059
+ }
1060
+ };
1061
+
1062
+ // ../worker/src/components/Camera.ts
1063
+ var Camera = class extends Component {
1064
+ name = "camera";
1065
+ sceneId = -1;
1066
+ _fov = 60;
1067
+ projectionMatrix = new Float32Array(16);
1068
+ get fov() {
1069
+ return _creator.getCameraFov(this.sceneId, 0);
1070
+ }
1071
+ get horizontalFov() {
1072
+ return _creator.getCameraFov(this.sceneId, 1);
1073
+ }
1074
+ get displaySize() {
1075
+ return _creator.getDisplaySize();
1076
+ }
1077
+ onProjectionChange(mat, fov) {
1078
+ this._fov = fov;
1079
+ for (let i = 0; i < 16; i++) {
1080
+ this.projectionMatrix[i] = mat[i];
1081
+ }
1082
+ }
1083
+ static attachToScene(camera, scene) {
1084
+ _creator.attachCameraToAR(scene._id, camera._id, camera.camera.onProjectionChange);
1085
+ camera.camera.sceneId = scene._id;
1086
+ }
1087
+ getViewDirection(screenX, screenY) {
1088
+ if (this.sceneId < 0) throw new Error("Camera not attached to scene");
1089
+ const vec = new Float32Array(3);
1090
+ _creator.getCameraViewDirection(this.sceneId, screenX, screenY, vec);
1091
+ return vec;
1092
+ }
1093
+ getRay(clientX, clientY) {
1094
+ return new Ray(this.entity.worldPosition, this.getViewDirection(clientX, clientY));
1095
+ }
1096
+ };
1097
+
1098
+ // ../worker/src/Scene.ts
1099
+ var Scene = class _Scene {
1100
+ /** Main scene camera */
1101
+ camera;
1102
+ /** Internal scene ID */
1103
+ _id;
1104
+ /** Entities added to this scene */
1105
+ // protected _entities: Entity[] = []
1106
+ /**
1107
+ * Create a new scene
1108
+ * @param options Scene configuration (IBL, sun light, shadows, etc.)
1109
+ */
1110
+ constructor(options = {}) {
1111
+ if (options._parent) {
1112
+ this.camera = options._parent.camera;
1113
+ this._id = _creator.createOverlayScene(options._parent._id);
1114
+ } else {
1115
+ this.camera = new Entity(new Camera());
1116
+ this._id = _creator.createScene();
1117
+ }
1118
+ Camera.attachToScene(this.camera, this);
1119
+ if (options.ibl !== false) {
1120
+ _creator.setDefaultIbl(this._id, options.iblIntensity ?? 2e4);
1121
+ }
1122
+ if (options.sunLight !== false) {
1123
+ const lightEntity = new Entity();
1124
+ _creator.createSunLight(lightEntity._id, 0.548267, -0.473983, -0.689016, 1e5, 16777215, options.castShadows ?? true);
1125
+ _creator.addEntityToScene(this._id, lightEntity._id);
1126
+ }
1127
+ if (options.bloom) {
1128
+ _creator.setBloomOptions(this._id, true, options.bloomIntensity ?? 0.2, 1);
1129
+ }
1130
+ }
1131
+ static _activeScene = null;
1132
+ /** Currently active scene (if any) */
1133
+ static get activeScene() {
1134
+ return this._activeScene;
1135
+ }
1136
+ /** Open this scene and set it as active */
1137
+ open() {
1138
+ _creator.openScene(this._id);
1139
+ _Scene._activeScene = this;
1140
+ }
1141
+ close() {
1142
+ _creator.closeScene();
1143
+ _Scene._activeScene = null;
1144
+ }
1145
+ // /** Get entities in this scene (readonly) */
1146
+ // get entities() {
1147
+ // return this._entities as Readonly<Entity[]>
1148
+ // }
1149
+ _material;
1150
+ /** Get scene occlusion material */
1151
+ get occlusionMaterial() {
1152
+ if (!this._material) {
1153
+ this._material = new Material(_creator.getSceneMaterial(this._id));
1154
+ }
1155
+ return this._material;
1156
+ }
1157
+ setMaterialGlobalParameter(i, x, y, z, w) {
1158
+ _creator.setMaterialGlobalParameter(this._id, i, x, y, z, w);
1159
+ }
1160
+ /**
1161
+ * Set skybox background color
1162
+ * @param color RGB hex value
1163
+ */
1164
+ setSkyboxColor(color) {
1165
+ _creator.setSkybox(this._id, color);
1166
+ }
1167
+ setMultiSampleAntiAliasing(enabled, scale = 4) {
1168
+ _creator.setSceneMultiSampleAntiAliasing(this._id, enabled, scale);
1169
+ }
1170
+ createOverlayScene(options) {
1171
+ return new _Scene({ ...options, _parent: this });
1172
+ }
1173
+ /**
1174
+ * Add entities to this scene
1175
+ * @param entities Entities to add
1176
+ */
1177
+ add(...entities) {
1178
+ for (let entity of entities) {
1179
+ _creator.addEntityToScene(this._id, entity._id);
1180
+ }
1181
+ }
1182
+ /**
1183
+ * Remove entities from this scene
1184
+ * @param entities Entities to remove
1185
+ */
1186
+ remove(...entities) {
1187
+ for (let entity of entities) {
1188
+ _creator.removeEntityFromScene(this._id, entity._id);
1189
+ }
1190
+ }
1191
+ warmRender() {
1192
+ return new Promise((res, _rej) => _creator.warmRender(this._id, res));
1193
+ }
1194
+ _clickListeners = [];
1195
+ _touchStartListeners = [];
1196
+ addEventListener(channel, callback) {
1197
+ if (channel === "click") {
1198
+ if (this._clickListeners.includes(callback)) return;
1199
+ this._clickListeners.push(callback);
1200
+ registerTouchEndEvent();
1201
+ } else if (channel === "touchstart") {
1202
+ if (this._touchStartListeners.includes(callback)) return;
1203
+ this._touchStartListeners.push(callback);
1204
+ registerTouchStartEvent();
1205
+ }
1206
+ }
1207
+ removeEventListener(channel, callback) {
1208
+ if (channel === "click") {
1209
+ const itemIndex = this._clickListeners.indexOf(callback);
1210
+ if (itemIndex >= 0) {
1211
+ this._clickListeners.splice(itemIndex);
1212
+ }
1213
+ } else if (channel === "touchstart") {
1214
+ const itemIndex = this._touchStartListeners.indexOf(callback);
1215
+ if (itemIndex >= 0) {
1216
+ this._touchStartListeners.splice(itemIndex);
1217
+ }
1218
+ }
1219
+ }
1220
+ };
1221
+ var onTrackStateChange = (entityId, track) => {
1222
+ const entity = entityMap.get(entityId);
1223
+ if (!entity) return;
1224
+ entity.isTracked = track;
1225
+ if (track) {
1226
+ Entity.dispatch(entity, "track");
1227
+ } else {
1228
+ Entity.dispatch(entity, "untrack");
1229
+ }
1230
+ };
1231
+ var ARScene = class extends Scene {
1232
+ /** Current AR mode */
1233
+ mode;
1234
+ _root;
1235
+ useWarmRender = true;
1236
+ /**
1237
+ * Create a new AR scene
1238
+ * @param options AR scene configuration (mode, lights, IBL, etc.)
1239
+ */
1240
+ constructor(options = {}) {
1241
+ super(options);
1242
+ this.mode = options.mode ?? "default";
1243
+ _creator.createARController(this._id, this.camera._id, this.mode, onTrackStateChange);
1244
+ }
1245
+ /** Root anchor entity (not available in marker mode) */
1246
+ get root() {
1247
+ if (this._root) return this._root;
1248
+ const entityId = _creator.createRootAnchor(this._id);
1249
+ this._root = new Entity(entityId);
1250
+ return this._root;
1251
+ }
1252
+ /** Current AR mode */
1253
+ // get mode(): T {
1254
+ // return modes[this._mode] as T
1255
+ // }
1256
+ /**
1257
+ * Create an anchor from a given source (e.g. image target)
1258
+ * @param source Tracking source (image, object, etc.)
1259
+ * @param physicalWidth Real-world width in meters (default 0.2)
1260
+ * @returns Anchor entity
1261
+ */
1262
+ createAnchor(source, physicalWidth = 0.2) {
1263
+ const entityId = _creator.createAnchor(this._id, physicalWidth, source._id);
1264
+ return new Entity(entityId);
1265
+ }
1266
+ /** Open AR session and activate this scene */
1267
+ async open() {
1268
+ await new Promise((res, rej) => {
1269
+ _creator.requestCamera(res, rej);
1270
+ });
1271
+ if (this.useWarmRender) {
1272
+ _creator.createGLView();
1273
+ await this.warmRender();
1274
+ }
1275
+ await new Promise((res, rej) => {
1276
+ _creator.launchAR(this._id, res, rej);
1277
+ });
1278
+ super.open();
1279
+ }
1280
+ close() {
1281
+ _creator.stopAR();
1282
+ super.close();
1283
+ }
1284
+ };
1285
+
1286
+ // ../worker/src/TouchEventSystem.ts
1287
+ var onTouchEnd = (pointerId, clientX, clientY, entityId) => {
1288
+ if (!Scene.activeScene) return null;
1289
+ const touchEvent = new ClickEvent(clientX, clientY, pointerId);
1290
+ if (entityId > 0) {
1291
+ touchEvent.target = entityMap.get(entityId);
1292
+ Entity.dispatchEvent(touchEvent.target, touchEvent);
1293
+ } else {
1294
+ touchEvent.target = null;
1295
+ }
1296
+ for (let listener of Scene.activeScene._clickListeners) {
1297
+ listener(touchEvent);
1298
+ }
1299
+ return null;
1300
+ };
1301
+ var onTouchStart = (pointerId, clientX, clientY, entityId) => {
1302
+ if (!Scene.activeScene) return null;
1303
+ const touchEvent = new TouchStartEvent(clientX, clientY, pointerId);
1304
+ if (entityId > 0) {
1305
+ touchEvent.target = entityMap.get(entityId);
1306
+ Entity.dispatchEvent(touchEvent.target, touchEvent);
1307
+ if (touchEvent._trackHandler) {
1308
+ return touchEvent._trackHandler;
1309
+ }
1310
+ } else {
1311
+ touchEvent.target = null;
1312
+ }
1313
+ for (let listener of Scene.activeScene._touchStartListeners) {
1314
+ listener(touchEvent);
1315
+ if (touchEvent._trackHandler) {
1316
+ return touchEvent._trackHandler;
1317
+ }
1318
+ }
1319
+ return null;
1320
+ };
1321
+ var onResizeEvents = [];
1322
+ var onResizeEvent = (width, height) => {
1323
+ for (let listener of onResizeEvents) {
1324
+ listener(width, height);
1325
+ }
1326
+ };
1327
+ function addEventListener(channel, callback) {
1328
+ if (channel === "resize") {
1329
+ onResizeEvents.push(callback);
1330
+ if (onResizeEvents.length === 1) {
1331
+ _creatorUI.registerResizeEvent(onResizeEvent);
1332
+ }
1333
+ }
1334
+ }
1335
+ function removeEventListener(channel, callback) {
1336
+ if (channel === "resize") {
1337
+ const index = onResizeEvents.indexOf(callback);
1338
+ if (index >= 0) {
1339
+ onResizeEvents.splice(index, 1);
1340
+ }
1341
+ }
1342
+ }
1343
+ var touchStartRegistered = false;
1344
+ var registerTouchStartEvent = () => {
1345
+ if (!touchStartRegistered) {
1346
+ _creatorUI.registerTouchStartEvent(onTouchStart);
1347
+ touchStartRegistered = true;
1348
+ }
1349
+ };
1350
+ var touchEndRegistered = false;
1351
+ var registerTouchEndEvent = () => {
1352
+ if (!touchEndRegistered) {
1353
+ _creatorUI.registerTouchEndEvent(onTouchEnd);
1354
+ touchEndRegistered = true;
1355
+ }
1356
+ };
1357
+
1358
+ export {
1359
+ getPosition,
1360
+ getScale,
1361
+ vec3Cross,
1362
+ normalizeInPlace,
1363
+ Component,
1364
+ fetch2 as fetch,
1365
+ fetchLocal,
1366
+ FormData,
1367
+ File,
1368
+ Texture,
1369
+ Material,
1370
+ LitMaterial,
1371
+ UnlitMaterial,
1372
+ VideoMaterial,
1373
+ ShadowMaterial,
1374
+ MeshGeometry,
1375
+ createCubeGeometry,
1376
+ createCylinderGeometry,
1377
+ createPlaneGeometry,
1378
+ createSphereGeometry,
1379
+ Mesh,
1380
+ createCubeMesh,
1381
+ createCylinderMesh,
1382
+ createPlaneMesh,
1383
+ createSphereMesh,
1384
+ entityMap,
1385
+ getEntityById,
1386
+ Entity,
1387
+ Ray,
1388
+ Camera,
1389
+ addEventListener,
1390
+ removeEventListener,
1391
+ registerTouchStartEvent,
1392
+ registerTouchEndEvent,
1393
+ Scene,
1394
+ ARScene
1395
+ };