@babylonjs/lite-compat 1.38.1-preview → 1.39.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,4 +1,4 @@
1
- import { addToScene, cloneTransformNode, computeAabb, createBox, createCylinder, createDashedLines, createDisc, createExtrudeShape, createGround, createGroundFromHeightMap, createLineMaterial, createLineSystem, createMeshFromData, createPbrMaterial, createPlane, createPolyhedron, createQuatFromRotationMat4, createRibbon, createSolidTexture2D, createSphere, createStandardMaterial, createTorus, createTorusKnot, createTransformNode, createTube, markMaterialUboDirty, maximizeMat4InPlace, normalizeVec2ToRef, projectPointToViewportToRef, rebuildMaterial, removeFromScene, resizeMeshGeometry, scaleBoundsFromCenterToRef, setAccessibilityTag, setLineMaterialColor, setMat4Translation, setMeshVisible, setParent, setPbrAnisotropy, setPbrClearCoat, setPbrEmissive, setPbrGammaAlbedo, setPbrIridescence, setPbrSheen, setStandardBumpTexture, setStandardEmissiveTexture, setThinInstanceColors, setThinInstances, updateDashedLines, updateLineSystem, updateMeshGeometry, updateMeshUvs, writeMat4FromLookDirectionLHIntoBuffer, writeMat4FromLookDirectionRHIntoBuffer, writeMat4FromQuatIntoBuffer, writeQuatFromRotationMat4IntoRef } from "@babylonjs/lite";
1
+ import { addToScene, adoptMeshMorphTargets, cloneTransformNode, computeAabb, createBox, createCylinder, createDashedLines, createDisc, createExtrudeShape, createGround, createGroundFromHeightMap, createLineMaterial, createLineSystem, createMeshFromData, createMorphTargets, createPbrMaterial, createPlane, createPolyhedron, createQuatFromRotationMat4, createRibbon, createSolidTexture2D, createSphere, createStandardMaterial, createTorus, createTorusKnot, createTransformNode, createTube, getMaterialFamily, getMeshOpacity, markMaterialUboDirty, maximizeMat4InPlace, normalizeVec2ToRef, projectPointToViewportToRef, rebuildMaterial, releaseMorphTargets, removeFromScene, resizeMeshGeometry, retainMorphTargets, scaleBoundsFromCenterToRef, setAccessibilityTag, setLineMaterialColor, setMat4Translation, setMeshOpacity, setMeshVisible, setMorphTargetWeight, setMorphTargetWeights, setParent, setPbrAnisotropy, setPbrClearCoat, setPbrEmissive, setPbrGammaAlbedo, setPbrIridescence, setPbrSheen, setStandardBumpTexture, setStandardEmissiveTexture, setThinInstanceColors, setThinInstances, shareMeshMorphTargets, updateDashedLines, updateLineSystem, updateMeshGeometry, updateMeshUvs, writeMat4FromLookDirectionLHIntoBuffer, writeMat4FromLookDirectionRHIntoBuffer, writeMat4FromQuatIntoBuffer, writeQuatFromRotationMat4IntoRef } from "@babylonjs/lite";
2
2
  // src/error.ts
3
3
  /**
4
4
  * Error thrown when Babylon.js code reaches an API surface that the Babylon Lite
@@ -2680,6 +2680,160 @@ function mergeMeshGeometry(engine, name, meshes) {
2680
2680
  }
2681
2681
  return createMeshFromData(engine, name, positions, normals, indices, uvs);
2682
2682
  }
2683
+ // src/morph/morph.ts
2684
+ /**
2685
+ * Babylon.js-compatible `MorphTarget` / `MorphTargetManager` over the Babylon
2686
+ * Lite native morph API (`createMorphTargets` / `setMorphTargetWeights`).
2687
+ *
2688
+ * Babylon.js morph targets carry **absolute** vertex positions/normals
2689
+ * (`target.setPositions(abs)`); Babylon Lite's `createMorphTargets` consumes
2690
+ * per-target **deltas** (target − base). The manager defers building the Lite
2691
+ * morph until engine start (when the owning mesh's base CPU geometry exists),
2692
+ * computes the deltas, and assigns the resulting `MorphTargetData` onto the
2693
+ * Lite mesh so the Standard/NME pipelines sample it. Weight changes
2694
+ * (`target.influence = …`) re-upload via `setMorphTargetWeights`.
2695
+ */
2696
+ /** Babylon.js `MorphTarget` — a single named morph influence with absolute target geometry. */
2697
+ var MorphTarget = class MorphTarget {
2698
+ name;
2699
+ /** @internal Absolute target positions (Babylon.js `setPositions`). */
2700
+ _positions = null;
2701
+ /** @internal Absolute target normals (Babylon.js `setNormals`). */
2702
+ _normals = null;
2703
+ /** @internal Owning manager, set on `addTarget`, used to push weight updates. */
2704
+ _manager;
2705
+ /** @internal Index in loader-produced Lite morph data. */
2706
+ _liteIndex;
2707
+ _influence;
2708
+ constructor(name, influence = 0, _scene) {
2709
+ this.name = name;
2710
+ this._influence = influence;
2711
+ }
2712
+ get influence() {
2713
+ return this._liteIndex === void 0 ? this._influence : this._manager?._getWeight(this._liteIndex) ?? this._influence;
2714
+ }
2715
+ set influence(value) {
2716
+ this._influence = value;
2717
+ if (this._liteIndex === void 0) this._manager?._syncWeights();
2718
+ else this._manager?._setWeight(this._liteIndex, value);
2719
+ }
2720
+ /** Babylon.js `MorphTarget.setPositions(data)` — absolute target positions. */
2721
+ setPositions(data) {
2722
+ this._positions = data ? data instanceof Float32Array ? data : Float32Array.from(data) : null;
2723
+ }
2724
+ /** Babylon.js `MorphTarget.getPositions()`. */
2725
+ getPositions() {
2726
+ return this._positions;
2727
+ }
2728
+ /** Babylon.js `MorphTarget.setNormals(data)` — absolute target normals. */
2729
+ setNormals(data) {
2730
+ this._normals = data ? data instanceof Float32Array ? data : Float32Array.from(data) : null;
2731
+ }
2732
+ /** Babylon.js `MorphTarget.getNormals()`. */
2733
+ getNormals() {
2734
+ return this._normals;
2735
+ }
2736
+ /** @internal Wrap a loader-produced Lite morph target. */
2737
+ static _fromLite(name, influence, manager, index) {
2738
+ const target = new MorphTarget(name, influence);
2739
+ target._manager = manager;
2740
+ target._liteIndex = index;
2741
+ return target;
2742
+ }
2743
+ };
2744
+ /** Babylon.js `MorphTargetManager` — owns a mesh's morph targets (Babylon Lite supports up to 4). */
2745
+ var MorphTargetManager = class MorphTargetManager {
2746
+ /** @internal */
2747
+ _engine;
2748
+ /** @internal Built Lite morph data (created at engine start). */
2749
+ _lite;
2750
+ _targets = [];
2751
+ constructor(_scene) {}
2752
+ /** @internal Wrap morph data produced by a Babylon Lite asset loader. */
2753
+ static _fromLite(lite, engine) {
2754
+ const manager = new MorphTargetManager();
2755
+ manager._lite = lite;
2756
+ retainMorphTargets(lite);
2757
+ manager._engine = engine;
2758
+ for (let index = 0; index < lite.count; index++) manager._targets.push(MorphTarget._fromLite(lite.names?.[index] ?? `morphTarget${index}`, lite.weights[index] ?? 0, manager, index));
2759
+ return manager;
2760
+ }
2761
+ /** @internal Attach the scene engine after a loader wrapper is adopted into a scene. */
2762
+ _adoptEngine(engine) {
2763
+ this._engine = engine;
2764
+ if (this._lite) setMorphTargetWeights(engine, this._lite, Array.from(this._lite.weights));
2765
+ }
2766
+ /** @internal Read the live influence of a loader-produced target. */
2767
+ _getWeight(index) {
2768
+ return this._lite?.weights[index] ?? 0;
2769
+ }
2770
+ /** @internal Update one loader-produced influence through Lite's public upload path. */
2771
+ _setWeight(index, value) {
2772
+ if (!this._lite) return;
2773
+ if (!this._engine) {
2774
+ this._lite.weights[index] = value;
2775
+ return;
2776
+ }
2777
+ setMorphTargetWeight(this._engine, this._lite, index, value);
2778
+ }
2779
+ get numTargets() {
2780
+ return this._targets.length;
2781
+ }
2782
+ getTarget(index) {
2783
+ return this._targets[index];
2784
+ }
2785
+ /** Babylon.js `MorphTargetManager.addTarget(target)`. */
2786
+ addTarget(target) {
2787
+ target._manager = this;
2788
+ this._targets.push(target);
2789
+ }
2790
+ /**
2791
+ * @internal Build the Lite morph data from the mesh's base CPU geometry and
2792
+ * each target's absolute positions/normals (converted to deltas), then assign
2793
+ * it onto the Lite mesh. Called by the engine at start, once geometry exists.
2794
+ */
2795
+ _build(mesh, engine) {
2796
+ const lite = mesh._lite;
2797
+ const base = lite._cpuPositions;
2798
+ if (!base) return;
2799
+ this._engine = engine;
2800
+ const vertexCount = base.length / 3;
2801
+ const baseNormals = lite._cpuNormals;
2802
+ const targets = this._targets.slice(0, 4).map((t) => {
2803
+ const abs = t._positions;
2804
+ const positions = new Float32Array(base.length);
2805
+ if (abs) for (let i = 0; i < base.length; i++) positions[i] = (abs[i] ?? 0) - base[i];
2806
+ let normals = null;
2807
+ if (t._normals && baseNormals) {
2808
+ normals = new Float32Array(baseNormals.length);
2809
+ for (let i = 0; i < baseNormals.length; i++) normals[i] = (t._normals[i] ?? 0) - baseNormals[i];
2810
+ }
2811
+ return {
2812
+ positions,
2813
+ normals
2814
+ };
2815
+ });
2816
+ const weights = this._targets.slice(0, 4).map((t) => t.influence);
2817
+ if (this._lite) releaseMorphTargets(this._lite);
2818
+ this._lite = createMorphTargets(engine, targets, vertexCount, weights);
2819
+ retainMorphTargets(this._lite);
2820
+ adoptMeshMorphTargets(mesh._lite, this._lite);
2821
+ }
2822
+ /** @internal Re-upload current target influences to the GPU weights buffer. */
2823
+ _syncWeights() {
2824
+ if (!this._lite || !this._engine) return;
2825
+ const weights = this._targets.slice(0, 4).map((t) => t.influence);
2826
+ setMorphTargetWeights(this._engine, this._lite, weights);
2827
+ }
2828
+ /** Babylon.js `MorphTargetManager.dispose()` — release this manager's morph-resource claim. */
2829
+ dispose() {
2830
+ if (this._lite) {
2831
+ releaseMorphTargets(this._lite);
2832
+ this._lite = void 0;
2833
+ }
2834
+ this._engine = void 0;
2835
+ }
2836
+ };
2683
2837
  // src/meshes/meshes.ts
2684
2838
  /**
2685
2839
  * Babylon.js-compatible mesh hierarchy and `MeshBuilder`.
@@ -2692,6 +2846,104 @@ function mergeMeshGeometry(engine, name, meshes) {
2692
2846
  * `mesh.position.x = 1` and `mesh.rotation.y += 0.01` propagate; reassignment
2693
2847
  * (`mesh.position = new Vector3(...)`) also works.
2694
2848
  */
2849
+ var numberPropertyStates;
2850
+ function bindNumberProperty(target, key, onAccess, onChange) {
2851
+ const states = numberPropertyStates ??= /* @__PURE__ */ new WeakMap();
2852
+ let properties = states.get(target);
2853
+ if (!properties) {
2854
+ properties = /* @__PURE__ */ new Map();
2855
+ states.set(target, properties);
2856
+ }
2857
+ let state = properties.get(key);
2858
+ if (!state) {
2859
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
2860
+ let stored = target[key];
2861
+ state = {
2862
+ descriptor,
2863
+ read: descriptor?.get ? () => descriptor.get.call(target) : () => stored,
2864
+ write: descriptor?.set ? (value) => descriptor.set.call(target, value) : (value) => stored = value,
2865
+ subscriptions: /* @__PURE__ */ new Set()
2866
+ };
2867
+ properties.set(key, state);
2868
+ Object.defineProperty(target, key, {
2869
+ enumerable: descriptor?.enumerable ?? true,
2870
+ configurable: true,
2871
+ get: () => {
2872
+ for (const subscription of state.subscriptions) subscription.onAccess();
2873
+ return state.read();
2874
+ },
2875
+ set: (value) => {
2876
+ for (const subscription of state.subscriptions) subscription.onAccess();
2877
+ state.write(value);
2878
+ for (const subscription of state.subscriptions) subscription.onChange();
2879
+ }
2880
+ });
2881
+ }
2882
+ const subscription = {
2883
+ onAccess,
2884
+ onChange
2885
+ };
2886
+ state.subscriptions.add(subscription);
2887
+ return {
2888
+ setSilently: state.write,
2889
+ notifyOtherSubscribers() {
2890
+ for (const other of state.subscriptions) if (other !== subscription) other.onChange();
2891
+ },
2892
+ unbind() {
2893
+ state.subscriptions.delete(subscription);
2894
+ if (state.subscriptions.size !== 0) return;
2895
+ const value = state.read();
2896
+ const descriptor = state.descriptor;
2897
+ Object.defineProperty(target, key, descriptor?.get || descriptor?.set ? descriptor : {
2898
+ ...descriptor,
2899
+ enumerable: descriptor?.enumerable ?? true,
2900
+ configurable: descriptor?.configurable ?? true,
2901
+ writable: descriptor?.writable ?? true,
2902
+ value
2903
+ });
2904
+ properties.delete(key);
2905
+ }
2906
+ };
2907
+ }
2908
+ function bindVector3(value, onAccess, onChange) {
2909
+ const x = bindNumberProperty(value, "x", onAccess, onChange);
2910
+ const y = bindNumberProperty(value, "y", onAccess, onChange);
2911
+ const z = bindNumberProperty(value, "z", onAccess, onChange);
2912
+ return {
2913
+ setSilently(nextX, nextY, nextZ) {
2914
+ x.setSilently(nextX);
2915
+ y.setSilently(nextY);
2916
+ z.setSilently(nextZ);
2917
+ x.notifyOtherSubscribers();
2918
+ },
2919
+ unbind() {
2920
+ x.unbind();
2921
+ y.unbind();
2922
+ z.unbind();
2923
+ }
2924
+ };
2925
+ }
2926
+ function bindQuaternion(value, onAccess, onChange) {
2927
+ const x = bindNumberProperty(value, "x", onAccess, onChange);
2928
+ const y = bindNumberProperty(value, "y", onAccess, onChange);
2929
+ const z = bindNumberProperty(value, "z", onAccess, onChange);
2930
+ const w = bindNumberProperty(value, "w", onAccess, onChange);
2931
+ return {
2932
+ setSilently(nextX, nextY, nextZ, nextW) {
2933
+ x.setSilently(nextX);
2934
+ y.setSilently(nextY);
2935
+ z.setSilently(nextZ);
2936
+ w.setSilently(nextW);
2937
+ x.notifyOtherSubscribers();
2938
+ },
2939
+ unbind() {
2940
+ x.unbind();
2941
+ y.unbind();
2942
+ z.unbind();
2943
+ w.unbind();
2944
+ }
2945
+ };
2946
+ }
2695
2947
  var LinesMaterial = class LinesMaterial extends Material {
2696
2948
  _lite;
2697
2949
  constructor(name, lite, scene) {
@@ -2733,6 +2985,12 @@ function liteNodeOf(node) {
2733
2985
  const n = node;
2734
2986
  return n._node ?? n._lite ?? null;
2735
2987
  }
2988
+ function validateOpacityMaterial(api, name, material) {
2989
+ if (material) {
2990
+ const family = getMaterialFamily(material);
2991
+ if (family !== "standard" && family !== "pbr") unsupported(api, `Mesh "${name}" uses a "${family}" material; visibility below 1 supports only Standard and PBR materials.`);
2992
+ }
2993
+ }
2736
2994
  var PLACEHOLDER_POSITIONS = new Float32Array([
2737
2995
  0,
2738
2996
  0,
@@ -2837,6 +3095,14 @@ var TransformNode = class TransformNode extends Node {
2837
3095
  /** @internal The Lite scene node that carries this transform. */
2838
3096
  _node;
2839
3097
  physicsBody = null;
3098
+ _rotation;
3099
+ _rotationBinding;
3100
+ _rotationQuaternion = null;
3101
+ _rotationQuaternionBinding;
3102
+ _nativeRotationVersion;
3103
+ _nativeRotationValues;
3104
+ _isSyncingRotationFromNative = false;
3105
+ _sceneDisposeObserver;
2840
3106
  /**
2841
3107
  * @internal The Lite asset container this node was loaded from, when produced
2842
3108
  * by a loader. Used by the `KHR_materials_variants` helpers (which key off the
@@ -2853,6 +3119,7 @@ var TransformNode = class TransformNode extends Node {
2853
3119
  if (this._scene === scene) return;
2854
3120
  this._scene = scene;
2855
3121
  scene._registerMesh(this, this._node);
3122
+ this._bindRotationSceneDisposal(scene);
2856
3123
  }
2857
3124
  /** @internal Link an already-parented Lite node without mutating its Lite hierarchy. */
2858
3125
  _adoptLoadedParent(parent) {
@@ -2865,6 +3132,24 @@ var TransformNode = class TransformNode extends Node {
2865
3132
  this._node = createTransformNode(name);
2866
3133
  if (scene) addToScene(scene._lite, this._node);
2867
3134
  }
3135
+ const q = this._node.rotationQuaternion;
3136
+ this._rotation = q ? new Quaternion(q.x, q.y, q.z, q.w).toEulerAngles() : new Vector3();
3137
+ this._nativeRotationVersion = q?.version;
3138
+ this._nativeRotationValues = q ? [
3139
+ q.x,
3140
+ q.y,
3141
+ q.z,
3142
+ q.w
3143
+ ] : [
3144
+ 0,
3145
+ 0,
3146
+ 0,
3147
+ 1
3148
+ ];
3149
+ this._rotationBinding = bindVector3(this._rotation, () => this._syncRotationFromNative(), () => {
3150
+ if (!this._rotationQuaternion) this._applyEulerRotation();
3151
+ });
3152
+ if (scene) this._bindRotationSceneDisposal(scene);
2868
3153
  }
2869
3154
  getClassName() {
2870
3155
  return "TransformNode";
@@ -2876,10 +3161,17 @@ var TransformNode = class TransformNode extends Node {
2876
3161
  this._node.position.set(value.x, value.y, value.z);
2877
3162
  }
2878
3163
  get rotation() {
2879
- return liteBackedVector3(this._node.rotation);
3164
+ this._syncRotationFromNative();
3165
+ return this._rotation;
2880
3166
  }
2881
3167
  set rotation(value) {
2882
- this._node.rotation.set(value.x, value.y, value.z);
3168
+ this._markNativeRotationSynced();
3169
+ this._rotationBinding.unbind();
3170
+ this._rotation = value;
3171
+ this._rotationBinding = bindVector3(value, () => this._syncRotationFromNative(), () => {
3172
+ if (!this._rotationQuaternion) this._applyEulerRotation();
3173
+ });
3174
+ this.rotationQuaternion = null;
2883
3175
  }
2884
3176
  get scaling() {
2885
3177
  return liteBackedVector3(this._node.scaling);
@@ -2887,24 +3179,88 @@ var TransformNode = class TransformNode extends Node {
2887
3179
  set scaling(value) {
2888
3180
  this._node.scaling.set(value.x, value.y, value.z);
2889
3181
  }
2890
- /** @internal Whether `rotationQuaternion` was explicitly set (Babylon.js returns null otherwise). */
2891
- _useQuat = false;
2892
- /**
2893
- * Babylon.js `rotationQuaternion`. Babylon Lite always drives a node's world
2894
- * matrix from a quaternion (its euler `rotation` is a proxy over the same
2895
- * quaternion), so this reads/writes that quaternion. Returns `null` until
2896
- * explicitly assigned, matching Babylon.js's euler-by-default convention.
2897
- */
3182
+ /** Babylon.js `rotationQuaternion`, kept live while Lite receives translated component writes. */
2898
3183
  get rotationQuaternion() {
2899
- if (!this._useQuat) return null;
2900
- const q = this._node.rotationQuaternion;
2901
- return new Quaternion(q.x, q.y, q.z, q.w);
3184
+ this._syncRotationFromNative();
3185
+ return this._rotationQuaternion;
2902
3186
  }
2903
3187
  set rotationQuaternion(value) {
3188
+ this._markNativeRotationSynced();
3189
+ this._rotationQuaternionBinding?.unbind();
3190
+ this._rotationQuaternionBinding = void 0;
3191
+ this._rotationQuaternion = value;
2904
3192
  if (value) {
2905
- this._useQuat = true;
2906
- this._node.rotationQuaternion.set(value.x, value.y, value.z, value.w);
2907
- } else this._useQuat = false;
3193
+ this._rotation.setAll(0);
3194
+ this._rotationQuaternionBinding = bindQuaternion(value, () => this._syncRotationFromNative(), () => this._applyQuaternionRotation());
3195
+ this._applyQuaternionRotation();
3196
+ } else this._applyEulerRotation();
3197
+ }
3198
+ _applyEulerRotation() {
3199
+ const q = Quaternion.FromEulerAngles(this._rotation.x, this._rotation.y, this._rotation.z);
3200
+ this._node.rotationQuaternion.set(q.x, q.y, q.z, q.w);
3201
+ this._markNativeRotationSynced();
3202
+ }
3203
+ _applyQuaternionRotation() {
3204
+ const q = this._rotationQuaternion;
3205
+ if (q) {
3206
+ this._node.rotationQuaternion.set(q.x, q.y, q.z, q.w);
3207
+ this._markNativeRotationSynced();
3208
+ }
3209
+ }
3210
+ _markNativeRotationSynced() {
3211
+ const q = this._node?.rotationQuaternion;
3212
+ if (!q) return;
3213
+ this._nativeRotationVersion = q.version;
3214
+ this._nativeRotationValues[0] = q.x;
3215
+ this._nativeRotationValues[1] = q.y;
3216
+ this._nativeRotationValues[2] = q.z;
3217
+ this._nativeRotationValues[3] = q.w;
3218
+ }
3219
+ _syncRotationFromNative() {
3220
+ if (this._isSyncingRotationFromNative) return;
3221
+ const q = this._node?.rotationQuaternion;
3222
+ const previous = this._nativeRotationValues;
3223
+ if (!q) return;
3224
+ const valuesChanged = q.x !== previous[0] || q.y !== previous[1] || q.z !== previous[2] || q.w !== previous[3];
3225
+ if (q.version === this._nativeRotationVersion && !valuesChanged) return;
3226
+ this._isSyncingRotationFromNative = true;
3227
+ try {
3228
+ if (this._rotationQuaternion) this._rotationQuaternionBinding?.setSilently(q.x, q.y, q.z, q.w);
3229
+ else {
3230
+ const euler = new Quaternion(q.x, q.y, q.z, q.w).toEulerAngles();
3231
+ this._rotationBinding.setSilently(euler.x, euler.y, euler.z);
3232
+ }
3233
+ } finally {
3234
+ this._isSyncingRotationFromNative = false;
3235
+ }
3236
+ this._nativeRotationVersion = q.version;
3237
+ previous[0] = q.x;
3238
+ previous[1] = q.y;
3239
+ previous[2] = q.z;
3240
+ previous[3] = q.w;
3241
+ }
3242
+ /** @internal Preserve the source node's active rotation representation on a clone. */
3243
+ _copyRotationMode(source) {
3244
+ const q = source.rotationQuaternion;
3245
+ const rotation = source.rotation;
3246
+ if (!q && !rotation) return;
3247
+ this._rotationBinding.unbind();
3248
+ this._rotationQuaternionBinding?.unbind();
3249
+ this._rotationQuaternionBinding = void 0;
3250
+ this._rotation = rotation.clone();
3251
+ if (q) {
3252
+ this._rotationQuaternion = q.clone();
3253
+ this._rotationQuaternionBinding = bindQuaternion(this._rotationQuaternion, () => this._syncRotationFromNative(), () => this._applyQuaternionRotation());
3254
+ } else this._rotationQuaternion = null;
3255
+ this._rotationBinding = bindVector3(this._rotation, () => this._syncRotationFromNative(), () => {
3256
+ if (!this._rotationQuaternion) this._applyEulerRotation();
3257
+ });
3258
+ this._markNativeRotationSynced();
3259
+ }
3260
+ /** @internal Synchronize compat state after baking resets the Lite transform directly. */
3261
+ _resetRotationAfterBake() {
3262
+ this._rotationBinding?.setSilently(0, 0, 0);
3263
+ if (this._rotationQuaternion) this.rotationQuaternion = Quaternion.Identity();
2908
3264
  }
2909
3265
  /**
2910
3266
  * Babylon.js `getChildTransformNodes(directDescendantsOnly?, predicate?)` — the descendants that are transform nodes
@@ -2945,6 +3301,21 @@ var TransformNode = class TransformNode extends Node {
2945
3301
  this._node.children.length = 0;
2946
3302
  removeFromScene(this._scene._lite, this._node);
2947
3303
  }
3304
+ /** @internal Release component bindings when either the node or its scene retires this wrapper. */
3305
+ _releaseRotationBindings() {
3306
+ this._scene?.onDisposeObservable?.remove(this._sceneDisposeObserver);
3307
+ this._sceneDisposeObserver = void 0;
3308
+ this._rotationBinding.unbind();
3309
+ this._rotationQuaternionBinding?.unbind();
3310
+ this._rotationQuaternionBinding = void 0;
3311
+ }
3312
+ _bindRotationSceneDisposal(scene) {
3313
+ this._sceneDisposeObserver = scene.onDisposeObservable?.addOnce(() => this._releaseRotationBindings());
3314
+ }
3315
+ _retireFromScene() {
3316
+ this._releaseRotationBindings();
3317
+ super._retireFromScene();
3318
+ }
2948
3319
  };
2949
3320
  /**
2950
3321
  * Babylon.js `AbstractMesh` — a renderable transform node with a material,
@@ -2961,11 +3332,13 @@ var AbstractMesh = class extends TransformNode {
2961
3332
  */
2962
3333
  _liteOnlyMaterial = false;
2963
3334
  _meshBlendingTag = 0;
3335
+ _visibilityValue = 1;
2964
3336
  _visible = true;
2965
3337
  constructor(name, lite, scene) {
2966
3338
  super(name, scene, lite);
2967
3339
  this._lite = lite;
2968
3340
  this._lite.name = name;
3341
+ this._visibilityValue = "_gpu" in lite ? getMeshOpacity(lite) : 1;
2969
3342
  if (scene) {
2970
3343
  this.material = scene.defaultMaterial;
2971
3344
  scene._registerMesh(this, this._lite);
@@ -2983,16 +3356,18 @@ var AbstractMesh = class extends TransformNode {
2983
3356
  * `AbstractMesh.dispose` does in its own `Lights` loop. Container-retired wrappers prune too.
2984
3357
  */
2985
3358
  _retireFromScene() {
3359
+ super._retireFromScene();
2986
3360
  for (const light of this._scene?.lights ?? []) light._pruneDisposedMesh(this);
2987
3361
  }
2988
3362
  get material() {
2989
3363
  return this._material;
2990
3364
  }
2991
3365
  set material(value) {
2992
- this._material = value;
2993
- this._liteOnlyMaterial = false;
2994
3366
  const scene = this._scene;
2995
3367
  const renderMaterial = value ?? scene?.defaultMaterial;
3368
+ if (renderMaterial && (this._visibilityValue < 1 || this._opacityTargets().some((target) => getMeshOpacity(target) < 1))) this._validateCompatOpacityMaterial("Mesh.material", renderMaterial);
3369
+ this._material = value;
3370
+ this._liteOnlyMaterial = false;
2996
3371
  if (renderMaterial && scene) {
2997
3372
  if (scene._hasStarted) attachMaterialToScene(renderMaterial, scene);
2998
3373
  else adoptMaterialScene(renderMaterial, scene);
@@ -3007,6 +3382,30 @@ var AbstractMesh = class extends TransformNode {
3007
3382
  this._visible = value;
3008
3383
  this._syncVisibility(this.isEnabled());
3009
3384
  }
3385
+ /** Raw finite Babylon visibility; rendering clamps it to [0, 1]. Independent of isVisible. */
3386
+ get visibility() {
3387
+ return this._visibilityValue;
3388
+ }
3389
+ set visibility(value) {
3390
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new RangeError("Mesh.visibility must be a finite number.");
3391
+ const targets = this._opacityTargets();
3392
+ if (value < 1 && this._material) this._validateCompatOpacityMaterial("Mesh.visibility", this._material);
3393
+ for (const target of targets) {
3394
+ if (target._disposed) throw new Error(`Mesh "${target.name}" cannot set opacity: it was disposed when it left its last scene. Create a new mesh instead.`);
3395
+ if (value < 1) validateOpacityMaterial("Mesh.visibility", target.name ?? this.name, target.material);
3396
+ }
3397
+ for (const target of targets) setMeshOpacity(target, value);
3398
+ this._visibilityValue = value;
3399
+ }
3400
+ _validateCompatOpacityMaterial(api, material) {
3401
+ if (!material._lite) unsupported(api, `Mesh "${this.name}" cannot fade a deferred ${material.getClassName()} material; visibility below 1 supports only Standard and PBR materials.`);
3402
+ validateOpacityMaterial(api, this.name, material._lite);
3403
+ }
3404
+ /** A glTF node owns its immediate primitive meshes, never a child glTF node's primitives. */
3405
+ _opacityTargets() {
3406
+ const node = this._lite;
3407
+ return "_gpu" in node ? [node] : node.children.filter((child) => "_gpu" in child);
3408
+ }
3010
3409
  get isPickable() {
3011
3410
  return this._lite.pickable !== false;
3012
3411
  }
@@ -3252,6 +3651,7 @@ var AbstractMesh = class extends TransformNode {
3252
3651
  node.position.set(0, 0, 0);
3253
3652
  node.rotation.set(0, 0, 0);
3254
3653
  node.scaling.set(1, 1, 1);
3654
+ this._resetRotationAfterBake();
3255
3655
  return this;
3256
3656
  }
3257
3657
  /**
@@ -3294,6 +3694,13 @@ var Mesh = class Mesh extends AbstractMesh {
3294
3694
  if (scene) mesh._bindLoadedScene(scene);
3295
3695
  return mesh;
3296
3696
  }
3697
+ /** @internal Bind a loaded mesh and its discovered morph manager to the owning scene. */
3698
+ _bindLoadedScene(scene) {
3699
+ super._bindLoadedScene(scene);
3700
+ for (const manager of this._ownedMorphTargetManagers) scene._retainMorphTargetManagerOwnership(manager);
3701
+ if (this._morphTargetManager?._lite) this._morphTargetManager._adoptEngine(scene._getLiteEngine());
3702
+ else if (this._morphTargetManager) scene._registerMorphTargetManager(this, this._morphTargetManager);
3703
+ }
3297
3704
  /** @internal Wrap and link a complete Lite hierarchy, registering every wrapper. */
3298
3705
  static _fromLiteHierarchy(lite, container, scene, registry = /* @__PURE__ */ new Map(), parent = null) {
3299
3706
  let wrapper = registry.get(lite);
@@ -3307,6 +3714,11 @@ var Mesh = class Mesh extends AbstractMesh {
3307
3714
  return wrapper;
3308
3715
  }
3309
3716
  _morphTargetManager = null;
3717
+ _ownedMorphTargetManagers = /* @__PURE__ */ new Set();
3718
+ _retainMorphTargetManagerOwnership(manager) {
3719
+ this._ownedMorphTargetManagers.add(manager);
3720
+ this._scene?._retainMorphTargetManagerOwnership?.(manager);
3721
+ }
3310
3722
  /**
3311
3723
  * Babylon.js `mesh.morphTargetManager`. Babylon Lite builds morph GPU data via
3312
3724
  * `createMorphTargets` and stores it on the Lite mesh; the compat manager is
@@ -3314,11 +3726,31 @@ var Mesh = class Mesh extends AbstractMesh {
3314
3726
  * CPU geometry exists) and assigns it onto the Lite mesh before registration.
3315
3727
  */
3316
3728
  get morphTargetManager() {
3729
+ if (!this._morphTargetManager && this._lite.morphTargets) {
3730
+ this._morphTargetManager = MorphTargetManager._fromLite(this._lite.morphTargets, this._scene?._getLiteEngine());
3731
+ this._retainMorphTargetManagerOwnership(this._morphTargetManager);
3732
+ }
3317
3733
  return this._morphTargetManager;
3318
3734
  }
3319
3735
  set morphTargetManager(value) {
3736
+ const lite = value?._lite ?? null;
3737
+ if (this._morphTargetManager === value && this._lite.morphTargets === lite) return;
3320
3738
  this._morphTargetManager = value;
3321
- if (value && this._scene) this._scene._registerMorphTargetManager(this, value);
3739
+ if (value) this._retainMorphTargetManagerOwnership(value);
3740
+ this._scene?._registerMorphTargetManager(this, value?._lite ? null : value);
3741
+ if (!value) {
3742
+ shareMeshMorphTargets(this._lite, null);
3743
+ return;
3744
+ }
3745
+ if (lite) {
3746
+ shareMeshMorphTargets(this._lite, lite);
3747
+ if (this._scene) value._adoptEngine(this._scene._getLiteEngine());
3748
+ }
3749
+ }
3750
+ /** @internal Release manager ownership claims during scene/container teardown. */
3751
+ _releaseMorphTargetManagerOwnership() {
3752
+ for (const manager of this._ownedMorphTargetManagers) manager.dispose();
3753
+ this._ownedMorphTargetManagers.clear();
3322
3754
  }
3323
3755
  /** Legacy `Mesh.CreateSphere(name, segments, diameter, scene)`. */
3324
3756
  static CreateSphere(name, segments, diameter, scene) {
@@ -3410,6 +3842,7 @@ var Mesh = class Mesh extends AbstractMesh {
3410
3842
  const isMesh = source instanceof Mesh || "_gpu" in lite && "material" in lite;
3411
3843
  if (isMesh) lite.id = void 0;
3412
3844
  const wrapper = isMesh ? new Mesh(lite.name ?? "", lite) : new TransformNode(lite.name ?? "", scene, lite);
3845
+ if (source instanceof TransformNode) wrapper._copyRotationMode(source);
3413
3846
  wrapper._container = source?._container;
3414
3847
  if (wrapper instanceof Mesh) {
3415
3848
  wrapper._scene = scene;
@@ -3421,6 +3854,7 @@ var Mesh = class Mesh extends AbstractMesh {
3421
3854
  wrapper.metadata = source.metadata;
3422
3855
  wrapper.setEnabled(source.isEnabled(false));
3423
3856
  if (wrapper instanceof Mesh && source instanceof Mesh) {
3857
+ wrapper._visibilityValue = source._visibilityValue;
3424
3858
  if (source._liteOnlyMaterial) wrapper._liteOnlyMaterial = true;
3425
3859
  else wrapper.material = source.material;
3426
3860
  wrapper.isVisible = source.isVisible;
@@ -3935,6 +4369,6 @@ var PolygonBuilder = {
3935
4369
  * methods directly, so importing or calling this function requires no mutation.
3936
4370
  */
3937
4371
  function RegisterPolygonBuilder() {}
3938
- export { Vector4 as $, PBRClearCoatConfiguration as A, Observable as B, RegisterPolygonBuilder as C, registerMeshAtStart as D, VertexData as E, PBRSpecularGlossinessMaterial as F, transformCoordinates as G, BoundingInfo as H, PushMaterial as I, Color3 as J, transformNormal as K, StandardMaterial as L, PBRMaterial as M, PBRMetallicRoughnessMaterial as N, Material as O, PBRSheenConfiguration as P, Vector3 as Q, attachMaterialToScene as R, PolygonBuilder as S, VertexBuffer as T, BoundingSphere as U, BoundingBox as V, Matrix as W, liteBackedColor3 as X, Color4 as Y, Vector2 as Z, GroundMesh as _, CreateDisc as a, Mesh as b, CreateLines as c, CreatePolygonVertexData as d, liteBackedVector3 as et, CreateSphere as f, ExtrudePolygon as g, CreateTorus as h, CreateDashedLines as i, PBRIridescenceConfiguration as j, PBRAnisotropicConfiguration as k, CreatePlane as l, CreateTiledPlane as m, CreateBox as n, unsupported as nt, CreateGround as o, CreateTiledBox as p, Quaternion as q, CreateCylinder as r, CreateLineSystem as s, AbstractMesh as t, LiteCompatError as tt, CreatePolygon as u, InstancedMesh as v, TransformNode as w, MeshBuilder as x, LinesMesh as y, Node as z };
4372
+ export { Vector2 as $, Material as A, attachMaterialToScene as B, RegisterPolygonBuilder as C, registerMeshAtStart as D, VertexData as E, PBRMetallicRoughnessMaterial as F, BoundingSphere as G, Observable as H, PBRSheenConfiguration as I, transformNormal as J, Matrix as K, PBRSpecularGlossinessMaterial as L, PBRClearCoatConfiguration as M, PBRIridescenceConfiguration as N, MorphTarget as O, PBRMaterial as P, liteBackedColor3 as Q, PushMaterial as R, PolygonBuilder as S, VertexBuffer as T, BoundingBox as U, Node as V, BoundingInfo as W, Color3 as X, Quaternion as Y, Color4 as Z, GroundMesh as _, CreateDisc as a, Mesh as b, CreateLines as c, CreatePolygonVertexData as d, Vector3 as et, CreateSphere as f, ExtrudePolygon as g, CreateTorus as h, CreateDashedLines as i, unsupported as it, PBRAnisotropicConfiguration as j, MorphTargetManager as k, CreatePlane as l, CreateTiledPlane as m, CreateBox as n, liteBackedVector3 as nt, CreateGround as o, CreateTiledBox as p, transformCoordinates as q, CreateCylinder as r, LiteCompatError as rt, CreateLineSystem as s, AbstractMesh as t, Vector4 as tt, CreatePolygon as u, InstancedMesh as v, TransformNode as w, MeshBuilder as x, LinesMesh as y, StandardMaterial as z };
3939
4373
 
3940
- //# sourceMappingURL=meshes-CTqDBeGc.js.map
4374
+ //# sourceMappingURL=meshes-C-PkzbPM.js.map