@babylonjs/lite-compat 1.38.2-preview → 1.39.1
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/CHANGELOG.md +1725 -0
- package/README.md +24 -24
- package/index.d.ts +212 -19
- package/index.js +790 -545
- package/index.js.map +1 -1
- package/{meshes-Bt_UAqXU.js → meshes-C-PkzbPM.js} +420 -20
- package/meshes-C-PkzbPM.js.map +1 -0
- package/navigation.d.ts +178 -17
- package/navigation.js +1 -1
- package/package.json +8 -5
- package/meshes-Bt_UAqXU.js.map +0 -1
|
@@ -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, getMaterialFamily, getMeshOpacity, markMaterialUboDirty, maximizeMat4InPlace, normalizeVec2ToRef, projectPointToViewportToRef, rebuildMaterial, removeFromScene, resizeMeshGeometry, scaleBoundsFromCenterToRef, setAccessibilityTag, setLineMaterialColor, setMat4Translation, setMeshOpacity, 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) {
|
|
@@ -2843,6 +3095,14 @@ var TransformNode = class TransformNode extends Node {
|
|
|
2843
3095
|
/** @internal The Lite scene node that carries this transform. */
|
|
2844
3096
|
_node;
|
|
2845
3097
|
physicsBody = null;
|
|
3098
|
+
_rotation;
|
|
3099
|
+
_rotationBinding;
|
|
3100
|
+
_rotationQuaternion = null;
|
|
3101
|
+
_rotationQuaternionBinding;
|
|
3102
|
+
_nativeRotationVersion;
|
|
3103
|
+
_nativeRotationValues;
|
|
3104
|
+
_isSyncingRotationFromNative = false;
|
|
3105
|
+
_sceneDisposeObserver;
|
|
2846
3106
|
/**
|
|
2847
3107
|
* @internal The Lite asset container this node was loaded from, when produced
|
|
2848
3108
|
* by a loader. Used by the `KHR_materials_variants` helpers (which key off the
|
|
@@ -2859,6 +3119,7 @@ var TransformNode = class TransformNode extends Node {
|
|
|
2859
3119
|
if (this._scene === scene) return;
|
|
2860
3120
|
this._scene = scene;
|
|
2861
3121
|
scene._registerMesh(this, this._node);
|
|
3122
|
+
this._bindRotationSceneDisposal(scene);
|
|
2862
3123
|
}
|
|
2863
3124
|
/** @internal Link an already-parented Lite node without mutating its Lite hierarchy. */
|
|
2864
3125
|
_adoptLoadedParent(parent) {
|
|
@@ -2871,6 +3132,24 @@ var TransformNode = class TransformNode extends Node {
|
|
|
2871
3132
|
this._node = createTransformNode(name);
|
|
2872
3133
|
if (scene) addToScene(scene._lite, this._node);
|
|
2873
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);
|
|
2874
3153
|
}
|
|
2875
3154
|
getClassName() {
|
|
2876
3155
|
return "TransformNode";
|
|
@@ -2882,10 +3161,17 @@ var TransformNode = class TransformNode extends Node {
|
|
|
2882
3161
|
this._node.position.set(value.x, value.y, value.z);
|
|
2883
3162
|
}
|
|
2884
3163
|
get rotation() {
|
|
2885
|
-
|
|
3164
|
+
this._syncRotationFromNative();
|
|
3165
|
+
return this._rotation;
|
|
2886
3166
|
}
|
|
2887
3167
|
set rotation(value) {
|
|
2888
|
-
this.
|
|
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;
|
|
2889
3175
|
}
|
|
2890
3176
|
get scaling() {
|
|
2891
3177
|
return liteBackedVector3(this._node.scaling);
|
|
@@ -2893,24 +3179,88 @@ var TransformNode = class TransformNode extends Node {
|
|
|
2893
3179
|
set scaling(value) {
|
|
2894
3180
|
this._node.scaling.set(value.x, value.y, value.z);
|
|
2895
3181
|
}
|
|
2896
|
-
/**
|
|
2897
|
-
_useQuat = false;
|
|
2898
|
-
/**
|
|
2899
|
-
* Babylon.js `rotationQuaternion`. Babylon Lite always drives a node's world
|
|
2900
|
-
* matrix from a quaternion (its euler `rotation` is a proxy over the same
|
|
2901
|
-
* quaternion), so this reads/writes that quaternion. Returns `null` until
|
|
2902
|
-
* explicitly assigned, matching Babylon.js's euler-by-default convention.
|
|
2903
|
-
*/
|
|
3182
|
+
/** Babylon.js `rotationQuaternion`, kept live while Lite receives translated component writes. */
|
|
2904
3183
|
get rotationQuaternion() {
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
return new Quaternion(q.x, q.y, q.z, q.w);
|
|
3184
|
+
this._syncRotationFromNative();
|
|
3185
|
+
return this._rotationQuaternion;
|
|
2908
3186
|
}
|
|
2909
3187
|
set rotationQuaternion(value) {
|
|
3188
|
+
this._markNativeRotationSynced();
|
|
3189
|
+
this._rotationQuaternionBinding?.unbind();
|
|
3190
|
+
this._rotationQuaternionBinding = void 0;
|
|
3191
|
+
this._rotationQuaternion = value;
|
|
2910
3192
|
if (value) {
|
|
2911
|
-
this.
|
|
2912
|
-
this.
|
|
2913
|
-
|
|
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();
|
|
2914
3264
|
}
|
|
2915
3265
|
/**
|
|
2916
3266
|
* Babylon.js `getChildTransformNodes(directDescendantsOnly?, predicate?)` — the descendants that are transform nodes
|
|
@@ -2951,6 +3301,21 @@ var TransformNode = class TransformNode extends Node {
|
|
|
2951
3301
|
this._node.children.length = 0;
|
|
2952
3302
|
removeFromScene(this._scene._lite, this._node);
|
|
2953
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
|
+
}
|
|
2954
3319
|
};
|
|
2955
3320
|
/**
|
|
2956
3321
|
* Babylon.js `AbstractMesh` — a renderable transform node with a material,
|
|
@@ -2991,6 +3356,7 @@ var AbstractMesh = class extends TransformNode {
|
|
|
2991
3356
|
* `AbstractMesh.dispose` does in its own `Lights` loop. Container-retired wrappers prune too.
|
|
2992
3357
|
*/
|
|
2993
3358
|
_retireFromScene() {
|
|
3359
|
+
super._retireFromScene();
|
|
2994
3360
|
for (const light of this._scene?.lights ?? []) light._pruneDisposedMesh(this);
|
|
2995
3361
|
}
|
|
2996
3362
|
get material() {
|
|
@@ -3285,6 +3651,7 @@ var AbstractMesh = class extends TransformNode {
|
|
|
3285
3651
|
node.position.set(0, 0, 0);
|
|
3286
3652
|
node.rotation.set(0, 0, 0);
|
|
3287
3653
|
node.scaling.set(1, 1, 1);
|
|
3654
|
+
this._resetRotationAfterBake();
|
|
3288
3655
|
return this;
|
|
3289
3656
|
}
|
|
3290
3657
|
/**
|
|
@@ -3327,6 +3694,13 @@ var Mesh = class Mesh extends AbstractMesh {
|
|
|
3327
3694
|
if (scene) mesh._bindLoadedScene(scene);
|
|
3328
3695
|
return mesh;
|
|
3329
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
|
+
}
|
|
3330
3704
|
/** @internal Wrap and link a complete Lite hierarchy, registering every wrapper. */
|
|
3331
3705
|
static _fromLiteHierarchy(lite, container, scene, registry = /* @__PURE__ */ new Map(), parent = null) {
|
|
3332
3706
|
let wrapper = registry.get(lite);
|
|
@@ -3340,6 +3714,11 @@ var Mesh = class Mesh extends AbstractMesh {
|
|
|
3340
3714
|
return wrapper;
|
|
3341
3715
|
}
|
|
3342
3716
|
_morphTargetManager = null;
|
|
3717
|
+
_ownedMorphTargetManagers = /* @__PURE__ */ new Set();
|
|
3718
|
+
_retainMorphTargetManagerOwnership(manager) {
|
|
3719
|
+
this._ownedMorphTargetManagers.add(manager);
|
|
3720
|
+
this._scene?._retainMorphTargetManagerOwnership?.(manager);
|
|
3721
|
+
}
|
|
3343
3722
|
/**
|
|
3344
3723
|
* Babylon.js `mesh.morphTargetManager`. Babylon Lite builds morph GPU data via
|
|
3345
3724
|
* `createMorphTargets` and stores it on the Lite mesh; the compat manager is
|
|
@@ -3347,11 +3726,31 @@ var Mesh = class Mesh extends AbstractMesh {
|
|
|
3347
3726
|
* CPU geometry exists) and assigns it onto the Lite mesh before registration.
|
|
3348
3727
|
*/
|
|
3349
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
|
+
}
|
|
3350
3733
|
return this._morphTargetManager;
|
|
3351
3734
|
}
|
|
3352
3735
|
set morphTargetManager(value) {
|
|
3736
|
+
const lite = value?._lite ?? null;
|
|
3737
|
+
if (this._morphTargetManager === value && this._lite.morphTargets === lite) return;
|
|
3353
3738
|
this._morphTargetManager = value;
|
|
3354
|
-
if (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();
|
|
3355
3754
|
}
|
|
3356
3755
|
/** Legacy `Mesh.CreateSphere(name, segments, diameter, scene)`. */
|
|
3357
3756
|
static CreateSphere(name, segments, diameter, scene) {
|
|
@@ -3443,6 +3842,7 @@ var Mesh = class Mesh extends AbstractMesh {
|
|
|
3443
3842
|
const isMesh = source instanceof Mesh || "_gpu" in lite && "material" in lite;
|
|
3444
3843
|
if (isMesh) lite.id = void 0;
|
|
3445
3844
|
const wrapper = isMesh ? new Mesh(lite.name ?? "", lite) : new TransformNode(lite.name ?? "", scene, lite);
|
|
3845
|
+
if (source instanceof TransformNode) wrapper._copyRotationMode(source);
|
|
3446
3846
|
wrapper._container = source?._container;
|
|
3447
3847
|
if (wrapper instanceof Mesh) {
|
|
3448
3848
|
wrapper._scene = scene;
|
|
@@ -3969,6 +4369,6 @@ var PolygonBuilder = {
|
|
|
3969
4369
|
* methods directly, so importing or calling this function requires no mutation.
|
|
3970
4370
|
*/
|
|
3971
4371
|
function RegisterPolygonBuilder() {}
|
|
3972
|
-
export {
|
|
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 };
|
|
3973
4373
|
|
|
3974
|
-
//# sourceMappingURL=meshes-
|
|
4374
|
+
//# sourceMappingURL=meshes-C-PkzbPM.js.map
|