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