@babylonjs/lite-compat 0.0.1-preview.54961

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,1460 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { setMeshVisible, resizeMeshGeometry, removeFromScene, createMeshFromData, setThinInstances, setThinInstanceColors, createExtrudeShape, createTube, createRibbon, createPolyhedron, createDisc, createTorusKnot, createTorus, createCylinder, createPlane, createGroundFromHeightMap, updateMeshUvs, createGround, createSphere, createBox, createTransformNode, addToScene, setParent } from "@babylonjs/lite";
5
+ class LiteCompatError extends Error {
6
+ constructor(api, detail) {
7
+ super(detail ? `'${api}' is not supported by the Babylon Lite compat layer. ${detail}` : `'${api}' is not supported by the Babylon Lite compat layer.`);
8
+ this.name = "LiteCompatError";
9
+ }
10
+ }
11
+ function unsupported(api, detail) {
12
+ throw new LiteCompatError(api, detail);
13
+ }
14
+ class Vector2 {
15
+ constructor(x = 0, y = 0) {
16
+ this.x = x;
17
+ this.y = y;
18
+ }
19
+ set(x, y) {
20
+ this.x = x;
21
+ this.y = y;
22
+ return this;
23
+ }
24
+ copyFrom(source) {
25
+ this.x = source.x;
26
+ this.y = source.y;
27
+ return this;
28
+ }
29
+ copyFromFloats(x, y) {
30
+ this.x = x;
31
+ this.y = y;
32
+ return this;
33
+ }
34
+ add(other) {
35
+ return new Vector2(this.x + other.x, this.y + other.y);
36
+ }
37
+ addInPlace(other) {
38
+ this.x += other.x;
39
+ this.y += other.y;
40
+ return this;
41
+ }
42
+ subtract(other) {
43
+ return new Vector2(this.x - other.x, this.y - other.y);
44
+ }
45
+ scale(scale) {
46
+ return new Vector2(this.x * scale, this.y * scale);
47
+ }
48
+ scaleInPlace(scale) {
49
+ this.x *= scale;
50
+ this.y *= scale;
51
+ return this;
52
+ }
53
+ length() {
54
+ return Math.sqrt(this.x * this.x + this.y * this.y);
55
+ }
56
+ lengthSquared() {
57
+ return this.x * this.x + this.y * this.y;
58
+ }
59
+ normalize() {
60
+ const len = this.length();
61
+ if (len !== 0) {
62
+ this.x /= len;
63
+ this.y /= len;
64
+ }
65
+ return this;
66
+ }
67
+ clone() {
68
+ return new Vector2(this.x, this.y);
69
+ }
70
+ equals(other) {
71
+ return this.x === other.x && this.y === other.y;
72
+ }
73
+ asArray() {
74
+ return [this.x, this.y];
75
+ }
76
+ static Zero() {
77
+ return new Vector2(0, 0);
78
+ }
79
+ static One() {
80
+ return new Vector2(1, 1);
81
+ }
82
+ static Dot(a, b) {
83
+ return a.x * b.x + a.y * b.y;
84
+ }
85
+ }
86
+ class Vector3 {
87
+ constructor(x = 0, y = 0, z = 0) {
88
+ this.x = x;
89
+ this.y = y;
90
+ this.z = z;
91
+ }
92
+ set(x, y, z) {
93
+ this.x = x;
94
+ this.y = y;
95
+ this.z = z;
96
+ return this;
97
+ }
98
+ setAll(value) {
99
+ this.x = this.y = this.z = value;
100
+ return this;
101
+ }
102
+ copyFrom(source) {
103
+ this.x = source.x;
104
+ this.y = source.y;
105
+ this.z = source.z;
106
+ return this;
107
+ }
108
+ copyFromFloats(x, y, z) {
109
+ this.x = x;
110
+ this.y = y;
111
+ this.z = z;
112
+ return this;
113
+ }
114
+ add(other) {
115
+ return new Vector3(this.x + other.x, this.y + other.y, this.z + other.z);
116
+ }
117
+ addInPlace(other) {
118
+ this.x += other.x;
119
+ this.y += other.y;
120
+ this.z += other.z;
121
+ return this;
122
+ }
123
+ addInPlaceFromFloats(x, y, z) {
124
+ this.x += x;
125
+ this.y += y;
126
+ this.z += z;
127
+ return this;
128
+ }
129
+ subtract(other) {
130
+ return new Vector3(this.x - other.x, this.y - other.y, this.z - other.z);
131
+ }
132
+ subtractInPlace(other) {
133
+ this.x -= other.x;
134
+ this.y -= other.y;
135
+ this.z -= other.z;
136
+ return this;
137
+ }
138
+ multiply(other) {
139
+ return new Vector3(this.x * other.x, this.y * other.y, this.z * other.z);
140
+ }
141
+ scale(scale) {
142
+ return new Vector3(this.x * scale, this.y * scale, this.z * scale);
143
+ }
144
+ scaleInPlace(scale) {
145
+ this.x *= scale;
146
+ this.y *= scale;
147
+ this.z *= scale;
148
+ return this;
149
+ }
150
+ negate() {
151
+ return new Vector3(-this.x, -this.y, -this.z);
152
+ }
153
+ length() {
154
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
155
+ }
156
+ lengthSquared() {
157
+ return this.x * this.x + this.y * this.y + this.z * this.z;
158
+ }
159
+ normalize() {
160
+ const len = this.length();
161
+ if (len !== 0) {
162
+ this.x /= len;
163
+ this.y /= len;
164
+ this.z /= len;
165
+ }
166
+ return this;
167
+ }
168
+ clone() {
169
+ return new Vector3(this.x, this.y, this.z);
170
+ }
171
+ equals(other) {
172
+ return this.x === other.x && this.y === other.y && this.z === other.z;
173
+ }
174
+ equalsWithEpsilon(other, epsilon = 1e-6) {
175
+ return Math.abs(this.x - other.x) <= epsilon && Math.abs(this.y - other.y) <= epsilon && Math.abs(this.z - other.z) <= epsilon;
176
+ }
177
+ asArray() {
178
+ return [this.x, this.y, this.z];
179
+ }
180
+ toArray(array, index = 0) {
181
+ array[index] = this.x;
182
+ array[index + 1] = this.y;
183
+ array[index + 2] = this.z;
184
+ return this;
185
+ }
186
+ static Zero() {
187
+ return new Vector3(0, 0, 0);
188
+ }
189
+ static One() {
190
+ return new Vector3(1, 1, 1);
191
+ }
192
+ static Up() {
193
+ return new Vector3(0, 1, 0);
194
+ }
195
+ static Down() {
196
+ return new Vector3(0, -1, 0);
197
+ }
198
+ static Forward() {
199
+ return new Vector3(0, 0, 1);
200
+ }
201
+ static Backward() {
202
+ return new Vector3(0, 0, -1);
203
+ }
204
+ static Right() {
205
+ return new Vector3(1, 0, 0);
206
+ }
207
+ static Left() {
208
+ return new Vector3(-1, 0, 0);
209
+ }
210
+ static FromArray(array, offset = 0) {
211
+ return new Vector3(array[offset] ?? 0, array[offset + 1] ?? 0, array[offset + 2] ?? 0);
212
+ }
213
+ static Dot(a, b) {
214
+ return a.x * b.x + a.y * b.y + a.z * b.z;
215
+ }
216
+ static Cross(a, b) {
217
+ return new Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
218
+ }
219
+ static Distance(a, b) {
220
+ return Math.sqrt(Vector3.DistanceSquared(a, b));
221
+ }
222
+ static DistanceSquared(a, b) {
223
+ const dx = a.x - b.x;
224
+ const dy = a.y - b.y;
225
+ const dz = a.z - b.z;
226
+ return dx * dx + dy * dy + dz * dz;
227
+ }
228
+ static Lerp(start, end, amount) {
229
+ return new Vector3(start.x + (end.x - start.x) * amount, start.y + (end.y - start.y) * amount, start.z + (end.z - start.z) * amount);
230
+ }
231
+ /** Midpoint between two vectors. */
232
+ static Center(a, b) {
233
+ return new Vector3((a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2);
234
+ }
235
+ /** Midpoint between two vectors, written into `ref`. */
236
+ static CenterToRef(a, b, ref) {
237
+ return ref.set((a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2);
238
+ }
239
+ static Normalize(vector) {
240
+ return vector.clone().normalize();
241
+ }
242
+ static Minimize(a, b) {
243
+ return new Vector3(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
244
+ }
245
+ static Maximize(a, b) {
246
+ return new Vector3(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
247
+ }
248
+ /** Transform a coordinate (point) by a matrix using the row-vector convention. */
249
+ static TransformCoordinates(vector, transformation) {
250
+ const m = transformation.m;
251
+ const x = vector.x;
252
+ const y = vector.y;
253
+ const z = vector.z;
254
+ const rx = x * m[0] + y * m[4] + z * m[8] + m[12];
255
+ const ry = x * m[1] + y * m[5] + z * m[9] + m[13];
256
+ const rz = x * m[2] + y * m[6] + z * m[10] + m[14];
257
+ const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);
258
+ return new Vector3(rx * rw, ry * rw, rz * rw);
259
+ }
260
+ /** Transform a direction (normal) by a matrix, ignoring translation. */
261
+ static TransformNormal(vector, transformation) {
262
+ const m = transformation.m;
263
+ const x = vector.x;
264
+ const y = vector.y;
265
+ const z = vector.z;
266
+ return new Vector3(x * m[0] + y * m[4] + z * m[8], x * m[1] + y * m[5] + z * m[9], x * m[2] + y * m[6] + z * m[10]);
267
+ }
268
+ }
269
+ class LiteBackedVector3 extends Vector3 {
270
+ constructor(lite) {
271
+ super(0, 0, 0);
272
+ Object.defineProperty(this, "x", { enumerable: true, configurable: true, get: () => lite.x, set: (v) => lite.x = v });
273
+ Object.defineProperty(this, "y", { enumerable: true, configurable: true, get: () => lite.y, set: (v) => lite.y = v });
274
+ Object.defineProperty(this, "z", { enumerable: true, configurable: true, get: () => lite.z, set: (v) => lite.z = v });
275
+ }
276
+ }
277
+ const _liteVec3Proxies = /* @__PURE__ */ new WeakMap();
278
+ function liteBackedVector3(lite) {
279
+ let proxy = _liteVec3Proxies.get(lite);
280
+ if (!proxy) {
281
+ proxy = new LiteBackedVector3(lite);
282
+ _liteVec3Proxies.set(lite, proxy);
283
+ }
284
+ return proxy;
285
+ }
286
+ class Vector4 {
287
+ constructor(x = 0, y = 0, z = 0, w = 0) {
288
+ this.x = x;
289
+ this.y = y;
290
+ this.z = z;
291
+ this.w = w;
292
+ }
293
+ set(x, y, z, w) {
294
+ this.x = x;
295
+ this.y = y;
296
+ this.z = z;
297
+ this.w = w;
298
+ return this;
299
+ }
300
+ copyFrom(source) {
301
+ this.x = source.x;
302
+ this.y = source.y;
303
+ this.z = source.z;
304
+ this.w = source.w;
305
+ return this;
306
+ }
307
+ add(other) {
308
+ return new Vector4(this.x + other.x, this.y + other.y, this.z + other.z, this.w + other.w);
309
+ }
310
+ scale(scale) {
311
+ return new Vector4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
312
+ }
313
+ length() {
314
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
315
+ }
316
+ clone() {
317
+ return new Vector4(this.x, this.y, this.z, this.w);
318
+ }
319
+ equals(other) {
320
+ return this.x === other.x && this.y === other.y && this.z === other.z && this.w === other.w;
321
+ }
322
+ asArray() {
323
+ return [this.x, this.y, this.z, this.w];
324
+ }
325
+ static Zero() {
326
+ return new Vector4(0, 0, 0, 0);
327
+ }
328
+ }
329
+ class Quaternion {
330
+ constructor(x = 0, y = 0, z = 0, w = 1) {
331
+ this.x = x;
332
+ this.y = y;
333
+ this.z = z;
334
+ this.w = w;
335
+ }
336
+ set(x, y, z, w) {
337
+ this.x = x;
338
+ this.y = y;
339
+ this.z = z;
340
+ this.w = w;
341
+ return this;
342
+ }
343
+ copyFrom(source) {
344
+ this.x = source.x;
345
+ this.y = source.y;
346
+ this.z = source.z;
347
+ this.w = source.w;
348
+ return this;
349
+ }
350
+ multiply(other) {
351
+ return new Quaternion(
352
+ other.w * this.x + other.x * this.w + other.y * this.z - other.z * this.y,
353
+ other.w * this.y - other.x * this.z + other.y * this.w + other.z * this.x,
354
+ other.w * this.z + other.x * this.y - other.y * this.x + other.z * this.w,
355
+ other.w * this.w - other.x * this.x - other.y * this.y - other.z * this.z
356
+ );
357
+ }
358
+ length() {
359
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
360
+ }
361
+ normalize() {
362
+ const len = this.length();
363
+ if (len !== 0) {
364
+ const inv = 1 / len;
365
+ this.x *= inv;
366
+ this.y *= inv;
367
+ this.z *= inv;
368
+ this.w *= inv;
369
+ }
370
+ return this;
371
+ }
372
+ conjugate() {
373
+ return new Quaternion(-this.x, -this.y, -this.z, this.w);
374
+ }
375
+ clone() {
376
+ return new Quaternion(this.x, this.y, this.z, this.w);
377
+ }
378
+ equals(other) {
379
+ return this.x === other.x && this.y === other.y && this.z === other.z && this.w === other.w;
380
+ }
381
+ asArray() {
382
+ return [this.x, this.y, this.z, this.w];
383
+ }
384
+ toEulerAngles() {
385
+ const result = new Vector3();
386
+ const qz = this.z;
387
+ const qx = this.x;
388
+ const qy = this.y;
389
+ const qw = this.w;
390
+ const sqw = qw * qw;
391
+ const sqz = qz * qz;
392
+ const sqx = qx * qx;
393
+ const sqy = qy * qy;
394
+ const zAxisY = qy * qz - qx * qw;
395
+ const limit = 0.4999999;
396
+ if (zAxisY < -limit) {
397
+ result.y = 2 * Math.atan2(qy, qw);
398
+ result.x = Math.PI / 2;
399
+ result.z = 0;
400
+ } else if (zAxisY > limit) {
401
+ result.y = 2 * Math.atan2(qy, qw);
402
+ result.x = -Math.PI / 2;
403
+ result.z = 0;
404
+ } else {
405
+ result.z = Math.atan2(2 * (qx * qy + qz * qw), -sqz - sqx + sqy + sqw);
406
+ result.x = Math.asin(-2 * (qz * qy - qx * qw));
407
+ result.y = Math.atan2(2 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);
408
+ }
409
+ return result;
410
+ }
411
+ static Identity() {
412
+ return new Quaternion(0, 0, 0, 1);
413
+ }
414
+ static FromEulerAngles(x, y, z) {
415
+ return Quaternion.RotationYawPitchRoll(y, x, z);
416
+ }
417
+ static RotationYawPitchRoll(yaw, pitch, roll) {
418
+ const halfRoll = roll * 0.5;
419
+ const halfPitch = pitch * 0.5;
420
+ const halfYaw = yaw * 0.5;
421
+ const sinRoll = Math.sin(halfRoll);
422
+ const cosRoll = Math.cos(halfRoll);
423
+ const sinPitch = Math.sin(halfPitch);
424
+ const cosPitch = Math.cos(halfPitch);
425
+ const sinYaw = Math.sin(halfYaw);
426
+ const cosYaw = Math.cos(halfYaw);
427
+ return new Quaternion(
428
+ cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll,
429
+ sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll,
430
+ cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll,
431
+ cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll
432
+ );
433
+ }
434
+ static RotationAxis(axis, angle) {
435
+ const sin = Math.sin(angle / 2);
436
+ const len = axis.length() || 1;
437
+ return new Quaternion(axis.x / len * sin, axis.y / len * sin, axis.z / len * sin, Math.cos(angle / 2));
438
+ }
439
+ static Slerp(left, right, amount) {
440
+ let num2;
441
+ let num3;
442
+ const num = amount;
443
+ let dot = left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
444
+ let flip = false;
445
+ if (dot < 0) {
446
+ flip = true;
447
+ dot = -dot;
448
+ }
449
+ if (dot > 0.999999) {
450
+ num3 = 1 - num;
451
+ num2 = flip ? -num : num;
452
+ } else {
453
+ const angle = Math.acos(dot);
454
+ const invSin = 1 / Math.sin(angle);
455
+ num3 = Math.sin((1 - num) * angle) * invSin;
456
+ num2 = flip ? -Math.sin(num * angle) * invSin : Math.sin(num * angle) * invSin;
457
+ }
458
+ return new Quaternion(num3 * left.x + num2 * right.x, num3 * left.y + num2 * right.y, num3 * left.z + num2 * right.z, num3 * left.w + num2 * right.w);
459
+ }
460
+ }
461
+ class Matrix {
462
+ constructor() {
463
+ __publicField(this, "m");
464
+ this.m = new Float32Array(16);
465
+ }
466
+ set(index, value) {
467
+ this.m[index] = value;
468
+ return this;
469
+ }
470
+ copyFrom(source) {
471
+ this.m.set(source.m);
472
+ return this;
473
+ }
474
+ clone() {
475
+ const result = new Matrix();
476
+ result.m.set(this.m);
477
+ return result;
478
+ }
479
+ asArray() {
480
+ return this.m;
481
+ }
482
+ toArray() {
483
+ return Array.from(this.m);
484
+ }
485
+ /** Babylon.js `Matrix.copyToArray` — copy the 16 elements into `array` at `offset`. */
486
+ copyToArray(array, offset = 0) {
487
+ for (let i = 0; i < 16; i++) {
488
+ array[offset + i] = this.m[i];
489
+ }
490
+ return this;
491
+ }
492
+ equals(other) {
493
+ for (let i = 0; i < 16; i++) {
494
+ if (this.m[i] !== other.m[i]) {
495
+ return false;
496
+ }
497
+ }
498
+ return true;
499
+ }
500
+ multiply(other) {
501
+ return Matrix.FromValues(...multiplyValues(this.m, other.m));
502
+ }
503
+ multiplyToRef(other, result) {
504
+ const values = multiplyValues(this.m, other.m);
505
+ result.m.set(values);
506
+ return result;
507
+ }
508
+ transpose() {
509
+ const a = this.m;
510
+ return Matrix.FromValues(a[0], a[4], a[8], a[12], a[1], a[5], a[9], a[13], a[2], a[6], a[10], a[14], a[3], a[7], a[11], a[15]);
511
+ }
512
+ determinant() {
513
+ return determinant(this.m);
514
+ }
515
+ invert() {
516
+ const result = new Matrix();
517
+ this.invertToRef(result);
518
+ return result;
519
+ }
520
+ invertToRef(result) {
521
+ const inv = invertValues(this.m);
522
+ result.m.set(inv);
523
+ return result;
524
+ }
525
+ getTranslation() {
526
+ return new Vector3(this.m[12], this.m[13], this.m[14]);
527
+ }
528
+ static FromValues(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
529
+ const result = new Matrix();
530
+ result.m.set([m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15]);
531
+ return result;
532
+ }
533
+ static FromArray(array, offset = 0) {
534
+ const result = new Matrix();
535
+ for (let i = 0; i < 16; i++) {
536
+ result.m[i] = array[offset + i] ?? 0;
537
+ }
538
+ return result;
539
+ }
540
+ static Identity() {
541
+ return Matrix.FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
542
+ }
543
+ static Zero() {
544
+ return new Matrix();
545
+ }
546
+ static Translation(x, y, z) {
547
+ return Matrix.FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1);
548
+ }
549
+ static Scaling(x, y, z) {
550
+ return Matrix.FromValues(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
551
+ }
552
+ static RotationX(angle) {
553
+ const s = Math.sin(angle);
554
+ const c = Math.cos(angle);
555
+ return Matrix.FromValues(1, 0, 0, 0, 0, c, s, 0, 0, -s, c, 0, 0, 0, 0, 1);
556
+ }
557
+ static RotationY(angle) {
558
+ const s = Math.sin(angle);
559
+ const c = Math.cos(angle);
560
+ return Matrix.FromValues(c, 0, -s, 0, 0, 1, 0, 0, s, 0, c, 0, 0, 0, 0, 1);
561
+ }
562
+ static RotationZ(angle) {
563
+ const s = Math.sin(angle);
564
+ const c = Math.cos(angle);
565
+ return Matrix.FromValues(c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
566
+ }
567
+ /** Babylon.js `Matrix.LookAtLH(eye, target, up)` — left-handed view matrix. */
568
+ static LookAtLH(eye, target, up) {
569
+ let zx = target.x - eye.x, zy = target.y - eye.y, zz = target.z - eye.z;
570
+ const zl = Math.hypot(zx, zy, zz) || 1;
571
+ zx /= zl;
572
+ zy /= zl;
573
+ zz /= zl;
574
+ let xx = up.y * zz - up.z * zy, xy = up.z * zx - up.x * zz, xz = up.x * zy - up.y * zx;
575
+ const xl = Math.hypot(xx, xy, xz) || 1;
576
+ xx /= xl;
577
+ xy /= xl;
578
+ xz /= xl;
579
+ const yx = zy * xz - zz * xy, yy = zz * xx - zx * xz, yz = zx * xy - zy * xx;
580
+ const ex = -(xx * eye.x + xy * eye.y + xz * eye.z);
581
+ const ey = -(yx * eye.x + yy * eye.y + yz * eye.z);
582
+ const ez = -(zx * eye.x + zy * eye.y + zz * eye.z);
583
+ return Matrix.FromValues(xx, yx, zx, 0, xy, yy, zy, 0, xz, yz, zz, 0, ex, ey, ez, 1);
584
+ }
585
+ /** Babylon.js `Matrix.OrthoOffCenterLH(left, right, bottom, top, znear, zfar, halfZRange?)` — LH ortho projection. */
586
+ static OrthoOffCenterLH(left, right, bottom, top, znear, zfar, _halfZRange) {
587
+ const a = 2 / (right - left);
588
+ const b = 2 / (top - bottom);
589
+ const c = 1 / (zfar - znear);
590
+ const tx = (left + right) / (left - right);
591
+ const ty = (top + bottom) / (bottom - top);
592
+ const tz = -znear * c;
593
+ return Matrix.FromValues(a, 0, 0, 0, 0, b, 0, 0, 0, 0, c, 0, tx, ty, tz, 1);
594
+ }
595
+ /**
596
+ * Babylon.js `Matrix.Compose(scale, rotation, translation)` — build a TRS matrix
597
+ * from a scale vector, a rotation quaternion, and a translation vector (row-vector
598
+ * convention, translation in elements 12/13/14).
599
+ */
600
+ static Compose(scale, rotation, translation) {
601
+ const { x, y, z, w } = rotation;
602
+ const x2 = x + x, y2 = y + y, z2 = z + z;
603
+ const xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2, wx = w * x2, wy = w * y2, wz = w * z2;
604
+ const sx = scale.x, sy = scale.y, sz = scale.z;
605
+ return Matrix.FromValues(
606
+ (1 - (yy + zz)) * sx,
607
+ (xy + wz) * sx,
608
+ (xz - wy) * sx,
609
+ 0,
610
+ (xy - wz) * sy,
611
+ (1 - (xx + zz)) * sy,
612
+ (yz + wx) * sy,
613
+ 0,
614
+ (xz + wy) * sz,
615
+ (yz - wx) * sz,
616
+ (1 - (xx + yy)) * sz,
617
+ 0,
618
+ translation.x,
619
+ translation.y,
620
+ translation.z,
621
+ 1
622
+ );
623
+ }
624
+ /** Babylon.js `Matrix.markAsUpdated()` — Lite has no per-matrix dirty flag; no-op for parity. */
625
+ markAsUpdated() {
626
+ return this;
627
+ }
628
+ }
629
+ function multiplyValues(a, b) {
630
+ const result = new Array(16);
631
+ for (let r = 0; r < 4; r++) {
632
+ for (let c = 0; c < 4; c++) {
633
+ result[r * 4 + c] = a[r * 4] * b[c] + a[r * 4 + 1] * b[4 + c] + a[r * 4 + 2] * b[8 + c] + a[r * 4 + 3] * b[12 + c];
634
+ }
635
+ }
636
+ return result;
637
+ }
638
+ function determinant(m) {
639
+ const m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3];
640
+ const m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7];
641
+ const m20 = m[8], m21 = m[9], m22 = m[10], m23 = m[11];
642
+ const m30 = m[12], m31 = m[13], m32 = m[14], m33 = m[15];
643
+ const b00 = m00 * m11 - m01 * m10;
644
+ const b01 = m00 * m12 - m02 * m10;
645
+ const b02 = m00 * m13 - m03 * m10;
646
+ const b03 = m01 * m12 - m02 * m11;
647
+ const b04 = m01 * m13 - m03 * m11;
648
+ const b05 = m02 * m13 - m03 * m12;
649
+ const b06 = m20 * m31 - m21 * m30;
650
+ const b07 = m20 * m32 - m22 * m30;
651
+ const b08 = m20 * m33 - m23 * m30;
652
+ const b09 = m21 * m32 - m22 * m31;
653
+ const b10 = m21 * m33 - m23 * m31;
654
+ const b11 = m22 * m33 - m23 * m32;
655
+ return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
656
+ }
657
+ function invertValues(m) {
658
+ const m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3];
659
+ const m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7];
660
+ const m20 = m[8], m21 = m[9], m22 = m[10], m23 = m[11];
661
+ const m30 = m[12], m31 = m[13], m32 = m[14], m33 = m[15];
662
+ const b00 = m00 * m11 - m01 * m10;
663
+ const b01 = m00 * m12 - m02 * m10;
664
+ const b02 = m00 * m13 - m03 * m10;
665
+ const b03 = m01 * m12 - m02 * m11;
666
+ const b04 = m01 * m13 - m03 * m11;
667
+ const b05 = m02 * m13 - m03 * m12;
668
+ const b06 = m20 * m31 - m21 * m30;
669
+ const b07 = m20 * m32 - m22 * m30;
670
+ const b08 = m20 * m33 - m23 * m30;
671
+ const b09 = m21 * m32 - m22 * m31;
672
+ const b10 = m21 * m33 - m23 * m31;
673
+ const b11 = m22 * m33 - m23 * m32;
674
+ const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
675
+ if (det === 0) {
676
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
677
+ }
678
+ const invDet = 1 / det;
679
+ return [
680
+ (m11 * b11 - m12 * b10 + m13 * b09) * invDet,
681
+ (m02 * b10 - m01 * b11 - m03 * b09) * invDet,
682
+ (m31 * b05 - m32 * b04 + m33 * b03) * invDet,
683
+ (m22 * b04 - m21 * b05 - m23 * b03) * invDet,
684
+ (m12 * b08 - m10 * b11 - m13 * b07) * invDet,
685
+ (m00 * b11 - m02 * b08 + m03 * b07) * invDet,
686
+ (m32 * b02 - m30 * b05 - m33 * b01) * invDet,
687
+ (m20 * b05 - m22 * b02 + m23 * b01) * invDet,
688
+ (m10 * b10 - m11 * b08 + m13 * b06) * invDet,
689
+ (m01 * b08 - m00 * b10 - m03 * b06) * invDet,
690
+ (m30 * b04 - m31 * b02 + m33 * b00) * invDet,
691
+ (m21 * b02 - m20 * b04 - m23 * b00) * invDet,
692
+ (m11 * b07 - m10 * b09 - m12 * b06) * invDet,
693
+ (m00 * b09 - m01 * b07 + m02 * b06) * invDet,
694
+ (m31 * b01 - m30 * b03 - m32 * b00) * invDet,
695
+ (m20 * b03 - m21 * b01 + m22 * b00) * invDet
696
+ ];
697
+ }
698
+ function transformCoordinates(vector, transformation) {
699
+ const m = transformation.m;
700
+ const x = vector.x;
701
+ const y = vector.y;
702
+ const z = vector.z;
703
+ const rx = x * m[0] + y * m[4] + z * m[8] + m[12];
704
+ const ry = x * m[1] + y * m[5] + z * m[9] + m[13];
705
+ const rz = x * m[2] + y * m[6] + z * m[10] + m[14];
706
+ const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);
707
+ return new Vector3(rx * rw, ry * rw, rz * rw);
708
+ }
709
+ function transformNormal(vector, transformation) {
710
+ const m = transformation.m;
711
+ const x = vector.x;
712
+ const y = vector.y;
713
+ const z = vector.z;
714
+ return new Vector3(x * m[0] + y * m[4] + z * m[8], x * m[1] + y * m[5] + z * m[9], x * m[2] + y * m[6] + z * m[10]);
715
+ }
716
+ let _uniqueIdCounter = 0;
717
+ class Node {
718
+ constructor(name, scene) {
719
+ __publicField(this, "name");
720
+ /** String id. Defaults to the name (Babylon.js parity). */
721
+ __publicField(this, "id");
722
+ /** Process-unique numeric id, assigned at construction. */
723
+ __publicField(this, "uniqueId");
724
+ /** Free-form user data slot (Babylon.js `Node.metadata`). */
725
+ __publicField(this, "metadata", null);
726
+ /** @internal Owning compat scene, when constructed against one. */
727
+ __publicField(this, "_scene");
728
+ /** @internal */
729
+ __publicField(this, "_parent", null);
730
+ /** @internal Direct children, maintained as `parent` / `setParent` links change. */
731
+ __publicField(this, "_children", []);
732
+ /** @internal */
733
+ __publicField(this, "_enabled", true);
734
+ /** @internal */
735
+ __publicField(this, "_disposed", false);
736
+ this.name = name;
737
+ this.id = name;
738
+ this.uniqueId = ++_uniqueIdCounter;
739
+ this._scene = scene;
740
+ }
741
+ /** The runtime class name (overridden by each subclass). */
742
+ getClassName() {
743
+ return "Node";
744
+ }
745
+ /** The scene this node belongs to, if any. */
746
+ getScene() {
747
+ return this._scene;
748
+ }
749
+ /** The engine backing this node's scene, if any. */
750
+ getEngine() {
751
+ var _a;
752
+ return (_a = this._scene) == null ? void 0 : _a.getEngine();
753
+ }
754
+ get parent() {
755
+ return this._parent;
756
+ }
757
+ set parent(value) {
758
+ this._linkParent(value);
759
+ this._applyParent(value);
760
+ }
761
+ /**
762
+ * @internal Update the parent link and both nodes' child registries. Shared by
763
+ * the `parent` setter and `TransformNode.setParent` (which differ only in how
764
+ * the Lite-side transform is reparented, handled by their own callers).
765
+ */
766
+ _linkParent(value) {
767
+ if (this._parent === value) {
768
+ return;
769
+ }
770
+ if (this._parent) {
771
+ const i = this._parent._children.indexOf(this);
772
+ if (i !== -1) {
773
+ this._parent._children.splice(i, 1);
774
+ }
775
+ }
776
+ this._parent = value;
777
+ if (value && !value._children.includes(this)) {
778
+ value._children.push(this);
779
+ }
780
+ }
781
+ /** @internal Whether this node is an `AbstractMesh` (overridden there) — drives `getChildMeshes`. */
782
+ _isMeshNode() {
783
+ return false;
784
+ }
785
+ /**
786
+ * Babylon.js `node.getDescendants(directDescendantsOnly?, predicate?)` — the
787
+ * nodes parented (directly or transitively) under this one, optionally filtered.
788
+ */
789
+ getDescendants(directDescendantsOnly = false, predicate) {
790
+ const results = [];
791
+ const collect = (node) => {
792
+ for (const child of node._children) {
793
+ if (!predicate || predicate(child)) {
794
+ results.push(child);
795
+ }
796
+ if (!directDescendantsOnly) {
797
+ collect(child);
798
+ }
799
+ }
800
+ };
801
+ collect(this);
802
+ return results;
803
+ }
804
+ /**
805
+ * Babylon.js `node.getChildren(predicate?, directDescendantsOnly?)` — descendant
806
+ * nodes (direct children by default), optionally filtered by a predicate.
807
+ */
808
+ getChildren(predicate, directDescendantsOnly = true) {
809
+ return this.getDescendants(directDescendantsOnly, predicate);
810
+ }
811
+ /**
812
+ * Babylon.js `node.getChildMeshes(directDescendantsOnly?, predicate?)` — the
813
+ * descendant nodes that are meshes (all descendants by default).
814
+ */
815
+ getChildMeshes(directDescendantsOnly = false, predicate) {
816
+ return this.getDescendants(directDescendantsOnly, (node) => node._isMeshNode() && (!predicate || predicate(node)));
817
+ }
818
+ isEnabled() {
819
+ return this._enabled;
820
+ }
821
+ setEnabled(value) {
822
+ this._enabled = value;
823
+ }
824
+ isDisposed() {
825
+ return this._disposed;
826
+ }
827
+ dispose() {
828
+ var _a;
829
+ this._disposed = true;
830
+ this._linkParent(null);
831
+ (_a = this._scene) == null ? void 0 : _a._unregisterNode(this);
832
+ }
833
+ /** @internal Hook for subclasses to wire the parent link into the Lite scene graph. */
834
+ _applyParent(_parent) {
835
+ }
836
+ }
837
+ function isCompatScene(value) {
838
+ return typeof value.getEngine === "function";
839
+ }
840
+ function liteNodeOf(node) {
841
+ if (!node) {
842
+ return null;
843
+ }
844
+ const n = node;
845
+ return n._node ?? n._lite ?? null;
846
+ }
847
+ const PLACEHOLDER_POSITIONS = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0]);
848
+ const PLACEHOLDER_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1]);
849
+ const PLACEHOLDER_UVS = new Float32Array([0, 0, 0, 0, 0, 0]);
850
+ const PLACEHOLDER_INDICES = new Uint32Array([0, 1, 2]);
851
+ function toF32(data) {
852
+ return data instanceof Float32Array ? data : Float32Array.from(data);
853
+ }
854
+ function toU32(data) {
855
+ return data instanceof Uint32Array ? data : Uint32Array.from(data);
856
+ }
857
+ function computeFlatNormals(positions, indices) {
858
+ const normals = new Float32Array(positions.length);
859
+ for (let i = 0; i < indices.length; i += 3) {
860
+ const a = indices[i] * 3;
861
+ const b = indices[i + 1] * 3;
862
+ const c = indices[i + 2] * 3;
863
+ const ux = positions[b] - positions[a];
864
+ const uy = positions[b + 1] - positions[a + 1];
865
+ const uz = positions[b + 2] - positions[a + 2];
866
+ const vx = positions[c] - positions[a];
867
+ const vy = positions[c + 1] - positions[a + 1];
868
+ const vz = positions[c + 2] - positions[a + 2];
869
+ let nx = uy * vz - uz * vy;
870
+ let ny = uz * vx - ux * vz;
871
+ let nz = ux * vy - uy * vx;
872
+ const len = Math.hypot(nx, ny, nz) || 1;
873
+ nx /= len;
874
+ ny /= len;
875
+ nz /= len;
876
+ for (const vi of [a, b, c]) {
877
+ normals[vi] = nx;
878
+ normals[vi + 1] = ny;
879
+ normals[vi + 2] = nz;
880
+ }
881
+ }
882
+ return normals;
883
+ }
884
+ class TransformNode extends Node {
885
+ constructor(name, scene, liteNode) {
886
+ super(name, scene);
887
+ /** @internal The Lite scene node that carries this transform. */
888
+ __publicField(this, "_node");
889
+ /** @internal Whether `rotationQuaternion` was explicitly set (Babylon.js returns null otherwise). */
890
+ __publicField(this, "_useQuat", false);
891
+ if (liteNode) {
892
+ this._node = liteNode;
893
+ } else {
894
+ this._node = createTransformNode(name);
895
+ if (scene) {
896
+ addToScene(scene._lite, this._node);
897
+ }
898
+ }
899
+ }
900
+ getClassName() {
901
+ return "TransformNode";
902
+ }
903
+ get position() {
904
+ return liteBackedVector3(this._node.position);
905
+ }
906
+ set position(value) {
907
+ this._node.position.set(value.x, value.y, value.z);
908
+ }
909
+ get rotation() {
910
+ return liteBackedVector3(this._node.rotation);
911
+ }
912
+ set rotation(value) {
913
+ this._node.rotation.set(value.x, value.y, value.z);
914
+ }
915
+ get scaling() {
916
+ return liteBackedVector3(this._node.scaling);
917
+ }
918
+ set scaling(value) {
919
+ this._node.scaling.set(value.x, value.y, value.z);
920
+ }
921
+ /**
922
+ * Babylon.js `rotationQuaternion`. Babylon Lite always drives a node's world
923
+ * matrix from a quaternion (its euler `rotation` is a proxy over the same
924
+ * quaternion), so this reads/writes that quaternion. Returns `null` until
925
+ * explicitly assigned, matching Babylon.js's euler-by-default convention.
926
+ */
927
+ get rotationQuaternion() {
928
+ if (!this._useQuat) {
929
+ return null;
930
+ }
931
+ const q = this._node.rotationQuaternion;
932
+ return new Quaternion(q.x, q.y, q.z, q.w);
933
+ }
934
+ set rotationQuaternion(value) {
935
+ if (value) {
936
+ this._useQuat = true;
937
+ this._node.rotationQuaternion.set(value.x, value.y, value.z, value.w);
938
+ } else {
939
+ this._useQuat = false;
940
+ }
941
+ }
942
+ /**
943
+ * Babylon.js `setParent(node)` — reparent while **preserving world position**
944
+ * (the child's local transform is recomputed). Distinct from the `parent`
945
+ * setter, which keeps the local transform and lets the world move.
946
+ */
947
+ setParent(parent) {
948
+ this._linkParent(parent);
949
+ setParent(this._node, liteNodeOf(parent));
950
+ return this;
951
+ }
952
+ _applyParent(parent) {
953
+ this._node.parent = liteNodeOf(parent);
954
+ }
955
+ }
956
+ class AbstractMesh extends TransformNode {
957
+ constructor(name, lite, scene) {
958
+ super(name, scene, lite);
959
+ /** @internal Underlying Babylon Lite mesh. */
960
+ __publicField(this, "_lite");
961
+ __publicField(this, "_material", null);
962
+ __publicField(this, "_visible", true);
963
+ /** @internal Retained tangent/color buffers so successive `setVerticesData` calls keep both. */
964
+ __publicField(this, "_lastTangents");
965
+ __publicField(this, "_lastColors");
966
+ this._lite = lite;
967
+ this._lite.name = name;
968
+ if (scene) {
969
+ this.material = scene.defaultMaterial;
970
+ }
971
+ }
972
+ getClassName() {
973
+ return "AbstractMesh";
974
+ }
975
+ /** @internal An `AbstractMesh` counts as a mesh node for `getChildMeshes`. */
976
+ _isMeshNode() {
977
+ return true;
978
+ }
979
+ get material() {
980
+ return this._material;
981
+ }
982
+ set material(value) {
983
+ this._material = value;
984
+ if (value == null ? void 0 : value._lite) {
985
+ this._lite.material = value._lite;
986
+ }
987
+ }
988
+ get isVisible() {
989
+ return this._visible;
990
+ }
991
+ set isVisible(value) {
992
+ this._visible = value;
993
+ setMeshVisible(this._lite, value);
994
+ }
995
+ get receiveShadows() {
996
+ return this._lite.receiveShadows;
997
+ }
998
+ set receiveShadows(value) {
999
+ this._lite.receiveShadows = value;
1000
+ }
1001
+ setEnabled(enabled) {
1002
+ super.setEnabled(enabled);
1003
+ this.isVisible = enabled;
1004
+ }
1005
+ /** Bounding info accessor — needs a public Lite bounds accessor that does not yet exist. */
1006
+ getBoundingInfo() {
1007
+ return unsupported("AbstractMesh.getBoundingInfo", "Babylon Lite does not expose a public mesh bounding-info accessor yet.");
1008
+ }
1009
+ /**
1010
+ * Babylon.js `mesh.getVerticesData(kind)` — read back the CPU geometry buffer
1011
+ * for `position` / `normal` / `uv`. Babylon Lite retains these on the mesh
1012
+ * (for picking + device-loss recovery); other kinds are not stored.
1013
+ */
1014
+ getVerticesData(kind) {
1015
+ switch (kind) {
1016
+ case "position":
1017
+ return this._lite._cpuPositions ?? null;
1018
+ case "normal":
1019
+ return this._lite._cpuNormals ?? null;
1020
+ case "uv":
1021
+ return this._lite._cpuUvs ?? null;
1022
+ default:
1023
+ return null;
1024
+ }
1025
+ }
1026
+ /**
1027
+ * Babylon.js `mesh.setVerticesData(kind, data)` — replace a vertex attribute.
1028
+ * `position` / `normal` / `uv` / `color` / `tangent` re-upload the geometry in
1029
+ * place; the last-set `color`/`tangent` buffers are retained so successive calls
1030
+ * (e.g. set tangent then set color) keep both. Skinning/morph attributes
1031
+ * (`matricesIndices`, etc.) are accepted but not applied (Babylon Lite drives
1032
+ * skinning through its own loaded-skeleton path).
1033
+ */
1034
+ setVerticesData(kind, data, _updatable) {
1035
+ var _a;
1036
+ const engine = (_a = this._scene) == null ? void 0 : _a.getEngine()._lite;
1037
+ const lite = this._lite;
1038
+ if (!engine || !lite._cpuPositions || !lite._cpuIndices) {
1039
+ return;
1040
+ }
1041
+ if (kind !== "position" && kind !== "normal" && kind !== "uv" && kind !== "color" && kind !== "tangent") {
1042
+ return;
1043
+ }
1044
+ const f32 = data instanceof Float32Array ? data : Float32Array.from(data);
1045
+ if (kind === "color") {
1046
+ this._lastColors = f32;
1047
+ }
1048
+ if (kind === "tangent") {
1049
+ this._lastTangents = f32;
1050
+ }
1051
+ const positions = kind === "position" ? f32 : lite._cpuPositions;
1052
+ const normals = kind === "normal" ? f32 : lite._cpuNormals ?? computeFlatNormals(positions, lite._cpuIndices);
1053
+ const uvs = kind === "uv" ? f32 : lite._cpuUvs;
1054
+ resizeMeshGeometry(engine, this._lite, positions, normals, lite._cpuIndices, uvs, void 0, this._lastTangents, this._lastColors);
1055
+ }
1056
+ /** Babylon.js `mesh.getTotalVertices()` — vertex count from the position buffer. */
1057
+ getTotalVertices() {
1058
+ const positions = this._lite._cpuPositions;
1059
+ return positions ? positions.length / 3 : 0;
1060
+ }
1061
+ /**
1062
+ * Babylon.js `mesh.refreshBoundingInfo()` — Babylon Lite recomputes a mesh's
1063
+ * bounds from its CPU geometry on demand (and on geometry upload), so this is a
1064
+ * no-op that returns the mesh for chaining. The deformed-pick options
1065
+ * (`applySkeleton` / `applyMorph`) are accepted for parity but not used.
1066
+ */
1067
+ refreshBoundingInfo(_options) {
1068
+ return this;
1069
+ }
1070
+ /**
1071
+ * Babylon.js `mesh.bakeCurrentTransformIntoVertices()` — fold the node's local
1072
+ * transform (position / rotation / scaling) into the CPU geometry and reset the
1073
+ * transform to identity. Babylon Lite has no built-in mesh-transform bake, so we
1074
+ * transform the retained CPU positions (full matrix) and normals (rotation only,
1075
+ * renormalized), re-upload via `resizeMeshGeometry`, then clear the transform.
1076
+ */
1077
+ bakeCurrentTransformIntoVertices() {
1078
+ var _a;
1079
+ const engine = (_a = this._scene) == null ? void 0 : _a.getEngine()._lite;
1080
+ const lite = this._lite;
1081
+ const positions = lite._cpuPositions;
1082
+ const indices = lite._cpuIndices;
1083
+ if (!engine || !positions || !indices) {
1084
+ return this;
1085
+ }
1086
+ const node = this._node;
1087
+ const s = node.scaling;
1088
+ const q = node.rotationQuaternion;
1089
+ const t = node.position;
1090
+ const matrix = Matrix.Compose(liteBackedVector3(s), { x: q.x, y: q.y, z: q.z, w: q.w }, liteBackedVector3(t));
1091
+ const m = matrix.m;
1092
+ const newPositions = new Float32Array(positions.length);
1093
+ for (let i = 0; i < positions.length; i += 3) {
1094
+ const x = positions[i], y = positions[i + 1], z = positions[i + 2];
1095
+ newPositions[i] = x * m[0] + y * m[4] + z * m[8] + m[12];
1096
+ newPositions[i + 1] = x * m[1] + y * m[5] + z * m[9] + m[13];
1097
+ newPositions[i + 2] = x * m[2] + y * m[6] + z * m[10] + m[14];
1098
+ }
1099
+ let newNormals;
1100
+ const normals = lite._cpuNormals;
1101
+ if (normals) {
1102
+ newNormals = new Float32Array(normals.length);
1103
+ for (let i = 0; i < normals.length; i += 3) {
1104
+ const x = normals[i], y = normals[i + 1], z = normals[i + 2];
1105
+ let nx = x * m[0] + y * m[4] + z * m[8];
1106
+ let ny = x * m[1] + y * m[5] + z * m[9];
1107
+ let nz = x * m[2] + y * m[6] + z * m[10];
1108
+ const len = Math.hypot(nx, ny, nz) || 1;
1109
+ nx /= len;
1110
+ ny /= len;
1111
+ nz /= len;
1112
+ newNormals[i] = nx;
1113
+ newNormals[i + 1] = ny;
1114
+ newNormals[i + 2] = nz;
1115
+ }
1116
+ } else {
1117
+ newNormals = computeFlatNormals(newPositions, indices);
1118
+ }
1119
+ resizeMeshGeometry(engine, this._lite, newPositions, newNormals, indices, lite._cpuUvs);
1120
+ node.position.set(0, 0, 0);
1121
+ node.rotation.set(0, 0, 0);
1122
+ node.scaling.set(1, 1, 1);
1123
+ return this;
1124
+ }
1125
+ dispose() {
1126
+ if (this._scene) {
1127
+ removeFromScene(this._scene._lite, this._lite);
1128
+ }
1129
+ super.dispose();
1130
+ }
1131
+ }
1132
+ class Mesh extends AbstractMesh {
1133
+ constructor(name, sceneOrLite, scene) {
1134
+ var __super = (...args) => {
1135
+ super(...args);
1136
+ __publicField(this, "_morphTargetManager", null);
1137
+ return this;
1138
+ };
1139
+ if (sceneOrLite !== void 0 && isCompatScene(sceneOrLite)) {
1140
+ const realScene = sceneOrLite;
1141
+ const lite = createMeshFromData(realScene.getEngine()._lite, name, PLACEHOLDER_POSITIONS, PLACEHOLDER_NORMALS, PLACEHOLDER_INDICES, PLACEHOLDER_UVS);
1142
+ __super(name, lite, realScene);
1143
+ addPrimitive(this, realScene);
1144
+ } else {
1145
+ __super(name, sceneOrLite, scene);
1146
+ }
1147
+ }
1148
+ getClassName() {
1149
+ return "Mesh";
1150
+ }
1151
+ /**
1152
+ * Babylon.js `mesh.morphTargetManager`. Babylon Lite builds morph GPU data via
1153
+ * `createMorphTargets` and stores it on the Lite mesh; the compat manager is
1154
+ * registered with the scene so the engine builds it at start (once the base
1155
+ * CPU geometry exists) and assigns it onto the Lite mesh before registration.
1156
+ */
1157
+ get morphTargetManager() {
1158
+ return this._morphTargetManager;
1159
+ }
1160
+ set morphTargetManager(value) {
1161
+ this._morphTargetManager = value;
1162
+ if (value && this._scene) {
1163
+ this._scene._registerMorphTargetManager(this, value);
1164
+ }
1165
+ }
1166
+ // ── Legacy pre-MeshBuilder static creators (Babylon.js `Mesh.CreateX`) ──
1167
+ /** Legacy `Mesh.CreateSphere(name, segments, diameter, scene)`. */
1168
+ static CreateSphere(name, segments, diameter, scene) {
1169
+ return MeshBuilder.CreateSphere(name, { segments, diameter }, scene);
1170
+ }
1171
+ /** Legacy `Mesh.CreateBox(name, size, scene)`. */
1172
+ static CreateBox(name, size, scene) {
1173
+ return MeshBuilder.CreateBox(name, { size }, scene);
1174
+ }
1175
+ /** Legacy `Mesh.CreateGround(name, width, height, subdivisions, scene)`. */
1176
+ static CreateGround(name, width, height, subdivisions, scene) {
1177
+ return MeshBuilder.CreateGround(name, { width, height, subdivisions }, scene);
1178
+ }
1179
+ /** Legacy `Mesh.CreatePlane(name, size, scene)`. */
1180
+ static CreatePlane(name, size, scene) {
1181
+ return MeshBuilder.CreatePlane(name, { size }, scene);
1182
+ }
1183
+ /** Legacy `Mesh.CreateCylinder(name, height, diameterTop, diameterBottom, tessellation, _subdivisions, scene)`. */
1184
+ static CreateCylinder(name, height, diameterTop, diameterBottom, tessellation, _subdivisions, scene) {
1185
+ const diameter = Math.max(diameterTop, diameterBottom);
1186
+ return MeshBuilder.CreateCylinder(name, { height, diameter, tessellation }, scene);
1187
+ }
1188
+ /** Legacy `Mesh.CreateTorus(name, diameter, thickness, tessellation, scene)`. */
1189
+ static CreateTorus(name, diameter, thickness, tessellation, scene) {
1190
+ return MeshBuilder.CreateTorus(name, { diameter, thickness, tessellation }, scene);
1191
+ }
1192
+ /** Hardware-instanced copy — unsupported. Use native thin instances instead. */
1193
+ createInstance() {
1194
+ return unsupported("Mesh.createInstance", "Babylon Lite has no hardware-instance object. Use the native thin-instance API (`setThinInstances`).");
1195
+ }
1196
+ /**
1197
+ * Babylon.js `mesh.thinInstanceSetBuffer(kind, buffer, stride)`. Maps the
1198
+ * `"matrix"` and `"color"` instance buffers onto Babylon Lite's thin-instance
1199
+ * API. Applied immediately to the Lite mesh (before the scene builds).
1200
+ */
1201
+ thinInstanceSetBuffer(kind, buffer, _stride = 16) {
1202
+ if (!buffer) {
1203
+ return;
1204
+ }
1205
+ if (kind === "matrix") {
1206
+ setThinInstances(this._lite, buffer, buffer.length / 16);
1207
+ } else if (kind === "color") {
1208
+ setThinInstanceColors(this._lite, buffer);
1209
+ }
1210
+ }
1211
+ /** Deep mesh clone — not yet wrapped. */
1212
+ clone() {
1213
+ return unsupported("Mesh.clone", "Mesh cloning is not yet wrapped in the compat layer.");
1214
+ }
1215
+ /** Level-of-detail — unsupported (no LOD system in Babylon Lite). */
1216
+ addLODLevel() {
1217
+ return unsupported("Mesh.addLODLevel", "Level-of-detail is not implemented in Babylon Lite.");
1218
+ }
1219
+ }
1220
+ class GroundMesh extends Mesh {
1221
+ getClassName() {
1222
+ return "GroundMesh";
1223
+ }
1224
+ /** CPU height-at-coordinates query — needs a CPU heightmap accessor not present in Babylon Lite. */
1225
+ getHeightAtCoordinates() {
1226
+ return unsupported("GroundMesh.getHeightAtCoordinates", "CPU height queries are not implemented in Babylon Lite.");
1227
+ }
1228
+ }
1229
+ class InstancedMesh {
1230
+ constructor() {
1231
+ unsupported("InstancedMesh", "Babylon Lite has no hardware-instance object. Use the native thin-instance API (`setThinInstances`).");
1232
+ }
1233
+ }
1234
+ const VertexBuffer = {
1235
+ PositionKind: "position",
1236
+ NormalKind: "normal",
1237
+ TangentKind: "tangent",
1238
+ UVKind: "uv",
1239
+ UV2Kind: "uv2",
1240
+ ColorKind: "color",
1241
+ MatricesIndicesKind: "matricesIndices",
1242
+ MatricesWeightsKind: "matricesWeights"
1243
+ };
1244
+ class VertexData {
1245
+ constructor() {
1246
+ __publicField(this, "positions", null);
1247
+ __publicField(this, "normals", null);
1248
+ __publicField(this, "uvs", null);
1249
+ __publicField(this, "colors", null);
1250
+ __publicField(this, "indices", null);
1251
+ }
1252
+ /**
1253
+ * Babylon.js `VertexData.applyToMesh(mesh)` — upload this CPU geometry onto a
1254
+ * mesh (typically one created via `new Mesh(name, scene)`). Replaces the Lite
1255
+ * mesh's geometry in place via `resizeMeshGeometry`. Normals are computed flat
1256
+ * if omitted (Babylon Lite requires a normals buffer).
1257
+ */
1258
+ applyToMesh(mesh) {
1259
+ if (!this.positions || !this.indices) {
1260
+ return;
1261
+ }
1262
+ const scene = mesh.getScene();
1263
+ if (!scene) {
1264
+ return;
1265
+ }
1266
+ const engine = scene.getEngine()._lite;
1267
+ const positions = toF32(this.positions);
1268
+ const indices = toU32(this.indices);
1269
+ const normals = this.normals ? toF32(this.normals) : computeFlatNormals(positions, indices);
1270
+ const uvs = this.uvs ? toF32(this.uvs) : void 0;
1271
+ const colors = this.colors ? toF32(this.colors) : void 0;
1272
+ resizeMeshGeometry(engine, mesh._lite, positions, normals, indices, uvs, void 0, void 0, colors);
1273
+ }
1274
+ /** Merge another `VertexData` into this one (concatenating attributes + reindexing). */
1275
+ merge(other) {
1276
+ const baseVertexCount = this.positions ? this.positions.length / 3 : 0;
1277
+ this.positions = concat(this.positions, other.positions);
1278
+ this.normals = concat(this.normals, other.normals);
1279
+ this.uvs = concat(this.uvs, other.uvs);
1280
+ this.colors = concat(this.colors, other.colors);
1281
+ if (other.indices) {
1282
+ const shifted = Array.from(other.indices, (i) => i + baseVertexCount);
1283
+ this.indices = this.indices ? [...Array.from(this.indices), ...shifted] : shifted;
1284
+ }
1285
+ return this;
1286
+ }
1287
+ }
1288
+ function concat(a, b) {
1289
+ if (!a && !b) {
1290
+ return null;
1291
+ }
1292
+ return [...a ? Array.from(a) : [], ...b ? Array.from(b) : []];
1293
+ }
1294
+ function engineOf(scene) {
1295
+ return scene.getEngine()._lite;
1296
+ }
1297
+ function addPrimitive(mesh, scene) {
1298
+ scene._deferAdd(() => {
1299
+ const mat = mesh.material;
1300
+ mat == null ? void 0 : mat._ensureRenderable(engineOf(scene));
1301
+ if (mat == null ? void 0 : mat._lite) {
1302
+ mesh._lite.material = mat._lite;
1303
+ }
1304
+ addToScene(scene._lite, mesh._lite);
1305
+ });
1306
+ return mesh;
1307
+ }
1308
+ const MeshBuilder = {
1309
+ CreateBox(name, options, scene) {
1310
+ const lite = createBox(engineOf(scene), options.size ?? options.width ?? 1);
1311
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1312
+ },
1313
+ CreateSphere(name, options, scene) {
1314
+ const lite = createSphere(engineOf(scene), options);
1315
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1316
+ },
1317
+ CreateGround(name, options, scene) {
1318
+ const lite = createGround(engineOf(scene), options);
1319
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1320
+ },
1321
+ /**
1322
+ * Babylon.js `MeshBuilder.CreateGroundFromHeightMap(name, url, options, scene)`.
1323
+ * Babylon.js returns the mesh synchronously and fills its geometry once the
1324
+ * heightmap image loads; we mirror that by returning a placeholder `GroundMesh`
1325
+ * immediately and swapping in the real geometry (via `resizeMeshGeometry`) when
1326
+ * the async Lite `createGroundFromHeightMap` resolves. The load is tracked so
1327
+ * the engine awaits it before the scene is registered.
1328
+ */
1329
+ CreateGroundFromHeightMap(name, url, options, scene) {
1330
+ const engine = engineOf(scene);
1331
+ const mesh = new GroundMesh(name, scene);
1332
+ scene._trackTextureLoad(
1333
+ createGroundFromHeightMap(engine, url, options).then((lite) => {
1334
+ resizeMeshGeometry(engine, mesh._lite, lite._cpuPositions, lite._cpuNormals, lite._cpuIndices, lite._cpuUvs);
1335
+ const baseUvs = lite._cpuUvs;
1336
+ if (baseUvs) {
1337
+ scene._registerGroundUvBake(() => {
1338
+ const groundMat = mesh.material;
1339
+ const albedo = (groundMat == null ? void 0 : groundMat.albedoTexture) ?? null;
1340
+ const uScale = (albedo == null ? void 0 : albedo.uScale) ?? 1;
1341
+ const vScale = (albedo == null ? void 0 : albedo.vScale) ?? 1;
1342
+ if (uScale === 1 && vScale === 1) {
1343
+ return;
1344
+ }
1345
+ const scaled = new Float32Array(baseUvs.length);
1346
+ for (let i = 0; i < baseUvs.length; i += 2) {
1347
+ scaled[i] = baseUvs[i] * uScale;
1348
+ scaled[i + 1] = baseUvs[i + 1] * vScale;
1349
+ }
1350
+ updateMeshUvs(engine, mesh._lite, scaled);
1351
+ mesh._lite._cpuUvs = scaled;
1352
+ });
1353
+ }
1354
+ })
1355
+ );
1356
+ return mesh;
1357
+ },
1358
+ CreatePlane(name, options, scene) {
1359
+ const lite = createPlane(engineOf(scene), options);
1360
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1361
+ },
1362
+ CreateCylinder(name, options, scene) {
1363
+ const lite = createCylinder(engineOf(scene), options);
1364
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1365
+ },
1366
+ CreateTorus(name, options, scene) {
1367
+ const lite = createTorus(engineOf(scene), options);
1368
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1369
+ },
1370
+ CreateTorusKnot(name, options, scene) {
1371
+ const lite = createTorusKnot(engineOf(scene), options);
1372
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1373
+ },
1374
+ CreateDisc(name, options, scene) {
1375
+ const lite = createDisc(engineOf(scene), options);
1376
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1377
+ },
1378
+ CreatePolyhedron(name, options, scene) {
1379
+ const lite = createPolyhedron(engineOf(scene), options);
1380
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1381
+ },
1382
+ CreateRibbon(name, options, scene) {
1383
+ const lite = createRibbon(engineOf(scene), options);
1384
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1385
+ },
1386
+ CreateTube(name, options, scene) {
1387
+ const lite = createTube(engineOf(scene), options);
1388
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1389
+ },
1390
+ ExtrudeShape(name, options, scene) {
1391
+ const lite = createExtrudeShape(engineOf(scene), options);
1392
+ return addPrimitive(new Mesh(name, lite, scene), scene);
1393
+ },
1394
+ // ── Known but unsupported (not present in Babylon Lite) ────────────────
1395
+ CreateLines() {
1396
+ return unsupported("MeshBuilder.CreateLines", "Line meshes are not implemented in Babylon Lite.");
1397
+ },
1398
+ CreateLineSystem() {
1399
+ return unsupported("MeshBuilder.CreateLineSystem", "Line meshes are not implemented in Babylon Lite.");
1400
+ },
1401
+ CreateDashedLines() {
1402
+ return unsupported("MeshBuilder.CreateDashedLines", "Dashed line meshes are not implemented in Babylon Lite.");
1403
+ },
1404
+ CreateDecal() {
1405
+ return unsupported("MeshBuilder.CreateDecal", "Decal projection is not implemented in Babylon Lite.");
1406
+ },
1407
+ CreateText() {
1408
+ return unsupported("MeshBuilder.CreateText", "Extruded font meshes are not implemented in Babylon Lite. For 2D/SDF text use the native `createTextRenderable` API.");
1409
+ }
1410
+ };
1411
+ function CreateBox(name, options, scene) {
1412
+ return MeshBuilder.CreateBox(name, options, scene);
1413
+ }
1414
+ function CreateSphere(name, options, scene) {
1415
+ return MeshBuilder.CreateSphere(name, options, scene);
1416
+ }
1417
+ function CreateGround(name, options, scene) {
1418
+ return MeshBuilder.CreateGround(name, options, scene);
1419
+ }
1420
+ function CreatePlane(name, options, scene) {
1421
+ return MeshBuilder.CreatePlane(name, options, scene);
1422
+ }
1423
+ function CreateCylinder(name, options, scene) {
1424
+ return MeshBuilder.CreateCylinder(name, options, scene);
1425
+ }
1426
+ function CreateTorus(name, options, scene) {
1427
+ return MeshBuilder.CreateTorus(name, options, scene);
1428
+ }
1429
+ function CreateDisc(name, options, scene) {
1430
+ return MeshBuilder.CreateDisc(name, options, scene);
1431
+ }
1432
+ export {
1433
+ AbstractMesh as A,
1434
+ CreateBox as C,
1435
+ GroundMesh as G,
1436
+ InstancedMesh as I,
1437
+ LiteCompatError as L,
1438
+ Matrix as M,
1439
+ Node as N,
1440
+ Quaternion as Q,
1441
+ TransformNode as T,
1442
+ Vector3 as V,
1443
+ Mesh as a,
1444
+ CreateCylinder as b,
1445
+ CreateDisc as c,
1446
+ CreateGround as d,
1447
+ CreatePlane as e,
1448
+ CreateSphere as f,
1449
+ CreateTorus as g,
1450
+ MeshBuilder as h,
1451
+ Vector2 as i,
1452
+ Vector4 as j,
1453
+ VertexBuffer as k,
1454
+ liteBackedVector3 as l,
1455
+ VertexData as m,
1456
+ transformNormal as n,
1457
+ transformCoordinates as t,
1458
+ unsupported as u
1459
+ };
1460
+ //# sourceMappingURL=meshes-BQZyNGmT.js.map