@babylonjs/lite-compat 1.29.0-preview → 1.31.0-preview

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,3642 @@
1
+ import { addToScene, cloneTransformNode, computeAabb, createBox, createCylinder, createDashedLines, createDisc, createExtrudeShape, createGround, createGroundFromHeightMap, createLineMaterial, createLineSystem, createMeshFromData, createPbrMaterial, createPlane, createPolyhedron, createQuatFromRotationMat4, createRibbon, createSolidTexture2D, createSphere, createStandardMaterial, createTorus, createTorusKnot, createTransformNode, createTube, markMaterialUboDirty, maximizeMat4InPlace, normalizeVec2ToRef, projectPointToViewportToRef, rebuildMaterial, removeFromScene, resizeMeshGeometry, scaleBoundsFromCenterToRef, setLineMaterialColor, setMat4Translation, setMeshVisible, setParent, setPbrAnisotropy, setPbrClearCoat, setPbrEmissive, setPbrGammaAlbedo, setPbrIridescence, setPbrSheen, setStandardBumpTexture, setStandardEmissiveTexture, setThinInstanceColors, setThinInstances, updateDashedLines, updateLineSystem, updateMeshUvs, writeMat4FromQuatIntoBuffer } from "@babylonjs/lite";
2
+ //#region src/error.ts
3
+ /**
4
+ * Error thrown when Babylon.js code reaches an API surface that the Babylon Lite
5
+ * compatibility layer cannot (or does not yet) support.
6
+ *
7
+ * The compat layer intentionally favours a loud, discoverable failure over a
8
+ * silent wrong result: if a ported scene hits one of these, the porting gap is
9
+ * surfaced immediately with a pointer to the reason and (where relevant) the
10
+ * native Lite API to use instead.
11
+ */
12
+ var LiteCompatError = class extends Error {
13
+ constructor(api, detail) {
14
+ super(detail ? `'${api}' is not supported by the Babylon Lite compat layer. ${detail}` : `'${api}' is not supported by the Babylon Lite compat layer.`);
15
+ this.name = "LiteCompatError";
16
+ }
17
+ };
18
+ /** Throw a {@link LiteCompatError} for an unsupported API. */
19
+ function unsupported(api, detail) {
20
+ throw new LiteCompatError(api, detail);
21
+ }
22
+ //#endregion
23
+ //#region src/math/vector.ts
24
+ /**
25
+ * Babylon.js-compatible vector classes (`Vector2`, `Vector3`, `Vector4`).
26
+ *
27
+ * These are mutable classes backed by plain `x`/`y`/`z`/`w` fields. Because a
28
+ * `Vector3` is structurally `{ x, y, z }`, it can be passed directly anywhere
29
+ * the Babylon Lite API expects a `Vec3`. For APIs that want a tuple, use
30
+ * `asArray()`.
31
+ */
32
+ var Vector2 = class Vector2 {
33
+ x;
34
+ y;
35
+ constructor(x = 0, y = 0) {
36
+ this.x = x;
37
+ this.y = y;
38
+ }
39
+ set(x, y) {
40
+ this.x = x;
41
+ this.y = y;
42
+ return this;
43
+ }
44
+ copyFrom(source) {
45
+ this.x = source.x;
46
+ this.y = source.y;
47
+ return this;
48
+ }
49
+ copyFromFloats(x, y) {
50
+ this.x = x;
51
+ this.y = y;
52
+ return this;
53
+ }
54
+ add(other) {
55
+ return new Vector2(this.x + other.x, this.y + other.y);
56
+ }
57
+ addInPlace(other) {
58
+ this.x += other.x;
59
+ this.y += other.y;
60
+ return this;
61
+ }
62
+ subtract(other) {
63
+ return new Vector2(this.x - other.x, this.y - other.y);
64
+ }
65
+ scale(scale) {
66
+ return new Vector2(this.x * scale, this.y * scale);
67
+ }
68
+ scaleInPlace(scale) {
69
+ this.x *= scale;
70
+ this.y *= scale;
71
+ return this;
72
+ }
73
+ length() {
74
+ return Math.sqrt(this.x * this.x + this.y * this.y);
75
+ }
76
+ lengthSquared() {
77
+ return this.x * this.x + this.y * this.y;
78
+ }
79
+ normalize() {
80
+ return this.normalizeToRef(this);
81
+ }
82
+ normalizeToRef(result) {
83
+ return normalizeVec2ToRef(this, result);
84
+ }
85
+ clone() {
86
+ return new Vector2(this.x, this.y);
87
+ }
88
+ equals(other) {
89
+ return this.x === other.x && this.y === other.y;
90
+ }
91
+ asArray() {
92
+ return [this.x, this.y];
93
+ }
94
+ static Zero() {
95
+ return new Vector2(0, 0);
96
+ }
97
+ static One() {
98
+ return new Vector2(1, 1);
99
+ }
100
+ static Dot(a, b) {
101
+ return a.x * b.x + a.y * b.y;
102
+ }
103
+ };
104
+ var Vector3 = class Vector3 {
105
+ x;
106
+ y;
107
+ z;
108
+ constructor(x = 0, y = 0, z = 0) {
109
+ this.x = x;
110
+ this.y = y;
111
+ this.z = z;
112
+ }
113
+ set(x, y, z) {
114
+ this.x = x;
115
+ this.y = y;
116
+ this.z = z;
117
+ return this;
118
+ }
119
+ setAll(value) {
120
+ this.x = this.y = this.z = value;
121
+ return this;
122
+ }
123
+ copyFrom(source) {
124
+ this.x = source.x;
125
+ this.y = source.y;
126
+ this.z = source.z;
127
+ return this;
128
+ }
129
+ copyFromFloats(x, y, z) {
130
+ this.x = x;
131
+ this.y = y;
132
+ this.z = z;
133
+ return this;
134
+ }
135
+ add(other) {
136
+ return new Vector3(this.x + other.x, this.y + other.y, this.z + other.z);
137
+ }
138
+ addInPlace(other) {
139
+ this.x += other.x;
140
+ this.y += other.y;
141
+ this.z += other.z;
142
+ return this;
143
+ }
144
+ addInPlaceFromFloats(x, y, z) {
145
+ this.x += x;
146
+ this.y += y;
147
+ this.z += z;
148
+ return this;
149
+ }
150
+ subtract(other) {
151
+ return new Vector3(this.x - other.x, this.y - other.y, this.z - other.z);
152
+ }
153
+ subtractInPlace(other) {
154
+ this.x -= other.x;
155
+ this.y -= other.y;
156
+ this.z -= other.z;
157
+ return this;
158
+ }
159
+ multiply(other) {
160
+ return new Vector3(this.x * other.x, this.y * other.y, this.z * other.z);
161
+ }
162
+ scale(scale) {
163
+ return new Vector3(this.x * scale, this.y * scale, this.z * scale);
164
+ }
165
+ scaleInPlace(scale) {
166
+ this.x *= scale;
167
+ this.y *= scale;
168
+ this.z *= scale;
169
+ return this;
170
+ }
171
+ negate() {
172
+ return new Vector3(-this.x, -this.y, -this.z);
173
+ }
174
+ minimizeInPlace(other) {
175
+ return this.minimizeInPlaceFromFloats(other.x, other.y, other.z);
176
+ }
177
+ maximizeInPlace(other) {
178
+ return this.maximizeInPlaceFromFloats(other.x, other.y, other.z);
179
+ }
180
+ minimizeInPlaceFromFloats(x, y, z) {
181
+ if (x < this.x) this.x = x;
182
+ if (y < this.y) this.y = y;
183
+ if (z < this.z) this.z = z;
184
+ return this;
185
+ }
186
+ maximizeInPlaceFromFloats(x, y, z) {
187
+ if (x > this.x) this.x = x;
188
+ if (y > this.y) this.y = y;
189
+ if (z > this.z) this.z = z;
190
+ return this;
191
+ }
192
+ length() {
193
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
194
+ }
195
+ lengthSquared() {
196
+ return this.x * this.x + this.y * this.y + this.z * this.z;
197
+ }
198
+ normalize() {
199
+ const len = this.length();
200
+ if (len !== 0) {
201
+ this.x /= len;
202
+ this.y /= len;
203
+ this.z /= len;
204
+ }
205
+ return this;
206
+ }
207
+ clone() {
208
+ return new Vector3(this.x, this.y, this.z);
209
+ }
210
+ equals(other) {
211
+ return this.x === other.x && this.y === other.y && this.z === other.z;
212
+ }
213
+ equalsWithEpsilon(other, epsilon = 1e-6) {
214
+ return Math.abs(this.x - other.x) <= epsilon && Math.abs(this.y - other.y) <= epsilon && Math.abs(this.z - other.z) <= epsilon;
215
+ }
216
+ asArray() {
217
+ return [
218
+ this.x,
219
+ this.y,
220
+ this.z
221
+ ];
222
+ }
223
+ toArray(array, index = 0) {
224
+ array[index] = this.x;
225
+ array[index + 1] = this.y;
226
+ array[index + 2] = this.z;
227
+ return this;
228
+ }
229
+ static Zero() {
230
+ return new Vector3(0, 0, 0);
231
+ }
232
+ static One() {
233
+ return new Vector3(1, 1, 1);
234
+ }
235
+ static Up() {
236
+ return new Vector3(0, 1, 0);
237
+ }
238
+ static Down() {
239
+ return new Vector3(0, -1, 0);
240
+ }
241
+ static Forward() {
242
+ return new Vector3(0, 0, 1);
243
+ }
244
+ static Backward() {
245
+ return new Vector3(0, 0, -1);
246
+ }
247
+ static Right() {
248
+ return new Vector3(1, 0, 0);
249
+ }
250
+ static Left() {
251
+ return new Vector3(-1, 0, 0);
252
+ }
253
+ static FromArray(array, offset = 0) {
254
+ return new Vector3(array[offset] ?? 0, array[offset + 1] ?? 0, array[offset + 2] ?? 0);
255
+ }
256
+ static FromArrayToRef(array, offset, result) {
257
+ result.set(array[offset] ?? 0, array[offset + 1] ?? 0, array[offset + 2] ?? 0);
258
+ return result;
259
+ }
260
+ static FromFloatsToRef(x, y, z, result) {
261
+ result.set(x, y, z);
262
+ return result;
263
+ }
264
+ static Dot(a, b) {
265
+ return a.x * b.x + a.y * b.y + a.z * b.z;
266
+ }
267
+ static Cross(a, b) {
268
+ return Vector3.CrossToRef(a, b, new Vector3());
269
+ }
270
+ static CrossToRef(a, b, result) {
271
+ result.set(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
272
+ return result;
273
+ }
274
+ static Distance(a, b) {
275
+ return Math.sqrt(Vector3.DistanceSquared(a, b));
276
+ }
277
+ static DistanceSquared(a, b) {
278
+ const dx = a.x - b.x;
279
+ const dy = a.y - b.y;
280
+ const dz = a.z - b.z;
281
+ return dx * dx + dy * dy + dz * dz;
282
+ }
283
+ static Lerp(start, end, amount) {
284
+ return Vector3.LerpToRef(start, end, amount, new Vector3());
285
+ }
286
+ static LerpToRef(start, end, amount, result) {
287
+ result.set(start.x + (end.x - start.x) * amount, start.y + (end.y - start.y) * amount, start.z + (end.z - start.z) * amount);
288
+ return result;
289
+ }
290
+ /** Midpoint between two vectors. */
291
+ static Center(a, b) {
292
+ return Vector3.CenterToRef(a, b, new Vector3());
293
+ }
294
+ /** Midpoint between two vectors, written into `ref`. */
295
+ static CenterToRef(a, b, ref) {
296
+ return ref.set((a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2);
297
+ }
298
+ static Normalize(vector) {
299
+ return Vector3.NormalizeToRef(vector, new Vector3());
300
+ }
301
+ static NormalizeToRef(vector, result) {
302
+ const len = vector.length();
303
+ if (len === 0) result.set(0, 0, 0);
304
+ else result.set(vector.x / len, vector.y / len, vector.z / len);
305
+ return result;
306
+ }
307
+ static Minimize(a, b) {
308
+ return a.clone().minimizeInPlace(b);
309
+ }
310
+ static Maximize(a, b) {
311
+ return a.clone().maximizeInPlace(b);
312
+ }
313
+ /** Project a world-space point into a Babylon.js viewport. */
314
+ static Project(vector, world, transform, viewport) {
315
+ return Vector3.ProjectToRef(vector, world, transform, viewport, new Vector3());
316
+ }
317
+ /** Project a world-space point into a Babylon.js viewport, writing into `result`. */
318
+ static ProjectToRef(vector, world, transform, viewport, result) {
319
+ return projectPointToViewportToRef(vector, world.m, transform.m, viewport, result);
320
+ }
321
+ /** Transform a coordinate (point) by a matrix using the row-vector convention. */
322
+ static TransformCoordinates(vector, transformation) {
323
+ return Vector3.TransformCoordinatesToRef(vector, transformation, new Vector3());
324
+ }
325
+ /** Transform a coordinate (point) by a matrix using the row-vector convention. */
326
+ static TransformCoordinatesToRef(vector, transformation, result) {
327
+ const m = transformation.m;
328
+ const x = vector.x;
329
+ const y = vector.y;
330
+ const z = vector.z;
331
+ const rx = x * m[0] + y * m[4] + z * m[8] + m[12];
332
+ const ry = x * m[1] + y * m[5] + z * m[9] + m[13];
333
+ const rz = x * m[2] + y * m[6] + z * m[10] + m[14];
334
+ const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);
335
+ result.set(rx * rw, ry * rw, rz * rw);
336
+ return result;
337
+ }
338
+ /** Transform a direction (normal) by a matrix, ignoring translation. */
339
+ static TransformNormal(vector, transformation) {
340
+ return Vector3.TransformNormalToRef(vector, transformation, new Vector3());
341
+ }
342
+ /** Transform a direction (normal) by a matrix, ignoring translation. */
343
+ static TransformNormalToRef(vector, transformation, result) {
344
+ const m = transformation.m;
345
+ const x = vector.x;
346
+ const y = vector.y;
347
+ const z = vector.z;
348
+ result.set(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]);
349
+ return result;
350
+ }
351
+ };
352
+ /**
353
+ * @internal A `Vector3` whose `x`/`y`/`z` read and write **through** to a live
354
+ * Babylon Lite vector (`ObservableVec3`). This lets compat code expose
355
+ * `mesh.position` / `rotation` / `scaling` as a real `Vector3` — so inherited
356
+ * in-place methods (`scaleInPlace`, `addInPlace`, `set`, …) mutate the Lite node
357
+ * and trigger its dirty tracking, matching Babylon.js's live-transform semantics.
358
+ *
359
+ * The accessors are installed with `Object.defineProperty` **after** `super()`,
360
+ * which redefines the own `x`/`y`/`z` data properties the base constructor created
361
+ * (parameter properties). This is required under `useDefineForClassFields` (ES2022),
362
+ * where overriding the accessors via a subclass field/prototype alone would be
363
+ * shadowed by the base's own data properties.
364
+ */
365
+ var LiteBackedVector3 = class extends Vector3 {
366
+ constructor(lite) {
367
+ super(0, 0, 0);
368
+ Object.defineProperty(this, "x", {
369
+ enumerable: true,
370
+ configurable: true,
371
+ get: () => lite.x,
372
+ set: (v) => lite.x = v
373
+ });
374
+ Object.defineProperty(this, "y", {
375
+ enumerable: true,
376
+ configurable: true,
377
+ get: () => lite.y,
378
+ set: (v) => lite.y = v
379
+ });
380
+ Object.defineProperty(this, "z", {
381
+ enumerable: true,
382
+ configurable: true,
383
+ get: () => lite.z,
384
+ set: (v) => lite.z = v
385
+ });
386
+ }
387
+ };
388
+ /** One stable proxy per Lite vector, so `mesh.position === mesh.position` (Babylon.js identity parity). */
389
+ var _liteVec3Proxies = /* @__PURE__ */ new WeakMap();
390
+ /**
391
+ * @internal Return the cached write-through `Vector3` proxy over a Lite
392
+ * `ObservableVec3` (creating it on first use). Stable identity per Lite vector.
393
+ */
394
+ function liteBackedVector3(lite) {
395
+ let proxy = _liteVec3Proxies.get(lite);
396
+ if (!proxy) {
397
+ proxy = new LiteBackedVector3(lite);
398
+ _liteVec3Proxies.set(lite, proxy);
399
+ }
400
+ return proxy;
401
+ }
402
+ var Vector4 = class Vector4 {
403
+ x;
404
+ y;
405
+ z;
406
+ w;
407
+ constructor(x = 0, y = 0, z = 0, w = 0) {
408
+ this.x = x;
409
+ this.y = y;
410
+ this.z = z;
411
+ this.w = w;
412
+ }
413
+ set(x, y, z, w) {
414
+ this.x = x;
415
+ this.y = y;
416
+ this.z = z;
417
+ this.w = w;
418
+ return this;
419
+ }
420
+ copyFrom(source) {
421
+ this.x = source.x;
422
+ this.y = source.y;
423
+ this.z = source.z;
424
+ this.w = source.w;
425
+ return this;
426
+ }
427
+ add(other) {
428
+ return new Vector4(this.x + other.x, this.y + other.y, this.z + other.z, this.w + other.w);
429
+ }
430
+ scale(scale) {
431
+ return new Vector4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
432
+ }
433
+ length() {
434
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
435
+ }
436
+ clone() {
437
+ return new Vector4(this.x, this.y, this.z, this.w);
438
+ }
439
+ equals(other) {
440
+ return this.x === other.x && this.y === other.y && this.z === other.z && this.w === other.w;
441
+ }
442
+ asArray() {
443
+ return [
444
+ this.x,
445
+ this.y,
446
+ this.z,
447
+ this.w
448
+ ];
449
+ }
450
+ static Zero() {
451
+ return new Vector4(0, 0, 0, 0);
452
+ }
453
+ };
454
+ //#endregion
455
+ //#region src/math/color.ts
456
+ /**
457
+ * Babylon.js-compatible colour classes (`Color3`, `Color4`).
458
+ *
459
+ * Mutable, backed by `r`/`g`/`b`/`a` fields. `asArray()` yields the tuple shape
460
+ * (`[r, g, b]` / `[r, g, b, a]`) consumed by the Babylon Lite material and light
461
+ * APIs.
462
+ */
463
+ var Color3 = class Color3 {
464
+ r;
465
+ g;
466
+ b;
467
+ constructor(r = 0, g = 0, b = 0) {
468
+ this.r = r;
469
+ this.g = g;
470
+ this.b = b;
471
+ }
472
+ set(r, g, b) {
473
+ this.r = r;
474
+ this.g = g;
475
+ this.b = b;
476
+ return this;
477
+ }
478
+ copyFrom(source) {
479
+ this.r = source.r;
480
+ this.g = source.g;
481
+ this.b = source.b;
482
+ return this;
483
+ }
484
+ scale(scale) {
485
+ return new Color3(this.r * scale, this.g * scale, this.b * scale);
486
+ }
487
+ scaleInPlace(scale) {
488
+ this.r *= scale;
489
+ this.g *= scale;
490
+ this.b *= scale;
491
+ return this;
492
+ }
493
+ multiply(other) {
494
+ return new Color3(this.r * other.r, this.g * other.g, this.b * other.b);
495
+ }
496
+ add(other) {
497
+ return new Color3(this.r + other.r, this.g + other.g, this.b + other.b);
498
+ }
499
+ clone() {
500
+ return new Color3(this.r, this.g, this.b);
501
+ }
502
+ equals(other) {
503
+ return this.r === other.r && this.g === other.g && this.b === other.b;
504
+ }
505
+ asArray() {
506
+ return [
507
+ this.r,
508
+ this.g,
509
+ this.b
510
+ ];
511
+ }
512
+ toColor4(alpha = 1) {
513
+ return new Color4(this.r, this.g, this.b, alpha);
514
+ }
515
+ toHexString() {
516
+ const intR = Math.round(Math.min(Math.max(this.r, 0), 1) * 255);
517
+ const intG = Math.round(Math.min(Math.max(this.g, 0), 1) * 255);
518
+ const intB = Math.round(Math.min(Math.max(this.b, 0), 1) * 255);
519
+ return "#" + toHex(intR) + toHex(intG) + toHex(intB);
520
+ }
521
+ static Black() {
522
+ return new Color3(0, 0, 0);
523
+ }
524
+ static White() {
525
+ return new Color3(1, 1, 1);
526
+ }
527
+ static Red() {
528
+ return new Color3(1, 0, 0);
529
+ }
530
+ static Green() {
531
+ return new Color3(0, 1, 0);
532
+ }
533
+ static Blue() {
534
+ return new Color3(0, 0, 1);
535
+ }
536
+ static FromArray(array, offset = 0) {
537
+ return new Color3(array[offset] ?? 0, array[offset + 1] ?? 0, array[offset + 2] ?? 0);
538
+ }
539
+ static FromInts(r, g, b) {
540
+ return new Color3(r / 255, g / 255, b / 255);
541
+ }
542
+ static FromHexString(hex) {
543
+ if (hex.charAt(0) !== "#" || hex.length < 7) return new Color3(0, 0, 0);
544
+ const r = parseInt(hex.substring(1, 3), 16);
545
+ const g = parseInt(hex.substring(3, 5), 16);
546
+ const b = parseInt(hex.substring(5, 7), 16);
547
+ return Color3.FromInts(r, g, b);
548
+ }
549
+ static Lerp(start, end, amount) {
550
+ return new Color3(start.r + (end.r - start.r) * amount, start.g + (end.g - start.g) * amount, start.b + (end.b - start.b) * amount);
551
+ }
552
+ };
553
+ /**
554
+ * @internal A `Color3` whose `r`/`g`/`b` read and write **through** to a live Babylon Lite colour tuple, so
555
+ * inherited in-place methods (`copyFrom`, `set`, `scaleInPlace`, …) reach the Lite object — the colour
556
+ * counterpart of `LiteBackedVector3`. A tuple write cannot notify anyone by itself, so `onWrite` lets the
557
+ * owner publish the change.
558
+ */
559
+ var LiteBackedColor3 = class extends Color3 {
560
+ constructor(tuple, onWrite) {
561
+ super(0, 0, 0);
562
+ [
563
+ "r",
564
+ "g",
565
+ "b"
566
+ ].forEach((key, i) => {
567
+ Object.defineProperty(this, key, {
568
+ enumerable: true,
569
+ configurable: true,
570
+ get: () => tuple[i],
571
+ set: (value) => {
572
+ tuple[i] = value;
573
+ onWrite();
574
+ }
575
+ });
576
+ });
577
+ }
578
+ };
579
+ /** One stable proxy per Lite tuple, so `light.diffuse === light.diffuse` (Babylon.js identity parity).
580
+ * Created on first use: a module-level `new WeakMap()` would be an import-time side effect. */
581
+ var _liteColor3Proxies = null;
582
+ /**
583
+ * @internal Return the cached write-through `Color3` proxy over a Lite colour tuple (creating it on first
584
+ * use). `onWrite` runs after every component write.
585
+ */
586
+ function liteBackedColor3(tuple, onWrite) {
587
+ const proxies = _liteColor3Proxies ??= /* @__PURE__ */ new WeakMap();
588
+ let proxy = proxies.get(tuple);
589
+ if (!proxy) {
590
+ proxy = new LiteBackedColor3(tuple, onWrite);
591
+ proxies.set(tuple, proxy);
592
+ }
593
+ return proxy;
594
+ }
595
+ var Color4 = class Color4 {
596
+ r;
597
+ g;
598
+ b;
599
+ a;
600
+ constructor(r = 0, g = 0, b = 0, a = 1) {
601
+ this.r = r;
602
+ this.g = g;
603
+ this.b = b;
604
+ this.a = a;
605
+ }
606
+ set(r, g, b, a) {
607
+ this.r = r;
608
+ this.g = g;
609
+ this.b = b;
610
+ this.a = a;
611
+ return this;
612
+ }
613
+ copyFrom(source) {
614
+ this.r = source.r;
615
+ this.g = source.g;
616
+ this.b = source.b;
617
+ this.a = source.a;
618
+ return this;
619
+ }
620
+ scale(scale) {
621
+ return new Color4(this.r * scale, this.g * scale, this.b * scale, this.a * scale);
622
+ }
623
+ add(other) {
624
+ return new Color4(this.r + other.r, this.g + other.g, this.b + other.b, this.a + other.a);
625
+ }
626
+ clone() {
627
+ return new Color4(this.r, this.g, this.b, this.a);
628
+ }
629
+ equals(other) {
630
+ return this.r === other.r && this.g === other.g && this.b === other.b && this.a === other.a;
631
+ }
632
+ asArray() {
633
+ return [
634
+ this.r,
635
+ this.g,
636
+ this.b,
637
+ this.a
638
+ ];
639
+ }
640
+ static FromArray(array, offset = 0) {
641
+ return new Color4(array[offset] ?? 0, array[offset + 1] ?? 0, array[offset + 2] ?? 0, array[offset + 3] ?? 1);
642
+ }
643
+ static FromInts(r, g, b, a) {
644
+ return new Color4(r / 255, g / 255, b / 255, a / 255);
645
+ }
646
+ };
647
+ function toHex(value) {
648
+ const hex = value.toString(16).toUpperCase();
649
+ return hex.length === 1 ? "0" + hex : hex;
650
+ }
651
+ //#endregion
652
+ //#region src/math/quaternion.ts
653
+ /**
654
+ * Babylon.js-compatible `Quaternion`.
655
+ *
656
+ * Mutable, backed by `x`/`y`/`z`/`w` fields. Structurally compatible with the
657
+ * Babylon Lite `{ x, y, z, w }` quaternion shape used on transform nodes.
658
+ */
659
+ var Quaternion = class Quaternion {
660
+ x;
661
+ y;
662
+ z;
663
+ w;
664
+ constructor(x = 0, y = 0, z = 0, w = 1) {
665
+ this.x = x;
666
+ this.y = y;
667
+ this.z = z;
668
+ this.w = w;
669
+ }
670
+ set(x, y, z, w) {
671
+ this.x = x;
672
+ this.y = y;
673
+ this.z = z;
674
+ this.w = w;
675
+ return this;
676
+ }
677
+ copyFrom(source) {
678
+ this.x = source.x;
679
+ this.y = source.y;
680
+ this.z = source.z;
681
+ this.w = source.w;
682
+ return this;
683
+ }
684
+ multiply(other) {
685
+ return new Quaternion(other.w * this.x + other.x * this.w + other.y * this.z - other.z * this.y, other.w * this.y - other.x * this.z + other.y * this.w + other.z * this.x, other.w * this.z + other.x * this.y - other.y * this.x + other.z * this.w, other.w * this.w - other.x * this.x - other.y * this.y - other.z * this.z);
686
+ }
687
+ length() {
688
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
689
+ }
690
+ normalize() {
691
+ const len = this.length();
692
+ if (len !== 0) {
693
+ const inv = 1 / len;
694
+ this.x *= inv;
695
+ this.y *= inv;
696
+ this.z *= inv;
697
+ this.w *= inv;
698
+ }
699
+ return this;
700
+ }
701
+ conjugate() {
702
+ return new Quaternion(-this.x, -this.y, -this.z, this.w);
703
+ }
704
+ /**
705
+ * Babylon.js `Quaternion.fromRotationMatrix` — update this quaternion in place
706
+ * from the rotation part of `matrix`. Backed by Lite's `createQuatFromRotationMat4`.
707
+ */
708
+ fromRotationMatrix(matrix) {
709
+ const q = createQuatFromRotationMat4(matrix.m);
710
+ this.x = q.x;
711
+ this.y = q.y;
712
+ this.z = q.z;
713
+ this.w = q.w;
714
+ return this;
715
+ }
716
+ /**
717
+ * Babylon.js `Quaternion.toRotationMatrix` — write this quaternion's rotation
718
+ * into `result`.
719
+ */
720
+ toRotationMatrix(result) {
721
+ writeMat4FromQuatIntoBuffer(result.m, this.x, this.y, this.z, this.w);
722
+ return result;
723
+ }
724
+ clone() {
725
+ return new Quaternion(this.x, this.y, this.z, this.w);
726
+ }
727
+ equals(other) {
728
+ return this.x === other.x && this.y === other.y && this.z === other.z && this.w === other.w;
729
+ }
730
+ asArray() {
731
+ return [
732
+ this.x,
733
+ this.y,
734
+ this.z,
735
+ this.w
736
+ ];
737
+ }
738
+ toEulerAngles() {
739
+ const result = new Vector3();
740
+ const qz = this.z;
741
+ const qx = this.x;
742
+ const qy = this.y;
743
+ const qw = this.w;
744
+ const sqw = qw * qw;
745
+ const sqz = qz * qz;
746
+ const sqx = qx * qx;
747
+ const sqy = qy * qy;
748
+ const zAxisY = qy * qz - qx * qw;
749
+ const limit = .4999999;
750
+ if (zAxisY < -.4999999) {
751
+ result.y = 2 * Math.atan2(qy, qw);
752
+ result.x = Math.PI / 2;
753
+ result.z = 0;
754
+ } else if (zAxisY > limit) {
755
+ result.y = 2 * Math.atan2(qy, qw);
756
+ result.x = -Math.PI / 2;
757
+ result.z = 0;
758
+ } else {
759
+ result.z = Math.atan2(2 * (qx * qy + qz * qw), -sqz - sqx + sqy + sqw);
760
+ result.x = Math.asin(-2 * (qz * qy - qx * qw));
761
+ result.y = Math.atan2(2 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);
762
+ }
763
+ return result;
764
+ }
765
+ static Identity() {
766
+ return new Quaternion(0, 0, 0, 1);
767
+ }
768
+ /**
769
+ * Babylon.js `Quaternion.FromRotationMatrix` — create a new quaternion from the
770
+ * rotation part of `matrix`. Backed by Lite's `createQuatFromRotationMat4`.
771
+ */
772
+ static FromRotationMatrix(matrix) {
773
+ const result = new Quaternion();
774
+ Quaternion.FromRotationMatrixToRef(matrix, result);
775
+ return result;
776
+ }
777
+ /**
778
+ * Babylon.js `Quaternion.FromRotationMatrixToRef` — write the rotation part of
779
+ * `matrix` into `result`. Backed by Lite's `createQuatFromRotationMat4`.
780
+ */
781
+ static FromRotationMatrixToRef(matrix, result) {
782
+ const q = createQuatFromRotationMat4(matrix.m);
783
+ result.x = q.x;
784
+ result.y = q.y;
785
+ result.z = q.z;
786
+ result.w = q.w;
787
+ return result;
788
+ }
789
+ static FromEulerAngles(x, y, z) {
790
+ return Quaternion.RotationYawPitchRoll(y, x, z);
791
+ }
792
+ static RotationYawPitchRoll(yaw, pitch, roll) {
793
+ const halfRoll = roll * .5;
794
+ const halfPitch = pitch * .5;
795
+ const halfYaw = yaw * .5;
796
+ const sinRoll = Math.sin(halfRoll);
797
+ const cosRoll = Math.cos(halfRoll);
798
+ const sinPitch = Math.sin(halfPitch);
799
+ const cosPitch = Math.cos(halfPitch);
800
+ const sinYaw = Math.sin(halfYaw);
801
+ const cosYaw = Math.cos(halfYaw);
802
+ return new Quaternion(cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll, sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll, cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll, cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll);
803
+ }
804
+ static RotationAxis(axis, angle) {
805
+ const sin = Math.sin(angle / 2);
806
+ const len = axis.length() || 1;
807
+ return new Quaternion(axis.x / len * sin, axis.y / len * sin, axis.z / len * sin, Math.cos(angle / 2));
808
+ }
809
+ static Slerp(left, right, amount) {
810
+ let num2;
811
+ let num3;
812
+ const num = amount;
813
+ let dot = left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
814
+ let flip = false;
815
+ if (dot < 0) {
816
+ flip = true;
817
+ dot = -dot;
818
+ }
819
+ if (dot > .999999) {
820
+ num3 = 1 - num;
821
+ num2 = flip ? -num : num;
822
+ } else {
823
+ const angle = Math.acos(dot);
824
+ const invSin = 1 / Math.sin(angle);
825
+ num3 = Math.sin((1 - num) * angle) * invSin;
826
+ num2 = flip ? -Math.sin(num * angle) * invSin : Math.sin(num * angle) * invSin;
827
+ }
828
+ 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);
829
+ }
830
+ };
831
+ //#endregion
832
+ //#region src/math/matrix.ts
833
+ /**
834
+ * Babylon.js-compatible `Matrix` (4x4).
835
+ *
836
+ * Storage and conventions match Babylon.js: a 16-element row-major `Float32Array`
837
+ * with translation in elements 12/13/14, and the row-vector convention
838
+ * (`v' = v · M`). `multiply(other)` applies `this` first, then `other`.
839
+ */
840
+ var matrixMaximizeValues;
841
+ var Matrix = class Matrix {
842
+ m;
843
+ constructor() {
844
+ this.m = /* @__PURE__ */ new Float32Array(16);
845
+ }
846
+ set(index, value) {
847
+ this.m[index] = value;
848
+ return this;
849
+ }
850
+ copyFrom(source) {
851
+ this.m.set(source.m);
852
+ return this;
853
+ }
854
+ /** Set only this matrix's translation components. */
855
+ setTranslationFromFloats(x, y, z) {
856
+ setMat4Translation(this.m, x, y, z);
857
+ return this;
858
+ }
859
+ maximizeInPlace(other) {
860
+ maximizeMat4InPlace(this.m, other.m);
861
+ return this.markAsUpdated();
862
+ }
863
+ maximizeInPlaceFromFloats(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
864
+ const values = matrixMaximizeValues ??= /* @__PURE__ */ new Float32Array(16);
865
+ values[0] = m0;
866
+ values[1] = m1;
867
+ values[2] = m2;
868
+ values[3] = m3;
869
+ values[4] = m4;
870
+ values[5] = m5;
871
+ values[6] = m6;
872
+ values[7] = m7;
873
+ values[8] = m8;
874
+ values[9] = m9;
875
+ values[10] = m10;
876
+ values[11] = m11;
877
+ values[12] = m12;
878
+ values[13] = m13;
879
+ values[14] = m14;
880
+ values[15] = m15;
881
+ maximizeMat4InPlace(this.m, values);
882
+ return this.markAsUpdated();
883
+ }
884
+ clone() {
885
+ const result = new Matrix();
886
+ result.m.set(this.m);
887
+ return result;
888
+ }
889
+ asArray() {
890
+ return this.m;
891
+ }
892
+ toArray() {
893
+ return Array.from(this.m);
894
+ }
895
+ /** Babylon.js `Matrix.copyToArray` — copy the 16 elements into `array` at `offset`. */
896
+ copyToArray(array, offset = 0) {
897
+ for (let i = 0; i < 16; i++) array[offset + i] = this.m[i];
898
+ return this;
899
+ }
900
+ equals(other) {
901
+ for (let i = 0; i < 16; i++) if (this.m[i] !== other.m[i]) return false;
902
+ return true;
903
+ }
904
+ multiply(other) {
905
+ return Matrix.FromValues(...multiplyValues(this.m, other.m));
906
+ }
907
+ multiplyToRef(other, result) {
908
+ const values = multiplyValues(this.m, other.m);
909
+ result.m.set(values);
910
+ return result;
911
+ }
912
+ transpose() {
913
+ const a = this.m;
914
+ 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]);
915
+ }
916
+ determinant() {
917
+ return determinant(this.m);
918
+ }
919
+ invert() {
920
+ const result = new Matrix();
921
+ this.invertToRef(result);
922
+ return result;
923
+ }
924
+ invertToRef(result) {
925
+ const inv = invertValues(this.m);
926
+ result.m.set(inv);
927
+ return result;
928
+ }
929
+ getTranslation() {
930
+ return new Vector3(this.m[12], this.m[13], this.m[14]);
931
+ }
932
+ /**
933
+ * Babylon.js `Matrix.decompose(scale?, rotation?, translation?)` — split this
934
+ * TRS matrix into its scale, rotation (quaternion), and translation parts,
935
+ * writing into any provided out-params. Returns `false` (matching BJS) when a
936
+ * scale axis is zero. The rotation extraction is backed by Lite's
937
+ * `createQuatFromRotationMat4` (via `Quaternion.FromRotationMatrixToRef`); the
938
+ * negative-determinant `scale.y` flip matches Babylon.js exactly.
939
+ */
940
+ decompose(scale, rotation, translation) {
941
+ const m = this.m;
942
+ if (translation) translation.copyFromFloats(m[12], m[13], m[14]);
943
+ const sc = scale ?? new Vector3();
944
+ sc.x = Math.sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]);
945
+ sc.y = Math.sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]);
946
+ sc.z = Math.sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]);
947
+ if (m[0] * (m[5] * m[10] - m[6] * m[9]) - m[1] * (m[4] * m[10] - m[6] * m[8]) + m[2] * (m[4] * m[9] - m[5] * m[8]) < 0) sc.y *= -1;
948
+ if (sc.x === 0 || sc.y === 0 || sc.z === 0) {
949
+ if (rotation) rotation.set(0, 0, 0, 1);
950
+ return false;
951
+ }
952
+ if (rotation) {
953
+ const sx = 1 / sc.x;
954
+ const sy = 1 / sc.y;
955
+ const sz = 1 / sc.z;
956
+ const r = (decomposeRotationScratch ??= new Matrix()).m;
957
+ r[0] = m[0] * sx;
958
+ r[1] = m[1] * sx;
959
+ r[2] = m[2] * sx;
960
+ r[3] = 0;
961
+ r[4] = m[4] * sy;
962
+ r[5] = m[5] * sy;
963
+ r[6] = m[6] * sy;
964
+ r[7] = 0;
965
+ r[8] = m[8] * sz;
966
+ r[9] = m[9] * sz;
967
+ r[10] = m[10] * sz;
968
+ r[11] = 0;
969
+ r[12] = 0;
970
+ r[13] = 0;
971
+ r[14] = 0;
972
+ r[15] = 1;
973
+ Quaternion.FromRotationMatrixToRef(decomposeRotationScratch, rotation);
974
+ }
975
+ return true;
976
+ }
977
+ static FromValues(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) {
978
+ const result = new Matrix();
979
+ result.m.set([
980
+ m0,
981
+ m1,
982
+ m2,
983
+ m3,
984
+ m4,
985
+ m5,
986
+ m6,
987
+ m7,
988
+ m8,
989
+ m9,
990
+ m10,
991
+ m11,
992
+ m12,
993
+ m13,
994
+ m14,
995
+ m15
996
+ ]);
997
+ return result;
998
+ }
999
+ static FromArray(array, offset = 0) {
1000
+ const result = new Matrix();
1001
+ for (let i = 0; i < 16; i++) result.m[i] = array[offset + i] ?? 0;
1002
+ return result;
1003
+ }
1004
+ static Identity() {
1005
+ return Matrix.FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
1006
+ }
1007
+ static Zero() {
1008
+ return new Matrix();
1009
+ }
1010
+ static Translation(x, y, z) {
1011
+ return Matrix.FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1);
1012
+ }
1013
+ static Scaling(x, y, z) {
1014
+ return Matrix.FromValues(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
1015
+ }
1016
+ static RotationX(angle) {
1017
+ const s = Math.sin(angle);
1018
+ const c = Math.cos(angle);
1019
+ return Matrix.FromValues(1, 0, 0, 0, 0, c, s, 0, 0, -s, c, 0, 0, 0, 0, 1);
1020
+ }
1021
+ static RotationY(angle) {
1022
+ const s = Math.sin(angle);
1023
+ const c = Math.cos(angle);
1024
+ return Matrix.FromValues(c, 0, -s, 0, 0, 1, 0, 0, s, 0, c, 0, 0, 0, 0, 1);
1025
+ }
1026
+ static RotationZ(angle) {
1027
+ const s = Math.sin(angle);
1028
+ const c = Math.cos(angle);
1029
+ return Matrix.FromValues(c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
1030
+ }
1031
+ /** Babylon.js `Matrix.LookAtLH(eye, target, up)` — left-handed view matrix. */
1032
+ static LookAtLH(eye, target, up) {
1033
+ let zx = target.x - eye.x, zy = target.y - eye.y, zz = target.z - eye.z;
1034
+ const zl = Math.hypot(zx, zy, zz) || 1;
1035
+ zx /= zl;
1036
+ zy /= zl;
1037
+ zz /= zl;
1038
+ let xx = up.y * zz - up.z * zy, xy = up.z * zx - up.x * zz, xz = up.x * zy - up.y * zx;
1039
+ const xl = Math.hypot(xx, xy, xz) || 1;
1040
+ xx /= xl;
1041
+ xy /= xl;
1042
+ xz /= xl;
1043
+ const yx = zy * xz - zz * xy, yy = zz * xx - zx * xz, yz = zx * xy - zy * xx;
1044
+ const ex = -(xx * eye.x + xy * eye.y + xz * eye.z);
1045
+ const ey = -(yx * eye.x + yy * eye.y + yz * eye.z);
1046
+ const ez = -(zx * eye.x + zy * eye.y + zz * eye.z);
1047
+ return Matrix.FromValues(xx, yx, zx, 0, xy, yy, zy, 0, xz, yz, zz, 0, ex, ey, ez, 1);
1048
+ }
1049
+ /** Babylon.js `Matrix.OrthoOffCenterLH(left, right, bottom, top, znear, zfar, halfZRange?)` — LH ortho projection. */
1050
+ static OrthoOffCenterLH(left, right, bottom, top, znear, zfar, _halfZRange) {
1051
+ const a = 2 / (right - left);
1052
+ const b = 2 / (top - bottom);
1053
+ const c = 1 / (zfar - znear);
1054
+ const tx = (left + right) / (left - right);
1055
+ const ty = (top + bottom) / (bottom - top);
1056
+ const tz = -znear * c;
1057
+ return Matrix.FromValues(a, 0, 0, 0, 0, b, 0, 0, 0, 0, c, 0, tx, ty, tz, 1);
1058
+ }
1059
+ /**
1060
+ * Babylon.js `Matrix.Compose(scale, rotation, translation)` — build a TRS matrix
1061
+ * from a scale vector, a rotation quaternion, and a translation vector (row-vector
1062
+ * convention, translation in elements 12/13/14).
1063
+ */
1064
+ static Compose(scale, rotation, translation) {
1065
+ const { x, y, z, w } = rotation;
1066
+ const x2 = x + x, y2 = y + y, z2 = z + z;
1067
+ 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;
1068
+ const sx = scale.x, sy = scale.y, sz = scale.z;
1069
+ return Matrix.FromValues((1 - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0, (xy - wz) * sy, (1 - (xx + zz)) * sy, (yz + wx) * sy, 0, (xz + wy) * sz, (yz - wx) * sz, (1 - (xx + yy)) * sz, 0, translation.x, translation.y, translation.z, 1);
1070
+ }
1071
+ /** Babylon.js `Matrix.markAsUpdated()` — Lite has no per-matrix dirty flag; no-op for parity. */
1072
+ markAsUpdated() {
1073
+ return this;
1074
+ }
1075
+ };
1076
+ var decomposeRotationScratch = null;
1077
+ function multiplyValues(a, b) {
1078
+ const result = new Array(16);
1079
+ for (let r = 0; r < 4; r++) for (let c = 0; c < 4; c++) 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];
1080
+ return result;
1081
+ }
1082
+ function determinant(m) {
1083
+ const m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3];
1084
+ const m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7];
1085
+ const m20 = m[8], m21 = m[9], m22 = m[10], m23 = m[11];
1086
+ const m30 = m[12], m31 = m[13], m32 = m[14], m33 = m[15];
1087
+ const b00 = m00 * m11 - m01 * m10;
1088
+ const b01 = m00 * m12 - m02 * m10;
1089
+ const b02 = m00 * m13 - m03 * m10;
1090
+ const b03 = m01 * m12 - m02 * m11;
1091
+ const b04 = m01 * m13 - m03 * m11;
1092
+ const b05 = m02 * m13 - m03 * m12;
1093
+ const b06 = m20 * m31 - m21 * m30;
1094
+ const b07 = m20 * m32 - m22 * m30;
1095
+ const b08 = m20 * m33 - m23 * m30;
1096
+ const b09 = m21 * m32 - m22 * m31;
1097
+ const b10 = m21 * m33 - m23 * m31;
1098
+ return b00 * (m22 * m33 - m23 * m32) - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1099
+ }
1100
+ function invertValues(m) {
1101
+ const m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3];
1102
+ const m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7];
1103
+ const m20 = m[8], m21 = m[9], m22 = m[10], m23 = m[11];
1104
+ const m30 = m[12], m31 = m[13], m32 = m[14], m33 = m[15];
1105
+ const b00 = m00 * m11 - m01 * m10;
1106
+ const b01 = m00 * m12 - m02 * m10;
1107
+ const b02 = m00 * m13 - m03 * m10;
1108
+ const b03 = m01 * m12 - m02 * m11;
1109
+ const b04 = m01 * m13 - m03 * m11;
1110
+ const b05 = m02 * m13 - m03 * m12;
1111
+ const b06 = m20 * m31 - m21 * m30;
1112
+ const b07 = m20 * m32 - m22 * m30;
1113
+ const b08 = m20 * m33 - m23 * m30;
1114
+ const b09 = m21 * m32 - m22 * m31;
1115
+ const b10 = m21 * m33 - m23 * m31;
1116
+ const b11 = m22 * m33 - m23 * m32;
1117
+ const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1118
+ if (det === 0) return [
1119
+ 1,
1120
+ 0,
1121
+ 0,
1122
+ 0,
1123
+ 0,
1124
+ 1,
1125
+ 0,
1126
+ 0,
1127
+ 0,
1128
+ 0,
1129
+ 1,
1130
+ 0,
1131
+ 0,
1132
+ 0,
1133
+ 0,
1134
+ 1
1135
+ ];
1136
+ const invDet = 1 / det;
1137
+ return [
1138
+ (m11 * b11 - m12 * b10 + m13 * b09) * invDet,
1139
+ (m02 * b10 - m01 * b11 - m03 * b09) * invDet,
1140
+ (m31 * b05 - m32 * b04 + m33 * b03) * invDet,
1141
+ (m22 * b04 - m21 * b05 - m23 * b03) * invDet,
1142
+ (m12 * b08 - m10 * b11 - m13 * b07) * invDet,
1143
+ (m00 * b11 - m02 * b08 + m03 * b07) * invDet,
1144
+ (m32 * b02 - m30 * b05 - m33 * b01) * invDet,
1145
+ (m20 * b05 - m22 * b02 + m23 * b01) * invDet,
1146
+ (m10 * b10 - m11 * b08 + m13 * b06) * invDet,
1147
+ (m01 * b08 - m00 * b10 - m03 * b06) * invDet,
1148
+ (m30 * b04 - m31 * b02 + m33 * b00) * invDet,
1149
+ (m21 * b02 - m20 * b04 - m23 * b00) * invDet,
1150
+ (m11 * b07 - m10 * b09 - m12 * b06) * invDet,
1151
+ (m00 * b09 - m01 * b07 + m02 * b06) * invDet,
1152
+ (m31 * b01 - m30 * b03 - m32 * b00) * invDet,
1153
+ (m20 * b03 - m21 * b01 + m22 * b00) * invDet
1154
+ ];
1155
+ }
1156
+ /**
1157
+ * Babylon.js-compatible vector × matrix transforms (static helpers that live on
1158
+ * `Vector3` in Babylon.js). Kept here to avoid a circular import between the
1159
+ * vector and matrix modules.
1160
+ */
1161
+ function transformCoordinates(vector, transformation) {
1162
+ const m = transformation.m;
1163
+ const x = vector.x;
1164
+ const y = vector.y;
1165
+ const z = vector.z;
1166
+ const rx = x * m[0] + y * m[4] + z * m[8] + m[12];
1167
+ const ry = x * m[1] + y * m[5] + z * m[9] + m[13];
1168
+ const rz = x * m[2] + y * m[6] + z * m[10] + m[14];
1169
+ const rw = 1 / (x * m[3] + y * m[7] + z * m[11] + m[15]);
1170
+ return new Vector3(rx * rw, ry * rw, rz * rw);
1171
+ }
1172
+ function transformNormal(vector, transformation) {
1173
+ const m = transformation.m;
1174
+ const x = vector.x;
1175
+ const y = vector.y;
1176
+ const z = vector.z;
1177
+ 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]);
1178
+ }
1179
+ //#endregion
1180
+ //#region src/culling/bounding.ts
1181
+ /**
1182
+ * Babylon.js-compatible bounding volumes (`BoundingBox`, `BoundingSphere`,
1183
+ * `BoundingInfo`) — pure JS over the compat math types.
1184
+ *
1185
+ * World-space members (`minimumWorld`, `maximumWorld`, `centerWorld`,
1186
+ * `extendSizeWorld`, `vectorsWorld`, `radiusWorld`) are derived by transforming
1187
+ * the local geometry by the supplied world matrix, exactly as Babylon.js does:
1188
+ * all eight corners are transformed and the world AABB is fitted around them, so
1189
+ * the result is correct under rotation (transforming only min/max is not).
1190
+ */
1191
+ var boundingSphereScaleMinimum;
1192
+ var boundingSphereScaleMaximum;
1193
+ var BoundingSphere = class {
1194
+ center = new Vector3();
1195
+ radius;
1196
+ centerWorld = new Vector3();
1197
+ radiusWorld;
1198
+ minimum = new Vector3();
1199
+ maximum = new Vector3();
1200
+ _worldMatrix;
1201
+ constructor(min, max, worldMatrix) {
1202
+ this.radius = 0;
1203
+ this.radiusWorld = 0;
1204
+ this._worldMatrix = Matrix.Identity();
1205
+ this.reConstruct(min, max, worldMatrix);
1206
+ }
1207
+ reConstruct(min, max, worldMatrix) {
1208
+ this.minimum.copyFrom(min);
1209
+ this.maximum.copyFrom(max);
1210
+ this.center.copyFrom(Vector3.Lerp(min, max, .5));
1211
+ this.radius = max.subtract(min).length() * .5;
1212
+ this._update(worldMatrix ?? Matrix.Identity());
1213
+ }
1214
+ getWorldMatrix() {
1215
+ return this._worldMatrix;
1216
+ }
1217
+ scale(factor) {
1218
+ const minimum = boundingSphereScaleMinimum ??= new Vector3();
1219
+ const maximum = boundingSphereScaleMaximum ??= new Vector3();
1220
+ scaleBoundsFromCenterToRef(this.minimum, this.maximum, this.center, factor, minimum, maximum);
1221
+ this.reConstruct(minimum, maximum, this._worldMatrix);
1222
+ return this;
1223
+ }
1224
+ /** @internal */
1225
+ _update(worldMatrix) {
1226
+ Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);
1227
+ const scaled = Vector3.TransformNormal(new Vector3(1, 1, 1), worldMatrix);
1228
+ this.radiusWorld = Math.max(Math.abs(scaled.x), Math.abs(scaled.y), Math.abs(scaled.z)) * this.radius;
1229
+ this._worldMatrix = worldMatrix;
1230
+ }
1231
+ intersectsPoint(point) {
1232
+ return Vector3.DistanceSquared(this.centerWorld, point) <= this.radiusWorld * this.radiusWorld;
1233
+ }
1234
+ static Intersects(a, b) {
1235
+ const r = a.radiusWorld + b.radiusWorld;
1236
+ return Vector3.DistanceSquared(a.centerWorld, b.centerWorld) <= r * r;
1237
+ }
1238
+ };
1239
+ var BoundingBox = class {
1240
+ minimum = new Vector3();
1241
+ maximum = new Vector3();
1242
+ center = new Vector3();
1243
+ extendSize = new Vector3();
1244
+ /** Center of the AABB in world space. */
1245
+ centerWorld = new Vector3();
1246
+ /** Half-size of the AABB in world space (multiply by 2 for the full size). */
1247
+ extendSizeWorld = new Vector3();
1248
+ /** Minimum corner of the world-space AABB. */
1249
+ minimumWorld = new Vector3();
1250
+ /** Maximum corner of the world-space AABB. */
1251
+ maximumWorld = new Vector3();
1252
+ /** The 8 corner points in local space (min/max combinations). */
1253
+ vectors = [];
1254
+ /** The 8 corner points transformed into world space. */
1255
+ vectorsWorld = [];
1256
+ /** The three world-space axis directions of the box (rows of the world matrix). */
1257
+ directions = [
1258
+ new Vector3(),
1259
+ new Vector3(),
1260
+ new Vector3()
1261
+ ];
1262
+ _worldMatrix;
1263
+ constructor(min, max, worldMatrix) {
1264
+ for (let i = 0; i < 8; i++) {
1265
+ this.vectors.push(new Vector3());
1266
+ this.vectorsWorld.push(new Vector3());
1267
+ }
1268
+ this._worldMatrix = Matrix.Identity();
1269
+ this.reConstruct(min, max, worldMatrix);
1270
+ }
1271
+ reConstruct(min, max, worldMatrix) {
1272
+ const minX = min.x, minY = min.y, minZ = min.z, maxX = max.x, maxY = max.y, maxZ = max.z;
1273
+ this.minimum.copyFromFloats(minX, minY, minZ);
1274
+ this.maximum.copyFromFloats(maxX, maxY, maxZ);
1275
+ this.vectors[0].copyFromFloats(minX, minY, minZ);
1276
+ this.vectors[1].copyFromFloats(maxX, maxY, maxZ);
1277
+ this.vectors[2].copyFromFloats(maxX, minY, minZ);
1278
+ this.vectors[3].copyFromFloats(minX, maxY, minZ);
1279
+ this.vectors[4].copyFromFloats(minX, minY, maxZ);
1280
+ this.vectors[5].copyFromFloats(maxX, maxY, minZ);
1281
+ this.vectors[6].copyFromFloats(minX, maxY, maxZ);
1282
+ this.vectors[7].copyFromFloats(maxX, minY, maxZ);
1283
+ this.center.copyFromFloats((minX + maxX) * .5, (minY + maxY) * .5, (minZ + maxZ) * .5);
1284
+ this.extendSize.copyFromFloats((maxX - minX) * .5, (maxY - minY) * .5, (maxZ - minZ) * .5);
1285
+ this._update(worldMatrix ?? Matrix.Identity());
1286
+ }
1287
+ getWorldMatrix() {
1288
+ return this._worldMatrix;
1289
+ }
1290
+ /** @internal */
1291
+ _update(world) {
1292
+ this.minimumWorld.setAll(Number.MAX_VALUE);
1293
+ this.maximumWorld.setAll(-Number.MAX_VALUE);
1294
+ for (let i = 0; i < 8; i++) {
1295
+ const v = this.vectorsWorld[i];
1296
+ Vector3.TransformCoordinatesToRef(this.vectors[i], world, v);
1297
+ this.minimumWorld.minimizeInPlace(v);
1298
+ this.maximumWorld.maximizeInPlace(v);
1299
+ }
1300
+ const minX = this.minimumWorld.x, minY = this.minimumWorld.y, minZ = this.minimumWorld.z, maxX = this.maximumWorld.x, maxY = this.maximumWorld.y, maxZ = this.maximumWorld.z;
1301
+ this.extendSizeWorld.copyFromFloats((maxX - minX) * .5, (maxY - minY) * .5, (maxZ - minZ) * .5);
1302
+ this.centerWorld.copyFromFloats((minX + maxX) * .5, (minY + maxY) * .5, (minZ + maxZ) * .5);
1303
+ const m = world.m;
1304
+ this.directions[0].copyFromFloats(m[0], m[1], m[2]);
1305
+ this.directions[1].copyFromFloats(m[4], m[5], m[6]);
1306
+ this.directions[2].copyFromFloats(m[8], m[9], m[10]);
1307
+ this._worldMatrix = world;
1308
+ }
1309
+ intersectsPoint(point) {
1310
+ return point.x >= this.minimumWorld.x && point.x <= this.maximumWorld.x && point.y >= this.minimumWorld.y && point.y <= this.maximumWorld.y && point.z >= this.minimumWorld.z && point.z <= this.maximumWorld.z;
1311
+ }
1312
+ static Intersects(a, b) {
1313
+ return a.minimumWorld.x <= b.maximumWorld.x && a.maximumWorld.x >= b.minimumWorld.x && a.minimumWorld.y <= b.maximumWorld.y && a.maximumWorld.y >= b.minimumWorld.y && a.minimumWorld.z <= b.maximumWorld.z && a.maximumWorld.z >= b.minimumWorld.z;
1314
+ }
1315
+ };
1316
+ var BoundingInfo = class {
1317
+ boundingBox;
1318
+ boundingSphere;
1319
+ constructor(min, max, worldMatrix) {
1320
+ this.boundingBox = new BoundingBox(min, max, worldMatrix);
1321
+ this.boundingSphere = new BoundingSphere(min, max, worldMatrix);
1322
+ }
1323
+ get minimum() {
1324
+ return this.boundingBox.minimum;
1325
+ }
1326
+ get maximum() {
1327
+ return this.boundingBox.maximum;
1328
+ }
1329
+ intersectsPoint(point) {
1330
+ return this.boundingSphere.intersectsPoint(point) && this.boundingBox.intersectsPoint(point);
1331
+ }
1332
+ /** Babylon.js `BoundingInfo.update` — re-derive the world-space bounds from the
1333
+ * local geometry and a new world matrix. */
1334
+ update(worldMatrix) {
1335
+ this.boundingBox._update(worldMatrix);
1336
+ this.boundingSphere._update(worldMatrix);
1337
+ }
1338
+ /** Rebuild the local bounds and (optionally) re-derive world-space bounds from
1339
+ * the supplied world matrix, transforming all eight corners. */
1340
+ reConstruct(min, max, worldMatrix) {
1341
+ this.boundingBox.reConstruct(min, max, worldMatrix);
1342
+ this.boundingSphere.reConstruct(min, max, worldMatrix);
1343
+ }
1344
+ };
1345
+ //#endregion
1346
+ //#region src/misc/observable.ts
1347
+ var Observable = class {
1348
+ _onObserverAdded;
1349
+ notifyIfTriggered;
1350
+ _observers = [];
1351
+ _hasNotified = false;
1352
+ _lastNotifiedValue;
1353
+ _lastNotifiedMask = -1;
1354
+ constructor(_onObserverAdded, notifyIfTriggered = false) {
1355
+ this._onObserverAdded = _onObserverAdded;
1356
+ this.notifyIfTriggered = notifyIfTriggered;
1357
+ }
1358
+ add(callback, mask = -1) {
1359
+ this._observers.push({
1360
+ callback,
1361
+ mask
1362
+ });
1363
+ this._onObserverAdded?.(callback);
1364
+ if (this._hasNotified && this.notifyIfTriggered && (mask & this._lastNotifiedMask) !== 0) callback(this._lastNotifiedValue);
1365
+ return callback;
1366
+ }
1367
+ addOnce(callback, mask = -1) {
1368
+ const wrapper = (eventData) => {
1369
+ this.removeCallback(wrapper);
1370
+ callback(eventData);
1371
+ };
1372
+ return this.add(wrapper, mask);
1373
+ }
1374
+ remove(callback) {
1375
+ return callback ? this.removeCallback(callback) : false;
1376
+ }
1377
+ removeCallback(callback) {
1378
+ const index = this._observers.findIndex((observer) => observer.callback === callback);
1379
+ if (index !== -1) {
1380
+ this._observers.splice(index, 1);
1381
+ return true;
1382
+ }
1383
+ return false;
1384
+ }
1385
+ notifyObservers(eventData, mask = -1) {
1386
+ if (this.notifyIfTriggered) {
1387
+ this._hasNotified = true;
1388
+ this._lastNotifiedValue = eventData;
1389
+ this._lastNotifiedMask = mask;
1390
+ }
1391
+ for (const observer of this._observers.slice()) if ((observer.mask & mask) !== 0) observer.callback(eventData);
1392
+ }
1393
+ hasObservers() {
1394
+ return this._observers.length > 0;
1395
+ }
1396
+ clear() {
1397
+ this._observers = [];
1398
+ this._onObserverAdded = void 0;
1399
+ this.cleanLastNotifiedState();
1400
+ }
1401
+ cleanLastNotifiedState() {
1402
+ this._hasNotified = false;
1403
+ this._lastNotifiedValue = void 0;
1404
+ this._lastNotifiedMask = -1;
1405
+ }
1406
+ };
1407
+ //#endregion
1408
+ //#region src/node/node.ts
1409
+ var _uniqueIdCounter = 0;
1410
+ var Node = class {
1411
+ name;
1412
+ /** String id. Defaults to the name (Babylon.js parity). */
1413
+ id;
1414
+ /** Process-unique numeric id, assigned at construction. */
1415
+ uniqueId;
1416
+ /** Free-form user data slot (Babylon.js `Node.metadata`). */
1417
+ metadata = null;
1418
+ onDisposeObservable = new Observable();
1419
+ /** @internal Owning compat scene, when constructed against one. */
1420
+ _scene;
1421
+ /** @internal */
1422
+ _parent = null;
1423
+ /** @internal Direct children, maintained as `parent` / `setParent` links change. */
1424
+ _children = [];
1425
+ /** @internal */
1426
+ _enabled = true;
1427
+ /** @internal Effective enabled state inherited from the parent chain. */
1428
+ _parentEnabled = true;
1429
+ /** @internal */
1430
+ _disposed = false;
1431
+ constructor(name, scene) {
1432
+ this.name = name;
1433
+ this.id = name;
1434
+ this.uniqueId = ++_uniqueIdCounter;
1435
+ this._scene = scene;
1436
+ }
1437
+ /** The runtime class name (overridden by each subclass). */
1438
+ getClassName() {
1439
+ return "Node";
1440
+ }
1441
+ /** The scene this node belongs to, if any. */
1442
+ getScene() {
1443
+ return this._scene;
1444
+ }
1445
+ /** The engine backing this node's scene, if any. */
1446
+ getEngine() {
1447
+ return this._scene?.getEngine();
1448
+ }
1449
+ get parent() {
1450
+ return this._parent;
1451
+ }
1452
+ set parent(value) {
1453
+ this._linkParent(value);
1454
+ this._applyParent(value);
1455
+ }
1456
+ /**
1457
+ * @internal Update the parent link and both nodes' child registries. Shared by
1458
+ * the `parent` setter and `TransformNode.setParent` (which differ only in how
1459
+ * the Lite-side transform is reparented, handled by their own callers).
1460
+ */
1461
+ _linkParent(value) {
1462
+ if (this._parent === value) return;
1463
+ if (this._parent) {
1464
+ const i = this._parent._children.indexOf(this);
1465
+ if (i !== -1) this._parent._children.splice(i, 1);
1466
+ }
1467
+ this._parent = value;
1468
+ if (value && !value._children.includes(this)) value._children.push(this);
1469
+ this._syncParentEnabledState();
1470
+ }
1471
+ /** @internal Whether this node is an `AbstractMesh` (overridden there) — drives `getChildMeshes`. */
1472
+ _isMeshNode() {
1473
+ return false;
1474
+ }
1475
+ /**
1476
+ * Babylon.js `node.getDescendants(directDescendantsOnly?, predicate?)` — the
1477
+ * nodes parented (directly or transitively) under this one, optionally filtered.
1478
+ */
1479
+ getDescendants(directDescendantsOnly = false, predicate) {
1480
+ const results = [];
1481
+ const collect = (node) => {
1482
+ for (const child of node._children) {
1483
+ if (!predicate || predicate(child)) results.push(child);
1484
+ if (!directDescendantsOnly) collect(child);
1485
+ }
1486
+ };
1487
+ collect(this);
1488
+ return results;
1489
+ }
1490
+ /**
1491
+ * Babylon.js `node.getChildren(predicate?, directDescendantsOnly?)` — descendant
1492
+ * nodes (direct children by default), optionally filtered by a predicate.
1493
+ */
1494
+ getChildren(predicate, directDescendantsOnly = true) {
1495
+ return this.getDescendants(directDescendantsOnly, predicate);
1496
+ }
1497
+ /**
1498
+ * Babylon.js `node.getChildMeshes(directDescendantsOnly?, predicate?)` — the
1499
+ * descendant nodes that are meshes (all descendants by default).
1500
+ */
1501
+ getChildMeshes(directDescendantsOnly = false, predicate) {
1502
+ return this.getDescendants(directDescendantsOnly, (node) => node._isMeshNode() && (!predicate || predicate(node)));
1503
+ }
1504
+ /**
1505
+ * Babylon.js `node.getHierarchyBoundingVectors(includeDescendants?, predicate?)`
1506
+ * — world-space bounds spanning this mesh and eligible descendant meshes.
1507
+ */
1508
+ getHierarchyBoundingVectors(includeDescendants = true, predicate = null) {
1509
+ const min = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1510
+ const max = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1511
+ if (this._isMeshNode()) {
1512
+ const boundingBox = this.getBoundingInfo().boundingBox;
1513
+ min.copyFrom(boundingBox.minimumWorld);
1514
+ max.copyFrom(boundingBox.maximumWorld);
1515
+ }
1516
+ if (includeDescendants) for (const descendant of this.getDescendants()) {
1517
+ const descendantMesh = descendant;
1518
+ if (predicate && !predicate(descendantMesh) || !descendant._isMeshNode() || descendantMesh.getTotalVertices() === 0) continue;
1519
+ const boundingBox = descendantMesh.getBoundingInfo().boundingBox;
1520
+ min.minimizeInPlace(boundingBox.minimumWorld);
1521
+ max.maximizeInPlace(boundingBox.maximumWorld);
1522
+ }
1523
+ return {
1524
+ min,
1525
+ max
1526
+ };
1527
+ }
1528
+ isEnabled(checkAncestors = true) {
1529
+ return this._enabled && (!checkAncestors || this._parentEnabled);
1530
+ }
1531
+ setEnabled(value) {
1532
+ if (this._enabled === value) return;
1533
+ this._enabled = value;
1534
+ this._syncParentEnabledState();
1535
+ }
1536
+ /** @internal Refresh this subtree after a local enabled or parent change. */
1537
+ _syncParentEnabledState() {
1538
+ this._parentEnabled = this._parent?.isEnabled() ?? true;
1539
+ this._onEffectiveEnabledStateChanged(this.isEnabled());
1540
+ for (const child of this._children) child._syncParentEnabledState();
1541
+ }
1542
+ /** @internal Hook for wrappers that must materialize effective enabled state in Lite. */
1543
+ _onEffectiveEnabledStateChanged(_enabled) {}
1544
+ isDisposed() {
1545
+ return this._disposed;
1546
+ }
1547
+ dispose(doNotRecurse = false) {
1548
+ this._disposeWrapperTree(doNotRecurse);
1549
+ }
1550
+ /** @internal Dispose this node's subclass-owned resources. */
1551
+ _disposeSelf(_doNotRecurse) {}
1552
+ /** @internal Dispose this compat wrapper tree in post-order. */
1553
+ _disposeWrapperTree(doNotRecurse = false) {
1554
+ if (this._disposed) return;
1555
+ if (doNotRecurse) for (const child of [...this._children]) child.parent = null;
1556
+ else for (const child of [...this._children]) child._disposeWrapperTree();
1557
+ this._disposeSelf(doNotRecurse);
1558
+ this._disposed = true;
1559
+ this.onDisposeObservable.notifyObservers(this);
1560
+ this.onDisposeObservable.clear();
1561
+ this._linkParent(null);
1562
+ this._scene?._unregisterNode(this);
1563
+ }
1564
+ /** @internal Hook for subclasses to wire the parent link into the Lite scene graph. */
1565
+ _applyParent(_parent) {}
1566
+ };
1567
+ //#endregion
1568
+ //#region src/materials/materials.ts
1569
+ /**
1570
+ * Babylon.js-compatible material classes over the Babylon Lite material
1571
+ * factories.
1572
+ *
1573
+ * The Lite material is plain-data props (`_lite`); assign it to a mesh via
1574
+ * `mesh.material = material`. Property setters mutate the props and mark the
1575
+ * material UBO dirty (matching Babylon.js's "mutate then it just works"
1576
+ * behaviour). Only the common property subset is mapped; rarely-used Babylon.js
1577
+ * material properties are intentionally omitted.
1578
+ */
1579
+ /** Babylon.js `Material` — base class for all materials. */
1580
+ var Material = class {
1581
+ name;
1582
+ /** @internal Whether a compat `MaterialPluginBase` is attached. */
1583
+ _usesMaterialPlugins = false;
1584
+ /** Babylon.js plugin manager, created lazily by the first `MaterialPluginBase`. */
1585
+ pluginManager;
1586
+ /** Common transparency mode flag (Babylon.js `Material.transparencyMode`). */
1587
+ transparencyMode = null;
1588
+ /** Back-face culling toggle (Babylon.js `Material.backFaceCulling`). */
1589
+ _backFaceCulling = true;
1590
+ get backFaceCulling() {
1591
+ return this._backFaceCulling;
1592
+ }
1593
+ set backFaceCulling(value) {
1594
+ this._backFaceCulling = value;
1595
+ this._applyBackFaceCulling(value);
1596
+ this._markDirty();
1597
+ }
1598
+ /** @internal Per-material hook to push culling onto the Lite props (Standard vs PBR differ). */
1599
+ _applyBackFaceCulling(_value) {}
1600
+ /** Wireframe rendering toggle (not honoured by all Lite materials). */
1601
+ wireframe = false;
1602
+ /** @internal Owning compat scene, when constructed against one. */
1603
+ _scene;
1604
+ constructor(name, scene) {
1605
+ this.name = name;
1606
+ this._scene = scene;
1607
+ scene?._registerMaterial(this);
1608
+ }
1609
+ getClassName() {
1610
+ return "Material";
1611
+ }
1612
+ /**
1613
+ * @internal Copy the shared base + Lite data-property state onto a freshly
1614
+ * constructed clone. The clone keeps the `_buildGroup`/UBO its own factory
1615
+ * created (internal `_`-prefixed fields are never copied), so only the observable
1616
+ * data properties — colours, scalars, and shared texture references — carry over.
1617
+ */
1618
+ _cloneBaseInto(target) {
1619
+ copyLiteMaterialData(this._lite, target._lite);
1620
+ target.transparencyMode = this.transparencyMode;
1621
+ target.wireframe = this.wireframe;
1622
+ target.backFaceCulling = this._backFaceCulling;
1623
+ }
1624
+ /** The scene this material was constructed against (Babylon.js `Material.getScene`). */
1625
+ getScene() {
1626
+ return this._scene;
1627
+ }
1628
+ /**
1629
+ * The textures currently bound to this material (Babylon.js
1630
+ * `Material.getActiveTextures`). The base material owns no texture slots, so
1631
+ * this returns an empty array; each subclass overrides it to enumerate its own
1632
+ * slots and those of its extensions.
1633
+ */
1634
+ getActiveTextures() {
1635
+ return [];
1636
+ }
1637
+ _markDirty() {
1638
+ markMaterialUboDirty(this._lite);
1639
+ }
1640
+ /**
1641
+ * @internal Finalize GPU-facing resources before the mesh is registered.
1642
+ * Base materials need nothing; PBR overrides this to synthesize the solid
1643
+ * textures Babylon Lite's PBR pipeline requires from factor-only materials.
1644
+ */
1645
+ _ensureRenderable(_engine) {}
1646
+ /**
1647
+ * @internal Adopt an owning scene discovered when the material is first assigned
1648
+ * to a mesh (Babylon.js allows `new StandardMaterial(name)` with no scene, then
1649
+ * `mesh.material = mat`). Needed so the texture-readiness path can reconcile the
1650
+ * material into the running scene. Registers with the scene the first time.
1651
+ */
1652
+ _adoptScene(scene) {
1653
+ if (!this._scene) {
1654
+ this._scene = scene;
1655
+ scene._registerMaterial(this);
1656
+ if (this._usesMaterialPlugins) scene._requestMaterialPlugins(this._lite);
1657
+ }
1658
+ }
1659
+ /** @internal Rebuild plugin shader state after a Babylon.js plugin dirties its defines. */
1660
+ _markPluginDefinesDirty() {
1661
+ this._markDirty();
1662
+ this._scene?._requestMaterialPlugins(this._lite);
1663
+ }
1664
+ /**
1665
+ * @internal Reconcile this material into its scene when the scene is already
1666
+ * live: finalize GPU-facing resources ({@link _ensureRenderable}) and rebuild
1667
+ * the renderables of every mesh using it. A no-op before engine start (the
1668
+ * boot-time build handles those meshes) or when the material has no scene.
1669
+ * Shared by the mesh `material` setter and the texture-readiness callback.
1670
+ */
1671
+ _refreshInScene() {
1672
+ const scene = this._scene;
1673
+ if (!scene?._hasStarted) return;
1674
+ this._ensureRenderable(scene.getEngine()._lite);
1675
+ rebuildMaterial(scene._lite, this._lite);
1676
+ }
1677
+ /**
1678
+ * @internal Rebind + rebuild this material once an asynchronously loaded texture
1679
+ * assigned to it becomes GPU-ready. Babylon.js `Texture`s load in the background,
1680
+ * so a texture assigned to a material (or a material assigned to a mesh) before
1681
+ * the load resolves must go back through the rebuild path once the handle exists.
1682
+ * Fires immediately when the texture is already ready (then gated by scene state).
1683
+ */
1684
+ _watchTexture(texture) {
1685
+ texture?._onReady?.(() => this._refreshInScene());
1686
+ }
1687
+ dispose() {
1688
+ this._scene?._unregisterMaterial(this);
1689
+ this._scene = void 0;
1690
+ }
1691
+ };
1692
+ /** Babylon.js `PushMaterial` — intermediate base; behaves like {@link Material} here. */
1693
+ var PushMaterial = class extends Material {
1694
+ getClassName() {
1695
+ return "PushMaterial";
1696
+ }
1697
+ };
1698
+ function readColor3(tuple) {
1699
+ return tuple ? new Color3(tuple[0], tuple[1], tuple[2]) : new Color3(0, 0, 0);
1700
+ }
1701
+ /**
1702
+ * Copy the observable Babylon Lite material data-properties from `src` onto `dst`.
1703
+ * `_`-prefixed internal fields (`_buildGroup`, `_uboVersion`, render-feature caches)
1704
+ * are skipped so the clone keeps its own renderable state. Arrays (colour/UV tuples)
1705
+ * are copied so mutating one material's colour does not alias the other; object
1706
+ * values (texture handles) are shared by reference, matching Babylon.js clone
1707
+ * semantics. Nested config objects (PBR clearcoat/sheen/…) are re-copied per-subclass.
1708
+ */
1709
+ function copyLiteMaterialData(src, dst) {
1710
+ const s = src;
1711
+ const d = dst;
1712
+ for (const key of Object.keys(s)) {
1713
+ if (key.startsWith("_")) continue;
1714
+ const value = s[key];
1715
+ d[key] = Array.isArray(value) ? value.slice() : value;
1716
+ }
1717
+ }
1718
+ /**
1719
+ * @internal Scene OWNERSHIP of a material, independent of GPU finalization. Babylon.js allows
1720
+ * `new StandardMaterial(name)` with no scene, so the material a mesh renders with adopts that mesh's scene
1721
+ * as soon as the two meet — whether or not the scene has started. A material rendered by a scene it never
1722
+ * adopted has no scene to rebuild in, and its later `_refreshInScene()` requests (a `disableLighting`
1723
+ * toggle, a texture that finished loading) silently do nothing.
1724
+ */
1725
+ function adoptMaterialScene(material, scene) {
1726
+ material._adoptScene?.(scene);
1727
+ }
1728
+ /**
1729
+ * @internal Ownership plus GPU finalization (`_ensureRenderable`). Finalization needs the engine, so it stays
1730
+ * gated to the moments a mesh actually enters the running scene: the live branch of the `material` setter
1731
+ * and the deferred registration at engine start.
1732
+ */
1733
+ function attachMaterialToScene(material, scene) {
1734
+ adoptMaterialScene(material, scene);
1735
+ material._ensureRenderable(scene.getEngine()._lite);
1736
+ }
1737
+ var StandardMaterial = class StandardMaterial extends PushMaterial {
1738
+ /** @internal Underlying Babylon Lite standard-material props. */
1739
+ _lite;
1740
+ /** Diffuse colour as the app set it. Kept apart from `_lite.diffuseColor`, which is forced to white
1741
+ * while the material is unlit (see `_syncDiffuse`). */
1742
+ _diffuse = null;
1743
+ constructor(name, scene) {
1744
+ super(name, scene);
1745
+ this._lite = createStandardMaterial();
1746
+ }
1747
+ /**
1748
+ * Babylon.js shades an unlit StandardMaterial as `emissive + ambient`: the diffuse colour only scales
1749
+ * the accumulated light, and there is none. Lite's unlit path is `emissive × diffuse`, so the usual
1750
+ * "unlit colour" setup (black diffuse, colour in emissive) rendered black. Hand Lite a neutral white
1751
+ * diffuse while lighting is disabled and the app's own colour otherwise.
1752
+ */
1753
+ _syncDiffuse() {
1754
+ const diffuse = this._diffuse ??= [...this._lite.diffuseColor];
1755
+ this._lite.diffuseColor = this._lite.disableLighting ? [
1756
+ 1,
1757
+ 1,
1758
+ 1
1759
+ ] : [
1760
+ diffuse[0],
1761
+ diffuse[1],
1762
+ diffuse[2]
1763
+ ];
1764
+ }
1765
+ getClassName() {
1766
+ return "StandardMaterial";
1767
+ }
1768
+ get diffuseColor() {
1769
+ return readColor3(this._diffuse ?? this._lite.diffuseColor);
1770
+ }
1771
+ set diffuseColor(value) {
1772
+ this._diffuse = [
1773
+ value.r,
1774
+ value.g,
1775
+ value.b
1776
+ ];
1777
+ this._syncDiffuse();
1778
+ this._markDirty();
1779
+ }
1780
+ get specularColor() {
1781
+ return readColor3(this._lite.specularColor);
1782
+ }
1783
+ set specularColor(value) {
1784
+ this._lite.specularColor = [
1785
+ value.r,
1786
+ value.g,
1787
+ value.b
1788
+ ];
1789
+ this._markDirty();
1790
+ }
1791
+ get emissiveColor() {
1792
+ return readColor3(this._lite.emissiveColor);
1793
+ }
1794
+ set emissiveColor(value) {
1795
+ this._lite.emissiveColor = [
1796
+ value.r,
1797
+ value.g,
1798
+ value.b
1799
+ ];
1800
+ this._markDirty();
1801
+ }
1802
+ get ambientColor() {
1803
+ return readColor3(this._lite.ambientColor);
1804
+ }
1805
+ set ambientColor(value) {
1806
+ this._lite.ambientColor = [
1807
+ value.r,
1808
+ value.g,
1809
+ value.b
1810
+ ];
1811
+ this._markDirty();
1812
+ }
1813
+ get disableLighting() {
1814
+ return this._lite.disableLighting;
1815
+ }
1816
+ set disableLighting(value) {
1817
+ const changed = this._lite.disableLighting !== value;
1818
+ this._lite.disableLighting = value;
1819
+ this._syncDiffuse();
1820
+ this._markDirty();
1821
+ if (changed) this._refreshInScene();
1822
+ }
1823
+ _applyBackFaceCulling(value) {
1824
+ this._lite.backFaceCulling = value;
1825
+ }
1826
+ get alpha() {
1827
+ return this._lite.alpha;
1828
+ }
1829
+ set alpha(value) {
1830
+ this._lite.alpha = value;
1831
+ this._markDirty();
1832
+ }
1833
+ get diffuseTexture() {
1834
+ return this._diffuseTexture;
1835
+ }
1836
+ set diffuseTexture(texture) {
1837
+ this._diffuseTexture = texture;
1838
+ this._lite.diffuseTexture = texture?._lite ?? null;
1839
+ this._watchTexture(texture);
1840
+ this._markDirty();
1841
+ }
1842
+ /**
1843
+ * Babylon.js `StandardMaterial.alphaCutOff` — alpha-test threshold. Fragments
1844
+ * whose diffuse-texture alpha is below this value are discarded. Babylon Lite's
1845
+ * Standard pipeline alpha-tests against the diffuse texture's alpha when
1846
+ * `alphaCutOff > 0`, so this is wired directly.
1847
+ */
1848
+ get alphaCutOff() {
1849
+ return this._lite.alphaCutOff;
1850
+ }
1851
+ set alphaCutOff(value) {
1852
+ this._lite.alphaCutOff = value;
1853
+ this._markDirty();
1854
+ }
1855
+ /**
1856
+ * Babylon.js `StandardMaterial.useAlphaFromDiffuseTexture`. Babylon Lite's
1857
+ * alpha test already samples the diffuse texture's alpha (enabled via
1858
+ * `alphaCutOff`), so this is accepted for parity.
1859
+ */
1860
+ useAlphaFromDiffuseTexture = false;
1861
+ get bumpTexture() {
1862
+ return this._bumpTexture;
1863
+ }
1864
+ set bumpTexture(texture) {
1865
+ this._bumpTexture = texture;
1866
+ setStandardBumpTexture(this._lite, texture?._lite ?? null);
1867
+ this._watchTexture(texture);
1868
+ this._markDirty();
1869
+ }
1870
+ get emissiveTexture() {
1871
+ return this._emissiveTexture;
1872
+ }
1873
+ set emissiveTexture(texture) {
1874
+ this._emissiveTexture = texture;
1875
+ setStandardEmissiveTexture(this._lite, texture?._lite ?? null);
1876
+ this._watchTexture(texture);
1877
+ this._markDirty();
1878
+ }
1879
+ _diffuseTexture = null;
1880
+ _bumpTexture = null;
1881
+ _emissiveTexture = null;
1882
+ /** Enumerate the standard-material texture slots that are bound (Babylon.js `getActiveTextures`). */
1883
+ getActiveTextures() {
1884
+ const textures = [];
1885
+ if (this._diffuseTexture) textures.push(this._diffuseTexture);
1886
+ if (this._bumpTexture) textures.push(this._bumpTexture);
1887
+ if (this._emissiveTexture) textures.push(this._emissiveTexture);
1888
+ return textures;
1889
+ }
1890
+ /**
1891
+ * @internal Re-bind texture maps to the Lite material. Babylon.js `Texture`s
1892
+ * load asynchronously, so when `material.diffuseTexture = new Texture(url)` ran
1893
+ * the Lite handle was still undefined. By engine-start the scene has awaited the
1894
+ * loads, so copy the now-resolved handles (and UV tiling) onto the Lite props.
1895
+ */
1896
+ _ensureRenderable(_engine) {
1897
+ const diff = this._diffuseTexture;
1898
+ if (diff?._lite) {
1899
+ this._lite.diffuseTexture = diff._lite;
1900
+ if (diff.uScale !== void 0 && diff.vScale !== void 0) this._lite.uvScale = [diff.uScale, diff.vScale];
1901
+ }
1902
+ const bump = this._bumpTexture;
1903
+ if (bump?._lite) setStandardBumpTexture(this._lite, bump._lite);
1904
+ const emissive = this._emissiveTexture;
1905
+ if (emissive?._lite) setStandardEmissiveTexture(this._lite, emissive._lite);
1906
+ this._markDirty();
1907
+ }
1908
+ /**
1909
+ * Babylon.js `StandardMaterial.clone(name)`. Copies the diffuse/specular/emissive/
1910
+ * ambient colours and scalars, shares the diffuse/bump/emissive texture references,
1911
+ * and gives the clone its own Lite standard-material renderable.
1912
+ */
1913
+ clone(name) {
1914
+ const cloned = new StandardMaterial(name, this._scene);
1915
+ this._cloneBaseInto(cloned);
1916
+ cloned._diffuse = this._diffuse && [
1917
+ this._diffuse[0],
1918
+ this._diffuse[1],
1919
+ this._diffuse[2]
1920
+ ];
1921
+ cloned.useAlphaFromDiffuseTexture = this.useAlphaFromDiffuseTexture;
1922
+ cloned._diffuseTexture = this._diffuseTexture;
1923
+ cloned._bumpTexture = this._bumpTexture;
1924
+ cloned._emissiveTexture = this._emissiveTexture;
1925
+ return cloned;
1926
+ }
1927
+ };
1928
+ /**
1929
+ * Babylon.js `PBRClearCoatConfiguration` — the `pbr.clearCoat` sub-object.
1930
+ * Proxies the common clearcoat fields onto a Babylon Lite `ClearCoatProps`.
1931
+ */
1932
+ var PBRClearCoatConfiguration = class {
1933
+ _props;
1934
+ _markDirty;
1935
+ constructor(_props, _markDirty) {
1936
+ this._props = _props;
1937
+ this._markDirty = _markDirty;
1938
+ }
1939
+ get isEnabled() {
1940
+ return this._props.isEnabled ?? false;
1941
+ }
1942
+ set isEnabled(value) {
1943
+ this._props.isEnabled = value;
1944
+ this._markDirty();
1945
+ }
1946
+ get intensity() {
1947
+ return this._props.intensity ?? 1;
1948
+ }
1949
+ set intensity(value) {
1950
+ this._props.intensity = value;
1951
+ this._markDirty();
1952
+ }
1953
+ get roughness() {
1954
+ return this._props.roughness ?? 0;
1955
+ }
1956
+ set roughness(value) {
1957
+ this._props.roughness = value;
1958
+ this._markDirty();
1959
+ }
1960
+ get indexOfRefraction() {
1961
+ return this._props.indexOfRefraction ?? 1.5;
1962
+ }
1963
+ set indexOfRefraction(value) {
1964
+ this._props.indexOfRefraction = value;
1965
+ this._markDirty();
1966
+ }
1967
+ };
1968
+ /** Babylon.js `PBRSheenConfiguration` — the `pbr.sheen` sub-object over Lite `SheenProps`. */
1969
+ var PBRSheenConfiguration = class {
1970
+ _props;
1971
+ _markDirty;
1972
+ constructor(_props, _markDirty) {
1973
+ this._props = _props;
1974
+ this._markDirty = _markDirty;
1975
+ }
1976
+ get isEnabled() {
1977
+ return this._props.isEnabled;
1978
+ }
1979
+ set isEnabled(value) {
1980
+ this._props.isEnabled = value;
1981
+ this._markDirty();
1982
+ }
1983
+ get intensity() {
1984
+ return this._props.intensity ?? 1;
1985
+ }
1986
+ set intensity(value) {
1987
+ this._props.intensity = value;
1988
+ this._markDirty();
1989
+ }
1990
+ get roughness() {
1991
+ return this._props.roughness ?? 0;
1992
+ }
1993
+ set roughness(value) {
1994
+ this._props.roughness = value;
1995
+ this._markDirty();
1996
+ }
1997
+ get color() {
1998
+ const c = this._props.color ?? [
1999
+ 1,
2000
+ 1,
2001
+ 1
2002
+ ];
2003
+ return new Color3(c[0], c[1], c[2]);
2004
+ }
2005
+ set color(value) {
2006
+ this._props.color = [
2007
+ value.r,
2008
+ value.g,
2009
+ value.b
2010
+ ];
2011
+ this._markDirty();
2012
+ }
2013
+ /** Babylon.js `sheen.texture`. Retains the wrapper and binds the Lite handle if the texture has resolved. */
2014
+ get texture() {
2015
+ return this._texture;
2016
+ }
2017
+ set texture(value) {
2018
+ this._texture = value;
2019
+ if (value?._lite) this._props.texture = value._lite;
2020
+ else delete this._props.texture;
2021
+ this._markDirty();
2022
+ }
2023
+ _texture = null;
2024
+ /** Enumerate the sheen texture slot for `Material.getActiveTextures`. */
2025
+ getActiveTextures() {
2026
+ return this._texture ? [this._texture] : [];
2027
+ }
2028
+ };
2029
+ /** Babylon.js `PBRAnisotropicConfiguration` — the `pbr.anisotropy` sub-object over Lite `AnisotropyProps`. */
2030
+ var PBRAnisotropicConfiguration = class {
2031
+ _props;
2032
+ _markDirty;
2033
+ constructor(_props, _markDirty) {
2034
+ this._props = _props;
2035
+ this._markDirty = _markDirty;
2036
+ }
2037
+ get isEnabled() {
2038
+ return this._props.isEnabled;
2039
+ }
2040
+ set isEnabled(value) {
2041
+ this._props.isEnabled = value;
2042
+ this._markDirty();
2043
+ }
2044
+ get intensity() {
2045
+ return this._props.intensity ?? 1;
2046
+ }
2047
+ set intensity(value) {
2048
+ this._props.intensity = value;
2049
+ this._markDirty();
2050
+ }
2051
+ get direction() {
2052
+ const d = this._props.direction ?? [1, 0];
2053
+ return {
2054
+ x: d[0],
2055
+ y: d[1]
2056
+ };
2057
+ }
2058
+ set direction(value) {
2059
+ this._props.direction = [value.x, value.y];
2060
+ this._markDirty();
2061
+ }
2062
+ };
2063
+ /** Babylon.js `PBRIridescenceConfiguration` — the `pbr.iridescence` sub-object over Lite `IridescenceProps`. */
2064
+ var PBRIridescenceConfiguration = class {
2065
+ _props;
2066
+ _markDirty;
2067
+ constructor(_props, _markDirty) {
2068
+ this._props = _props;
2069
+ this._markDirty = _markDirty;
2070
+ }
2071
+ get isEnabled() {
2072
+ return this._props.isEnabled ?? false;
2073
+ }
2074
+ set isEnabled(value) {
2075
+ this._props.isEnabled = value;
2076
+ this._markDirty();
2077
+ }
2078
+ get intensity() {
2079
+ return this._props.intensity ?? 1;
2080
+ }
2081
+ set intensity(value) {
2082
+ this._props.intensity = value;
2083
+ this._markDirty();
2084
+ }
2085
+ get indexOfRefraction() {
2086
+ return this._props.indexOfRefraction ?? 1.3;
2087
+ }
2088
+ set indexOfRefraction(value) {
2089
+ this._props.indexOfRefraction = value;
2090
+ this._markDirty();
2091
+ }
2092
+ get minimumThickness() {
2093
+ return this._props.minimumThickness ?? 100;
2094
+ }
2095
+ set minimumThickness(value) {
2096
+ this._props.minimumThickness = value;
2097
+ this._markDirty();
2098
+ }
2099
+ get maximumThickness() {
2100
+ return this._props.maximumThickness ?? 400;
2101
+ }
2102
+ set maximumThickness(value) {
2103
+ this._props.maximumThickness = value;
2104
+ this._markDirty();
2105
+ }
2106
+ };
2107
+ var PBRMaterial = class PBRMaterial extends PushMaterial {
2108
+ /** @internal Underlying Babylon Lite PBR-material props. */
2109
+ _lite;
2110
+ _albedoFactor = [
2111
+ 1,
2112
+ 1,
2113
+ 1,
2114
+ 1
2115
+ ];
2116
+ constructor(name, scene) {
2117
+ super(name, scene);
2118
+ this._lite = createPbrMaterial();
2119
+ if (!this._lite.baseColorFactor) this._lite.baseColorFactor = [
2120
+ 1,
2121
+ 1,
2122
+ 1,
2123
+ 1
2124
+ ];
2125
+ }
2126
+ getClassName() {
2127
+ return "PBRMaterial";
2128
+ }
2129
+ get albedoColor() {
2130
+ return new Color3(this._albedoFactor[0], this._albedoFactor[1], this._albedoFactor[2]);
2131
+ }
2132
+ set albedoColor(value) {
2133
+ this._albedoFactor = [
2134
+ value.r,
2135
+ value.g,
2136
+ value.b,
2137
+ this._albedoFactor[3]
2138
+ ];
2139
+ this._lite.baseColorFactor = [...this._albedoFactor];
2140
+ this._markDirty();
2141
+ }
2142
+ /**
2143
+ * Babylon.js `pbr.albedoTexture` (glTF base-color map). The texture loads
2144
+ * asynchronously, so the resolved Lite handle (+ sRGB flag) is bound in
2145
+ * {@link _ensureRenderable} at engine start rather than here.
2146
+ */
2147
+ get albedoTexture() {
2148
+ return this._albedoTexture;
2149
+ }
2150
+ set albedoTexture(texture) {
2151
+ this._albedoTexture = texture;
2152
+ this._watchTexture(texture);
2153
+ this._markDirty();
2154
+ }
2155
+ _albedoTexture = null;
2156
+ /**
2157
+ * Enumerate every bound PBR texture slot, including extension sub-configurations
2158
+ * (Babylon.js `PBRMaterial.getActiveTextures`).
2159
+ */
2160
+ getActiveTextures() {
2161
+ const textures = [];
2162
+ if (this._albedoTexture) textures.push(this._albedoTexture);
2163
+ const environmentTexture = this.environmentTexture;
2164
+ if (environmentTexture) textures.push(environmentTexture);
2165
+ if (this._sheen) textures.push(...this._sheen.getActiveTextures());
2166
+ return textures;
2167
+ }
2168
+ get metallic() {
2169
+ return this._lite.metallicFactor ?? 1;
2170
+ }
2171
+ set metallic(value) {
2172
+ this._lite.metallicFactor = value;
2173
+ this._markDirty();
2174
+ }
2175
+ get roughness() {
2176
+ return this._lite.roughnessFactor ?? 1;
2177
+ }
2178
+ set roughness(value) {
2179
+ this._lite.roughnessFactor = value;
2180
+ this._markDirty();
2181
+ }
2182
+ get emissiveColor() {
2183
+ return readColor3(this._lite._emissiveColor);
2184
+ }
2185
+ set emissiveColor(value) {
2186
+ setPbrEmissive(this._lite, [
2187
+ value.r,
2188
+ value.g,
2189
+ value.b
2190
+ ]);
2191
+ this._markDirty();
2192
+ }
2193
+ /**
2194
+ * Babylon.js `pbr.usePhysicalLightFalloff`. When false, point/spot lights use
2195
+ * Standard-style linear range falloff instead of physical inverse-square.
2196
+ * Default true (matches Babylon.js PBRMaterial).
2197
+ */
2198
+ get usePhysicalLightFalloff() {
2199
+ return this._lite.usePhysicalLightFalloff ?? true;
2200
+ }
2201
+ set usePhysicalLightFalloff(value) {
2202
+ this._lite.usePhysicalLightFalloff = value;
2203
+ this._markDirty();
2204
+ }
2205
+ get alpha() {
2206
+ return this._lite.alpha ?? 1;
2207
+ }
2208
+ set alpha(value) {
2209
+ this._lite.alpha = value;
2210
+ this._markDirty();
2211
+ }
2212
+ /**
2213
+ * Babylon.js `material.forceIrradianceInFragment`. Babylon Lite computes
2214
+ * irradiance in the fragment stage already, so this is accepted for parity.
2215
+ */
2216
+ forceIrradianceInFragment = false;
2217
+ _applyBackFaceCulling(value) {
2218
+ this._lite.doubleSided = !value;
2219
+ }
2220
+ /**
2221
+ * Babylon.js `pbr.clearCoat` sub-configuration. Lazily allocates the Lite
2222
+ * `clearCoat` props on first access and proxies the common fields
2223
+ * (`isEnabled`, `intensity`, `roughness`, `indexOfRefraction`) onto them.
2224
+ */
2225
+ get clearCoat() {
2226
+ if (!this._clearCoat) {
2227
+ setPbrClearCoat(this._lite, this._lite._clearCoat ?? { isEnabled: false });
2228
+ this._clearCoat = new PBRClearCoatConfiguration(this._lite._clearCoat, () => this._markDirty());
2229
+ }
2230
+ return this._clearCoat;
2231
+ }
2232
+ _clearCoat;
2233
+ /** Babylon.js `pbr.sheen` sub-configuration (Lite `SheenProps`). */
2234
+ get sheen() {
2235
+ if (!this._sheen) {
2236
+ setPbrSheen(this._lite, this._lite._sheen ?? { isEnabled: false });
2237
+ this._sheen = new PBRSheenConfiguration(this._lite._sheen, () => this._markDirty());
2238
+ }
2239
+ return this._sheen;
2240
+ }
2241
+ _sheen;
2242
+ /** Babylon.js `pbr.anisotropy` sub-configuration (Lite `AnisotropyProps`). */
2243
+ get anisotropy() {
2244
+ if (!this._anisotropy) {
2245
+ setPbrAnisotropy(this._lite, this._lite._anisotropy ?? { isEnabled: false });
2246
+ this._anisotropy = new PBRAnisotropicConfiguration(this._lite._anisotropy, () => this._markDirty());
2247
+ }
2248
+ return this._anisotropy;
2249
+ }
2250
+ _anisotropy;
2251
+ /** Babylon.js `pbr.iridescence` sub-configuration (Lite `IridescenceProps`). */
2252
+ get iridescence() {
2253
+ if (!this._iridescence) {
2254
+ setPbrIridescence(this._lite, this._lite._iridescence ?? { isEnabled: false });
2255
+ this._iridescence = new PBRIridescenceConfiguration(this._lite._iridescence, () => this._markDirty());
2256
+ }
2257
+ return this._iridescence;
2258
+ }
2259
+ _iridescence;
2260
+ /**
2261
+ * Babylon.js `material.environmentTexture` / `reflectionTexture`. Babylon Lite
2262
+ * applies image-based lighting scene-wide rather than per-material, so a cube
2263
+ * environment assigned to a material is routed to the owning scene's
2264
+ * environment (the dominant single-IBL case Babylon.js scenes use).
2265
+ */
2266
+ get environmentTexture() {
2267
+ return this._environmentTexture ?? this._scene?.environmentTexture ?? null;
2268
+ }
2269
+ set environmentTexture(value) {
2270
+ this._environmentTexture = value;
2271
+ if (this._scene) this._scene.environmentTexture = value;
2272
+ }
2273
+ _environmentTexture = null;
2274
+ get reflectionTexture() {
2275
+ return this.environmentTexture;
2276
+ }
2277
+ set reflectionTexture(value) {
2278
+ this.environmentTexture = value;
2279
+ }
2280
+ /** @internal Bind resolved textures and synthesize the solid textures Babylon Lite's PBR pipeline requires from a factor-only material. */
2281
+ _ensureRenderable(engine) {
2282
+ const lite = this._lite;
2283
+ const albedo = this._albedoTexture;
2284
+ if (albedo?._lite) {
2285
+ lite.baseColorTexture = albedo._lite;
2286
+ lite.baseColorFactor = [...this._albedoFactor];
2287
+ if (albedo.gammaSpace ?? true) setPbrGammaAlbedo(lite);
2288
+ else lite._gammaAlbedo = false;
2289
+ }
2290
+ if (!lite.baseColorTexture) {
2291
+ lite.baseColorTexture = createSolidTexture2D(engine, 1, 1, 1, 1);
2292
+ lite.baseColorFactor = [...this._albedoFactor];
2293
+ }
2294
+ if (!lite.ormTexture) lite.ormTexture = createSolidTexture2D(engine, 1, 1, 1);
2295
+ }
2296
+ /**
2297
+ * Babylon.js `PBRMaterial.clone(name)`. Copies the albedo/metallic/roughness/
2298
+ * emissive state, shares the albedo texture reference, gives the clone independent
2299
+ * clearcoat/sheen/anisotropy/iridescence sub-configurations (sharing any nested
2300
+ * texture), and a fresh Lite PBR renderable.
2301
+ */
2302
+ clone(name) {
2303
+ const cloned = new PBRMaterial(name, this._scene);
2304
+ this._clonePbrInto(cloned);
2305
+ return cloned;
2306
+ }
2307
+ /**
2308
+ * @internal Copy PBR-specific compat + Lite state onto a freshly constructed PBR
2309
+ * clone (used by every `PBRMaterial` subclass so each returns its own concrete
2310
+ * type). The base `_cloneBaseInto` shares the sub-config objects by reference; this
2311
+ * re-copies them so the clone's `clearCoat`/`sheen`/… mutate independently while
2312
+ * still sharing any nested texture handle.
2313
+ */
2314
+ _clonePbrInto(target) {
2315
+ this._cloneBaseInto(target);
2316
+ target.forceIrradianceInFragment = this.forceIrradianceInFragment;
2317
+ target._albedoFactor = [...this._albedoFactor];
2318
+ target._albedoTexture = this._albedoTexture;
2319
+ const src = this._lite;
2320
+ const dst = target._lite;
2321
+ if (src._emissiveColor) setPbrEmissive(dst, [...src._emissiveColor]);
2322
+ if (src._clearCoat) setPbrClearCoat(dst, { ...src._clearCoat });
2323
+ if (src._sheen) setPbrSheen(dst, { ...src._sheen });
2324
+ if (src._anisotropy) setPbrAnisotropy(dst, { ...src._anisotropy });
2325
+ if (src._iridescence) setPbrIridescence(dst, { ...src._iridescence });
2326
+ }
2327
+ };
2328
+ /**
2329
+ * Babylon.js `PBRMetallicRoughnessMaterial` — a simplified façade over
2330
+ * {@link PBRMaterial} exposing the metallic-roughness workflow directly.
2331
+ */
2332
+ var PBRMetallicRoughnessMaterial = class PBRMetallicRoughnessMaterial extends PBRMaterial {
2333
+ getClassName() {
2334
+ return "PBRMetallicRoughnessMaterial";
2335
+ }
2336
+ /** Alias of `albedoColor` (glTF "base color"). */
2337
+ get baseColor() {
2338
+ return this.albedoColor;
2339
+ }
2340
+ set baseColor(value) {
2341
+ this.albedoColor = value;
2342
+ }
2343
+ clone(name) {
2344
+ const cloned = new PBRMetallicRoughnessMaterial(name, this._scene);
2345
+ this._clonePbrInto(cloned);
2346
+ return cloned;
2347
+ }
2348
+ };
2349
+ /**
2350
+ * Babylon.js `PBRSpecularGlossinessMaterial` — the spec/gloss workflow is
2351
+ * supported when loaded from glTF (`KHR_materials_pbrSpecularGlossiness`), but a
2352
+ * standalone manual spec/gloss material is not mapped onto Lite's metallic-roughness
2353
+ * PBR. The constructor builds a metallic-roughness PBR material and exposes a
2354
+ * `diffuseColor`/`glossiness` façade; results will not match BJS spec/gloss exactly.
2355
+ */
2356
+ var PBRSpecularGlossinessMaterial = class PBRSpecularGlossinessMaterial extends PBRMaterial {
2357
+ getClassName() {
2358
+ return "PBRSpecularGlossinessMaterial";
2359
+ }
2360
+ get diffuseColor() {
2361
+ return this.albedoColor;
2362
+ }
2363
+ set diffuseColor(value) {
2364
+ this.albedoColor = value;
2365
+ }
2366
+ /** Maps glossiness → (1 - roughness). */
2367
+ get glossiness() {
2368
+ return 1 - this.roughness;
2369
+ }
2370
+ set glossiness(value) {
2371
+ this.roughness = 1 - value;
2372
+ }
2373
+ clone(name) {
2374
+ const cloned = new PBRSpecularGlossinessMaterial(name, this._scene);
2375
+ this._clonePbrInto(cloned);
2376
+ return cloned;
2377
+ }
2378
+ };
2379
+ //#endregion
2380
+ //#region src/meshes/merge-mesh-geometry.ts
2381
+ function fillFlatNormals(positions, indices, indexOffset, indexCount, vertexBase, out) {
2382
+ for (let i = 0; i < indexCount; i += 3) {
2383
+ const a = (indices[indexOffset + i] + vertexBase) * 3;
2384
+ const b = (indices[indexOffset + i + 1] + vertexBase) * 3;
2385
+ const c = (indices[indexOffset + i + 2] + vertexBase) * 3;
2386
+ const ux = positions[b] - positions[a];
2387
+ const uy = positions[b + 1] - positions[a + 1];
2388
+ const uz = positions[b + 2] - positions[a + 2];
2389
+ const vx = positions[c] - positions[a];
2390
+ const vy = positions[c + 1] - positions[a + 1];
2391
+ const vz = positions[c + 2] - positions[a + 2];
2392
+ let nx = uy * vz - uz * vy;
2393
+ let ny = uz * vx - ux * vz;
2394
+ let nz = ux * vy - uy * vx;
2395
+ const len = Math.hypot(nx, ny, nz) || 1;
2396
+ nx /= len;
2397
+ ny /= len;
2398
+ nz /= len;
2399
+ for (const vi of [
2400
+ a,
2401
+ b,
2402
+ c
2403
+ ]) {
2404
+ out[vi] = nx;
2405
+ out[vi + 1] = ny;
2406
+ out[vi + 2] = nz;
2407
+ }
2408
+ }
2409
+ }
2410
+ function mergeMeshGeometry(engine, name, meshes) {
2411
+ if (meshes.length === 0) throw new Error("mergeMeshGeometry requires at least one mesh");
2412
+ let totalVerts = 0;
2413
+ let totalIdx = 0;
2414
+ let anyUvs = false;
2415
+ for (const mesh of meshes) {
2416
+ if (!mesh._cpuPositions || !mesh._cpuIndices) throw new Error(`mergeMeshGeometry: mesh "${mesh.name}" is missing CPU geometry`);
2417
+ totalVerts += mesh._cpuPositions.length / 3;
2418
+ totalIdx += mesh._cpuIndices.length;
2419
+ if (mesh._cpuUvs?.length) anyUvs = true;
2420
+ }
2421
+ const positions = new Float32Array(totalVerts * 3);
2422
+ const normals = new Float32Array(totalVerts * 3);
2423
+ const uvs = anyUvs ? new Float32Array(totalVerts * 2) : void 0;
2424
+ const indices = new Uint32Array(totalIdx);
2425
+ let pOff = 0;
2426
+ let iOff = 0;
2427
+ let vertBase = 0;
2428
+ for (const mesh of meshes) {
2429
+ const src = mesh._cpuPositions;
2430
+ const srcNormals = mesh._cpuNormals;
2431
+ const srcUvs = mesh._cpuUvs;
2432
+ const wm = mesh.worldMatrix;
2433
+ const vertexCount = src.length / 3;
2434
+ const a = wm[0], b = wm[4], c = wm[8], d = wm[1], e = wm[5], f = wm[9], g = wm[2], h = wm[6], i = wm[10];
2435
+ const c00 = e * i - f * h, c01 = f * g - d * i, c02 = d * h - e * g, c10 = c * h - b * i, c11 = a * i - c * g, c12 = b * g - a * h, c20 = b * f - c * e, c21 = c * d - a * f, c22 = a * e - b * d;
2436
+ const normalSign = a * c00 + b * c01 + c * c02 < 0 ? -1 : 1;
2437
+ const reverseWinding = normalSign !== (mesh._authoredSign ?? 1);
2438
+ const meshVertexStart = pOff / 3;
2439
+ for (let v = 0; v < src.length; v += 3) {
2440
+ const x = src[v], y = src[v + 1], z = src[v + 2];
2441
+ positions[pOff] = x * a + y * b + z * c + wm[12];
2442
+ positions[pOff + 1] = x * d + y * e + z * f + wm[13];
2443
+ positions[pOff + 2] = x * g + y * h + z * i + wm[14];
2444
+ if (srcNormals) {
2445
+ const nx = srcNormals[v], ny = srcNormals[v + 1], nz = srcNormals[v + 2];
2446
+ let tx = (nx * c00 + ny * c01 + nz * c02) * normalSign;
2447
+ let ty = (nx * c10 + ny * c11 + nz * c12) * normalSign;
2448
+ let tz = (nx * c20 + ny * c21 + nz * c22) * normalSign;
2449
+ const len = Math.hypot(tx, ty, tz) || 1;
2450
+ tx /= len;
2451
+ ty /= len;
2452
+ tz /= len;
2453
+ normals[pOff] = tx;
2454
+ normals[pOff + 1] = ty;
2455
+ normals[pOff + 2] = tz;
2456
+ }
2457
+ pOff += 3;
2458
+ }
2459
+ if (uvs && srcUvs?.length) uvs.set(srcUvs.subarray(0, vertexCount * 2), meshVertexStart * 2);
2460
+ const meshIdx = mesh._cpuIndices;
2461
+ const indexCount = meshIdx.length;
2462
+ const indexStart = iOff;
2463
+ for (let k = 0; k < indexCount; k += 3) {
2464
+ indices[iOff++] = meshIdx[k] + vertBase;
2465
+ indices[iOff++] = meshIdx[k + (reverseWinding ? 2 : 1)] + vertBase;
2466
+ indices[iOff++] = meshIdx[k + (reverseWinding ? 1 : 2)] + vertBase;
2467
+ }
2468
+ if (!srcNormals) fillFlatNormals(positions, indices, indexStart, indexCount, 0, normals);
2469
+ vertBase += vertexCount;
2470
+ }
2471
+ return createMeshFromData(engine, name, positions, normals, indices, uvs);
2472
+ }
2473
+ //#endregion
2474
+ //#region src/meshes/meshes.ts
2475
+ /**
2476
+ * Babylon.js-compatible mesh hierarchy and `MeshBuilder`.
2477
+ *
2478
+ * Mirrors the Babylon.js inheritance chain:
2479
+ * `Mesh → AbstractMesh → TransformNode → Node`. Geometry is built through the
2480
+ * Babylon Lite mesh factories (which take the engine, not the scene) and
2481
+ * registered with `addToScene`. Transform properties (`position`, `rotation`,
2482
+ * `scaling`) are live views over Lite's observable vectors, so
2483
+ * `mesh.position.x = 1` and `mesh.rotation.y += 0.01` propagate; reassignment
2484
+ * (`mesh.position = new Vector3(...)`) also works.
2485
+ */
2486
+ var LinesMaterial = class LinesMaterial extends Material {
2487
+ _lite;
2488
+ constructor(name, lite, scene) {
2489
+ super(name, scene);
2490
+ this._lite = lite;
2491
+ }
2492
+ getClassName() {
2493
+ return "ShaderMaterial";
2494
+ }
2495
+ clone(name) {
2496
+ return new LinesMaterial(name, createLineMaterial({
2497
+ name,
2498
+ color: this._lite.color,
2499
+ useVertexColor: this._lite.useVertexColor,
2500
+ useVertexAlpha: this._lite.useVertexAlpha,
2501
+ useThinInstances: this._lite.useThinInstances,
2502
+ useThinInstanceColors: this._lite.useThinInstanceColors,
2503
+ depthWrite: this._lite.depthWrite,
2504
+ depthCompare: this._lite.depthCompare
2505
+ }), this.getScene());
2506
+ }
2507
+ };
2508
+ /**
2509
+ * @internal Runtime discriminator for the `Mesh` constructor's two call shapes:
2510
+ * `new Mesh(name, scene)` (empty mesh, Babylon.js) vs the internal
2511
+ * `new Mesh(name, liteMesh, scene)` (geometry-backed). A compat `Scene` exposes
2512
+ * `getEngine()`; a Lite mesh does not.
2513
+ */
2514
+ function isCompatScene(value) {
2515
+ return typeof value.getEngine === "function";
2516
+ }
2517
+ /**
2518
+ * @internal Resolve the backing Lite scene node for a compat node. Mesh/light/
2519
+ * camera wrappers store it as `_lite`; a plain `TransformNode` stores it as
2520
+ * `_node`. (Declared as optionals because the base `Node` exposes neither.)
2521
+ */
2522
+ function liteNodeOf(node) {
2523
+ if (!node) return null;
2524
+ const n = node;
2525
+ return n._node ?? n._lite ?? null;
2526
+ }
2527
+ var PLACEHOLDER_POSITIONS = new Float32Array([
2528
+ 0,
2529
+ 0,
2530
+ 0,
2531
+ 0,
2532
+ 0,
2533
+ 0,
2534
+ 0,
2535
+ 0,
2536
+ 0
2537
+ ]);
2538
+ var PLACEHOLDER_NORMALS = new Float32Array([
2539
+ 0,
2540
+ 0,
2541
+ 1,
2542
+ 0,
2543
+ 0,
2544
+ 1,
2545
+ 0,
2546
+ 0,
2547
+ 1
2548
+ ]);
2549
+ var PLACEHOLDER_UVS = new Float32Array([
2550
+ 0,
2551
+ 0,
2552
+ 0,
2553
+ 0,
2554
+ 0,
2555
+ 0
2556
+ ]);
2557
+ var PLACEHOLDER_INDICES = new Uint32Array([
2558
+ 0,
2559
+ 1,
2560
+ 2
2561
+ ]);
2562
+ /** @internal Coerce a number list / typed array to a `Float32Array` (reusing the buffer when possible). */
2563
+ function toF32(data) {
2564
+ return data instanceof Float32Array ? data : Float32Array.from(data);
2565
+ }
2566
+ /** @internal Coerce an index list / typed array to a `Uint32Array`. */
2567
+ function toU32(data) {
2568
+ return data instanceof Uint32Array ? data : Uint32Array.from(data);
2569
+ }
2570
+ /** @internal Flat per-face normals for vertex data that omits them (Lite requires a normals buffer). */
2571
+ function computeFlatNormals(positions, indices) {
2572
+ const normals = new Float32Array(positions.length);
2573
+ for (let i = 0; i < indices.length; i += 3) {
2574
+ const a = indices[i] * 3;
2575
+ const b = indices[i + 1] * 3;
2576
+ const c = indices[i + 2] * 3;
2577
+ const ux = positions[b] - positions[a];
2578
+ const uy = positions[b + 1] - positions[a + 1];
2579
+ const uz = positions[b + 2] - positions[a + 2];
2580
+ const vx = positions[c] - positions[a];
2581
+ const vy = positions[c + 1] - positions[a + 1];
2582
+ const vz = positions[c + 2] - positions[a + 2];
2583
+ let nx = uy * vz - uz * vy;
2584
+ let ny = uz * vx - ux * vz;
2585
+ let nz = ux * vy - uy * vx;
2586
+ const len = Math.hypot(nx, ny, nz) || 1;
2587
+ nx /= len;
2588
+ ny /= len;
2589
+ nz /= len;
2590
+ for (const vi of [
2591
+ a,
2592
+ b,
2593
+ c
2594
+ ]) {
2595
+ normals[vi] = nx;
2596
+ normals[vi + 1] = ny;
2597
+ normals[vi + 2] = nz;
2598
+ }
2599
+ }
2600
+ return normals;
2601
+ }
2602
+ /** @internal Return an attribute only when it has exactly one value tuple per vertex. */
2603
+ function matchingVertexAttribute(data, vertexCount, components) {
2604
+ return data?.length === vertexCount * components ? data : void 0;
2605
+ }
2606
+ /**
2607
+ * Babylon.js `TransformNode` — a positioned, rotated, scaled scene-graph node.
2608
+ * Wraps a Lite scene node (`_node`): either a standalone Lite transform node, or
2609
+ * (for meshes) the Lite mesh itself, which also carries the transform.
2610
+ */
2611
+ var TransformNode = class extends Node {
2612
+ /** @internal The Lite scene node that carries this transform. */
2613
+ _node;
2614
+ physicsBody = null;
2615
+ /**
2616
+ * @internal The Lite asset container this node was loaded from, when produced
2617
+ * by a loader. Used by the `KHR_materials_variants` helpers (which key off the
2618
+ * loaded root node) and to keep loaded meshes tied to their source asset.
2619
+ */
2620
+ _container;
2621
+ /**
2622
+ * @internal Bind a loader-produced wrapper to the scene the container was added
2623
+ * to. The loader already inserted the underlying Lite node (via
2624
+ * `addToScene(container)`), so this only wires the compat-side scene reference
2625
+ * and lists the wrapper in `scene.meshes` — it never re-inserts into Lite.
2626
+ */
2627
+ _bindLoadedScene(scene) {
2628
+ if (this._scene === scene) return;
2629
+ this._scene = scene;
2630
+ scene._registerMesh(this, this._node);
2631
+ }
2632
+ /** @internal Link an already-parented Lite node without mutating its Lite hierarchy. */
2633
+ _adoptLoadedParent(parent) {
2634
+ this._linkParent(parent);
2635
+ }
2636
+ constructor(name, scene, liteNode) {
2637
+ super(name, scene);
2638
+ if (liteNode) this._node = liteNode;
2639
+ else {
2640
+ this._node = createTransformNode(name);
2641
+ if (scene) addToScene(scene._lite, this._node);
2642
+ }
2643
+ }
2644
+ getClassName() {
2645
+ return "TransformNode";
2646
+ }
2647
+ get position() {
2648
+ return liteBackedVector3(this._node.position);
2649
+ }
2650
+ set position(value) {
2651
+ this._node.position.set(value.x, value.y, value.z);
2652
+ }
2653
+ get rotation() {
2654
+ return liteBackedVector3(this._node.rotation);
2655
+ }
2656
+ set rotation(value) {
2657
+ this._node.rotation.set(value.x, value.y, value.z);
2658
+ }
2659
+ get scaling() {
2660
+ return liteBackedVector3(this._node.scaling);
2661
+ }
2662
+ set scaling(value) {
2663
+ this._node.scaling.set(value.x, value.y, value.z);
2664
+ }
2665
+ /** @internal Whether `rotationQuaternion` was explicitly set (Babylon.js returns null otherwise). */
2666
+ _useQuat = false;
2667
+ /**
2668
+ * Babylon.js `rotationQuaternion`. Babylon Lite always drives a node's world
2669
+ * matrix from a quaternion (its euler `rotation` is a proxy over the same
2670
+ * quaternion), so this reads/writes that quaternion. Returns `null` until
2671
+ * explicitly assigned, matching Babylon.js's euler-by-default convention.
2672
+ */
2673
+ get rotationQuaternion() {
2674
+ if (!this._useQuat) return null;
2675
+ const q = this._node.rotationQuaternion;
2676
+ return new Quaternion(q.x, q.y, q.z, q.w);
2677
+ }
2678
+ set rotationQuaternion(value) {
2679
+ if (value) {
2680
+ this._useQuat = true;
2681
+ this._node.rotationQuaternion.set(value.x, value.y, value.z, value.w);
2682
+ } else this._useQuat = false;
2683
+ }
2684
+ /**
2685
+ * Babylon.js `setParent(node)` — reparent while **preserving world position**
2686
+ * (the child's local transform is recomputed). Distinct from the `parent`
2687
+ * setter, which keeps the local transform and lets the world move.
2688
+ */
2689
+ setParent(parent) {
2690
+ this._linkParent(parent);
2691
+ setParent(this._node, liteNodeOf(parent));
2692
+ return this;
2693
+ }
2694
+ _applyParent(parent) {
2695
+ this._node.parent = liteNodeOf(parent);
2696
+ }
2697
+ /** @internal Remove this wrapper's node without letting Lite recurse for `dispose(true)`. */
2698
+ _disposeSelf(doNotRecurse) {
2699
+ if (!this._scene) return;
2700
+ if (!doNotRecurse) {
2701
+ removeFromScene(this._scene._lite, this._node);
2702
+ return;
2703
+ }
2704
+ for (const child of this._node.children) child.parent = null;
2705
+ this._node.children.length = 0;
2706
+ removeFromScene(this._scene._lite, this._node);
2707
+ }
2708
+ };
2709
+ /**
2710
+ * Babylon.js `AbstractMesh` — a renderable transform node with a material,
2711
+ * visibility, and shadow-receipt. Concrete meshes derive from this.
2712
+ */
2713
+ var AbstractMesh = class extends TransformNode {
2714
+ /** @internal Underlying Babylon Lite mesh. */
2715
+ _lite;
2716
+ _material = null;
2717
+ _meshBlendingTag = 0;
2718
+ _visible = true;
2719
+ constructor(name, lite, scene) {
2720
+ super(name, scene, lite);
2721
+ this._lite = lite;
2722
+ this._lite.name = name;
2723
+ if (scene) {
2724
+ this.material = scene.defaultMaterial;
2725
+ scene._registerMesh(this, this._lite);
2726
+ }
2727
+ }
2728
+ getClassName() {
2729
+ return "AbstractMesh";
2730
+ }
2731
+ /** @internal An `AbstractMesh` counts as a mesh node for `getChildMeshes`. */
2732
+ _isMeshNode() {
2733
+ return true;
2734
+ }
2735
+ get material() {
2736
+ return this._material;
2737
+ }
2738
+ set material(value) {
2739
+ this._material = value;
2740
+ const scene = this._scene;
2741
+ const renderMaterial = value ?? scene?.defaultMaterial;
2742
+ if (renderMaterial && scene) {
2743
+ if (scene._hasStarted) attachMaterialToScene(renderMaterial, scene);
2744
+ else adoptMaterialScene(renderMaterial, scene);
2745
+ }
2746
+ if (renderMaterial?._lite) this._lite.material = renderMaterial._lite;
2747
+ if (value && "_bindMesh" in value) value._bindMesh(this._lite, () => this._material === value);
2748
+ }
2749
+ get isVisible() {
2750
+ return this._visible;
2751
+ }
2752
+ set isVisible(value) {
2753
+ this._visible = value;
2754
+ this._syncVisibility(this.isEnabled());
2755
+ }
2756
+ get isPickable() {
2757
+ return this._lite.pickable !== false;
2758
+ }
2759
+ set isPickable(value) {
2760
+ this._lite.pickable = value;
2761
+ }
2762
+ get receiveShadows() {
2763
+ return this._lite.receiveShadows;
2764
+ }
2765
+ set receiveShadows(value) {
2766
+ this._lite.receiveShadows = value;
2767
+ }
2768
+ get meshBlendingTag() {
2769
+ return this._meshBlendingTag ?? 0;
2770
+ }
2771
+ set meshBlendingTag(value) {
2772
+ if (!Number.isInteger(value) || value < 0 || value > 255 || value !== 0 && (value & 63) === 0) throw new RangeError("Mesh-blending tag must be 0 or contain a group ID between 1 and 63.");
2773
+ this._meshBlendingTag = value;
2774
+ this._lite.meshBlendingTag = value;
2775
+ }
2776
+ _onEffectiveEnabledStateChanged(enabled) {
2777
+ this._syncVisibility(enabled);
2778
+ }
2779
+ /** @internal Apply local visibility and effective enabled state to Lite. */
2780
+ _syncVisibility(enabled) {
2781
+ const visible = this._visible && enabled;
2782
+ if (this._lite.visible !== visible) setMeshVisible(this._lite, visible);
2783
+ }
2784
+ /**
2785
+ * Babylon.js `mesh.getBoundingInfo()` — the mesh's AABB. `minimum`/`maximum`
2786
+ * are the local-space bounds; the returned `BoundingInfo`'s world members
2787
+ * (`minimumWorld`/`maximumWorld`/`centerWorld`/…) are derived by transforming
2788
+ * the eight local corners by the mesh's world matrix, so a mesh at (1,2,3)
2789
+ * reports correctly-offset world bounds. Babylon Lite stores `boundMin`/
2790
+ * `boundMax` (local space) on factory- and loader-built meshes; when absent
2791
+ * (e.g. a placeholder mesh whose bounds were never computed) we fold the
2792
+ * retained CPU positions through Lite's `computeAabb`. A mesh with no geometry
2793
+ * returns a degenerate zero-size box.
2794
+ */
2795
+ getBoundingInfo() {
2796
+ const world = this._worldMatrixForBounds();
2797
+ const lo = this._lite.boundMin;
2798
+ const hi = this._lite.boundMax;
2799
+ if (lo && hi) return new BoundingInfo(new Vector3(lo[0], lo[1], lo[2]), new Vector3(hi[0], hi[1], hi[2]), world);
2800
+ const positions = this._lite._cpuPositions;
2801
+ if (positions && positions.length >= 3 && positions.length % 3 === 0) {
2802
+ const [min, max] = computeAabb(positions);
2803
+ if (Number.isFinite(min[0]) && Number.isFinite(min[1]) && Number.isFinite(min[2]) && Number.isFinite(max[0]) && Number.isFinite(max[1]) && Number.isFinite(max[2])) return new BoundingInfo(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]), world);
2804
+ }
2805
+ return new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0), world);
2806
+ }
2807
+ /** Compat handle over Babylon Lite's world matrix for bounds derivation. Returns
2808
+ * `undefined` when the Lite node hasn't computed one (world bounds fall back to
2809
+ * local). */
2810
+ _worldMatrixForBounds() {
2811
+ const wm = this._lite.worldMatrix;
2812
+ return wm ? Matrix.FromArray(wm) : void 0;
2813
+ }
2814
+ /**
2815
+ * Babylon.js `mesh.getVerticesData(kind)` — read back the CPU geometry buffer.
2816
+ * `position` / `normal` / `uv` come from the buffers Babylon Lite retains on the
2817
+ * mesh (for picking + device-loss recovery). Prefer the last compat-side value
2818
+ * for `uv2` / `tangent` / `color`, falling back to attributes retained by Lite
2819
+ * for loader- and factory-created meshes.
2820
+ */
2821
+ getVerticesData(kind) {
2822
+ switch (kind) {
2823
+ case "position": return this._lite._cpuPositions ?? null;
2824
+ case "normal": return this._lite._cpuNormals ?? null;
2825
+ case "uv": return this._lite._cpuUvs ?? null;
2826
+ case "uv2": return this._lastUv2 ?? this._lite._cpuUv2s ?? null;
2827
+ case "tangent": return this._lastTangents ?? this._lite._cpuTangents ?? null;
2828
+ case "color": return this._lastColors ?? this._lite._cpuColors ?? null;
2829
+ default: return null;
2830
+ }
2831
+ }
2832
+ /**
2833
+ * Babylon.js `mesh.setVerticesData(kind, data)` — replace a vertex attribute.
2834
+ * `position` / `normal` / `uv` / `color` / `tangent` re-upload the geometry in
2835
+ * place; the last-set `color`/`tangent` buffers are retained so successive calls
2836
+ * (e.g. set tangent then set color) keep both. Skinning/morph attributes
2837
+ * (`matricesIndices`, etc.) are accepted but not applied (Babylon Lite drives
2838
+ * skinning through its own loaded-skeleton path).
2839
+ */
2840
+ setVerticesData(kind, data, _updatable) {
2841
+ const engine = this._scene?.getEngine()._lite;
2842
+ const lite = this._lite;
2843
+ if (!engine || !lite._cpuPositions || !lite._cpuIndices) return;
2844
+ if (kind !== "position" && kind !== "normal" && kind !== "uv" && kind !== "uv2" && kind !== "color" && kind !== "tangent") return;
2845
+ const f32 = data instanceof Float32Array ? data : Float32Array.from(data);
2846
+ if (kind === "uv2") this._lastUv2 = f32;
2847
+ if (kind === "color") this._lastColors = f32;
2848
+ if (kind === "tangent") this._lastTangents = f32;
2849
+ const positions = kind === "position" ? f32 : lite._cpuPositions;
2850
+ const vertexCount = positions.length / 3;
2851
+ const existingNormals = matchingVertexAttribute(lite._cpuNormals, vertexCount, 3);
2852
+ const normals = kind === "normal" ? f32 : existingNormals ?? computeFlatNormals(positions, lite._cpuIndices);
2853
+ if (kind === "position") this._normalsFollowIndices = !existingNormals;
2854
+ else if (kind === "normal") this._normalsFollowIndices = false;
2855
+ const existingUvs = matchingVertexAttribute(lite._cpuUvs, vertexCount, 2);
2856
+ const uvs = kind === "uv" ? f32 : existingUvs ?? (kind === "position" ? new Float32Array(vertexCount * 2) : void 0);
2857
+ const uvs2 = kind === "uv2" ? f32 : matchingVertexAttribute(this._lastUv2 ?? lite._cpuUv2s, vertexCount, 2);
2858
+ const tangents = matchingVertexAttribute(this._lastTangents ?? lite._cpuTangents, vertexCount, 4);
2859
+ const colors = matchingVertexAttribute(this._lastColors ?? lite._cpuColors, vertexCount, 4);
2860
+ resizeMeshGeometry(engine, this._lite, positions, normals, lite._cpuIndices, uvs, uvs2, tangents, colors);
2861
+ }
2862
+ /**
2863
+ * Babylon.js `mesh.getIndices()` — read back the mesh's index (topology) buffer.
2864
+ * Babylon Lite retains the indices on the mesh as a `Uint32Array` (for picking +
2865
+ * device-loss recovery), so we return that directly; a mesh with no geometry
2866
+ * returns `null`.
2867
+ */
2868
+ getIndices(_copyWhenShared, forceCopy) {
2869
+ const indices = this._lite._cpuIndices;
2870
+ return indices ? forceCopy ? indices.slice() : indices : null;
2871
+ }
2872
+ /**
2873
+ * Babylon.js `mesh.setIndices(indices)` — replace the mesh's index (topology)
2874
+ * buffer. Babylon Lite re-uploads the geometry in place via `resizeMeshGeometry`,
2875
+ * keeping the existing position/normal/uv/tangent/color attributes and swapping
2876
+ * only the indices. Returns the mesh for chaining.
2877
+ */
2878
+ setIndices(indices, _totalVertices, _updatable) {
2879
+ const engine = this._scene?.getEngine()._lite;
2880
+ const lite = this._lite;
2881
+ if (!engine || !lite._cpuPositions) return this;
2882
+ const u32 = indices instanceof Uint32Array ? indices : Uint32Array.from(indices);
2883
+ const positions = lite._cpuPositions;
2884
+ const vertexCount = positions.length / 3;
2885
+ const normals = this._normalsFollowIndices ? computeFlatNormals(positions, u32) : matchingVertexAttribute(lite._cpuNormals, vertexCount, 3) ?? computeFlatNormals(positions, u32);
2886
+ resizeMeshGeometry(engine, this._lite, positions, normals, u32, matchingVertexAttribute(lite._cpuUvs, vertexCount, 2), matchingVertexAttribute(this._lastUv2 ?? lite._cpuUv2s, vertexCount, 2), matchingVertexAttribute(this._lastTangents ?? lite._cpuTangents, vertexCount, 4), matchingVertexAttribute(this._lastColors ?? lite._cpuColors, vertexCount, 4));
2887
+ return this;
2888
+ }
2889
+ /** @internal Retained uv2/tangent/color buffers so successive `setVerticesData` (and a bake) keep them all. */
2890
+ _lastUv2;
2891
+ _lastTangents;
2892
+ _lastColors;
2893
+ /** @internal Position resizing generated normals from the old topology; regenerate after the next index update. */
2894
+ _normalsFollowIndices = false;
2895
+ /** Babylon.js `mesh.getTotalVertices()` — vertex count from the position buffer. */
2896
+ getTotalVertices() {
2897
+ const positions = this._lite._cpuPositions;
2898
+ return positions ? positions.length / 3 : 0;
2899
+ }
2900
+ /**
2901
+ * Babylon.js `mesh.refreshBoundingInfo()` — Babylon Lite recomputes a mesh's
2902
+ * bounds from its CPU geometry on demand (and on geometry upload), so this is a
2903
+ * no-op that returns the mesh for chaining. The deformed-pick options
2904
+ * (`applySkeleton` / `applyMorph`) are accepted for parity but not used.
2905
+ */
2906
+ refreshBoundingInfo(_options) {
2907
+ return this;
2908
+ }
2909
+ /**
2910
+ * @internal Shared bake: fold `matrix` into the retained CPU geometry and
2911
+ * re-upload it. Positions transform by the full matrix; **normals by the
2912
+ * inverse-transpose of the upper 3×3** (so they stay perpendicular to the baked
2913
+ * surface under non-uniform / sheared transforms, unlike a raw 3×3 multiply) and
2914
+ * are renormalized. The retained `uv` / `uv2` / `tangent` / `color` attributes are
2915
+ * forwarded unchanged so they survive the geometry reupload rather than being
2916
+ * dropped. Returns `false` when there is no geometry to bake.
2917
+ */
2918
+ _bakeMatrix(matrix) {
2919
+ const engine = this._scene?.getEngine()._lite;
2920
+ const lite = this._lite;
2921
+ const positions = lite._cpuPositions;
2922
+ const indices = lite._cpuIndices;
2923
+ if (!engine || !positions || !indices) return false;
2924
+ const m = matrix.m;
2925
+ const newPositions = new Float32Array(positions.length);
2926
+ for (let i = 0; i < positions.length; i += 3) {
2927
+ const x = positions[i], y = positions[i + 1], z = positions[i + 2];
2928
+ newPositions[i] = x * m[0] + y * m[4] + z * m[8] + m[12];
2929
+ newPositions[i + 1] = x * m[1] + y * m[5] + z * m[9] + m[13];
2930
+ newPositions[i + 2] = x * m[2] + y * m[6] + z * m[10] + m[14];
2931
+ }
2932
+ let bakedIndices = indices;
2933
+ if (matrix.determinant() < 0) {
2934
+ bakedIndices = new Uint32Array(indices);
2935
+ for (let i = 0; i + 2 < bakedIndices.length; i += 3) {
2936
+ const second = bakedIndices[i + 1];
2937
+ bakedIndices[i + 1] = bakedIndices[i + 2];
2938
+ bakedIndices[i + 2] = second;
2939
+ }
2940
+ }
2941
+ let newNormals;
2942
+ const normals = lite._cpuNormals;
2943
+ if (normals) {
2944
+ const nm = matrix.invert().transpose().m;
2945
+ newNormals = new Float32Array(normals.length);
2946
+ for (let i = 0; i < normals.length; i += 3) {
2947
+ const x = normals[i], y = normals[i + 1], z = normals[i + 2];
2948
+ let nx = x * nm[0] + y * nm[4] + z * nm[8];
2949
+ let ny = x * nm[1] + y * nm[5] + z * nm[9];
2950
+ let nz = x * nm[2] + y * nm[6] + z * nm[10];
2951
+ const len = Math.hypot(nx, ny, nz) || 1;
2952
+ nx /= len;
2953
+ ny /= len;
2954
+ nz /= len;
2955
+ newNormals[i] = nx;
2956
+ newNormals[i + 1] = ny;
2957
+ newNormals[i + 2] = nz;
2958
+ }
2959
+ } else newNormals = computeFlatNormals(newPositions, bakedIndices);
2960
+ const tangents = this._lastTangents ?? lite._cpuTangents ?? void 0;
2961
+ let newTangents;
2962
+ if (tangents) {
2963
+ newTangents = new Float32Array(tangents.length);
2964
+ for (let i = 0; i < tangents.length; i += 4) {
2965
+ const x = tangents[i], y = tangents[i + 1], z = tangents[i + 2];
2966
+ let tx = x * m[0] + y * m[4] + z * m[8];
2967
+ let ty = x * m[1] + y * m[5] + z * m[9];
2968
+ let tz = x * m[2] + y * m[6] + z * m[10];
2969
+ const len = Math.hypot(tx, ty, tz) || 1;
2970
+ tx /= len;
2971
+ ty /= len;
2972
+ tz /= len;
2973
+ newTangents[i] = tx;
2974
+ newTangents[i + 1] = ty;
2975
+ newTangents[i + 2] = tz;
2976
+ newTangents[i + 3] = tangents[i + 3];
2977
+ }
2978
+ }
2979
+ resizeMeshGeometry(engine, this._lite, newPositions, newNormals, bakedIndices, lite._cpuUvs, this._lastUv2 ?? lite._cpuUv2s ?? void 0, newTangents, this._lastColors ?? lite._cpuColors ?? void 0);
2980
+ return true;
2981
+ }
2982
+ /**
2983
+ * Babylon.js `mesh.bakeCurrentTransformIntoVertices()` — fold the node's local
2984
+ * transform (position / rotation / scaling) into the CPU geometry via the shared
2985
+ * {@link _bakeMatrix} helper, then reset the node transform to identity (the
2986
+ * geometry now carries it).
2987
+ */
2988
+ bakeCurrentTransformIntoVertices() {
2989
+ const node = this._node;
2990
+ const q = node.rotationQuaternion;
2991
+ const matrix = Matrix.Compose(liteBackedVector3(node.scaling), {
2992
+ x: q.x,
2993
+ y: q.y,
2994
+ z: q.z,
2995
+ w: q.w
2996
+ }, liteBackedVector3(node.position));
2997
+ if (!this._bakeMatrix(matrix)) return this;
2998
+ node.position.set(0, 0, 0);
2999
+ node.rotation.set(0, 0, 0);
3000
+ node.scaling.set(1, 1, 1);
3001
+ return this;
3002
+ }
3003
+ /**
3004
+ * Babylon.js `mesh.bakeTransformIntoVertices(transform)` — fold an **arbitrary**
3005
+ * matrix into the CPU geometry via the shared {@link _bakeMatrix} helper. Unlike
3006
+ * {@link bakeCurrentTransformIntoVertices}, the node's own transform is **not**
3007
+ * reset: the supplied matrix is independent of the node transform.
3008
+ */
3009
+ bakeTransformIntoVertices(transform) {
3010
+ this._bakeMatrix(transform);
3011
+ return this;
3012
+ }
3013
+ };
3014
+ /** Babylon.js `Mesh` — a concrete renderable mesh with geometry. */
3015
+ var Mesh = class Mesh extends AbstractMesh {
3016
+ constructor(name, sceneOrLite, scene) {
3017
+ if (sceneOrLite !== void 0 && isCompatScene(sceneOrLite)) {
3018
+ const realScene = sceneOrLite;
3019
+ const lite = createMeshFromData(realScene.getEngine()._lite, name, PLACEHOLDER_POSITIONS, PLACEHOLDER_NORMALS, PLACEHOLDER_INDICES, PLACEHOLDER_UVS);
3020
+ super(name, lite, realScene);
3021
+ addPrimitive(this, realScene);
3022
+ } else super(name, sceneOrLite, scene);
3023
+ }
3024
+ getClassName() {
3025
+ return "Mesh";
3026
+ }
3027
+ /**
3028
+ * @internal Wrap an already-loaded Lite mesh (or the loader's synthetic root
3029
+ * node) as a canonical compat `Mesh`. Unlike the public constructor it does
3030
+ * **not** re-insert the node into the scene (the loader already added the whole
3031
+ * container) and does **not** override the natively-loaded material — it only
3032
+ * adopts the existing Lite node. Used by the loader to give
3033
+ * `AssetContainer.meshes` real, stable-identity mesh handles.
3034
+ */
3035
+ static _fromLite(lite, container, scene) {
3036
+ const mesh = new Mesh(lite.name ?? "", lite);
3037
+ mesh._container = container;
3038
+ mesh._visible = lite.visible !== false;
3039
+ if (scene) mesh._bindLoadedScene(scene);
3040
+ return mesh;
3041
+ }
3042
+ /** @internal Wrap and link a complete Lite hierarchy, registering every wrapper. */
3043
+ static _fromLiteHierarchy(lite, container, scene, registry = /* @__PURE__ */ new Map(), parent = null) {
3044
+ let wrapper = registry.get(lite);
3045
+ if (!wrapper) {
3046
+ wrapper = Mesh._fromLite(lite, container, scene);
3047
+ registry.set(lite, wrapper);
3048
+ } else if (scene) wrapper._bindLoadedScene(scene);
3049
+ wrapper._adoptLoadedParent(parent);
3050
+ const children = lite.children;
3051
+ if (children) for (const child of children) Mesh._fromLiteHierarchy(child, container, scene, registry, wrapper);
3052
+ return wrapper;
3053
+ }
3054
+ _morphTargetManager = null;
3055
+ /**
3056
+ * Babylon.js `mesh.morphTargetManager`. Babylon Lite builds morph GPU data via
3057
+ * `createMorphTargets` and stores it on the Lite mesh; the compat manager is
3058
+ * registered with the scene so the engine builds it at start (once the base
3059
+ * CPU geometry exists) and assigns it onto the Lite mesh before registration.
3060
+ */
3061
+ get morphTargetManager() {
3062
+ return this._morphTargetManager;
3063
+ }
3064
+ set morphTargetManager(value) {
3065
+ this._morphTargetManager = value;
3066
+ if (value && this._scene) this._scene._registerMorphTargetManager(this, value);
3067
+ }
3068
+ /** Legacy `Mesh.CreateSphere(name, segments, diameter, scene)`. */
3069
+ static CreateSphere(name, segments, diameter, scene) {
3070
+ return MeshBuilder.CreateSphere(name, {
3071
+ segments,
3072
+ diameter
3073
+ }, scene);
3074
+ }
3075
+ /** Legacy `Mesh.CreateBox(name, size, scene)`. */
3076
+ static CreateBox(name, size, scene) {
3077
+ return MeshBuilder.CreateBox(name, { size }, scene);
3078
+ }
3079
+ /** Legacy `Mesh.CreateGround(name, width, height, subdivisions, scene)`. */
3080
+ static CreateGround(name, width, height, subdivisions, scene) {
3081
+ return MeshBuilder.CreateGround(name, {
3082
+ width,
3083
+ height,
3084
+ subdivisions
3085
+ }, scene);
3086
+ }
3087
+ /** Legacy `Mesh.CreatePlane(name, size, scene)`. */
3088
+ static CreatePlane(name, size, scene) {
3089
+ return MeshBuilder.CreatePlane(name, { size }, scene);
3090
+ }
3091
+ /** Legacy `Mesh.CreateCylinder(name, height, diameterTop, diameterBottom, tessellation, _subdivisions, scene)`. */
3092
+ static CreateCylinder(name, height, diameterTop, diameterBottom, tessellation, _subdivisions, scene) {
3093
+ const diameter = Math.max(diameterTop, diameterBottom);
3094
+ return MeshBuilder.CreateCylinder(name, {
3095
+ height,
3096
+ diameter,
3097
+ tessellation
3098
+ }, scene);
3099
+ }
3100
+ /** Legacy `Mesh.CreateTorus(name, diameter, thickness, tessellation, scene)`. */
3101
+ static CreateTorus(name, diameter, thickness, tessellation, scene) {
3102
+ return MeshBuilder.CreateTorus(name, {
3103
+ diameter,
3104
+ thickness,
3105
+ tessellation
3106
+ }, scene);
3107
+ }
3108
+ /** Hardware-instanced copy — unsupported. Use native thin instances instead. */
3109
+ createInstance() {
3110
+ return unsupported("Mesh.createInstance", "Babylon Lite has no hardware-instance object. Use the native thin-instance API (`setThinInstances`).");
3111
+ }
3112
+ /**
3113
+ * Babylon.js `mesh.thinInstanceSetBuffer(kind, buffer, stride)`. Maps the
3114
+ * `"matrix"` and `"color"` instance buffers onto Babylon Lite's thin-instance
3115
+ * API. Applied immediately to the Lite mesh (before the scene builds).
3116
+ */
3117
+ thinInstanceSetBuffer(kind, buffer, _stride = 16) {
3118
+ if (!buffer) return;
3119
+ if (kind === "matrix") setThinInstances(this._lite, buffer, buffer.length / 16);
3120
+ else if (kind === "color") setThinInstanceColors(this._lite, buffer);
3121
+ }
3122
+ /**
3123
+ * Babylon.js `mesh.clone(name, newParent?, doNotCloneChildren?)` — a new mesh
3124
+ * that shares this mesh's geometry. Forwards to Lite's `cloneTransformNode`,
3125
+ * which shares the `_gpu`/skeleton/morph/thin-instance resources with the clone
3126
+ * under ref-counting (so both meshes own the buffers and they survive until the
3127
+ * last is disposed). Babylon.js uses the requested name verbatim, derives clone
3128
+ * IDs from that name plus the source ID, and prefixes descendant names with the
3129
+ * root clone name. The source material is kept (BJS shares it by reference), and
3130
+ * the clone is registered with the same compat scene through its own wrapper.
3131
+ * An omitted or `null` `newParent` keeps the source parent.
3132
+ * `doNotCloneChildren` drops the descendants Lite always clones.
3133
+ */
3134
+ clone(name = "", newParent = null, doNotCloneChildren) {
3135
+ const scene = this._scene;
3136
+ const liteClone = cloneTransformNode(this._lite);
3137
+ const wrappedClone = Mesh._wrapCloneHierarchy(this, liteClone, scene, null, doNotCloneChildren === true, name);
3138
+ if (!(wrappedClone instanceof Mesh)) throw new Error("Mesh.clone produced a non-mesh root.");
3139
+ const clone = wrappedClone;
3140
+ if (scene) addPrimitive(clone, scene, doNotCloneChildren ? () => pruneClonedDescendants(scene, liteClone) : void 0);
3141
+ const parent = newParent ?? this.parent;
3142
+ if (parent) clone.parent = parent;
3143
+ return clone;
3144
+ }
3145
+ static _wrapCloneHierarchy(source, lite, scene, parent, skipChildren, cloneName) {
3146
+ if (cloneName !== void 0) lite.name = cloneName;
3147
+ const wrapper = source instanceof Mesh || "_gpu" in lite && "material" in lite ? new Mesh(lite.name ?? "", lite) : new TransformNode(lite.name ?? "", scene, lite);
3148
+ wrapper._container = source?._container;
3149
+ if (wrapper instanceof Mesh) {
3150
+ wrapper._scene = scene;
3151
+ if (scene) scene._registerMesh(wrapper, lite);
3152
+ }
3153
+ wrapper.parent = parent;
3154
+ if (source) {
3155
+ wrapper.id = wrapper instanceof Mesh ? `${wrapper.name}.${source.id}` : wrapper.name;
3156
+ wrapper.metadata = source.metadata;
3157
+ wrapper.setEnabled(source.isEnabled(false));
3158
+ if (wrapper instanceof Mesh && source instanceof Mesh) {
3159
+ wrapper.material = source.material;
3160
+ wrapper.isVisible = source.isVisible;
3161
+ wrapper.meshBlendingTag = source.meshBlendingTag;
3162
+ }
3163
+ }
3164
+ if (!skipChildren) {
3165
+ const sourceLiteChildren = liteNodeOf(source ?? null)?.children ?? [];
3166
+ const sourceChildren = source?.getChildren(void 0, true) ?? [];
3167
+ for (let i = 0; i < lite.children.length; i++) {
3168
+ const sourceLiteChild = sourceLiteChildren[i];
3169
+ const sourceChild = sourceChildren.find((child) => liteNodeOf(child) === sourceLiteChild);
3170
+ const childName = sourceChild ? `${wrapper.name}.${sourceChild.name}` : void 0;
3171
+ Mesh._wrapCloneHierarchy(sourceChild, lite.children[i], scene, wrapper, false, childName);
3172
+ }
3173
+ }
3174
+ return wrapper;
3175
+ }
3176
+ /** Level-of-detail — unsupported (no LOD system in Babylon Lite). */
3177
+ addLODLevel() {
3178
+ return unsupported("Mesh.addLODLevel", "Level-of-detail is not implemented in Babylon Lite.");
3179
+ }
3180
+ /**
3181
+ * Babylon.js `Mesh.MergeMeshes` — bake several meshes into one, transforming
3182
+ * each source's geometry by its world matrix. Signature:
3183
+ * `MergeMeshes(meshes, disposeSource?, allow32BitsIndices?, meshSubclass?, subdivideWithSubMeshes?, multiMultiMaterials?)`.
3184
+ * Uses the compat-local `mergeMeshGeometry`; the merged mesh lives at
3185
+ * identity (world transforms are baked in) and takes the first mesh's material.
3186
+ *
3187
+ * **Supported semantics** (everything else is rejected, never silently dropped):
3188
+ * - `disposeSource` (default `true`) — source meshes are disposed after merge.
3189
+ * - `allow32BitsIndices` — Lite indices are always uint32, so 32-bit is always
3190
+ * available. When `allow32BitsIndices` is falsy and the merged vertex count
3191
+ * reaches 65536, this returns `null`, exactly like Babylon.js.
3192
+ * - Positions, normals (world-transformed) and one UV set are carried.
3193
+ *
3194
+ * **Rejected** (throws `LiteCompatError`): `multiMultiMaterials` /
3195
+ * `subdivideWithSubMeshes` (Lite has no submesh / multi-material partitioning),
3196
+ * a supplied `meshSubclass` target, and sources carrying vertex colours,
3197
+ * tangents or a second UV set, or sources carrying skeleton, morph-target, or
3198
+ * vertex-animation data (Lite would have to drop them).
3199
+ */
3200
+ static MergeMeshes(meshes, disposeSource = true, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials) {
3201
+ const sources = meshes.filter((m) => !!m);
3202
+ if (sources.length === 0) return null;
3203
+ if (multiMultiMaterials || subdivideWithSubMeshes) return unsupported("Mesh.MergeMeshes(multiMultiMaterials/subdivideWithSubMeshes)", "Babylon Lite renders one material per mesh with no submesh partitioning, so multi-material / subdivided merges cannot be produced. Merge per-material groups into separate meshes instead.");
3204
+ if (meshSubclass) return unsupported("Mesh.MergeMeshes(meshSubclass)", "Merging into an existing target mesh is not wrapped; the merge always returns a fresh mesh. Merge without a meshSubclass and use the result.");
3205
+ if (!allow32BitsIndices) {
3206
+ let totalVertices = 0;
3207
+ for (const mesh of sources) {
3208
+ totalVertices += mesh.getTotalVertices();
3209
+ if (totalVertices >= 65536) return null;
3210
+ }
3211
+ }
3212
+ for (const mesh of sources) {
3213
+ const lite = mesh._lite;
3214
+ if (lite._cpuColors || lite._cpuTangents || lite._cpuUv2s) return unsupported("Mesh.MergeMeshes(colors/tangents/uv2)", `Mesh "${mesh.name}" carries vertex colours, tangents or a second UV set, which the merge does not carry. Strip those attributes before merging, or keep the meshes separate.`);
3215
+ if (lite.skeleton || lite.morphTargets || lite.vat) return unsupported("Mesh.MergeMeshes(animation)", `Mesh "${mesh.name}" carries skeleton, morph-target, or vertex-animation data, which the merge does not carry. Bake the deformation before merging, or keep the meshes separate.`);
3216
+ }
3217
+ const scene = sources[0].getScene();
3218
+ if (!scene) return null;
3219
+ const lite = mergeMeshGeometry(scene.getEngine()._lite, sources[0].name, sources.map((m) => m._lite));
3220
+ const merged = new Mesh(sources[0].name, lite, scene);
3221
+ merged.material = sources[0].material;
3222
+ addPrimitive(merged, scene);
3223
+ if (disposeSource) for (const mesh of sources) mesh.dispose();
3224
+ return merged;
3225
+ }
3226
+ };
3227
+ function createObservableLineColor(onChange) {
3228
+ const color = new Color3(1, 1, 1);
3229
+ let r = color.r;
3230
+ let g = color.g;
3231
+ let b = color.b;
3232
+ Object.defineProperties(color, {
3233
+ r: {
3234
+ get: () => r,
3235
+ set: (value) => {
3236
+ r = value;
3237
+ onChange(color);
3238
+ },
3239
+ enumerable: true,
3240
+ configurable: true
3241
+ },
3242
+ g: {
3243
+ get: () => g,
3244
+ set: (value) => {
3245
+ g = value;
3246
+ onChange(color);
3247
+ },
3248
+ enumerable: true,
3249
+ configurable: true
3250
+ },
3251
+ b: {
3252
+ get: () => b,
3253
+ set: (value) => {
3254
+ b = value;
3255
+ onChange(color);
3256
+ },
3257
+ enumerable: true,
3258
+ configurable: true
3259
+ }
3260
+ });
3261
+ return color;
3262
+ }
3263
+ /** Babylon.js `LinesMesh` backed by a Babylon Lite line-system mesh. */
3264
+ var LinesMesh = class extends Mesh {
3265
+ useVertexColor;
3266
+ useVertexAlpha;
3267
+ intersectionThreshold = .1;
3268
+ _lineMaterial;
3269
+ _color;
3270
+ _alpha = 1;
3271
+ _suspendLineColorSync = false;
3272
+ constructor(name, sceneOrLite, scene, useVertexColor = false, useVertexAlpha = true) {
3273
+ const realScene = isCompatScene(sceneOrLite) ? sceneOrLite : scene;
3274
+ const lite = isCompatScene(sceneOrLite) ? createLineSystem(engineOf(sceneOrLite), {
3275
+ name,
3276
+ lines: [[new Vector3(0, 0, 0)]],
3277
+ ...useVertexColor ? { colors: [[new Color4(1, 1, 1, 1)]] } : {},
3278
+ useVertexAlpha
3279
+ }) : sceneOrLite;
3280
+ const lineMaterial = lite.material;
3281
+ super(name, lite, realScene);
3282
+ this.useVertexColor = useVertexColor;
3283
+ this.useVertexAlpha = useVertexAlpha;
3284
+ this._lineMaterial = new LinesMaterial("colorShader", lineMaterial, realScene);
3285
+ this.material = this._lineMaterial;
3286
+ this._color = createObservableLineColor(() => {
3287
+ if (!this._suspendLineColorSync) this._syncLineColor();
3288
+ });
3289
+ if (isCompatScene(sceneOrLite)) addPrimitive(this, sceneOrLite);
3290
+ }
3291
+ getClassName() {
3292
+ return "LinesMesh";
3293
+ }
3294
+ get color() {
3295
+ return this._color;
3296
+ }
3297
+ set color(value) {
3298
+ this._suspendLineColorSync = true;
3299
+ try {
3300
+ this._color.copyFrom(value);
3301
+ } finally {
3302
+ this._suspendLineColorSync = false;
3303
+ }
3304
+ this._syncLineColor();
3305
+ }
3306
+ get alpha() {
3307
+ return this._alpha;
3308
+ }
3309
+ set alpha(value) {
3310
+ this._alpha = value;
3311
+ this._syncLineColor();
3312
+ }
3313
+ thinInstanceSetBuffer(kind, buffer, stride = 16) {
3314
+ super.thinInstanceSetBuffer(kind, buffer, stride);
3315
+ if (buffer && (kind === "matrix" || kind === "color")) this._enableThinLineMaterial(kind === "color" || this._lineMaterial._lite.useThinInstanceColors);
3316
+ }
3317
+ _enableThinLineMaterial(useThinInstanceColors) {
3318
+ if (this._lineMaterial._lite.useThinInstances && this._lineMaterial._lite.useThinInstanceColors === useThinInstanceColors) return;
3319
+ const lite = createLineMaterial({
3320
+ name: this._lineMaterial.name,
3321
+ color: {
3322
+ r: this._color.r,
3323
+ g: this._color.g,
3324
+ b: this._color.b,
3325
+ a: this._alpha
3326
+ },
3327
+ useVertexColor: this.useVertexColor,
3328
+ useVertexAlpha: this.useVertexAlpha,
3329
+ useThinInstances: true,
3330
+ useThinInstanceColors,
3331
+ depthWrite: this._lineMaterial._lite.depthWrite,
3332
+ depthCompare: this._lineMaterial._lite.depthCompare
3333
+ });
3334
+ this._lineMaterial = new LinesMaterial(this._lineMaterial.name, lite, this.getScene());
3335
+ this.material = this._lineMaterial;
3336
+ }
3337
+ _syncLineColor() {
3338
+ setLineMaterialColor(this._lineMaterial._lite, {
3339
+ r: this._color.r,
3340
+ g: this._color.g,
3341
+ b: this._color.b,
3342
+ a: this._alpha
3343
+ });
3344
+ }
3345
+ };
3346
+ /** Babylon.js `GroundMesh` — a ground plane mesh. CPU height queries are not modelled. */
3347
+ var GroundMesh = class extends Mesh {
3348
+ getClassName() {
3349
+ return "GroundMesh";
3350
+ }
3351
+ /** CPU height-at-coordinates query — needs a CPU heightmap accessor not present in Babylon Lite. */
3352
+ getHeightAtCoordinates() {
3353
+ return unsupported("GroundMesh.getHeightAtCoordinates", "CPU height queries are not implemented in Babylon Lite.");
3354
+ }
3355
+ };
3356
+ /** Babylon.js `InstancedMesh` — hardware instances are not modelled; use thin instances. */
3357
+ var InstancedMesh = class {
3358
+ constructor() {
3359
+ unsupported("InstancedMesh", "Babylon Lite has no hardware-instance object. Use the native thin-instance API (`setThinInstances`).");
3360
+ }
3361
+ };
3362
+ /**
3363
+ * Babylon.js `VertexBuffer` — the per-attribute geometry buffer. Only the `kind`
3364
+ * string constants are surfaced (used with `mesh.getVerticesData` /
3365
+ * `setVerticesData`); the buffer-object API itself is not wrapped.
3366
+ */
3367
+ var VertexBuffer = {
3368
+ PositionKind: "position",
3369
+ NormalKind: "normal",
3370
+ TangentKind: "tangent",
3371
+ UVKind: "uv",
3372
+ UV2Kind: "uv2",
3373
+ ColorKind: "color",
3374
+ MatricesIndicesKind: "matricesIndices",
3375
+ MatricesWeightsKind: "matricesWeights"
3376
+ };
3377
+ /**
3378
+ * Babylon.js `VertexData` — CPU vertex attribute container. Pure data; apply it
3379
+ * to a Lite mesh via the native geometry-update APIs when needed.
3380
+ */
3381
+ var VertexData = class {
3382
+ positions = null;
3383
+ normals = null;
3384
+ uvs = null;
3385
+ colors = null;
3386
+ indices = null;
3387
+ /**
3388
+ * Babylon.js `VertexData.applyToMesh(mesh)` — upload this CPU geometry onto a
3389
+ * mesh (typically one created via `new Mesh(name, scene)`). Replaces the Lite
3390
+ * mesh's geometry in place via `resizeMeshGeometry`. Normals are computed flat
3391
+ * if omitted (Babylon Lite requires a normals buffer).
3392
+ */
3393
+ applyToMesh(mesh) {
3394
+ if (!this.positions || !this.indices) return;
3395
+ const scene = mesh.getScene();
3396
+ if (!scene) return;
3397
+ const engine = scene.getEngine()._lite;
3398
+ const positions = toF32(this.positions);
3399
+ const indices = toU32(this.indices);
3400
+ const normals = this.normals ? toF32(this.normals) : computeFlatNormals(positions, indices);
3401
+ const uvs = this.uvs ? toF32(this.uvs) : void 0;
3402
+ const colors = this.colors ? toF32(this.colors) : void 0;
3403
+ resizeMeshGeometry(engine, mesh._lite, positions, normals, indices, uvs, void 0, void 0, colors);
3404
+ }
3405
+ /** Merge another `VertexData` into this one (concatenating attributes + reindexing). */
3406
+ merge(other) {
3407
+ const baseVertexCount = this.positions ? this.positions.length / 3 : 0;
3408
+ this.positions = concat(this.positions, other.positions);
3409
+ this.normals = concat(this.normals, other.normals);
3410
+ this.uvs = concat(this.uvs, other.uvs);
3411
+ this.colors = concat(this.colors, other.colors);
3412
+ if (other.indices) {
3413
+ const shifted = Array.from(other.indices, (i) => i + baseVertexCount);
3414
+ this.indices = this.indices ? [...Array.from(this.indices), ...shifted] : shifted;
3415
+ }
3416
+ return this;
3417
+ }
3418
+ };
3419
+ function concat(a, b) {
3420
+ if (!a && !b) return null;
3421
+ return [...a ? Array.from(a) : [], ...b ? Array.from(b) : []];
3422
+ }
3423
+ function engineOf(scene) {
3424
+ return scene.getEngine()._lite;
3425
+ }
3426
+ /**
3427
+ * Add a freshly-constructed mesh to its Lite scene. The wrapper constructor has
3428
+ * already assigned the mesh's material (a real one or `scene.defaultMaterial`),
3429
+ * but Babylon.js code commonly reassigns `mesh.material` a line later. Lite locks
3430
+ * a mesh into a render group at add time, so we defer the add until engine start
3431
+ * (via `scene._deferAdd`) to let those assignments settle.
3432
+ */
3433
+ function addPrimitive(mesh, scene, afterAdd) {
3434
+ return registerMeshAtStart(mesh, scene, afterAdd);
3435
+ }
3436
+ /**
3437
+ * @internal The deferred registration shared by every compat path that builds a mesh before engine start
3438
+ * (primitives, legacy CSG results, the navigation debug mesh): at startup, finalize the mesh's EFFECTIVE
3439
+ * material — its own, or `scene.defaultMaterial` as it is by then — rebind its Lite handle and add the mesh.
3440
+ */
3441
+ function registerMeshAtStart(mesh, scene, afterAdd) {
3442
+ scene._deferAdd(() => {
3443
+ if (mesh.isDisposed()) return;
3444
+ const mat = mesh.material ?? scene.defaultMaterial;
3445
+ if (mat) attachMaterialToScene(mat, scene);
3446
+ if (mat?._lite) mesh._lite.material = mat._lite;
3447
+ addToScene(scene._lite, mesh._lite);
3448
+ afterAdd?.();
3449
+ });
3450
+ return mesh;
3451
+ }
3452
+ /**
3453
+ * Drop the descendants Lite's `cloneTransformNode` always clones, for
3454
+ * `mesh.clone(..., doNotCloneChildren = true)`. `addToScene` already registered
3455
+ * them (it recurses into `children`), so `removeFromScene` here releases their
3456
+ * shared, ref-counted GPU claims — the source keeps its buffers — and detaches
3457
+ * them, leaving the clone a lone node with no leak.
3458
+ */
3459
+ function pruneClonedDescendants(scene, liteClone) {
3460
+ for (const child of [...liteClone.children]) removeFromScene(scene._lite, child);
3461
+ liteClone.children.length = 0;
3462
+ }
3463
+ /** Babylon.js `MeshBuilder` — factory namespace for primitive meshes. */
3464
+ var MeshBuilder = {
3465
+ CreateBox(name, options, scene) {
3466
+ return addPrimitive(new Mesh(name, createBox(engineOf(scene), options), scene), scene);
3467
+ },
3468
+ CreateSphere(name, options, scene) {
3469
+ return addPrimitive(new Mesh(name, createSphere(engineOf(scene), options), scene), scene);
3470
+ },
3471
+ CreateGround(name, options, scene) {
3472
+ return addPrimitive(new Mesh(name, createGround(engineOf(scene), options), scene), scene);
3473
+ },
3474
+ /**
3475
+ * Babylon.js `MeshBuilder.CreateGroundFromHeightMap(name, url, options, scene)`.
3476
+ * Babylon.js returns the mesh synchronously and fills its geometry once the
3477
+ * heightmap image loads; we mirror that by returning a placeholder `GroundMesh`
3478
+ * immediately and swapping in the real geometry (via `resizeMeshGeometry`) when
3479
+ * the async Lite `createGroundFromHeightMap` resolves. The load is tracked so
3480
+ * the engine awaits it before the scene is registered.
3481
+ */
3482
+ CreateGroundFromHeightMap(name, url, options, scene) {
3483
+ const engine = engineOf(scene);
3484
+ const mesh = new GroundMesh(name, scene);
3485
+ scene._trackTextureLoad(createGroundFromHeightMap(engine, url, options).then((lite) => {
3486
+ resizeMeshGeometry(engine, mesh._lite, lite._cpuPositions, lite._cpuNormals, lite._cpuIndices, lite._cpuUvs);
3487
+ const baseUvs = lite._cpuUvs;
3488
+ if (baseUvs) scene._registerGroundUvBake(() => {
3489
+ const albedo = mesh.material?.albedoTexture ?? null;
3490
+ const uScale = albedo?.uScale ?? 1;
3491
+ const vScale = albedo?.vScale ?? 1;
3492
+ if (uScale === 1 && vScale === 1) return;
3493
+ const scaled = new Float32Array(baseUvs.length);
3494
+ for (let i = 0; i < baseUvs.length; i += 2) {
3495
+ scaled[i] = baseUvs[i] * uScale;
3496
+ scaled[i + 1] = baseUvs[i + 1] * vScale;
3497
+ }
3498
+ updateMeshUvs(engine, mesh._lite, scaled);
3499
+ mesh._lite._cpuUvs = scaled;
3500
+ });
3501
+ }));
3502
+ return mesh;
3503
+ },
3504
+ CreatePlane(name, options, scene) {
3505
+ return addPrimitive(new Mesh(name, createPlane(engineOf(scene), options), scene), scene);
3506
+ },
3507
+ CreateCylinder(name, options, scene) {
3508
+ return addPrimitive(new Mesh(name, createCylinder(engineOf(scene), options), scene), scene);
3509
+ },
3510
+ CreateTorus(name, options, scene) {
3511
+ return addPrimitive(new Mesh(name, createTorus(engineOf(scene), options), scene), scene);
3512
+ },
3513
+ CreateTorusKnot(name, options, scene) {
3514
+ return addPrimitive(new Mesh(name, createTorusKnot(engineOf(scene), options), scene), scene);
3515
+ },
3516
+ CreateDisc(name, options, scene) {
3517
+ return addPrimitive(new Mesh(name, createDisc(engineOf(scene), options), scene), scene);
3518
+ },
3519
+ CreatePolyhedron(name, options, scene) {
3520
+ return addPrimitive(new Mesh(name, createPolyhedron(engineOf(scene), options), scene), scene);
3521
+ },
3522
+ CreateRibbon(name, options, scene) {
3523
+ return addPrimitive(new Mesh(name, createRibbon(engineOf(scene), options), scene), scene);
3524
+ },
3525
+ CreateTube(name, options, scene) {
3526
+ return addPrimitive(new Mesh(name, createTube(engineOf(scene), options), scene), scene);
3527
+ },
3528
+ ExtrudeShape(name, options, scene) {
3529
+ return addPrimitive(new Mesh(name, createExtrudeShape(engineOf(scene), options), scene), scene);
3530
+ },
3531
+ CreateLines(name, options, scene) {
3532
+ return CreateLineSystem(name, {
3533
+ lines: [options.points],
3534
+ updatable: options.updatable,
3535
+ instance: options.instance,
3536
+ colors: options.colors ? [options.colors] : void 0,
3537
+ useVertexAlpha: options.useVertexAlpha,
3538
+ material: options.material
3539
+ }, scene);
3540
+ },
3541
+ CreateLineSystem(name, options, scene) {
3542
+ if (options.instance) {
3543
+ const instanceScene = options.instance.getScene() ?? scene;
3544
+ if (!instanceScene) throw new Error("MeshBuilder.CreateLineSystem requires the instance to belong to a scene");
3545
+ updateLineSystem(engineOf(instanceScene), options.instance._lite, {
3546
+ lines: options.lines,
3547
+ ...options.colors ? { colors: options.colors } : {}
3548
+ });
3549
+ return options.instance;
3550
+ }
3551
+ if (options.material) return unsupported("MeshBuilder.CreateLineSystem.material", "Custom line materials are not implemented in Babylon Lite compatibility mode.");
3552
+ if (!scene) throw new Error("MeshBuilder.CreateLineSystem requires a scene when creating a line system");
3553
+ return addPrimitive(new LinesMesh(name, createLineSystem(engineOf(scene), {
3554
+ name,
3555
+ lines: options.lines,
3556
+ ...options.colors ? { colors: options.colors } : {},
3557
+ useVertexAlpha: options.useVertexAlpha
3558
+ }), scene, !!options.colors, options.useVertexAlpha ?? true), scene);
3559
+ },
3560
+ CreateDashedLines(name, options, scene) {
3561
+ if (options.instance) {
3562
+ const instanceScene = options.instance.getScene() ?? scene;
3563
+ if (!instanceScene) throw new Error("MeshBuilder.CreateDashedLines requires the instance to belong to a scene");
3564
+ updateDashedLines(engineOf(instanceScene), options.instance._lite, { points: options.points });
3565
+ return options.instance;
3566
+ }
3567
+ if (options.material) return unsupported("MeshBuilder.CreateDashedLines.material", "Custom line materials are not implemented in Babylon Lite compatibility mode.");
3568
+ if (!scene) throw new Error("MeshBuilder.CreateDashedLines requires a scene");
3569
+ return addPrimitive(new LinesMesh(name, createDashedLines(engineOf(scene), {
3570
+ name,
3571
+ points: options.points,
3572
+ ...options.dashSize !== void 0 ? { dashSize: options.dashSize } : {},
3573
+ ...options.gapSize !== void 0 ? { gapSize: options.gapSize } : {},
3574
+ ...options.dashNb !== void 0 ? { dashNb: options.dashNb } : {},
3575
+ useVertexAlpha: options.useVertexAlpha
3576
+ }), scene, false, options.useVertexAlpha ?? true), scene);
3577
+ },
3578
+ CreateDecal() {
3579
+ return unsupported("MeshBuilder.CreateDecal", "Decal projection is not implemented in Babylon Lite.");
3580
+ },
3581
+ CreateText() {
3582
+ return unsupported("MeshBuilder.CreateText", "Extruded font meshes are not implemented in Babylon Lite. For 2D/SDF text use the native `createTextRenderable` API.");
3583
+ },
3584
+ CreateTiledBox(_name, _options, _scene) {
3585
+ return unsupported("MeshBuilder.CreateTiledBox", "Tiled box geometry is not implemented in Babylon Lite. Its per-face tile-pattern UV layout (tile size, alignment, per-tile flip/rotate patterns) is a non-trivial vertex-data generator with pattern design choices — not a mechanical addition — so it needs a Lite core mesh-builder decision.");
3586
+ },
3587
+ CreateTiledPlane(_name, _options, _scene) {
3588
+ return unsupported("MeshBuilder.CreateTiledPlane", "Tiled plane geometry is not implemented in Babylon Lite. Its per-tile UV layout (tile size, alignment, per-tile flip/rotate patterns) is a non-trivial vertex-data generator with pattern design choices — not a mechanical addition — so it needs a Lite core mesh-builder decision.");
3589
+ }
3590
+ };
3591
+ /** Babylon.js `CreateBox(name, options, scene)` (boxBuilder). */
3592
+ function CreateBox(name, options, scene) {
3593
+ return MeshBuilder.CreateBox(name, options, scene);
3594
+ }
3595
+ /** Babylon.js `CreateSphere(name, options, scene)` (sphereBuilder). */
3596
+ function CreateSphere(name, options, scene) {
3597
+ return MeshBuilder.CreateSphere(name, options, scene);
3598
+ }
3599
+ /** Babylon.js `CreateGround(name, options, scene)` (groundBuilder). */
3600
+ function CreateGround(name, options, scene) {
3601
+ return MeshBuilder.CreateGround(name, options, scene);
3602
+ }
3603
+ /** Babylon.js `CreatePlane(name, options, scene)` (planeBuilder). */
3604
+ function CreatePlane(name, options, scene) {
3605
+ return MeshBuilder.CreatePlane(name, options, scene);
3606
+ }
3607
+ /** Babylon.js `CreateCylinder(name, options, scene)` (cylinderBuilder). */
3608
+ function CreateCylinder(name, options, scene) {
3609
+ return MeshBuilder.CreateCylinder(name, options, scene);
3610
+ }
3611
+ /** Babylon.js `CreateTorus(name, options, scene)` (torusBuilder). */
3612
+ function CreateTorus(name, options, scene) {
3613
+ return MeshBuilder.CreateTorus(name, options, scene);
3614
+ }
3615
+ /** Babylon.js `CreateDisc(name, options, scene)` (discBuilder). */
3616
+ function CreateDisc(name, options, scene) {
3617
+ return MeshBuilder.CreateDisc(name, options, scene);
3618
+ }
3619
+ /** Babylon.js `CreateLines(name, options, scene)` (linesBuilder). */
3620
+ function CreateLines(name, options, scene) {
3621
+ return MeshBuilder.CreateLines(name, options, scene);
3622
+ }
3623
+ /** Babylon.js `CreateLineSystem(name, options, scene)` (linesBuilder). */
3624
+ function CreateLineSystem(name, options, scene) {
3625
+ return MeshBuilder.CreateLineSystem(name, options, scene);
3626
+ }
3627
+ /** Babylon.js `CreateDashedLines(name, options, scene)` (linesBuilder). */
3628
+ function CreateDashedLines(name, options, scene) {
3629
+ return MeshBuilder.CreateDashedLines(name, options, scene);
3630
+ }
3631
+ /** Babylon.js `CreateTiledBox(name, options, scene)` (tiledBoxBuilder) — throwing stub (see `MeshBuilder.CreateTiledBox`). */
3632
+ function CreateTiledBox(name, options, scene) {
3633
+ return MeshBuilder.CreateTiledBox(name, options, scene);
3634
+ }
3635
+ /** Babylon.js `CreateTiledPlane(name, options, scene)` (tiledPlaneBuilder) — throwing stub (see `MeshBuilder.CreateTiledPlane`). */
3636
+ function CreateTiledPlane(name, options, scene) {
3637
+ return MeshBuilder.CreateTiledPlane(name, options, scene);
3638
+ }
3639
+ //#endregion
3640
+ export { PBRSpecularGlossinessMaterial as A, transformCoordinates as B, Material as C, PBRMaterial as D, PBRIridescenceConfiguration as E, Observable as F, liteBackedColor3 as G, Quaternion as H, BoundingBox as I, Vector4 as J, Vector2 as K, BoundingInfo as L, StandardMaterial as M, attachMaterialToScene as N, PBRMetallicRoughnessMaterial as O, Node as P, BoundingSphere as R, registerMeshAtStart as S, PBRClearCoatConfiguration as T, Color3 as U, transformNormal as V, Color4 as W, LiteCompatError as X, liteBackedVector3 as Y, unsupported as Z, Mesh as _, CreateDisc as a, VertexBuffer as b, CreateLines as c, CreateTiledBox as d, CreateTiledPlane as f, LinesMesh as g, InstancedMesh as h, CreateDashedLines as i, PushMaterial as j, PBRSheenConfiguration as k, CreatePlane as l, GroundMesh as m, CreateBox as n, CreateGround as o, CreateTorus as p, Vector3 as q, CreateCylinder as r, CreateLineSystem as s, AbstractMesh as t, CreateSphere as u, MeshBuilder as v, PBRAnisotropicConfiguration as w, VertexData as x, TransformNode as y, Matrix as z };
3641
+
3642
+ //# sourceMappingURL=meshes-Fu955h5M.js.map