@babylonjs/lite-compat 1.15.0-preview → 1.16.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.
- package/README.md +10 -8
- package/brdf-lut-data-BFfYlW71.js +5 -0
- package/brdf-lut-data-BFfYlW71.js.map +1 -0
- package/index.d.ts +503 -97
- package/index.js +1277 -497
- package/index.js.map +1 -1
- package/{meshes-CPZtn6G5.js → meshes-DduMsRJk.js} +691 -104
- package/meshes-DduMsRJk.js.map +1 -0
- package/navigation.d.ts +264 -78
- package/navigation.js +1 -1
- package/package.json +4 -4
- package/meshes-CPZtn6G5.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { quatFromRotationMatrix, setMeshVisible, computeAabb, resizeMeshGeometry, removeFromScene,
|
|
4
|
+
import { quatFromRotationMatrix, mat4FromQuatInto, createMeshFromData, setMeshVisible, computeAabb, resizeMeshGeometry, removeFromScene, setThinInstances, setThinInstanceColors, cloneTransformNode, createExtrudeShape, createTube, createRibbon, createPolyhedron, createDisc, createTorusKnot, createTorus, createCylinder, createPlane, createGroundFromHeightMap, updateMeshUvs, createGround, createSphere, createBox, createTransformNode, addToScene, setParent } from "@babylonjs/lite";
|
|
5
5
|
class LiteCompatError extends Error {
|
|
6
6
|
constructor(api, detail) {
|
|
7
7
|
super(detail ? `'${api}' is not supported by the Babylon Lite compat layer. ${detail}` : `'${api}' is not supported by the Babylon Lite compat layer.`);
|
|
@@ -449,6 +449,14 @@ class Quaternion {
|
|
|
449
449
|
this.w = q.w;
|
|
450
450
|
return this;
|
|
451
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Babylon.js `Quaternion.toRotationMatrix` — write this quaternion's rotation
|
|
454
|
+
* into `result`.
|
|
455
|
+
*/
|
|
456
|
+
toRotationMatrix(result) {
|
|
457
|
+
mat4FromQuatInto(result.m, this.x, this.y, this.z, this.w);
|
|
458
|
+
return result;
|
|
459
|
+
}
|
|
452
460
|
clone() {
|
|
453
461
|
return new Quaternion(this.x, this.y, this.z, this.w);
|
|
454
462
|
}
|
|
@@ -865,66 +873,123 @@ function transformNormal(vector, transformation) {
|
|
|
865
873
|
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]);
|
|
866
874
|
}
|
|
867
875
|
class BoundingSphere {
|
|
868
|
-
constructor(min, max) {
|
|
869
|
-
__publicField(this, "center");
|
|
876
|
+
constructor(min, max, worldMatrix) {
|
|
877
|
+
__publicField(this, "center", new Vector3());
|
|
870
878
|
__publicField(this, "radius");
|
|
871
|
-
__publicField(this, "
|
|
872
|
-
__publicField(this, "
|
|
873
|
-
this
|
|
874
|
-
this
|
|
875
|
-
this
|
|
879
|
+
__publicField(this, "centerWorld", new Vector3());
|
|
880
|
+
__publicField(this, "radiusWorld");
|
|
881
|
+
__publicField(this, "minimum", new Vector3());
|
|
882
|
+
__publicField(this, "maximum", new Vector3());
|
|
883
|
+
__publicField(this, "_worldMatrix");
|
|
884
|
+
this.radius = 0;
|
|
885
|
+
this.radiusWorld = 0;
|
|
886
|
+
this._worldMatrix = Matrix.Identity();
|
|
887
|
+
this.reConstruct(min, max, worldMatrix);
|
|
888
|
+
}
|
|
889
|
+
reConstruct(min, max, worldMatrix) {
|
|
890
|
+
this.minimum.copyFrom(min);
|
|
891
|
+
this.maximum.copyFrom(max);
|
|
892
|
+
this.center.copyFrom(Vector3.Lerp(min, max, 0.5));
|
|
876
893
|
this.radius = max.subtract(min).length() * 0.5;
|
|
894
|
+
this._update(worldMatrix ?? Matrix.Identity());
|
|
895
|
+
}
|
|
896
|
+
getWorldMatrix() {
|
|
897
|
+
return this._worldMatrix;
|
|
898
|
+
}
|
|
899
|
+
/** @internal */
|
|
900
|
+
_update(worldMatrix) {
|
|
901
|
+
Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);
|
|
902
|
+
const scaled = Vector3.TransformNormal(new Vector3(1, 1, 1), worldMatrix);
|
|
903
|
+
this.radiusWorld = Math.max(Math.abs(scaled.x), Math.abs(scaled.y), Math.abs(scaled.z)) * this.radius;
|
|
904
|
+
this._worldMatrix = worldMatrix;
|
|
877
905
|
}
|
|
878
906
|
intersectsPoint(point) {
|
|
879
|
-
return Vector3.DistanceSquared(this.
|
|
907
|
+
return Vector3.DistanceSquared(this.centerWorld, point) <= this.radiusWorld * this.radiusWorld;
|
|
880
908
|
}
|
|
881
909
|
static Intersects(a, b) {
|
|
882
|
-
const r = a.
|
|
883
|
-
return Vector3.DistanceSquared(a.
|
|
910
|
+
const r = a.radiusWorld + b.radiusWorld;
|
|
911
|
+
return Vector3.DistanceSquared(a.centerWorld, b.centerWorld) <= r * r;
|
|
884
912
|
}
|
|
885
913
|
}
|
|
886
914
|
class BoundingBox {
|
|
887
|
-
constructor(min, max) {
|
|
888
|
-
__publicField(this, "minimum");
|
|
889
|
-
__publicField(this, "maximum");
|
|
890
|
-
__publicField(this, "center");
|
|
891
|
-
__publicField(this, "extendSize");
|
|
892
|
-
/**
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
__publicField(this, "
|
|
896
|
-
/**
|
|
897
|
-
__publicField(this, "
|
|
898
|
-
|
|
899
|
-
this
|
|
900
|
-
|
|
901
|
-
this
|
|
902
|
-
|
|
903
|
-
this
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
new Vector3(
|
|
909
|
-
new Vector3(
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
915
|
+
constructor(min, max, worldMatrix) {
|
|
916
|
+
__publicField(this, "minimum", new Vector3());
|
|
917
|
+
__publicField(this, "maximum", new Vector3());
|
|
918
|
+
__publicField(this, "center", new Vector3());
|
|
919
|
+
__publicField(this, "extendSize", new Vector3());
|
|
920
|
+
/** Center of the AABB in world space. */
|
|
921
|
+
__publicField(this, "centerWorld", new Vector3());
|
|
922
|
+
/** Half-size of the AABB in world space (multiply by 2 for the full size). */
|
|
923
|
+
__publicField(this, "extendSizeWorld", new Vector3());
|
|
924
|
+
/** Minimum corner of the world-space AABB. */
|
|
925
|
+
__publicField(this, "minimumWorld", new Vector3());
|
|
926
|
+
/** Maximum corner of the world-space AABB. */
|
|
927
|
+
__publicField(this, "maximumWorld", new Vector3());
|
|
928
|
+
/** The 8 corner points in local space (min/max combinations). */
|
|
929
|
+
__publicField(this, "vectors", []);
|
|
930
|
+
/** The 8 corner points transformed into world space. */
|
|
931
|
+
__publicField(this, "vectorsWorld", []);
|
|
932
|
+
/** The three world-space axis directions of the box (rows of the world matrix). */
|
|
933
|
+
__publicField(this, "directions", [new Vector3(), new Vector3(), new Vector3()]);
|
|
934
|
+
__publicField(this, "_worldMatrix");
|
|
935
|
+
for (let i = 0; i < 8; i++) {
|
|
936
|
+
this.vectors.push(new Vector3());
|
|
937
|
+
this.vectorsWorld.push(new Vector3());
|
|
938
|
+
}
|
|
939
|
+
this._worldMatrix = Matrix.Identity();
|
|
940
|
+
this.reConstruct(min, max, worldMatrix);
|
|
941
|
+
}
|
|
942
|
+
reConstruct(min, max, worldMatrix) {
|
|
943
|
+
const minX = min.x, minY = min.y, minZ = min.z, maxX = max.x, maxY = max.y, maxZ = max.z;
|
|
944
|
+
this.minimum.copyFromFloats(minX, minY, minZ);
|
|
945
|
+
this.maximum.copyFromFloats(maxX, maxY, maxZ);
|
|
946
|
+
this.vectors[0].copyFromFloats(minX, minY, minZ);
|
|
947
|
+
this.vectors[1].copyFromFloats(maxX, maxY, maxZ);
|
|
948
|
+
this.vectors[2].copyFromFloats(maxX, minY, minZ);
|
|
949
|
+
this.vectors[3].copyFromFloats(minX, maxY, minZ);
|
|
950
|
+
this.vectors[4].copyFromFloats(minX, minY, maxZ);
|
|
951
|
+
this.vectors[5].copyFromFloats(maxX, maxY, minZ);
|
|
952
|
+
this.vectors[6].copyFromFloats(minX, maxY, maxZ);
|
|
953
|
+
this.vectors[7].copyFromFloats(maxX, minY, maxZ);
|
|
954
|
+
this.center.copyFromFloats((minX + maxX) * 0.5, (minY + maxY) * 0.5, (minZ + maxZ) * 0.5);
|
|
955
|
+
this.extendSize.copyFromFloats((maxX - minX) * 0.5, (maxY - minY) * 0.5, (maxZ - minZ) * 0.5);
|
|
956
|
+
this._update(worldMatrix ?? Matrix.Identity());
|
|
957
|
+
}
|
|
958
|
+
getWorldMatrix() {
|
|
959
|
+
return this._worldMatrix;
|
|
960
|
+
}
|
|
961
|
+
/** @internal */
|
|
962
|
+
_update(world) {
|
|
963
|
+
this.minimumWorld.setAll(Number.MAX_VALUE);
|
|
964
|
+
this.maximumWorld.setAll(-Number.MAX_VALUE);
|
|
965
|
+
for (let i = 0; i < 8; i++) {
|
|
966
|
+
const v = this.vectorsWorld[i];
|
|
967
|
+
Vector3.TransformCoordinatesToRef(this.vectors[i], world, v);
|
|
968
|
+
this.minimumWorld.minimizeInPlace(v);
|
|
969
|
+
this.maximumWorld.maximizeInPlace(v);
|
|
970
|
+
}
|
|
971
|
+
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;
|
|
972
|
+
this.extendSizeWorld.copyFromFloats((maxX - minX) * 0.5, (maxY - minY) * 0.5, (maxZ - minZ) * 0.5);
|
|
973
|
+
this.centerWorld.copyFromFloats((minX + maxX) * 0.5, (minY + maxY) * 0.5, (minZ + maxZ) * 0.5);
|
|
974
|
+
const m = world.m;
|
|
975
|
+
this.directions[0].copyFromFloats(m[0], m[1], m[2]);
|
|
976
|
+
this.directions[1].copyFromFloats(m[4], m[5], m[6]);
|
|
977
|
+
this.directions[2].copyFromFloats(m[8], m[9], m[10]);
|
|
978
|
+
this._worldMatrix = world;
|
|
914
979
|
}
|
|
915
980
|
intersectsPoint(point) {
|
|
916
|
-
return point.x >= this.
|
|
981
|
+
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;
|
|
917
982
|
}
|
|
918
983
|
static Intersects(a, b) {
|
|
919
|
-
return a.
|
|
984
|
+
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;
|
|
920
985
|
}
|
|
921
986
|
}
|
|
922
987
|
class BoundingInfo {
|
|
923
|
-
constructor(min, max) {
|
|
988
|
+
constructor(min, max, worldMatrix) {
|
|
924
989
|
__publicField(this, "boundingBox");
|
|
925
990
|
__publicField(this, "boundingSphere");
|
|
926
|
-
this.boundingBox = new BoundingBox(min, max);
|
|
927
|
-
this.boundingSphere = new BoundingSphere(min, max);
|
|
991
|
+
this.boundingBox = new BoundingBox(min, max, worldMatrix);
|
|
992
|
+
this.boundingSphere = new BoundingSphere(min, max, worldMatrix);
|
|
928
993
|
}
|
|
929
994
|
get minimum() {
|
|
930
995
|
return this.boundingBox.minimum;
|
|
@@ -935,10 +1000,17 @@ class BoundingInfo {
|
|
|
935
1000
|
intersectsPoint(point) {
|
|
936
1001
|
return this.boundingSphere.intersectsPoint(point) && this.boundingBox.intersectsPoint(point);
|
|
937
1002
|
}
|
|
938
|
-
/**
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
this.
|
|
1003
|
+
/** Babylon.js `BoundingInfo.update` — re-derive the world-space bounds from the
|
|
1004
|
+
* local geometry and a new world matrix. */
|
|
1005
|
+
update(worldMatrix) {
|
|
1006
|
+
this.boundingBox._update(worldMatrix);
|
|
1007
|
+
this.boundingSphere._update(worldMatrix);
|
|
1008
|
+
}
|
|
1009
|
+
/** Rebuild the local bounds and (optionally) re-derive world-space bounds from
|
|
1010
|
+
* the supplied world matrix, transforming all eight corners. */
|
|
1011
|
+
reConstruct(min, max, worldMatrix) {
|
|
1012
|
+
this.boundingBox.reConstruct(min, max, worldMatrix);
|
|
1013
|
+
this.boundingSphere.reConstruct(min, max, worldMatrix);
|
|
942
1014
|
}
|
|
943
1015
|
}
|
|
944
1016
|
let _uniqueIdCounter = 0;
|
|
@@ -959,6 +1031,8 @@ class Node {
|
|
|
959
1031
|
__publicField(this, "_children", []);
|
|
960
1032
|
/** @internal */
|
|
961
1033
|
__publicField(this, "_enabled", true);
|
|
1034
|
+
/** @internal Effective enabled state inherited from the parent chain. */
|
|
1035
|
+
__publicField(this, "_parentEnabled", true);
|
|
962
1036
|
/** @internal */
|
|
963
1037
|
__publicField(this, "_disposed", false);
|
|
964
1038
|
this.name = name;
|
|
@@ -1005,6 +1079,7 @@ class Node {
|
|
|
1005
1079
|
if (value && !value._children.includes(this)) {
|
|
1006
1080
|
value._children.push(this);
|
|
1007
1081
|
}
|
|
1082
|
+
this._syncParentEnabledState();
|
|
1008
1083
|
}
|
|
1009
1084
|
/** @internal Whether this node is an `AbstractMesh` (overridden there) — drives `getChildMeshes`. */
|
|
1010
1085
|
_isMeshNode() {
|
|
@@ -1043,17 +1118,42 @@ class Node {
|
|
|
1043
1118
|
getChildMeshes(directDescendantsOnly = false, predicate) {
|
|
1044
1119
|
return this.getDescendants(directDescendantsOnly, (node) => node._isMeshNode() && (!predicate || predicate(node)));
|
|
1045
1120
|
}
|
|
1046
|
-
isEnabled() {
|
|
1047
|
-
return this._enabled;
|
|
1121
|
+
isEnabled(checkAncestors = true) {
|
|
1122
|
+
return this._enabled && (!checkAncestors || this._parentEnabled);
|
|
1048
1123
|
}
|
|
1049
1124
|
setEnabled(value) {
|
|
1125
|
+
if (this._enabled === value) {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1050
1128
|
this._enabled = value;
|
|
1129
|
+
this._syncParentEnabledState();
|
|
1130
|
+
}
|
|
1131
|
+
/** @internal Refresh this subtree after a local enabled or parent change. */
|
|
1132
|
+
_syncParentEnabledState() {
|
|
1133
|
+
var _a;
|
|
1134
|
+
this._parentEnabled = ((_a = this._parent) == null ? void 0 : _a.isEnabled()) ?? true;
|
|
1135
|
+
this._onEffectiveEnabledStateChanged(this.isEnabled());
|
|
1136
|
+
for (const child of this._children) {
|
|
1137
|
+
child._syncParentEnabledState();
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
/** @internal Hook for wrappers that must materialize effective enabled state in Lite. */
|
|
1141
|
+
_onEffectiveEnabledStateChanged(_enabled) {
|
|
1051
1142
|
}
|
|
1052
1143
|
isDisposed() {
|
|
1053
1144
|
return this._disposed;
|
|
1054
1145
|
}
|
|
1055
|
-
dispose() {
|
|
1146
|
+
dispose(doNotRecurse = false) {
|
|
1147
|
+
this._disposeWrapperTree(doNotRecurse);
|
|
1148
|
+
}
|
|
1149
|
+
/** @internal Dispose compat wrapper state without touching Lite resources. */
|
|
1150
|
+
_disposeWrapperTree(doNotRecurse = false) {
|
|
1056
1151
|
var _a;
|
|
1152
|
+
if (!doNotRecurse) {
|
|
1153
|
+
for (const child of [...this._children]) {
|
|
1154
|
+
child._disposeWrapperTree();
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1057
1157
|
this._disposed = true;
|
|
1058
1158
|
this._linkParent(null);
|
|
1059
1159
|
(_a = this._scene) == null ? void 0 : _a._unregisterNode(this);
|
|
@@ -1062,6 +1162,106 @@ class Node {
|
|
|
1062
1162
|
_applyParent(_parent) {
|
|
1063
1163
|
}
|
|
1064
1164
|
}
|
|
1165
|
+
function fillFlatNormals(positions, indices, indexOffset, indexCount, vertexBase, out) {
|
|
1166
|
+
for (let i = 0; i < indexCount; i += 3) {
|
|
1167
|
+
const a = (indices[indexOffset + i] + vertexBase) * 3;
|
|
1168
|
+
const b = (indices[indexOffset + i + 1] + vertexBase) * 3;
|
|
1169
|
+
const c = (indices[indexOffset + i + 2] + vertexBase) * 3;
|
|
1170
|
+
const ux = positions[b] - positions[a];
|
|
1171
|
+
const uy = positions[b + 1] - positions[a + 1];
|
|
1172
|
+
const uz = positions[b + 2] - positions[a + 2];
|
|
1173
|
+
const vx = positions[c] - positions[a];
|
|
1174
|
+
const vy = positions[c + 1] - positions[a + 1];
|
|
1175
|
+
const vz = positions[c + 2] - positions[a + 2];
|
|
1176
|
+
let nx = uy * vz - uz * vy;
|
|
1177
|
+
let ny = uz * vx - ux * vz;
|
|
1178
|
+
let nz = ux * vy - uy * vx;
|
|
1179
|
+
const len = Math.hypot(nx, ny, nz) || 1;
|
|
1180
|
+
nx /= len;
|
|
1181
|
+
ny /= len;
|
|
1182
|
+
nz /= len;
|
|
1183
|
+
for (const vi of [a, b, c]) {
|
|
1184
|
+
out[vi] = nx;
|
|
1185
|
+
out[vi + 1] = ny;
|
|
1186
|
+
out[vi + 2] = nz;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
function mergeMeshGeometry(engine, name, meshes) {
|
|
1191
|
+
var _a;
|
|
1192
|
+
if (meshes.length === 0) {
|
|
1193
|
+
throw new Error("mergeMeshGeometry requires at least one mesh");
|
|
1194
|
+
}
|
|
1195
|
+
let totalVerts = 0;
|
|
1196
|
+
let totalIdx = 0;
|
|
1197
|
+
let anyUvs = false;
|
|
1198
|
+
for (const mesh of meshes) {
|
|
1199
|
+
if (!mesh._cpuPositions || !mesh._cpuIndices) {
|
|
1200
|
+
throw new Error(`mergeMeshGeometry: mesh "${mesh.name}" is missing CPU geometry`);
|
|
1201
|
+
}
|
|
1202
|
+
totalVerts += mesh._cpuPositions.length / 3;
|
|
1203
|
+
totalIdx += mesh._cpuIndices.length;
|
|
1204
|
+
if ((_a = mesh._cpuUvs) == null ? void 0 : _a.length) {
|
|
1205
|
+
anyUvs = true;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
const positions = new Float32Array(totalVerts * 3);
|
|
1209
|
+
const normals = new Float32Array(totalVerts * 3);
|
|
1210
|
+
const uvs = anyUvs ? new Float32Array(totalVerts * 2) : void 0;
|
|
1211
|
+
const indices = new Uint32Array(totalIdx);
|
|
1212
|
+
let pOff = 0;
|
|
1213
|
+
let iOff = 0;
|
|
1214
|
+
let vertBase = 0;
|
|
1215
|
+
for (const mesh of meshes) {
|
|
1216
|
+
const src = mesh._cpuPositions;
|
|
1217
|
+
const srcNormals = mesh._cpuNormals;
|
|
1218
|
+
const srcUvs = mesh._cpuUvs;
|
|
1219
|
+
const wm = mesh.worldMatrix;
|
|
1220
|
+
const vertexCount = src.length / 3;
|
|
1221
|
+
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];
|
|
1222
|
+
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;
|
|
1223
|
+
const determinant2 = a * c00 + b * c01 + c * c02;
|
|
1224
|
+
const normalSign = determinant2 < 0 ? -1 : 1;
|
|
1225
|
+
const reverseWinding = normalSign !== (mesh._authoredSign ?? 1);
|
|
1226
|
+
const meshVertexStart = pOff / 3;
|
|
1227
|
+
for (let v = 0; v < src.length; v += 3) {
|
|
1228
|
+
const x = src[v], y = src[v + 1], z = src[v + 2];
|
|
1229
|
+
positions[pOff] = x * a + y * b + z * c + wm[12];
|
|
1230
|
+
positions[pOff + 1] = x * d + y * e + z * f + wm[13];
|
|
1231
|
+
positions[pOff + 2] = x * g + y * h + z * i + wm[14];
|
|
1232
|
+
if (srcNormals) {
|
|
1233
|
+
const nx = srcNormals[v], ny = srcNormals[v + 1], nz = srcNormals[v + 2];
|
|
1234
|
+
let tx = (nx * c00 + ny * c01 + nz * c02) * normalSign;
|
|
1235
|
+
let ty = (nx * c10 + ny * c11 + nz * c12) * normalSign;
|
|
1236
|
+
let tz = (nx * c20 + ny * c21 + nz * c22) * normalSign;
|
|
1237
|
+
const len = Math.hypot(tx, ty, tz) || 1;
|
|
1238
|
+
tx /= len;
|
|
1239
|
+
ty /= len;
|
|
1240
|
+
tz /= len;
|
|
1241
|
+
normals[pOff] = tx;
|
|
1242
|
+
normals[pOff + 1] = ty;
|
|
1243
|
+
normals[pOff + 2] = tz;
|
|
1244
|
+
}
|
|
1245
|
+
pOff += 3;
|
|
1246
|
+
}
|
|
1247
|
+
if (uvs && (srcUvs == null ? void 0 : srcUvs.length)) {
|
|
1248
|
+
uvs.set(srcUvs.subarray(0, vertexCount * 2), meshVertexStart * 2);
|
|
1249
|
+
}
|
|
1250
|
+
const meshIdx = mesh._cpuIndices;
|
|
1251
|
+
const indexCount = meshIdx.length;
|
|
1252
|
+
const indexStart = iOff;
|
|
1253
|
+
for (let k = 0; k < indexCount; k += 3) {
|
|
1254
|
+
indices[iOff++] = meshIdx[k] + vertBase;
|
|
1255
|
+
indices[iOff++] = meshIdx[k + (reverseWinding ? 2 : 1)] + vertBase;
|
|
1256
|
+
indices[iOff++] = meshIdx[k + (reverseWinding ? 1 : 2)] + vertBase;
|
|
1257
|
+
}
|
|
1258
|
+
if (!srcNormals) {
|
|
1259
|
+
fillFlatNormals(positions, indices, indexStart, indexCount, 0, normals);
|
|
1260
|
+
}
|
|
1261
|
+
vertBase += vertexCount;
|
|
1262
|
+
}
|
|
1263
|
+
return createMeshFromData(engine, name, positions, normals, indices, uvs);
|
|
1264
|
+
}
|
|
1065
1265
|
function isCompatScene(value) {
|
|
1066
1266
|
return typeof value.getEngine === "function";
|
|
1067
1267
|
}
|
|
@@ -1109,11 +1309,20 @@ function computeFlatNormals(positions, indices) {
|
|
|
1109
1309
|
}
|
|
1110
1310
|
return normals;
|
|
1111
1311
|
}
|
|
1312
|
+
function matchingVertexAttribute(data, vertexCount, components) {
|
|
1313
|
+
return (data == null ? void 0 : data.length) === vertexCount * components ? data : void 0;
|
|
1314
|
+
}
|
|
1112
1315
|
class TransformNode extends Node {
|
|
1113
1316
|
constructor(name, scene, liteNode) {
|
|
1114
1317
|
super(name, scene);
|
|
1115
1318
|
/** @internal The Lite scene node that carries this transform. */
|
|
1116
1319
|
__publicField(this, "_node");
|
|
1320
|
+
/**
|
|
1321
|
+
* @internal The Lite asset container this node was loaded from, when produced
|
|
1322
|
+
* by a loader. Used by the `KHR_materials_variants` helpers (which key off the
|
|
1323
|
+
* loaded root node) and to keep loaded meshes tied to their source asset.
|
|
1324
|
+
*/
|
|
1325
|
+
__publicField(this, "_container");
|
|
1117
1326
|
/** @internal Whether `rotationQuaternion` was explicitly set (Babylon.js returns null otherwise). */
|
|
1118
1327
|
__publicField(this, "_useQuat", false);
|
|
1119
1328
|
if (liteNode) {
|
|
@@ -1125,6 +1334,23 @@ class TransformNode extends Node {
|
|
|
1125
1334
|
}
|
|
1126
1335
|
}
|
|
1127
1336
|
}
|
|
1337
|
+
/**
|
|
1338
|
+
* @internal Bind a loader-produced wrapper to the scene the container was added
|
|
1339
|
+
* to. The loader already inserted the underlying Lite node (via
|
|
1340
|
+
* `addToScene(container)`), so this only wires the compat-side scene reference
|
|
1341
|
+
* and lists the wrapper in `scene.meshes` — it never re-inserts into Lite.
|
|
1342
|
+
*/
|
|
1343
|
+
_bindLoadedScene(scene) {
|
|
1344
|
+
if (this._scene === scene) {
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
this._scene = scene;
|
|
1348
|
+
scene._registerMesh(this, this._node);
|
|
1349
|
+
}
|
|
1350
|
+
/** @internal Link an already-parented Lite node without mutating its Lite hierarchy. */
|
|
1351
|
+
_adoptLoadedParent(parent) {
|
|
1352
|
+
this._linkParent(parent);
|
|
1353
|
+
}
|
|
1128
1354
|
getClassName() {
|
|
1129
1355
|
return "TransformNode";
|
|
1130
1356
|
}
|
|
@@ -1188,13 +1414,17 @@ class AbstractMesh extends TransformNode {
|
|
|
1188
1414
|
__publicField(this, "_lite");
|
|
1189
1415
|
__publicField(this, "_material", null);
|
|
1190
1416
|
__publicField(this, "_visible", true);
|
|
1191
|
-
/** @internal Retained tangent/color buffers so successive `setVerticesData`
|
|
1417
|
+
/** @internal Retained uv2/tangent/color buffers so successive `setVerticesData` (and a bake) keep them all. */
|
|
1418
|
+
__publicField(this, "_lastUv2");
|
|
1192
1419
|
__publicField(this, "_lastTangents");
|
|
1193
1420
|
__publicField(this, "_lastColors");
|
|
1421
|
+
/** @internal Position resizing generated normals from the old topology; regenerate after the next index update. */
|
|
1422
|
+
__publicField(this, "_normalsFollowIndices", false);
|
|
1194
1423
|
this._lite = lite;
|
|
1195
1424
|
this._lite.name = name;
|
|
1196
1425
|
if (scene) {
|
|
1197
1426
|
this.material = scene.defaultMaterial;
|
|
1427
|
+
scene._registerMesh(this, this._lite);
|
|
1198
1428
|
}
|
|
1199
1429
|
}
|
|
1200
1430
|
getClassName() {
|
|
@@ -1208,9 +1438,19 @@ class AbstractMesh extends TransformNode {
|
|
|
1208
1438
|
return this._material;
|
|
1209
1439
|
}
|
|
1210
1440
|
set material(value) {
|
|
1441
|
+
var _a;
|
|
1211
1442
|
this._material = value;
|
|
1212
|
-
|
|
1213
|
-
|
|
1443
|
+
const scene = this._scene;
|
|
1444
|
+
const renderMaterial = value ?? (scene == null ? void 0 : scene.defaultMaterial);
|
|
1445
|
+
if (renderMaterial && (scene == null ? void 0 : scene._hasStarted)) {
|
|
1446
|
+
(_a = renderMaterial._adoptScene) == null ? void 0 : _a.call(renderMaterial, scene);
|
|
1447
|
+
renderMaterial._ensureRenderable(engineOf(scene));
|
|
1448
|
+
}
|
|
1449
|
+
if (renderMaterial == null ? void 0 : renderMaterial._lite) {
|
|
1450
|
+
this._lite.material = renderMaterial._lite;
|
|
1451
|
+
}
|
|
1452
|
+
if (value && "_bindMesh" in value) {
|
|
1453
|
+
value._bindMesh(this._lite, () => this._material === value);
|
|
1214
1454
|
}
|
|
1215
1455
|
}
|
|
1216
1456
|
get isVisible() {
|
|
@@ -1218,7 +1458,7 @@ class AbstractMesh extends TransformNode {
|
|
|
1218
1458
|
}
|
|
1219
1459
|
set isVisible(value) {
|
|
1220
1460
|
this._visible = value;
|
|
1221
|
-
|
|
1461
|
+
this._syncVisibility(this.isEnabled());
|
|
1222
1462
|
}
|
|
1223
1463
|
get receiveShadows() {
|
|
1224
1464
|
return this._lite.receiveShadows;
|
|
@@ -1226,36 +1466,56 @@ class AbstractMesh extends TransformNode {
|
|
|
1226
1466
|
set receiveShadows(value) {
|
|
1227
1467
|
this._lite.receiveShadows = value;
|
|
1228
1468
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1469
|
+
_onEffectiveEnabledStateChanged(enabled) {
|
|
1470
|
+
this._syncVisibility(enabled);
|
|
1471
|
+
}
|
|
1472
|
+
/** @internal Apply local visibility and effective enabled state to Lite. */
|
|
1473
|
+
_syncVisibility(enabled) {
|
|
1474
|
+
const visible = this._visible && enabled;
|
|
1475
|
+
if (this._lite.visible !== visible) {
|
|
1476
|
+
setMeshVisible(this._lite, visible);
|
|
1477
|
+
}
|
|
1232
1478
|
}
|
|
1233
1479
|
/**
|
|
1234
|
-
* Babylon.js `mesh.getBoundingInfo()` —
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1480
|
+
* Babylon.js `mesh.getBoundingInfo()` — the mesh's AABB. `minimum`/`maximum`
|
|
1481
|
+
* are the local-space bounds; the returned `BoundingInfo`'s world members
|
|
1482
|
+
* (`minimumWorld`/`maximumWorld`/`centerWorld`/…) are derived by transforming
|
|
1483
|
+
* the eight local corners by the mesh's world matrix, so a mesh at (1,2,3)
|
|
1484
|
+
* reports correctly-offset world bounds. Babylon Lite stores `boundMin`/
|
|
1485
|
+
* `boundMax` (local space) on factory- and loader-built meshes; when absent
|
|
1486
|
+
* (e.g. a placeholder mesh whose bounds were never computed) we fold the
|
|
1487
|
+
* retained CPU positions through Lite's `computeAabb`. A mesh with no geometry
|
|
1488
|
+
* returns a degenerate zero-size box.
|
|
1239
1489
|
*/
|
|
1240
1490
|
getBoundingInfo() {
|
|
1491
|
+
const world = this._worldMatrixForBounds();
|
|
1241
1492
|
const lo = this._lite.boundMin;
|
|
1242
1493
|
const hi = this._lite.boundMax;
|
|
1243
1494
|
if (lo && hi) {
|
|
1244
|
-
return new BoundingInfo(new Vector3(lo[0], lo[1], lo[2]), new Vector3(hi[0], hi[1], hi[2]));
|
|
1495
|
+
return new BoundingInfo(new Vector3(lo[0], lo[1], lo[2]), new Vector3(hi[0], hi[1], hi[2]), world);
|
|
1245
1496
|
}
|
|
1246
1497
|
const positions = this._lite._cpuPositions;
|
|
1247
1498
|
if (positions && positions.length >= 3 && positions.length % 3 === 0) {
|
|
1248
1499
|
const [min, max] = computeAabb(positions);
|
|
1249
1500
|
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])) {
|
|
1250
|
-
return new BoundingInfo(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]));
|
|
1501
|
+
return new BoundingInfo(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]), world);
|
|
1251
1502
|
}
|
|
1252
1503
|
}
|
|
1253
|
-
return new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
|
|
1504
|
+
return new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0), world);
|
|
1505
|
+
}
|
|
1506
|
+
/** Compat handle over Babylon Lite's world matrix for bounds derivation. Returns
|
|
1507
|
+
* `undefined` when the Lite node hasn't computed one (world bounds fall back to
|
|
1508
|
+
* local). */
|
|
1509
|
+
_worldMatrixForBounds() {
|
|
1510
|
+
const wm = this._lite.worldMatrix;
|
|
1511
|
+
return wm ? Matrix.FromArray(wm) : void 0;
|
|
1254
1512
|
}
|
|
1255
1513
|
/**
|
|
1256
|
-
* Babylon.js `mesh.getVerticesData(kind)` — read back the CPU geometry buffer
|
|
1257
|
-
*
|
|
1258
|
-
* (for picking + device-loss recovery)
|
|
1514
|
+
* Babylon.js `mesh.getVerticesData(kind)` — read back the CPU geometry buffer.
|
|
1515
|
+
* `position` / `normal` / `uv` come from the buffers Babylon Lite retains on the
|
|
1516
|
+
* mesh (for picking + device-loss recovery). Prefer the last compat-side value
|
|
1517
|
+
* for `uv2` / `tangent` / `color`, falling back to attributes retained by Lite
|
|
1518
|
+
* for loader- and factory-created meshes.
|
|
1259
1519
|
*/
|
|
1260
1520
|
getVerticesData(kind) {
|
|
1261
1521
|
switch (kind) {
|
|
@@ -1265,6 +1525,12 @@ class AbstractMesh extends TransformNode {
|
|
|
1265
1525
|
return this._lite._cpuNormals ?? null;
|
|
1266
1526
|
case "uv":
|
|
1267
1527
|
return this._lite._cpuUvs ?? null;
|
|
1528
|
+
case "uv2":
|
|
1529
|
+
return this._lastUv2 ?? this._lite._cpuUv2s ?? null;
|
|
1530
|
+
case "tangent":
|
|
1531
|
+
return this._lastTangents ?? this._lite._cpuTangents ?? null;
|
|
1532
|
+
case "color":
|
|
1533
|
+
return this._lastColors ?? this._lite._cpuColors ?? null;
|
|
1268
1534
|
default:
|
|
1269
1535
|
return null;
|
|
1270
1536
|
}
|
|
@@ -1284,10 +1550,13 @@ class AbstractMesh extends TransformNode {
|
|
|
1284
1550
|
if (!engine || !lite._cpuPositions || !lite._cpuIndices) {
|
|
1285
1551
|
return;
|
|
1286
1552
|
}
|
|
1287
|
-
if (kind !== "position" && kind !== "normal" && kind !== "uv" && kind !== "color" && kind !== "tangent") {
|
|
1553
|
+
if (kind !== "position" && kind !== "normal" && kind !== "uv" && kind !== "uv2" && kind !== "color" && kind !== "tangent") {
|
|
1288
1554
|
return;
|
|
1289
1555
|
}
|
|
1290
1556
|
const f32 = data instanceof Float32Array ? data : Float32Array.from(data);
|
|
1557
|
+
if (kind === "uv2") {
|
|
1558
|
+
this._lastUv2 = f32;
|
|
1559
|
+
}
|
|
1291
1560
|
if (kind === "color") {
|
|
1292
1561
|
this._lastColors = f32;
|
|
1293
1562
|
}
|
|
@@ -1295,9 +1564,60 @@ class AbstractMesh extends TransformNode {
|
|
|
1295
1564
|
this._lastTangents = f32;
|
|
1296
1565
|
}
|
|
1297
1566
|
const positions = kind === "position" ? f32 : lite._cpuPositions;
|
|
1298
|
-
const
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1567
|
+
const vertexCount = positions.length / 3;
|
|
1568
|
+
const existingNormals = matchingVertexAttribute(lite._cpuNormals, vertexCount, 3);
|
|
1569
|
+
const normals = kind === "normal" ? f32 : existingNormals ?? computeFlatNormals(positions, lite._cpuIndices);
|
|
1570
|
+
if (kind === "position") {
|
|
1571
|
+
this._normalsFollowIndices = !existingNormals;
|
|
1572
|
+
} else if (kind === "normal") {
|
|
1573
|
+
this._normalsFollowIndices = false;
|
|
1574
|
+
}
|
|
1575
|
+
const existingUvs = matchingVertexAttribute(lite._cpuUvs, vertexCount, 2);
|
|
1576
|
+
const uvs = kind === "uv" ? f32 : existingUvs ?? (kind === "position" ? new Float32Array(vertexCount * 2) : void 0);
|
|
1577
|
+
const uvs2 = kind === "uv2" ? f32 : matchingVertexAttribute(this._lastUv2 ?? lite._cpuUv2s, vertexCount, 2);
|
|
1578
|
+
const tangents = matchingVertexAttribute(this._lastTangents ?? lite._cpuTangents, vertexCount, 4);
|
|
1579
|
+
const colors = matchingVertexAttribute(this._lastColors ?? lite._cpuColors, vertexCount, 4);
|
|
1580
|
+
resizeMeshGeometry(engine, this._lite, positions, normals, lite._cpuIndices, uvs, uvs2, tangents, colors);
|
|
1581
|
+
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Babylon.js `mesh.getIndices()` — read back the mesh's index (topology) buffer.
|
|
1584
|
+
* Babylon Lite retains the indices on the mesh as a `Uint32Array` (for picking +
|
|
1585
|
+
* device-loss recovery), so we return that directly; a mesh with no geometry
|
|
1586
|
+
* returns `null`.
|
|
1587
|
+
*/
|
|
1588
|
+
getIndices(_copyWhenShared, forceCopy) {
|
|
1589
|
+
const indices = this._lite._cpuIndices;
|
|
1590
|
+
return indices ? forceCopy ? indices.slice() : indices : null;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Babylon.js `mesh.setIndices(indices)` — replace the mesh's index (topology)
|
|
1594
|
+
* buffer. Babylon Lite re-uploads the geometry in place via `resizeMeshGeometry`,
|
|
1595
|
+
* keeping the existing position/normal/uv/tangent/color attributes and swapping
|
|
1596
|
+
* only the indices. Returns the mesh for chaining.
|
|
1597
|
+
*/
|
|
1598
|
+
setIndices(indices, _totalVertices, _updatable) {
|
|
1599
|
+
var _a;
|
|
1600
|
+
const engine = (_a = this._scene) == null ? void 0 : _a.getEngine()._lite;
|
|
1601
|
+
const lite = this._lite;
|
|
1602
|
+
if (!engine || !lite._cpuPositions) {
|
|
1603
|
+
return this;
|
|
1604
|
+
}
|
|
1605
|
+
const u32 = indices instanceof Uint32Array ? indices : Uint32Array.from(indices);
|
|
1606
|
+
const positions = lite._cpuPositions;
|
|
1607
|
+
const vertexCount = positions.length / 3;
|
|
1608
|
+
const normals = this._normalsFollowIndices ? computeFlatNormals(positions, u32) : matchingVertexAttribute(lite._cpuNormals, vertexCount, 3) ?? computeFlatNormals(positions, u32);
|
|
1609
|
+
resizeMeshGeometry(
|
|
1610
|
+
engine,
|
|
1611
|
+
this._lite,
|
|
1612
|
+
positions,
|
|
1613
|
+
normals,
|
|
1614
|
+
u32,
|
|
1615
|
+
matchingVertexAttribute(lite._cpuUvs, vertexCount, 2),
|
|
1616
|
+
matchingVertexAttribute(this._lastUv2 ?? lite._cpuUv2s, vertexCount, 2),
|
|
1617
|
+
matchingVertexAttribute(this._lastTangents ?? lite._cpuTangents, vertexCount, 4),
|
|
1618
|
+
matchingVertexAttribute(this._lastColors ?? lite._cpuColors, vertexCount, 4)
|
|
1619
|
+
);
|
|
1620
|
+
return this;
|
|
1301
1621
|
}
|
|
1302
1622
|
/** Babylon.js `mesh.getTotalVertices()` — vertex count from the position buffer. */
|
|
1303
1623
|
getTotalVertices() {
|
|
@@ -1314,26 +1634,23 @@ class AbstractMesh extends TransformNode {
|
|
|
1314
1634
|
return this;
|
|
1315
1635
|
}
|
|
1316
1636
|
/**
|
|
1317
|
-
*
|
|
1318
|
-
*
|
|
1319
|
-
*
|
|
1320
|
-
*
|
|
1321
|
-
* renormalized
|
|
1637
|
+
* @internal Shared bake: fold `matrix` into the retained CPU geometry and
|
|
1638
|
+
* re-upload it. Positions transform by the full matrix; **normals by the
|
|
1639
|
+
* inverse-transpose of the upper 3×3** (so they stay perpendicular to the baked
|
|
1640
|
+
* surface under non-uniform / sheared transforms, unlike a raw 3×3 multiply) and
|
|
1641
|
+
* are renormalized. The retained `uv` / `uv2` / `tangent` / `color` attributes are
|
|
1642
|
+
* forwarded unchanged so they survive the geometry reupload rather than being
|
|
1643
|
+
* dropped. Returns `false` when there is no geometry to bake.
|
|
1322
1644
|
*/
|
|
1323
|
-
|
|
1645
|
+
_bakeMatrix(matrix) {
|
|
1324
1646
|
var _a;
|
|
1325
1647
|
const engine = (_a = this._scene) == null ? void 0 : _a.getEngine()._lite;
|
|
1326
1648
|
const lite = this._lite;
|
|
1327
1649
|
const positions = lite._cpuPositions;
|
|
1328
1650
|
const indices = lite._cpuIndices;
|
|
1329
1651
|
if (!engine || !positions || !indices) {
|
|
1330
|
-
return
|
|
1652
|
+
return false;
|
|
1331
1653
|
}
|
|
1332
|
-
const node = this._node;
|
|
1333
|
-
const s = node.scaling;
|
|
1334
|
-
const q = node.rotationQuaternion;
|
|
1335
|
-
const t = node.position;
|
|
1336
|
-
const matrix = Matrix.Compose(liteBackedVector3(s), { x: q.x, y: q.y, z: q.z, w: q.w }, liteBackedVector3(t));
|
|
1337
1654
|
const m = matrix.m;
|
|
1338
1655
|
const newPositions = new Float32Array(positions.length);
|
|
1339
1656
|
for (let i = 0; i < positions.length; i += 3) {
|
|
@@ -1342,15 +1659,25 @@ class AbstractMesh extends TransformNode {
|
|
|
1342
1659
|
newPositions[i + 1] = x * m[1] + y * m[5] + z * m[9] + m[13];
|
|
1343
1660
|
newPositions[i + 2] = x * m[2] + y * m[6] + z * m[10] + m[14];
|
|
1344
1661
|
}
|
|
1662
|
+
let bakedIndices = indices;
|
|
1663
|
+
if (matrix.determinant() < 0) {
|
|
1664
|
+
bakedIndices = new Uint32Array(indices);
|
|
1665
|
+
for (let i = 0; i + 2 < bakedIndices.length; i += 3) {
|
|
1666
|
+
const second = bakedIndices[i + 1];
|
|
1667
|
+
bakedIndices[i + 1] = bakedIndices[i + 2];
|
|
1668
|
+
bakedIndices[i + 2] = second;
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1345
1671
|
let newNormals;
|
|
1346
1672
|
const normals = lite._cpuNormals;
|
|
1347
1673
|
if (normals) {
|
|
1674
|
+
const nm = matrix.invert().transpose().m;
|
|
1348
1675
|
newNormals = new Float32Array(normals.length);
|
|
1349
1676
|
for (let i = 0; i < normals.length; i += 3) {
|
|
1350
1677
|
const x = normals[i], y = normals[i + 1], z = normals[i + 2];
|
|
1351
|
-
let nx = x *
|
|
1352
|
-
let ny = x *
|
|
1353
|
-
let nz = x *
|
|
1678
|
+
let nx = x * nm[0] + y * nm[4] + z * nm[8];
|
|
1679
|
+
let ny = x * nm[1] + y * nm[5] + z * nm[9];
|
|
1680
|
+
let nz = x * nm[2] + y * nm[6] + z * nm[10];
|
|
1354
1681
|
const len = Math.hypot(nx, ny, nz) || 1;
|
|
1355
1682
|
nx /= len;
|
|
1356
1683
|
ny /= len;
|
|
@@ -1360,14 +1687,68 @@ class AbstractMesh extends TransformNode {
|
|
|
1360
1687
|
newNormals[i + 2] = nz;
|
|
1361
1688
|
}
|
|
1362
1689
|
} else {
|
|
1363
|
-
newNormals = computeFlatNormals(newPositions,
|
|
1690
|
+
newNormals = computeFlatNormals(newPositions, bakedIndices);
|
|
1691
|
+
}
|
|
1692
|
+
const tangents = this._lastTangents ?? lite._cpuTangents ?? void 0;
|
|
1693
|
+
let newTangents;
|
|
1694
|
+
if (tangents) {
|
|
1695
|
+
newTangents = new Float32Array(tangents.length);
|
|
1696
|
+
for (let i = 0; i < tangents.length; i += 4) {
|
|
1697
|
+
const x = tangents[i], y = tangents[i + 1], z = tangents[i + 2];
|
|
1698
|
+
let tx = x * m[0] + y * m[4] + z * m[8];
|
|
1699
|
+
let ty = x * m[1] + y * m[5] + z * m[9];
|
|
1700
|
+
let tz = x * m[2] + y * m[6] + z * m[10];
|
|
1701
|
+
const len = Math.hypot(tx, ty, tz) || 1;
|
|
1702
|
+
tx /= len;
|
|
1703
|
+
ty /= len;
|
|
1704
|
+
tz /= len;
|
|
1705
|
+
newTangents[i] = tx;
|
|
1706
|
+
newTangents[i + 1] = ty;
|
|
1707
|
+
newTangents[i + 2] = tz;
|
|
1708
|
+
newTangents[i + 3] = tangents[i + 3];
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
resizeMeshGeometry(
|
|
1712
|
+
engine,
|
|
1713
|
+
this._lite,
|
|
1714
|
+
newPositions,
|
|
1715
|
+
newNormals,
|
|
1716
|
+
bakedIndices,
|
|
1717
|
+
lite._cpuUvs,
|
|
1718
|
+
this._lastUv2 ?? lite._cpuUv2s ?? void 0,
|
|
1719
|
+
newTangents,
|
|
1720
|
+
this._lastColors ?? lite._cpuColors ?? void 0
|
|
1721
|
+
);
|
|
1722
|
+
return true;
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Babylon.js `mesh.bakeCurrentTransformIntoVertices()` — fold the node's local
|
|
1726
|
+
* transform (position / rotation / scaling) into the CPU geometry via the shared
|
|
1727
|
+
* {@link _bakeMatrix} helper, then reset the node transform to identity (the
|
|
1728
|
+
* geometry now carries it).
|
|
1729
|
+
*/
|
|
1730
|
+
bakeCurrentTransformIntoVertices() {
|
|
1731
|
+
const node = this._node;
|
|
1732
|
+
const q = node.rotationQuaternion;
|
|
1733
|
+
const matrix = Matrix.Compose(liteBackedVector3(node.scaling), { x: q.x, y: q.y, z: q.z, w: q.w }, liteBackedVector3(node.position));
|
|
1734
|
+
if (!this._bakeMatrix(matrix)) {
|
|
1735
|
+
return this;
|
|
1364
1736
|
}
|
|
1365
|
-
resizeMeshGeometry(engine, this._lite, newPositions, newNormals, indices, lite._cpuUvs);
|
|
1366
1737
|
node.position.set(0, 0, 0);
|
|
1367
1738
|
node.rotation.set(0, 0, 0);
|
|
1368
1739
|
node.scaling.set(1, 1, 1);
|
|
1369
1740
|
return this;
|
|
1370
1741
|
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Babylon.js `mesh.bakeTransformIntoVertices(transform)` — fold an **arbitrary**
|
|
1744
|
+
* matrix into the CPU geometry via the shared {@link _bakeMatrix} helper. Unlike
|
|
1745
|
+
* {@link bakeCurrentTransformIntoVertices}, the node's own transform is **not**
|
|
1746
|
+
* reset: the supplied matrix is independent of the node transform.
|
|
1747
|
+
*/
|
|
1748
|
+
bakeTransformIntoVertices(transform) {
|
|
1749
|
+
this._bakeMatrix(transform);
|
|
1750
|
+
return this;
|
|
1751
|
+
}
|
|
1371
1752
|
dispose() {
|
|
1372
1753
|
if (this._scene) {
|
|
1373
1754
|
removeFromScene(this._scene._lite, this._lite);
|
|
@@ -1394,6 +1775,41 @@ class Mesh extends AbstractMesh {
|
|
|
1394
1775
|
getClassName() {
|
|
1395
1776
|
return "Mesh";
|
|
1396
1777
|
}
|
|
1778
|
+
/**
|
|
1779
|
+
* @internal Wrap an already-loaded Lite mesh (or the loader's synthetic root
|
|
1780
|
+
* node) as a canonical compat `Mesh`. Unlike the public constructor it does
|
|
1781
|
+
* **not** re-insert the node into the scene (the loader already added the whole
|
|
1782
|
+
* container) and does **not** override the natively-loaded material — it only
|
|
1783
|
+
* adopts the existing Lite node. Used by the loader to give
|
|
1784
|
+
* `AssetContainer.meshes` real, stable-identity mesh handles.
|
|
1785
|
+
*/
|
|
1786
|
+
static _fromLite(lite, container, scene) {
|
|
1787
|
+
const mesh = new Mesh(lite.name ?? "", lite);
|
|
1788
|
+
mesh._container = container;
|
|
1789
|
+
mesh._visible = lite.visible !== false;
|
|
1790
|
+
if (scene) {
|
|
1791
|
+
mesh._bindLoadedScene(scene);
|
|
1792
|
+
}
|
|
1793
|
+
return mesh;
|
|
1794
|
+
}
|
|
1795
|
+
/** @internal Wrap and link a complete Lite hierarchy, registering every wrapper. */
|
|
1796
|
+
static _fromLiteHierarchy(lite, container, scene, registry = /* @__PURE__ */ new Map(), parent = null) {
|
|
1797
|
+
let wrapper = registry.get(lite);
|
|
1798
|
+
if (!wrapper) {
|
|
1799
|
+
wrapper = Mesh._fromLite(lite, container, scene);
|
|
1800
|
+
registry.set(lite, wrapper);
|
|
1801
|
+
} else if (scene) {
|
|
1802
|
+
wrapper._bindLoadedScene(scene);
|
|
1803
|
+
}
|
|
1804
|
+
wrapper._adoptLoadedParent(parent);
|
|
1805
|
+
const children = lite.children;
|
|
1806
|
+
if (children) {
|
|
1807
|
+
for (const child of children) {
|
|
1808
|
+
Mesh._fromLiteHierarchy(child, container, scene, registry, wrapper);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return wrapper;
|
|
1812
|
+
}
|
|
1397
1813
|
/**
|
|
1398
1814
|
* Babylon.js `mesh.morphTargetManager`. Babylon Lite builds morph GPU data via
|
|
1399
1815
|
* `createMorphTargets` and stores it on the Lite mesh; the compat manager is
|
|
@@ -1454,14 +1870,155 @@ class Mesh extends AbstractMesh {
|
|
|
1454
1870
|
setThinInstanceColors(this._lite, buffer);
|
|
1455
1871
|
}
|
|
1456
1872
|
}
|
|
1457
|
-
/**
|
|
1458
|
-
|
|
1459
|
-
|
|
1873
|
+
/**
|
|
1874
|
+
* Babylon.js `mesh.clone(name, newParent?, doNotCloneChildren?)` — a new mesh
|
|
1875
|
+
* that shares this mesh's geometry. Forwards to Lite's `cloneTransformNode`,
|
|
1876
|
+
* which shares the `_gpu`/skeleton/morph/thin-instance resources with the clone
|
|
1877
|
+
* under ref-counting (so both meshes own the buffers and they survive until the
|
|
1878
|
+
* last is disposed). Babylon.js uses the requested name verbatim, derives clone
|
|
1879
|
+
* IDs from that name plus the source ID, and prefixes descendant names with the
|
|
1880
|
+
* root clone name. The source material is kept (BJS shares it by reference), and
|
|
1881
|
+
* the clone is registered with the same compat scene through its own wrapper.
|
|
1882
|
+
* An omitted or `null` `newParent` keeps the source parent.
|
|
1883
|
+
* `doNotCloneChildren` drops the descendants Lite always clones.
|
|
1884
|
+
*/
|
|
1885
|
+
clone(name = "", newParent = null, doNotCloneChildren) {
|
|
1886
|
+
const scene = this._scene;
|
|
1887
|
+
const liteClone = cloneTransformNode(this._lite);
|
|
1888
|
+
const wrappedClone = Mesh._wrapCloneHierarchy(this, liteClone, scene, null, doNotCloneChildren === true, name);
|
|
1889
|
+
if (!(wrappedClone instanceof Mesh)) {
|
|
1890
|
+
throw new Error("Mesh.clone produced a non-mesh root.");
|
|
1891
|
+
}
|
|
1892
|
+
const clone = wrappedClone;
|
|
1893
|
+
if (scene) {
|
|
1894
|
+
addPrimitive(clone, scene, doNotCloneChildren ? () => pruneClonedDescendants(scene, liteClone) : void 0);
|
|
1895
|
+
}
|
|
1896
|
+
const parent = newParent ?? this.parent;
|
|
1897
|
+
if (parent) {
|
|
1898
|
+
clone.parent = parent;
|
|
1899
|
+
}
|
|
1900
|
+
return clone;
|
|
1901
|
+
}
|
|
1902
|
+
static _wrapCloneHierarchy(source, lite, scene, parent, skipChildren, cloneName) {
|
|
1903
|
+
var _a;
|
|
1904
|
+
if (cloneName !== void 0) {
|
|
1905
|
+
lite.name = cloneName;
|
|
1906
|
+
}
|
|
1907
|
+
const isMesh = source instanceof Mesh || "_gpu" in lite && "material" in lite;
|
|
1908
|
+
const wrapper = isMesh ? new Mesh(lite.name ?? "", lite) : new TransformNode(lite.name ?? "", scene, lite);
|
|
1909
|
+
wrapper._container = source == null ? void 0 : source._container;
|
|
1910
|
+
if (wrapper instanceof Mesh) {
|
|
1911
|
+
wrapper._scene = scene;
|
|
1912
|
+
if (scene) {
|
|
1913
|
+
scene._registerMesh(wrapper, lite);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
wrapper.parent = parent;
|
|
1917
|
+
if (source) {
|
|
1918
|
+
wrapper.id = wrapper instanceof Mesh ? `${wrapper.name}.${source.id}` : wrapper.name;
|
|
1919
|
+
wrapper.metadata = source.metadata;
|
|
1920
|
+
wrapper.setEnabled(source.isEnabled(false));
|
|
1921
|
+
if (wrapper instanceof Mesh && source instanceof Mesh) {
|
|
1922
|
+
wrapper.material = source.material;
|
|
1923
|
+
wrapper.isVisible = source.isVisible;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
if (!skipChildren) {
|
|
1927
|
+
const sourceLiteChildren = ((_a = liteNodeOf(source ?? null)) == null ? void 0 : _a.children) ?? [];
|
|
1928
|
+
const sourceChildren = (source == null ? void 0 : source.getChildren(void 0, true)) ?? [];
|
|
1929
|
+
for (let i = 0; i < lite.children.length; i++) {
|
|
1930
|
+
const sourceLiteChild = sourceLiteChildren[i];
|
|
1931
|
+
const sourceChild = sourceChildren.find((child) => liteNodeOf(child) === sourceLiteChild);
|
|
1932
|
+
const childName = sourceChild ? `${wrapper.name}.${sourceChild.name}` : void 0;
|
|
1933
|
+
Mesh._wrapCloneHierarchy(sourceChild, lite.children[i], scene, wrapper, false, childName);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
return wrapper;
|
|
1460
1937
|
}
|
|
1461
1938
|
/** Level-of-detail — unsupported (no LOD system in Babylon Lite). */
|
|
1462
1939
|
addLODLevel() {
|
|
1463
1940
|
return unsupported("Mesh.addLODLevel", "Level-of-detail is not implemented in Babylon Lite.");
|
|
1464
1941
|
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Babylon.js `Mesh.MergeMeshes` — bake several meshes into one, transforming
|
|
1944
|
+
* each source's geometry by its world matrix. Signature:
|
|
1945
|
+
* `MergeMeshes(meshes, disposeSource?, allow32BitsIndices?, meshSubclass?, subdivideWithSubMeshes?, multiMultiMaterials?)`.
|
|
1946
|
+
* Uses the compat-local `mergeMeshGeometry`; the merged mesh lives at
|
|
1947
|
+
* identity (world transforms are baked in) and takes the first mesh's material.
|
|
1948
|
+
*
|
|
1949
|
+
* **Supported semantics** (everything else is rejected, never silently dropped):
|
|
1950
|
+
* - `disposeSource` (default `true`) — source meshes are disposed after merge.
|
|
1951
|
+
* - `allow32BitsIndices` — Lite indices are always uint32, so 32-bit is always
|
|
1952
|
+
* available. When `allow32BitsIndices` is falsy and the merged vertex count
|
|
1953
|
+
* reaches 65536, this returns `null`, exactly like Babylon.js.
|
|
1954
|
+
* - Positions, normals (world-transformed) and one UV set are carried.
|
|
1955
|
+
*
|
|
1956
|
+
* **Rejected** (throws `LiteCompatError`): `multiMultiMaterials` /
|
|
1957
|
+
* `subdivideWithSubMeshes` (Lite has no submesh / multi-material partitioning),
|
|
1958
|
+
* a supplied `meshSubclass` target, and sources carrying vertex colours,
|
|
1959
|
+
* tangents or a second UV set, or sources carrying skeleton, morph-target, or
|
|
1960
|
+
* vertex-animation data (Lite would have to drop them).
|
|
1961
|
+
*/
|
|
1962
|
+
static MergeMeshes(meshes, disposeSource = true, allow32BitsIndices, meshSubclass, subdivideWithSubMeshes, multiMultiMaterials) {
|
|
1963
|
+
const sources = meshes.filter((m) => !!m);
|
|
1964
|
+
if (sources.length === 0) {
|
|
1965
|
+
return null;
|
|
1966
|
+
}
|
|
1967
|
+
if (multiMultiMaterials || subdivideWithSubMeshes) {
|
|
1968
|
+
return unsupported(
|
|
1969
|
+
"Mesh.MergeMeshes(multiMultiMaterials/subdivideWithSubMeshes)",
|
|
1970
|
+
"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."
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
if (meshSubclass) {
|
|
1974
|
+
return unsupported(
|
|
1975
|
+
"Mesh.MergeMeshes(meshSubclass)",
|
|
1976
|
+
"Merging into an existing target mesh is not wrapped; the merge always returns a fresh mesh. Merge without a meshSubclass and use the result."
|
|
1977
|
+
);
|
|
1978
|
+
}
|
|
1979
|
+
if (!allow32BitsIndices) {
|
|
1980
|
+
let totalVertices = 0;
|
|
1981
|
+
for (const mesh of sources) {
|
|
1982
|
+
totalVertices += mesh.getTotalVertices();
|
|
1983
|
+
if (totalVertices >= 65536) {
|
|
1984
|
+
return null;
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
for (const mesh of sources) {
|
|
1989
|
+
const lite2 = mesh._lite;
|
|
1990
|
+
if (lite2._cpuColors || lite2._cpuTangents || lite2._cpuUv2s) {
|
|
1991
|
+
return unsupported(
|
|
1992
|
+
"Mesh.MergeMeshes(colors/tangents/uv2)",
|
|
1993
|
+
`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.`
|
|
1994
|
+
);
|
|
1995
|
+
}
|
|
1996
|
+
if (lite2.skeleton || lite2.morphTargets || lite2.vat) {
|
|
1997
|
+
return unsupported(
|
|
1998
|
+
"Mesh.MergeMeshes(animation)",
|
|
1999
|
+
`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.`
|
|
2000
|
+
);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
const scene = sources[0].getScene();
|
|
2004
|
+
if (!scene) {
|
|
2005
|
+
return null;
|
|
2006
|
+
}
|
|
2007
|
+
const lite = mergeMeshGeometry(
|
|
2008
|
+
scene.getEngine()._lite,
|
|
2009
|
+
sources[0].name,
|
|
2010
|
+
sources.map((m) => m._lite)
|
|
2011
|
+
);
|
|
2012
|
+
const merged = new Mesh(sources[0].name, lite, scene);
|
|
2013
|
+
merged.material = sources[0].material;
|
|
2014
|
+
addPrimitive(merged, scene);
|
|
2015
|
+
if (disposeSource) {
|
|
2016
|
+
for (const mesh of sources) {
|
|
2017
|
+
mesh.dispose();
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
return merged;
|
|
2021
|
+
}
|
|
1465
2022
|
}
|
|
1466
2023
|
class GroundMesh extends Mesh {
|
|
1467
2024
|
getClassName() {
|
|
@@ -1540,20 +2097,30 @@ function concat(a, b) {
|
|
|
1540
2097
|
function engineOf(scene) {
|
|
1541
2098
|
return scene.getEngine()._lite;
|
|
1542
2099
|
}
|
|
1543
|
-
function addPrimitive(mesh, scene) {
|
|
2100
|
+
function addPrimitive(mesh, scene, afterAdd) {
|
|
1544
2101
|
scene._deferAdd(() => {
|
|
2102
|
+
if (mesh.isDisposed()) {
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
1545
2105
|
const mat = mesh.material;
|
|
1546
2106
|
mat == null ? void 0 : mat._ensureRenderable(engineOf(scene));
|
|
1547
2107
|
if (mat == null ? void 0 : mat._lite) {
|
|
1548
2108
|
mesh._lite.material = mat._lite;
|
|
1549
2109
|
}
|
|
1550
2110
|
addToScene(scene._lite, mesh._lite);
|
|
2111
|
+
afterAdd == null ? void 0 : afterAdd();
|
|
1551
2112
|
});
|
|
1552
2113
|
return mesh;
|
|
1553
2114
|
}
|
|
2115
|
+
function pruneClonedDescendants(scene, liteClone) {
|
|
2116
|
+
for (const child of [...liteClone.children]) {
|
|
2117
|
+
removeFromScene(scene._lite, child);
|
|
2118
|
+
}
|
|
2119
|
+
liteClone.children.length = 0;
|
|
2120
|
+
}
|
|
1554
2121
|
const MeshBuilder = {
|
|
1555
2122
|
CreateBox(name, options, scene) {
|
|
1556
|
-
const lite = createBox(engineOf(scene), options
|
|
2123
|
+
const lite = createBox(engineOf(scene), options);
|
|
1557
2124
|
return addPrimitive(new Mesh(name, lite, scene), scene);
|
|
1558
2125
|
},
|
|
1559
2126
|
CreateSphere(name, options, scene) {
|
|
@@ -1652,6 +2219,18 @@ const MeshBuilder = {
|
|
|
1652
2219
|
},
|
|
1653
2220
|
CreateText() {
|
|
1654
2221
|
return unsupported("MeshBuilder.CreateText", "Extruded font meshes are not implemented in Babylon Lite. For 2D/SDF text use the native `createTextRenderable` API.");
|
|
2222
|
+
},
|
|
2223
|
+
CreateTiledBox(_name, _options, _scene) {
|
|
2224
|
+
return unsupported(
|
|
2225
|
+
"MeshBuilder.CreateTiledBox",
|
|
2226
|
+
"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."
|
|
2227
|
+
);
|
|
2228
|
+
},
|
|
2229
|
+
CreateTiledPlane(_name, _options, _scene) {
|
|
2230
|
+
return unsupported(
|
|
2231
|
+
"MeshBuilder.CreateTiledPlane",
|
|
2232
|
+
"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."
|
|
2233
|
+
);
|
|
1655
2234
|
}
|
|
1656
2235
|
};
|
|
1657
2236
|
function CreateBox(name, options, scene) {
|
|
@@ -1675,9 +2254,15 @@ function CreateTorus(name, options, scene) {
|
|
|
1675
2254
|
function CreateDisc(name, options, scene) {
|
|
1676
2255
|
return MeshBuilder.CreateDisc(name, options, scene);
|
|
1677
2256
|
}
|
|
2257
|
+
function CreateTiledBox(name, options, scene) {
|
|
2258
|
+
return MeshBuilder.CreateTiledBox(name, options, scene);
|
|
2259
|
+
}
|
|
2260
|
+
function CreateTiledPlane(name, options, scene) {
|
|
2261
|
+
return MeshBuilder.CreateTiledPlane(name, options, scene);
|
|
2262
|
+
}
|
|
1678
2263
|
export {
|
|
1679
2264
|
AbstractMesh as A,
|
|
1680
|
-
|
|
2265
|
+
BoundingBox as B,
|
|
1681
2266
|
CreateBox as C,
|
|
1682
2267
|
GroundMesh as G,
|
|
1683
2268
|
InstancedMesh as I,
|
|
@@ -1688,22 +2273,24 @@ export {
|
|
|
1688
2273
|
TransformNode as T,
|
|
1689
2274
|
Vector3 as V,
|
|
1690
2275
|
Mesh as a,
|
|
1691
|
-
|
|
2276
|
+
BoundingInfo as b,
|
|
1692
2277
|
BoundingSphere as c,
|
|
1693
2278
|
CreateCylinder as d,
|
|
1694
2279
|
CreateDisc as e,
|
|
1695
2280
|
CreateGround as f,
|
|
1696
2281
|
CreatePlane as g,
|
|
1697
2282
|
CreateSphere as h,
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
2283
|
+
CreateTiledBox as i,
|
|
2284
|
+
CreateTiledPlane as j,
|
|
2285
|
+
CreateTorus as k,
|
|
1701
2286
|
liteBackedVector3 as l,
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2287
|
+
MeshBuilder as m,
|
|
2288
|
+
Vector2 as n,
|
|
2289
|
+
Vector4 as o,
|
|
2290
|
+
VertexBuffer as p,
|
|
2291
|
+
VertexData as q,
|
|
2292
|
+
transformNormal as r,
|
|
1706
2293
|
transformCoordinates as t,
|
|
1707
2294
|
unsupported as u
|
|
1708
2295
|
};
|
|
1709
|
-
//# sourceMappingURL=meshes-
|
|
2296
|
+
//# sourceMappingURL=meshes-DduMsRJk.js.map
|