@babylonjs/lite-compat 1.29.0-preview → 1.31.0-preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -31
- package/brdf-lut-data-BRUnY8c5.js +17 -0
- package/brdf-lut-data-BRUnY8c5.js.map +1 -0
- package/bundler-resolve-CVkl7m-0.js +57 -0
- package/bundler-resolve-CVkl7m-0.js.map +1 -0
- package/esbuild.js +51 -25
- package/esbuild.js.map +1 -1
- package/index.d.ts +492 -9
- package/index.js +11148 -10214
- package/index.js.map +1 -1
- package/meshes-Fu955h5M.js +3642 -0
- package/meshes-Fu955h5M.js.map +1 -0
- package/navigation.d.ts +130 -2
- package/navigation.js +191 -135
- package/navigation.js.map +1 -1
- package/package.json +4 -4
- package/recast-shim.js +19 -6
- package/recast-shim.js.map +1 -1
- package/rollup.js +39 -16
- package/rollup.js.map +1 -1
- package/vite.js +23 -22
- package/vite.js.map +1 -1
- package/webpack.js +44 -15
- package/webpack.js.map +1 -1
- package/brdf-lut-data-BFfYlW71.js +0 -5
- package/brdf-lut-data-BFfYlW71.js.map +0 -1
- package/bundler-resolve-0pEkTP9X.js +0 -33
- package/bundler-resolve-0pEkTP9X.js.map +0 -1
- package/meshes-C1K63hzW.js +0 -3503
- package/meshes-C1K63hzW.js.map +0 -1
package/navigation.d.ts
CHANGED
|
@@ -148,6 +148,7 @@ declare abstract class AbstractEngine {
|
|
|
148
148
|
* visibility, and shadow-receipt. Concrete meshes derive from this.
|
|
149
149
|
*/
|
|
150
150
|
declare class AbstractMesh extends TransformNode {
|
|
151
151
|
private _material;
|
|
152
|
+
private _meshBlendingTag;
|
|
152
153
|
protected _visible: boolean;
|
|
153
154
|
constructor(name: string, lite: Mesh, scene?: Scene);
|
|
154
155
|
getClassName(): string;
|
|
155
156
|
get material(): CompatMaterial | null;
|
|
@@ -158,6 +159,8 @@ declare class AbstractMesh extends TransformNode {
|
|
|
158
159
|
private _material;
|
|
159
160
|
set isPickable(value: boolean);
|
|
160
161
|
get receiveShadows(): boolean;
|
|
161
162
|
set receiveShadows(value: boolean);
|
|
163
|
+
get meshBlendingTag(): number;
|
|
164
|
+
set meshBlendingTag(value: number);
|
|
162
165
|
protected _onEffectiveEnabledStateChanged(enabled: boolean): void;
|
|
163
166
|
/**
|
|
164
167
|
* Babylon.js `mesh.getBoundingInfo()` — the mesh's AABB. `minimum`/`maximum`
|
|
165
168
|
* are the local-space bounds; the returned `BoundingInfo`'s world members
|
|
@@ -813,7 +816,8 @@ declare class LinesMaterial extends Material {
|
|
|
813
816
|
|
|
814
817
|
/** Babylon.js `Material` — base class for all materials. */
|
|
815
818
|
declare abstract class Material {
|
|
816
|
-
name: string;
|
|
819
|
+
name: string;
|
|
817
820
|
/** Babylon.js plugin manager, created lazily by the first `MaterialPluginBase`. */
|
|
821
|
+
pluginManager: MaterialPluginManager | undefined;
|
|
818
822
|
/** Common transparency mode flag (Babylon.js `Material.transparencyMode`). */
|
|
819
823
|
transparencyMode: number | null;
|
|
820
824
|
/** Back-face culling toggle (Babylon.js `Material.backFaceCulling`). */
|
|
@@ -841,6 +845,75 @@ declare abstract class Material {
|
|
|
841
845
|
protected _markDirty(): void;
|
|
842
846
|
dispose(): void;
|
|
843
847
|
}
|
|
844
848
|
|
|
849
|
+
/**
|
|
850
|
+
* Babylon.js `MaterialPluginBase` adapter over Lite's opt-in material-plugin
|
|
851
|
+
* bridge. Subclasses keep the Babylon.js override shape while Lite receives a
|
|
852
|
+
* plain plugin descriptor.
|
|
853
|
+
*/
|
|
854
|
+
declare class MaterialPluginBase {
|
|
855
|
+
private _name;
|
|
856
|
+
private _priority;
|
|
857
|
+
private _resolveIncludes;
|
|
858
|
+
readonly markAllDefinesAsDirty: () => void;
|
|
859
|
+
registerForExtraEvents: boolean;
|
|
860
|
+
doNotSerialize: boolean;
|
|
861
|
+
protected readonly _material: Material;
|
|
862
|
+
protected readonly _pluginManager: MaterialPluginManager;
|
|
863
|
+
protected readonly _pluginDefineNames?: MaterialPluginDefines;
|
|
845
864
|
constructor(material: Material, name: string, priority: number, defines?: MaterialPluginDefines, addToPluginList?: boolean, enable?: boolean, resolveIncludes?: boolean);
|
|
865
|
+
get name(): string;
|
|
866
|
+
set name(value: string);
|
|
867
|
+
get priority(): number;
|
|
868
|
+
set priority(value: number);
|
|
869
|
+
get resolveIncludes(): boolean;
|
|
870
|
+
set resolveIncludes(value: boolean);
|
|
846
871
|
protected _enable(enable: boolean): void;
|
|
847
872
|
private _assertSupportedExecution;
|
|
873
|
+
isCompatible(_shaderLanguage: ShaderLanguage): boolean;
|
|
874
|
+
getCustomCode(_shaderType: string, _shaderLanguage?: ShaderLanguage): MaterialPluginCustomCode | null;
|
|
875
|
+
isReadyForSubMesh(_defines: object, _scene: Scene, _engine: object, _subMesh: object): boolean;
|
|
876
|
+
hardBindForSubMesh(_uniformBuffer: object, _scene: Scene, _engine: object, _subMesh: object): void;
|
|
877
|
+
bindForSubMesh(_uniformBuffer: object, _scene: Scene, _engine: object, _subMesh: object): void;
|
|
878
|
+
collectDefines(defines: Record<string, {
|
|
879
|
+
type: string;
|
|
880
|
+
default: unknown;
|
|
881
|
+
}>): void;
|
|
882
|
+
prepareDefinesBeforeAttributes(_defines: object, _scene: Scene, _mesh: AbstractMesh): void;
|
|
883
|
+
prepareDefines(_defines: object, _scene: Scene, _mesh: AbstractMesh): void;
|
|
884
|
+
hasTexture(_texture: BaseTexture): boolean;
|
|
885
|
+
hasRenderTargetTextures(): boolean;
|
|
886
|
+
fillRenderTargetTextures(_renderTargets: SmartArray<RenderTargetTexture>): void;
|
|
887
|
+
getActiveTextures(_activeTextures: BaseTexture[]): void;
|
|
888
|
+
getAnimatables(_animatables: object[]): void;
|
|
889
|
+
addFallbacks(_defines: object, _fallbacks: object, currentRank: number): number;
|
|
890
|
+
getSamplers(_samplers: string[]): void;
|
|
891
|
+
getAttributes(_attributes: string[], _scene: Scene, _mesh: AbstractMesh): void;
|
|
892
|
+
getUniformBuffersNames(_ubos: string[]): void;
|
|
893
|
+
getUniforms(_shaderLanguage?: ShaderLanguage): {
|
|
894
|
+
ubo?: Array<{
|
|
895
|
+
name: string;
|
|
896
|
+
size?: number;
|
|
897
|
+
type?: string;
|
|
898
|
+
arraySize?: number;
|
|
899
|
+
}>;
|
|
900
|
+
vertex?: string;
|
|
901
|
+
fragment?: string;
|
|
902
|
+
externalUniforms?: string[];
|
|
903
|
+
};
|
|
904
|
+
getClassName(): string;
|
|
905
|
+
copyTo(plugin: MaterialPluginBase): void;
|
|
906
|
+
serialize(): Record<string, unknown>;
|
|
907
|
+
parse(source: Record<string, unknown>, _scene: Scene, _rootUrl: string): void;
|
|
908
|
+
dispose(_forceDisposeTextures?: boolean): void;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
declare type MaterialPluginCustomCode = Record<string, string>;
|
|
912
|
+
|
|
913
|
+
declare type MaterialPluginDefines = Record<string, unknown>;
|
|
914
|
+
|
|
915
|
+
/** Babylon.js-shaped manager for the adapter-visible material plugin list. */
|
|
916
|
+
declare class MaterialPluginManager {
|
|
917
|
+
private readonly _plugins;
|
|
918
|
+
constructor(material: Material);
|
|
848
919
|
getPlugin<T = MaterialPluginBase>(name: string): T | null;
|
|
920
|
+
}
|
|
921
|
+
|
|
849
922
|
declare class Matrix {
|
|
850
923
|
readonly m: Float32Array;
|
|
851
924
|
constructor();
|
|
@@ -1036,6 +1109,14 @@ declare abstract class Node_2 {
|
|
|
1036
1109
|
* descendant nodes that are meshes (all descendants by default).
|
|
1037
1110
|
*/
|
|
1038
1111
|
getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node_2) => boolean): Node_2[];
|
|
1112
|
+
/**
|
|
1113
|
+
* Babylon.js `node.getHierarchyBoundingVectors(includeDescendants?, predicate?)`
|
|
1114
|
+
* — world-space bounds spanning this mesh and eligible descendant meshes.
|
|
1115
|
+
*/
|
|
1116
|
+
getHierarchyBoundingVectors(includeDescendants?: boolean, predicate?: ((mesh: AbstractMesh) => boolean) | null): {
|
|
1117
|
+
min: Vector3;
|
|
1118
|
+
max: Vector3;
|
|
1119
|
+
};
|
|
1039
1120
|
isEnabled(checkAncestors?: boolean): boolean;
|
|
1040
1121
|
setEnabled(value: boolean): void;
|
|
1041
1122
|
isDisposed(): boolean;
|
|
1042
1123
|
dispose(doNotRecurse?: boolean): void;
|
|
@@ -1595,6 +1676,11 @@ export declare class RecastNavigationJSPluginV2 {
|
|
|
1595
1676
|
/**
|
|
1596
1677
|
createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): RecastJSCrowd;
|
|
1597
1678
|
}
|
|
1598
1679
|
|
|
1680
|
+
/** Babylon.js `RenderTargetTexture` — offscreen render target. Use the native frame-graph RTT APIs. */
|
|
1681
|
+
declare class RenderTargetTexture {
|
|
1682
|
+
constructor();
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1599
1685
|
declare class Scene extends AbstractScene {
|
|
1600
1686
|
/** Babylon.js fog-mode constants. */
|
|
1601
1687
|
static readonly FOGMODE_NONE = 0;
|
|
1602
1688
|
static readonly FOGMODE_EXP = 1;
|
|
@@ -1638,6 +1724,8 @@ declare class Scene extends AbstractScene {
|
|
|
1638
1724
|
/** Babylon.js fog-mode constant
|
|
1639
1725
|
private readonly _pendingTextures;
|
|
1640
1726
|
private readonly _pendingGroundBakes;
|
|
1641
1727
|
private readonly _pendingMorphBuilds;
|
|
1728
|
+
private _materialPluginsRequested;
|
|
1729
|
+
private readonly _pendingMaterialPluginReconciliations;
|
|
1642
1730
|
private readonly _runningAnimatables;
|
|
1643
1731
|
private readonly _animationGroupCache;
|
|
1644
1732
|
private _ambientColor;
|
|
1645
1733
|
private _environmentIntensity;
|
|
@@ -1814,7 +1902,47 @@ declare class Scene extends AbstractScene {
|
|
|
1814
1902
|
/** Babylon.js fog-mode constant
|
|
1815
1903
|
dispose(): void;
|
|
1816
1904
|
}
|
|
1817
1905
|
|
|
1818
|
-
declare class StandardMaterial extends PushMaterial {
|
|
1819
1906
|
constructor(name: string, scene?: Scene);
|
|
1907
|
+
/**
|
|
1908
|
+
* Babylon.js `ShaderLanguage` — the shader-source language selector. Babylon Lite
|
|
1909
|
+
* is WGSL-only, but the enum is surfaced (with Babylon.js's numeric values) so
|
|
1910
|
+
* scenes that import it to author `WGSL` shaders resolve the symbol; a `GLSL`
|
|
1911
|
+
* `ShaderMaterial`/`EffectWrapper` still fails loudly at construction.
|
|
1912
|
+
*/
|
|
1913
|
+
declare enum ShaderLanguage {
|
|
1914
|
+
GLSL = 0,
|
|
1915
|
+
WGSL = 1
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* Babylon.js-compatible Misc utilities — the pure-JS subset that has no Babylon
|
|
1920
|
+
* Lite or GPU dependency: `SmartArray`, `StringDictionary`, `Tags`,
|
|
1921
|
+
* `PerformanceMonitor`, and `ColorGradient`/`FactorGradient`.
|
|
1922
|
+
*/
|
|
1923
|
+
/** A pre-sized, reusable array that tracks a logical `length` separately from capacity. */
|
|
1924
|
+
declare class SmartArray<T> {
|
|
1925
|
+
data: Array<T | undefined>;
|
|
1926
|
+
length: number;
|
|
1927
|
+
constructor(capacity: number);
|
|
1928
|
+
push(value: T): void;
|
|
1929
|
+
reset(): void;
|
|
1930
|
+
concat(array: {
|
|
1931
|
+
length: number;
|
|
1932
|
+
data: Array<T | undefined>;
|
|
1933
|
+
}): void;
|
|
1934
|
+
dispose(): void;
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
declare class StandardMaterial extends PushMaterial {
|
|
1820
1938
|
/** Diffuse colour as the app set it. Kept apart from `_lite.diffuseColor`, which is forced to white
|
|
1939
|
+
* while the material is unlit (see `_syncDiffuse`). */
|
|
1940
|
+
private _diffuse;
|
|
1941
|
+
constructor(name: string, scene?: Scene);
|
|
1942
|
+
/**
|
|
1943
|
+
* Babylon.js shades an unlit StandardMaterial as `emissive + ambient`: the diffuse colour only scales
|
|
1944
|
+
* the accumulated light, and there is none. Lite's unlit path is `emissive × diffuse`, so the usual
|
|
1945
|
+
* "unlit colour" setup (black diffuse, colour in emissive) rendered black. Hand Lite a neutral white
|
|
1946
|
+
* diffuse while lighting is disabled and the app's own colour otherwise.
|
|
1947
|
+
*/
|
|
1948
|
+
private _syncDiffuse;
|
|
1821
1949
|
getClassName(): string;
|
|
1822
1950
|
get diffuseColor(): Color3;
|
|
1823
1951
|
set diffuseColor(value: Color3);
|
package/navigation.js
CHANGED
|
@@ -1,139 +1,195 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
1
|
+
import { S as registerMeshAtStart, _ as Mesh, q as Vector3 } from "./meshes-Fu955h5M.js";
|
|
2
|
+
import { addAgent, addBoxObstacle, addCylinderObstacle, agentGoto, computePath, createDebugNavMeshGeometry, createMeshFromData, createNavCrowd, createNavMesh, createNavigationPluginAsync, getAgentPosition, getClosestPoint, raycast, removeObstacle, updateNavCrowd, updateNavMeshObstacles } from "@babylonjs/lite";
|
|
3
|
+
//#region src/navigation/navigation.ts
|
|
4
|
+
/**
|
|
5
|
+
* Babylon.js `@babylonjs/addons/navigation` compatibility wrapper over Babylon
|
|
6
|
+
* Lite's native navigation API (`createNavigationPluginAsync` / `createNavMesh` /
|
|
7
|
+
* `createDebugNavMeshGeometry` / `createNavCrowd` / …).
|
|
8
|
+
*
|
|
9
|
+
* The Babylon.js navigation addon (`RecastNavigationJSPluginV2`, created via
|
|
10
|
+
* `CreateNavigationPluginAsync`) is a thin wrapper around `recast-navigation-js`.
|
|
11
|
+
* Babylon Lite ships its own Recast V2 integration with the same capabilities, so
|
|
12
|
+
* this module mirrors the addon's public plugin/crowd surface and delegates to
|
|
13
|
+
* Lite. The Recast instance the scene injects via `{ instance }` is ignored —
|
|
14
|
+
* Lite loads its own Recast wasm (served at `/recast-navigation.wasm`).
|
|
15
|
+
*
|
|
16
|
+
* Only the surface exercised by ported scenes is implemented (`createNavMesh`,
|
|
17
|
+
* `createDebugNavMesh`, `getClosestPoint`, `createCrowd` + `addAgent`); the rest
|
|
18
|
+
* of the addon API is intentionally omitted.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Babylon.js `RecastJSCrowd` (subset) — owns crowd agents and syncs each agent's
|
|
22
|
+
* Babylon transform to the simulated position every frame, exactly like the addon.
|
|
23
|
+
*/
|
|
24
|
+
var RecastJSCrowd = class {
|
|
25
|
+
/** @internal */ _lite;
|
|
26
|
+
_transforms = /* @__PURE__ */ new Map();
|
|
27
|
+
_plugin;
|
|
28
|
+
constructor(lite, plugin, scene) {
|
|
29
|
+
this._lite = lite;
|
|
30
|
+
this._plugin = plugin;
|
|
31
|
+
scene.onBeforeRenderObservable.add(() => {
|
|
32
|
+
updateNavCrowd(this._lite, 1 / 60 * this._plugin.timeFactor);
|
|
33
|
+
for (const [index, transform] of this._transforms) {
|
|
34
|
+
const p = getAgentPosition(this._lite, index);
|
|
35
|
+
transform.position.set(p.x, p.y, p.z);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Babylon.js `crowd.addAgent(pos, parameters, transform)` — returns the agent index. */
|
|
40
|
+
addAgent(pos, parameters, transform) {
|
|
41
|
+
const index = addAgent(this._lite, {
|
|
42
|
+
x: pos.x,
|
|
43
|
+
y: pos.y,
|
|
44
|
+
z: pos.z
|
|
45
|
+
}, parameters);
|
|
46
|
+
this._transforms.set(index, transform);
|
|
47
|
+
return index;
|
|
48
|
+
}
|
|
49
|
+
/** Babylon.js `crowd.getAgentPosition(index)`. */
|
|
50
|
+
getAgentPosition(index) {
|
|
51
|
+
const p = getAgentPosition(this._lite, index);
|
|
52
|
+
return new Vector3(p.x, p.y, p.z);
|
|
53
|
+
}
|
|
54
|
+
/** Babylon.js `crowd.agentGoto(index, destination)` — request the agent to move toward a target. */
|
|
55
|
+
agentGoto(index, destination) {
|
|
56
|
+
agentGoto(this._lite, index, {
|
|
57
|
+
x: destination.x,
|
|
58
|
+
y: destination.y,
|
|
59
|
+
z: destination.z
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Babylon.js `RecastNavigationJSPluginV2` (subset) over Babylon Lite navigation.
|
|
65
|
+
*/
|
|
66
|
+
var RecastNavigationJSPluginV2 = class {
|
|
67
|
+
/** @internal */ _lite;
|
|
68
|
+
/**
|
|
69
|
+
* Babylon.js `plugin.timeFactor` — multiplier applied to each crowd update step.
|
|
70
|
+
* `0` pauses crowd movement (used by parity tests); default `1`.
|
|
71
|
+
*/
|
|
72
|
+
timeFactor = 1;
|
|
73
|
+
constructor(lite) {
|
|
74
|
+
this._lite = lite;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Babylon.js `plugin.createNavMesh(meshes, parameters)`. Returns a
|
|
78
|
+
* `{ navMesh, tileCache }` handle (both reference this plugin) so scenes using
|
|
79
|
+
* the tile-cache obstacle API can pass them to {@link WaitForFullTileCacheUpdate}.
|
|
80
|
+
* Scenes that ignore the return (the non-obstacle navmesh scenes) are unaffected.
|
|
81
|
+
*/
|
|
82
|
+
createNavMesh(meshes, parameters) {
|
|
83
|
+
createNavMesh(this._lite, meshes.map((m) => m._lite), parameters);
|
|
84
|
+
return {
|
|
85
|
+
navMesh: this,
|
|
86
|
+
tileCache: this
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Babylon.js `plugin.addCylinderObstacle(position, radius, height)` — tile-cache obstacle. */
|
|
90
|
+
addCylinderObstacle(position, radius, height) {
|
|
91
|
+
return addCylinderObstacle(this._lite, {
|
|
92
|
+
x: position.x,
|
|
93
|
+
y: position.y,
|
|
94
|
+
z: position.z
|
|
95
|
+
}, radius, height);
|
|
96
|
+
}
|
|
97
|
+
/** Babylon.js `plugin.addBoxObstacle(position, extent, angle)` — tile-cache obstacle (`extent` = half-extents). */
|
|
98
|
+
addBoxObstacle(position, extent, angle) {
|
|
99
|
+
return addBoxObstacle(this._lite, {
|
|
100
|
+
x: position.x,
|
|
101
|
+
y: position.y,
|
|
102
|
+
z: position.z
|
|
103
|
+
}, {
|
|
104
|
+
x: extent.x,
|
|
105
|
+
y: extent.y,
|
|
106
|
+
z: extent.z
|
|
107
|
+
}, angle);
|
|
108
|
+
}
|
|
109
|
+
/** Babylon.js `plugin.removeObstacle(obstacle)` — remove a previously-added tile-cache obstacle. */
|
|
110
|
+
removeObstacle(obstacle) {
|
|
111
|
+
removeObstacle(this._lite, obstacle);
|
|
112
|
+
}
|
|
113
|
+
/** @internal Apply pending tile-cache obstacle updates (drives {@link WaitForFullTileCacheUpdate}). */
|
|
114
|
+
_updateObstacles() {
|
|
115
|
+
updateNavMeshObstacles(this._lite);
|
|
116
|
+
}
|
|
117
|
+
/** Babylon.js `plugin.createDebugNavMesh(scene)` — builds a renderable debug mesh. */
|
|
118
|
+
createDebugNavMesh(scene) {
|
|
119
|
+
const geo = createDebugNavMeshGeometry(this._lite);
|
|
120
|
+
const engine = scene.getEngine()._lite;
|
|
121
|
+
const lite = createMeshFromData(engine, "navDebugMesh", geo.positions, geo.normals, geo.indices);
|
|
122
|
+
return registerMeshAtStart(new Mesh("navDebugMesh", lite, scene), scene);
|
|
123
|
+
}
|
|
124
|
+
/** Babylon.js `plugin.getClosestPoint(position)` — snap to the navmesh. */
|
|
125
|
+
getClosestPoint(position) {
|
|
126
|
+
const p = getClosestPoint(this._lite, {
|
|
127
|
+
x: position.x,
|
|
128
|
+
y: position.y,
|
|
129
|
+
z: position.z
|
|
130
|
+
});
|
|
131
|
+
return new Vector3(p.x, p.y, p.z);
|
|
132
|
+
}
|
|
133
|
+
/** Babylon.js `plugin.computePath(start, end)` — navmesh-snapped path as world points. */
|
|
134
|
+
computePath(start, end) {
|
|
135
|
+
return computePath(this._lite, {
|
|
136
|
+
x: start.x,
|
|
137
|
+
y: start.y,
|
|
138
|
+
z: start.z
|
|
139
|
+
}, {
|
|
140
|
+
x: end.x,
|
|
141
|
+
y: end.y,
|
|
142
|
+
z: end.z
|
|
143
|
+
}).map((p) => new Vector3(p.x, p.y, p.z));
|
|
144
|
+
}
|
|
145
|
+
/** Babylon.js `plugin.computePathSmooth(start, end)` — alias of {@link computePath} (Lite smooths internally). */
|
|
146
|
+
computePathSmooth(start, end) {
|
|
147
|
+
return this.computePath(start, end);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Babylon.js `plugin.raycast(start, end)` — walkability raycast on the navmesh.
|
|
151
|
+
* Returns `{ hit, hitPoint? }` (`hitPoint` is a `Vector3` when `hit`).
|
|
152
|
+
*/
|
|
153
|
+
raycast(start, end) {
|
|
154
|
+
const r = raycast(this._lite, {
|
|
155
|
+
x: start.x,
|
|
156
|
+
y: start.y,
|
|
157
|
+
z: start.z
|
|
158
|
+
}, {
|
|
159
|
+
x: end.x,
|
|
160
|
+
y: end.y,
|
|
161
|
+
z: end.z
|
|
162
|
+
});
|
|
163
|
+
return r.hit && r.hitPoint ? {
|
|
164
|
+
hit: true,
|
|
165
|
+
hitPoint: new Vector3(r.hitPoint.x, r.hitPoint.y, r.hitPoint.z)
|
|
166
|
+
} : { hit: false };
|
|
167
|
+
}
|
|
168
|
+
/** Babylon.js `plugin.createCrowd(maxAgents, maxAgentRadius, scene)`. */
|
|
169
|
+
createCrowd(maxAgents, maxAgentRadius, scene) {
|
|
170
|
+
return new RecastJSCrowd(createNavCrowd(this._lite, maxAgents, maxAgentRadius), this, scene);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Babylon.js `@babylonjs/addons/navigation` `CreateNavigationPluginAsync`. The
|
|
175
|
+
* injected Recast `instance` (if any) is ignored — Babylon Lite loads its own
|
|
176
|
+
* Recast wasm from `/recast-navigation.wasm`.
|
|
177
|
+
*/
|
|
123
178
|
async function CreateNavigationPluginAsync(_options) {
|
|
124
|
-
|
|
125
|
-
return new RecastNavigationJSPluginV2(lite);
|
|
179
|
+
return new RecastNavigationJSPluginV2(await createNavigationPluginAsync({ locateFile: () => "/recast-navigation.wasm" }));
|
|
126
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Babylon.js `@babylonjs/addons/navigation/common/tile-cache`
|
|
183
|
+
* `WaitForFullTileCacheUpdate(navMesh, tileCache)` — block until pending
|
|
184
|
+
* tile-cache obstacle updates are applied. The addon takes the raw navMesh /
|
|
185
|
+
* tileCache; here `navMesh` is the compat plugin (returned from `createNavMesh`),
|
|
186
|
+
* so this delegates to Babylon Lite's `updateNavMeshObstacles`.
|
|
187
|
+
*/
|
|
127
188
|
function WaitForFullTileCacheUpdate(navMesh, _tileCache) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
plugin._updateObstacles();
|
|
131
|
-
}
|
|
189
|
+
const plugin = navMesh;
|
|
190
|
+
if (plugin && typeof plugin._updateObstacles === "function") plugin._updateObstacles();
|
|
132
191
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
WaitForFullTileCacheUpdate
|
|
138
|
-
};
|
|
139
|
-
//# sourceMappingURL=navigation.js.map
|
|
192
|
+
//#endregion
|
|
193
|
+
export { CreateNavigationPluginAsync, RecastJSCrowd, RecastNavigationJSPluginV2, WaitForFullTileCacheUpdate };
|
|
194
|
+
|
|
195
|
+
//# sourceMappingURL=navigation.js.map
|
package/navigation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","sources":["../src/navigation/navigation.ts"],"sourcesContent":["/**\n * Babylon.js `@babylonjs/addons/navigation` compatibility wrapper over Babylon\n * Lite's native navigation API (`createNavigationPluginAsync` / `createNavMesh` /\n * `createDebugNavMeshGeometry` / `createNavCrowd` / …).\n *\n * The Babylon.js navigation addon (`RecastNavigationJSPluginV2`, created via\n * `CreateNavigationPluginAsync`) is a thin wrapper around `recast-navigation-js`.\n * Babylon Lite ships its own Recast V2 integration with the same capabilities, so\n * this module mirrors the addon's public plugin/crowd surface and delegates to\n * Lite. The Recast instance the scene injects via `{ instance }` is ignored —\n * Lite loads its own Recast wasm (served at `/recast-navigation.wasm`).\n *\n * Only the surface exercised by ported scenes is implemented (`createNavMesh`,\n * `createDebugNavMesh`, `getClosestPoint`, `createCrowd` + `addAgent`); the rest\n * of the addon API is intentionally omitted.\n */\n\nimport {\n createNavigationPluginAsync as liteCreateNavigationPluginAsync,\n createNavMesh as liteCreateNavMesh,\n createDebugNavMeshGeometry as liteCreateDebugNavMeshGeometry,\n getClosestPoint as liteGetClosestPoint,\n computePath as liteComputePath,\n raycast as liteRaycast,\n createNavCrowd as liteCreateNavCrowd,\n addAgent as liteAddAgent,\n getAgentPosition as liteGetAgentPosition,\n agentGoto as liteAgentGoto,\n updateNavCrowd as liteUpdateNavCrowd,\n addBoxObstacle as liteAddBoxObstacle,\n addCylinderObstacle as liteAddCylinderObstacle,\n removeObstacle as liteRemoveObstacle,\n updateNavMeshObstacles as liteUpdateNavMeshObstacles,\n createMeshFromData,\n addToScene,\n type NavigationPlugin as LiteNavigationPlugin,\n type NavCrowd as LiteNavCrowd,\n type Mesh as LiteMesh,\n type ObstacleHandle as LiteObstacleHandle,\n} from \"babylon-lite\";\n\nimport { Mesh } from \"../meshes/meshes.js\";\nimport { Vector3 } from \"../math/vector.js\";\nimport type { Scene } from \"../scene/scene.js\";\n\ninterface Vec3Like {\n x: number;\n y: number;\n z: number;\n}\n\ninterface AgentTransform {\n position: { set(x: number, y: number, z: number): unknown };\n}\n\n/**\n * Result of {@link RecastNavigationJSPluginV2.createNavMesh}. Babylon.js's\n * tile-cache navmesh build returns `{ navMesh, tileCache }`; here both reference\n * the plugin so {@link WaitForFullTileCacheUpdate} can reach it.\n */\ninterface NavMeshResult {\n navMesh: RecastNavigationJSPluginV2;\n tileCache: RecastNavigationJSPluginV2;\n}\n\n/** Babylon.js `IAgentParameters` subset accepted by `RecastJSCrowd.addAgent`. */\ninterface AgentParameters {\n radius: number;\n height: number;\n maxAcceleration: number;\n maxSpeed: number;\n collisionQueryRange: number;\n pathOptimizationRange: number;\n separationWeight: number;\n reachRadius?: number;\n}\n\n/**\n * Babylon.js `RecastJSCrowd` (subset) — owns crowd agents and syncs each agent's\n * Babylon transform to the simulated position every frame, exactly like the addon.\n */\nclass RecastJSCrowd {\n /** @internal */ public readonly _lite: LiteNavCrowd;\n private readonly _transforms = new Map<number, AgentTransform>();\n private readonly _plugin: RecastNavigationJSPluginV2;\n\n public constructor(lite: LiteNavCrowd, plugin: RecastNavigationJSPluginV2, scene: Scene) {\n this._lite = lite;\n this._plugin = plugin;\n // Babylon.js' crowd advances the simulation and writes back agent transforms\n // on the scene's before-render tick; mirror that over Lite's manual crowd update.\n // The plugin's `timeFactor` scales the step (0 freezes the crowd — used by parity\n // tests via `?freeze=1`).\n scene.onBeforeRenderObservable.add(() => {\n liteUpdateNavCrowd(this._lite, (1 / 60) * this._plugin.timeFactor);\n for (const [index, transform] of this._transforms) {\n const p = liteGetAgentPosition(this._lite, index);\n transform.position.set(p.x, p.y, p.z);\n }\n });\n }\n\n /** Babylon.js `crowd.addAgent(pos, parameters, transform)` — returns the agent index. */\n public addAgent(pos: Vec3Like, parameters: AgentParameters, transform: AgentTransform): number {\n const index = liteAddAgent(this._lite, { x: pos.x, y: pos.y, z: pos.z }, parameters);\n this._transforms.set(index, transform);\n return index;\n }\n\n /** Babylon.js `crowd.getAgentPosition(index)`. */\n public getAgentPosition(index: number): Vector3 {\n const p = liteGetAgentPosition(this._lite, index);\n return new Vector3(p.x, p.y, p.z);\n }\n\n /** Babylon.js `crowd.agentGoto(index, destination)` — request the agent to move toward a target. */\n public agentGoto(index: number, destination: Vec3Like): void {\n liteAgentGoto(this._lite, index, { x: destination.x, y: destination.y, z: destination.z });\n }\n}\n\n/**\n * Babylon.js `RecastNavigationJSPluginV2` (subset) over Babylon Lite navigation.\n */\nclass RecastNavigationJSPluginV2 {\n /** @internal */ public readonly _lite: LiteNavigationPlugin;\n /**\n * Babylon.js `plugin.timeFactor` — multiplier applied to each crowd update step.\n * `0` pauses crowd movement (used by parity tests); default `1`.\n */\n public timeFactor = 1;\n\n public constructor(lite: LiteNavigationPlugin) {\n this._lite = lite;\n }\n\n /**\n * Babylon.js `plugin.createNavMesh(meshes, parameters)`. Returns a\n * `{ navMesh, tileCache }` handle (both reference this plugin) so scenes using\n * the tile-cache obstacle API can pass them to {@link WaitForFullTileCacheUpdate}.\n * Scenes that ignore the return (the non-obstacle navmesh scenes) are unaffected.\n */\n public createNavMesh(meshes: Array<{ _lite: LiteMesh }>, parameters: Record<string, unknown>): NavMeshResult {\n liteCreateNavMesh(\n this._lite,\n meshes.map((m) => m._lite),\n parameters as never\n );\n return { navMesh: this, tileCache: this };\n }\n\n /** Babylon.js `plugin.addCylinderObstacle(position, radius, height)` — tile-cache obstacle. */\n public addCylinderObstacle(position: Vec3Like, radius: number, height: number): LiteObstacleHandle | null {\n return liteAddCylinderObstacle(this._lite, { x: position.x, y: position.y, z: position.z }, radius, height);\n }\n\n /** Babylon.js `plugin.addBoxObstacle(position, extent, angle)` — tile-cache obstacle (`extent` = half-extents). */\n public addBoxObstacle(position: Vec3Like, extent: Vec3Like, angle: number): LiteObstacleHandle | null {\n return liteAddBoxObstacle(this._lite, { x: position.x, y: position.y, z: position.z }, { x: extent.x, y: extent.y, z: extent.z }, angle);\n }\n\n /** Babylon.js `plugin.removeObstacle(obstacle)` — remove a previously-added tile-cache obstacle. */\n public removeObstacle(obstacle: LiteObstacleHandle): void {\n liteRemoveObstacle(this._lite, obstacle);\n }\n\n /** @internal Apply pending tile-cache obstacle updates (drives {@link WaitForFullTileCacheUpdate}). */\n public _updateObstacles(): void {\n liteUpdateNavMeshObstacles(this._lite);\n }\n\n /** Babylon.js `plugin.createDebugNavMesh(scene)` — builds a renderable debug mesh. */\n public createDebugNavMesh(scene: Scene): Mesh {\n const geo = liteCreateDebugNavMeshGeometry(this._lite);\n const engine = scene.getEngine()._lite;\n const lite = createMeshFromData(engine, \"navDebugMesh\", geo.positions, geo.normals, geo.indices);\n const mesh = new Mesh(\"navDebugMesh\", lite, scene);\n scene._deferAdd(() => {\n const mat = mesh.material;\n mat?._ensureRenderable(engine);\n if (mat?._lite) {\n mesh._lite.material = mat._lite as never;\n }\n addToScene(scene._lite, mesh._lite);\n });\n return mesh;\n }\n\n /** Babylon.js `plugin.getClosestPoint(position)` — snap to the navmesh. */\n public getClosestPoint(position: Vec3Like): Vector3 {\n const p = liteGetClosestPoint(this._lite, { x: position.x, y: position.y, z: position.z });\n return new Vector3(p.x, p.y, p.z);\n }\n\n /** Babylon.js `plugin.computePath(start, end)` — navmesh-snapped path as world points. */\n public computePath(start: Vec3Like, end: Vec3Like): Vector3[] {\n const points = liteComputePath(this._lite, { x: start.x, y: start.y, z: start.z }, { x: end.x, y: end.y, z: end.z });\n return points.map((p) => new Vector3(p.x, p.y, p.z));\n }\n\n /** Babylon.js `plugin.computePathSmooth(start, end)` — alias of {@link computePath} (Lite smooths internally). */\n public computePathSmooth(start: Vec3Like, end: Vec3Like): Vector3[] {\n return this.computePath(start, end);\n }\n\n /**\n * Babylon.js `plugin.raycast(start, end)` — walkability raycast on the navmesh.\n * Returns `{ hit, hitPoint? }` (`hitPoint` is a `Vector3` when `hit`).\n */\n public raycast(start: Vec3Like, end: Vec3Like): { hit: boolean; hitPoint?: Vector3 } {\n const r = liteRaycast(this._lite, { x: start.x, y: start.y, z: start.z }, { x: end.x, y: end.y, z: end.z });\n return r.hit && r.hitPoint ? { hit: true, hitPoint: new Vector3(r.hitPoint.x, r.hitPoint.y, r.hitPoint.z) } : { hit: false };\n }\n\n /** Babylon.js `plugin.createCrowd(maxAgents, maxAgentRadius, scene)`. */\n public createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): RecastJSCrowd {\n const crowd = liteCreateNavCrowd(this._lite, maxAgents, maxAgentRadius);\n return new RecastJSCrowd(crowd, this, scene);\n }\n}\n\n/**\n * Babylon.js `@babylonjs/addons/navigation` `CreateNavigationPluginAsync`. The\n * injected Recast `instance` (if any) is ignored — Babylon Lite loads its own\n * Recast wasm from `/recast-navigation.wasm`.\n */\nexport async function CreateNavigationPluginAsync(_options?: { version?: string; instance?: unknown }): Promise<RecastNavigationJSPluginV2> {\n const lite = await liteCreateNavigationPluginAsync({ locateFile: () => \"/recast-navigation.wasm\" });\n return new RecastNavigationJSPluginV2(lite);\n}\n\nexport { RecastNavigationJSPluginV2, RecastJSCrowd };\n\n/**\n * Babylon.js `@babylonjs/addons/navigation/common/tile-cache`\n * `WaitForFullTileCacheUpdate(navMesh, tileCache)` — block until pending\n * tile-cache obstacle updates are applied. The addon takes the raw navMesh /\n * tileCache; here `navMesh` is the compat plugin (returned from `createNavMesh`),\n * so this delegates to Babylon Lite's `updateNavMeshObstacles`.\n */\nexport function WaitForFullTileCacheUpdate(navMesh: unknown, _tileCache?: unknown): void {\n const plugin = navMesh as RecastNavigationJSPluginV2 | undefined;\n if (plugin && typeof plugin._updateObstacles === \"function\") {\n plugin._updateObstacles();\n }\n}\n"],"names":["liteUpdateNavCrowd","liteGetAgentPosition","liteAddAgent","liteAgentGoto","liteCreateNavMesh","liteAddCylinderObstacle","liteAddBoxObstacle","liteRemoveObstacle","liteUpdateNavMeshObstacles","liteCreateDebugNavMeshGeometry","liteGetClosestPoint","liteComputePath","liteRaycast","liteCreateNavCrowd","liteCreateNavigationPluginAsync"],"mappings":";;;;;AAiFA,MAAM,cAAc;AAAA,EAKT,YAAY,MAAoB,QAAoC,OAAc;AAJxD;AAAA;AAChB,2DAAkB,IAAA;AAClB;AAGb,SAAK,QAAQ;AACb,SAAK,UAAU;AAKf,UAAM,yBAAyB,IAAI,MAAM;AACrCA,qBAAmB,KAAK,OAAQ,IAAI,KAAM,KAAK,QAAQ,UAAU;AACjE,iBAAW,CAAC,OAAO,SAAS,KAAK,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C,MAAM,IAAI,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;AAAA,EACvD;AAAA;AAAA,EAGO,kBAAkB,OAAiB,KAA0B;AAChE,WAAO,KAAK,YAAY,OAAO,GAAG;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAQ,OAAiB,KAAqD;AACjF,UAAM,IAAIC,QAAY,KAAK,OAAO,EAAE,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,GAAG,MAAM,KAAK,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,GAAG,GAAG,IAAI,EAAA,CAAG;AAC1G,WAAO,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,MAAM,UAAU,IAAI,QAAQ,EAAE,SAAS,GAAG,EAAE,SAAS,GAAG,EAAE,SAAS,CAAC,EAAA,IAAM,EAAE,KAAK,MAAA;AAAA,EACzH;AAAA;AAAA,EAGO,YAAY,WAAmB,gBAAwB,OAA6B;AACvF,UAAM,QAAQC,eAAmB,KAAK,OAAO,WAAW,cAAc;AACtE,WAAO,IAAI,cAAc,OAAO,MAAM,KAAK;AAAA,EAC/C;AACJ;AAOA,eAAsB,4BAA4B,UAA0F;AACxI,QAAM,OAAO,MAAMC,4BAAgC,EAAE,YAAY,MAAM,2BAA2B;AAClG,SAAO,IAAI,2BAA2B,IAAI;AAC9C;AAWO,SAAS,2BAA2B,SAAkB,YAA4B;AACrF,QAAM,SAAS;AACf,MAAI,UAAU,OAAO,OAAO,qBAAqB,YAAY;AACzD,WAAO,iBAAA;AAAA,EACX;AACJ;"}
|
|
1
|
+
{"version":3,"file":"navigation.js","names":[],"sources":["../src/navigation/navigation.ts"],"sourcesContent":["/**\n * Babylon.js `@babylonjs/addons/navigation` compatibility wrapper over Babylon\n * Lite's native navigation API (`createNavigationPluginAsync` / `createNavMesh` /\n * `createDebugNavMeshGeometry` / `createNavCrowd` / …).\n *\n * The Babylon.js navigation addon (`RecastNavigationJSPluginV2`, created via\n * `CreateNavigationPluginAsync`) is a thin wrapper around `recast-navigation-js`.\n * Babylon Lite ships its own Recast V2 integration with the same capabilities, so\n * this module mirrors the addon's public plugin/crowd surface and delegates to\n * Lite. The Recast instance the scene injects via `{ instance }` is ignored —\n * Lite loads its own Recast wasm (served at `/recast-navigation.wasm`).\n *\n * Only the surface exercised by ported scenes is implemented (`createNavMesh`,\n * `createDebugNavMesh`, `getClosestPoint`, `createCrowd` + `addAgent`); the rest\n * of the addon API is intentionally omitted.\n */\n\nimport {\n createNavigationPluginAsync as liteCreateNavigationPluginAsync,\n createNavMesh as liteCreateNavMesh,\n createDebugNavMeshGeometry as liteCreateDebugNavMeshGeometry,\n getClosestPoint as liteGetClosestPoint,\n computePath as liteComputePath,\n raycast as liteRaycast,\n createNavCrowd as liteCreateNavCrowd,\n addAgent as liteAddAgent,\n getAgentPosition as liteGetAgentPosition,\n agentGoto as liteAgentGoto,\n updateNavCrowd as liteUpdateNavCrowd,\n addBoxObstacle as liteAddBoxObstacle,\n addCylinderObstacle as liteAddCylinderObstacle,\n removeObstacle as liteRemoveObstacle,\n updateNavMeshObstacles as liteUpdateNavMeshObstacles,\n createMeshFromData,\n type NavigationPlugin as LiteNavigationPlugin,\n type NavCrowd as LiteNavCrowd,\n type Mesh as LiteMesh,\n type ObstacleHandle as LiteObstacleHandle,\n} from \"babylon-lite\";\n\nimport { Mesh, registerMeshAtStart } from \"../meshes/meshes.js\";\nimport { Vector3 } from \"../math/vector.js\";\nimport type { Scene } from \"../scene/scene.js\";\n\ninterface Vec3Like {\n x: number;\n y: number;\n z: number;\n}\n\ninterface AgentTransform {\n position: { set(x: number, y: number, z: number): unknown };\n}\n\n/**\n * Result of {@link RecastNavigationJSPluginV2.createNavMesh}. Babylon.js's\n * tile-cache navmesh build returns `{ navMesh, tileCache }`; here both reference\n * the plugin so {@link WaitForFullTileCacheUpdate} can reach it.\n */\ninterface NavMeshResult {\n navMesh: RecastNavigationJSPluginV2;\n tileCache: RecastNavigationJSPluginV2;\n}\n\n/** Babylon.js `IAgentParameters` subset accepted by `RecastJSCrowd.addAgent`. */\ninterface AgentParameters {\n radius: number;\n height: number;\n maxAcceleration: number;\n maxSpeed: number;\n collisionQueryRange: number;\n pathOptimizationRange: number;\n separationWeight: number;\n reachRadius?: number;\n}\n\n/**\n * Babylon.js `RecastJSCrowd` (subset) — owns crowd agents and syncs each agent's\n * Babylon transform to the simulated position every frame, exactly like the addon.\n */\nclass RecastJSCrowd {\n /** @internal */ public readonly _lite: LiteNavCrowd;\n private readonly _transforms = new Map<number, AgentTransform>();\n private readonly _plugin: RecastNavigationJSPluginV2;\n\n public constructor(lite: LiteNavCrowd, plugin: RecastNavigationJSPluginV2, scene: Scene) {\n this._lite = lite;\n this._plugin = plugin;\n // Babylon.js' crowd advances the simulation and writes back agent transforms\n // on the scene's before-render tick; mirror that over Lite's manual crowd update.\n // The plugin's `timeFactor` scales the step (0 freezes the crowd — used by parity\n // tests via `?freeze=1`).\n scene.onBeforeRenderObservable.add(() => {\n liteUpdateNavCrowd(this._lite, (1 / 60) * this._plugin.timeFactor);\n for (const [index, transform] of this._transforms) {\n const p = liteGetAgentPosition(this._lite, index);\n transform.position.set(p.x, p.y, p.z);\n }\n });\n }\n\n /** Babylon.js `crowd.addAgent(pos, parameters, transform)` — returns the agent index. */\n public addAgent(pos: Vec3Like, parameters: AgentParameters, transform: AgentTransform): number {\n const index = liteAddAgent(this._lite, { x: pos.x, y: pos.y, z: pos.z }, parameters);\n this._transforms.set(index, transform);\n return index;\n }\n\n /** Babylon.js `crowd.getAgentPosition(index)`. */\n public getAgentPosition(index: number): Vector3 {\n const p = liteGetAgentPosition(this._lite, index);\n return new Vector3(p.x, p.y, p.z);\n }\n\n /** Babylon.js `crowd.agentGoto(index, destination)` — request the agent to move toward a target. */\n public agentGoto(index: number, destination: Vec3Like): void {\n liteAgentGoto(this._lite, index, { x: destination.x, y: destination.y, z: destination.z });\n }\n}\n\n/**\n * Babylon.js `RecastNavigationJSPluginV2` (subset) over Babylon Lite navigation.\n */\nclass RecastNavigationJSPluginV2 {\n /** @internal */ public readonly _lite: LiteNavigationPlugin;\n /**\n * Babylon.js `plugin.timeFactor` — multiplier applied to each crowd update step.\n * `0` pauses crowd movement (used by parity tests); default `1`.\n */\n public timeFactor = 1;\n\n public constructor(lite: LiteNavigationPlugin) {\n this._lite = lite;\n }\n\n /**\n * Babylon.js `plugin.createNavMesh(meshes, parameters)`. Returns a\n * `{ navMesh, tileCache }` handle (both reference this plugin) so scenes using\n * the tile-cache obstacle API can pass them to {@link WaitForFullTileCacheUpdate}.\n * Scenes that ignore the return (the non-obstacle navmesh scenes) are unaffected.\n */\n public createNavMesh(meshes: Array<{ _lite: LiteMesh }>, parameters: Record<string, unknown>): NavMeshResult {\n liteCreateNavMesh(\n this._lite,\n meshes.map((m) => m._lite),\n parameters as never\n );\n return { navMesh: this, tileCache: this };\n }\n\n /** Babylon.js `plugin.addCylinderObstacle(position, radius, height)` — tile-cache obstacle. */\n public addCylinderObstacle(position: Vec3Like, radius: number, height: number): LiteObstacleHandle | null {\n return liteAddCylinderObstacle(this._lite, { x: position.x, y: position.y, z: position.z }, radius, height);\n }\n\n /** Babylon.js `plugin.addBoxObstacle(position, extent, angle)` — tile-cache obstacle (`extent` = half-extents). */\n public addBoxObstacle(position: Vec3Like, extent: Vec3Like, angle: number): LiteObstacleHandle | null {\n return liteAddBoxObstacle(this._lite, { x: position.x, y: position.y, z: position.z }, { x: extent.x, y: extent.y, z: extent.z }, angle);\n }\n\n /** Babylon.js `plugin.removeObstacle(obstacle)` — remove a previously-added tile-cache obstacle. */\n public removeObstacle(obstacle: LiteObstacleHandle): void {\n liteRemoveObstacle(this._lite, obstacle);\n }\n\n /** @internal Apply pending tile-cache obstacle updates (drives {@link WaitForFullTileCacheUpdate}). */\n public _updateObstacles(): void {\n liteUpdateNavMeshObstacles(this._lite);\n }\n\n /** Babylon.js `plugin.createDebugNavMesh(scene)` — builds a renderable debug mesh. */\n public createDebugNavMesh(scene: Scene): Mesh {\n const geo = liteCreateDebugNavMeshGeometry(this._lite);\n const engine = scene.getEngine()._lite;\n const lite = createMeshFromData(engine, \"navDebugMesh\", geo.positions, geo.normals, geo.indices);\n return registerMeshAtStart(new Mesh(\"navDebugMesh\", lite, scene), scene);\n }\n\n /** Babylon.js `plugin.getClosestPoint(position)` — snap to the navmesh. */\n public getClosestPoint(position: Vec3Like): Vector3 {\n const p = liteGetClosestPoint(this._lite, { x: position.x, y: position.y, z: position.z });\n return new Vector3(p.x, p.y, p.z);\n }\n\n /** Babylon.js `plugin.computePath(start, end)` — navmesh-snapped path as world points. */\n public computePath(start: Vec3Like, end: Vec3Like): Vector3[] {\n const points = liteComputePath(this._lite, { x: start.x, y: start.y, z: start.z }, { x: end.x, y: end.y, z: end.z });\n return points.map((p) => new Vector3(p.x, p.y, p.z));\n }\n\n /** Babylon.js `plugin.computePathSmooth(start, end)` — alias of {@link computePath} (Lite smooths internally). */\n public computePathSmooth(start: Vec3Like, end: Vec3Like): Vector3[] {\n return this.computePath(start, end);\n }\n\n /**\n * Babylon.js `plugin.raycast(start, end)` — walkability raycast on the navmesh.\n * Returns `{ hit, hitPoint? }` (`hitPoint` is a `Vector3` when `hit`).\n */\n public raycast(start: Vec3Like, end: Vec3Like): { hit: boolean; hitPoint?: Vector3 } {\n const r = liteRaycast(this._lite, { x: start.x, y: start.y, z: start.z }, { x: end.x, y: end.y, z: end.z });\n return r.hit && r.hitPoint ? { hit: true, hitPoint: new Vector3(r.hitPoint.x, r.hitPoint.y, r.hitPoint.z) } : { hit: false };\n }\n\n /** Babylon.js `plugin.createCrowd(maxAgents, maxAgentRadius, scene)`. */\n public createCrowd(maxAgents: number, maxAgentRadius: number, scene: Scene): RecastJSCrowd {\n const crowd = liteCreateNavCrowd(this._lite, maxAgents, maxAgentRadius);\n return new RecastJSCrowd(crowd, this, scene);\n }\n}\n\n/**\n * Babylon.js `@babylonjs/addons/navigation` `CreateNavigationPluginAsync`. The\n * injected Recast `instance` (if any) is ignored — Babylon Lite loads its own\n * Recast wasm from `/recast-navigation.wasm`.\n */\nexport async function CreateNavigationPluginAsync(_options?: { version?: string; instance?: unknown }): Promise<RecastNavigationJSPluginV2> {\n const lite = await liteCreateNavigationPluginAsync({ locateFile: () => \"/recast-navigation.wasm\" });\n return new RecastNavigationJSPluginV2(lite);\n}\n\nexport { RecastNavigationJSPluginV2, RecastJSCrowd };\n\n/**\n * Babylon.js `@babylonjs/addons/navigation/common/tile-cache`\n * `WaitForFullTileCacheUpdate(navMesh, tileCache)` — block until pending\n * tile-cache obstacle updates are applied. The addon takes the raw navMesh /\n * tileCache; here `navMesh` is the compat plugin (returned from `createNavMesh`),\n * so this delegates to Babylon Lite's `updateNavMeshObstacles`.\n */\nexport function WaitForFullTileCacheUpdate(navMesh: unknown, _tileCache?: unknown): void {\n const plugin = navMesh as RecastNavigationJSPluginV2 | undefined;\n if (plugin && typeof plugin._updateObstacles === \"function\") {\n plugin._updateObstacles();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgFA,IAAM,gBAAN,MAAoB;kBACC;CACjB,8BAA+B,IAAI,IAA4B;CAC/D;CAEA,YAAmB,MAAoB,QAAoC,OAAc;EACrF,KAAK,QAAQ;EACb,KAAK,UAAU;EAKf,MAAM,yBAAyB,UAAU;GACrC,eAAmB,KAAK,OAAQ,IAAI,KAAM,KAAK,QAAQ,UAAU;GACjE,KAAK,MAAM,CAAC,OAAO,cAAc,KAAK,aAAa;IAC/C,MAAM,IAAI,iBAAqB,KAAK,OAAO,KAAK;IAChD,UAAU,SAAS,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;GACxC;EACJ,CAAC;CACL;;CAGA,SAAgB,KAAe,YAA6B,WAAmC;EAC3F,MAAM,QAAQ,SAAa,KAAK,OAAO;GAAE,GAAG,IAAI;GAAG,GAAG,IAAI;GAAG,GAAG,IAAI;EAAE,GAAG,UAAU;EACnF,KAAK,YAAY,IAAI,OAAO,SAAS;EACrC,OAAO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B;CACrF,MAAM,SAAS;CACf,IAAI,UAAU,OAAO,OAAO,qBAAqB,YAC7C,OAAO,iBAAiB;AAEhC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/lite-compat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0-preview",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Opt-in Babylon.js-shaped compatibility layer implemented on top of the Babylon Lite public API. Provides a migration runway from Babylon.js to Babylon Lite.",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"babylonLiteRelease": {
|
|
50
|
-
"azureBuildId": "
|
|
51
|
-
"sourceVersion": "
|
|
52
|
-
"builtAgainstLite": "1.
|
|
50
|
+
"azureBuildId": "59904",
|
|
51
|
+
"sourceVersion": "3ce8ae6d34945f4c32c73e357714ffa43be41584",
|
|
52
|
+
"builtAgainstLite": "1.31.0"
|
|
53
53
|
}
|
|
54
54
|
}
|