Skip to content

Commit

Permalink
Hotfix to hardcode recast-detour package to previous release, as the …
Browse files Browse the repository at this point in the history
…latest package that BabylonJS automatically downloads breaks the build.
  • Loading branch information
ericbroberic committed Sep 24, 2021
1 parent 53eecdb commit d5b053d
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/gameplay/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RecastJSPlugin, Mesh, Vector3, ICrowd, TransformNode } from 'babylonjs';
import { BabylonStore } from '../store/babylonStore';
import * as Recast from '../libraries/recast-detour';

/**
* A Navigation utility class that will handle generating and interacting with the NavMesh. It will also handle AI agents moving around the map.
Expand All @@ -15,7 +16,7 @@ export class Navigation {
* @param meshes The meshes that will be used to generate the NavMesh.
*/
public static init(meshes: Mesh[]): void {
this._plugin = new RecastJSPlugin();
this._plugin = new RecastJSPlugin(Recast);

this._plugin.createNavMesh(meshes, {
cs: 0.2,
Expand Down
43 changes: 43 additions & 0 deletions src/libraries/recast-detour/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"_from": "[email protected]",
"_id": "[email protected]",
"_inBundle": false,
"_integrity": "sha512-d69n2yZl79MFynmAs/Vkkt2J6RYkBkdO5JOw3T7NfkGD9sltRAnstFVTH9mYJwBgOgdlXuzbUBV6EgpscTMzvA==",
"_location": "/recast-detour",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "[email protected]",
"name": "recast-detour",
"escapedName": "recast-detour",
"rawSpec": "1.3.0",
"saveSpec": null,
"fetchSpec": "1.3.0"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/recast-detour/-/recast-detour-1.3.0.tgz",
"_shasum": "d21532b219d10c6b6b578ac5220b8e50f4db3790",
"_spec": "[email protected]",
"_where": "C:\\Users\\eric\\source\\repos\\killer-bunnies",
"author": "",
"bundleDependencies": false,
"deprecated": false,
"description": "recastjs is a port of recastnavigation and a thin abstraction layer using emscripten. https://github.com/emscripten-core/emscripten\r This port allows the use of recastnavigation in your browser using JavaScript or WebAssembly.",
"keywords": [
"recast",
"detour",
"navigation",
"navmesh"
],
"license": "ISC",
"main": "recast.js",
"name": "recast-detour",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.3.0"
}
23 changes: 23 additions & 0 deletions src/libraries/recast-detour/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## What is recastjs ?

recastjs is a port of recastnavigation and a thin abstraction layer using emscripten. https://github.com/emscripten-core/emscripten
This port allows the use of recastnavigation in your browser using JavaScript or WebAssembly.

## What is recastnavigation ?

Recast is a navigation mesh construction toolset for games.
Recast is accompanied by Detour, a spatial reasoning toolkit.
You can use any navigation mesh with Detour, but of course the data generated by Recast fits perfectly.
The crowd management module provides you with features for agents handling and behavior customization

Some documentation is available here : http://masagroup.github.io/recastdetour/index.html

## How to extend recastjs ?

Recast/Detour can be difficult to use directly. A simplification layer is done thru src/recastjs.h/.cpp. All the functionnalities have to be exposed to JS by the IDL file.
Basically, that file lists all the structures, classes, methods visible to JS. The glue generation and build is handled ny make.py script. Any new functionnality should be written in recastjs.cpp file and exposed by the IDL
For more information on Web IDL : https://emscripten.org/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html

## License

Recastjs is licensed under the same terms as Recastnavigation.
114 changes: 114 additions & 0 deletions src/libraries/recast-detour/recast.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
export namespace Recast {
// eslint-disable-next-line @typescript-eslint/class-name-casing
export class rcConfig {
new ();
width: number;
height: number;
tileSize: number;
borderSize: number;
cs: number;
ch: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bmin: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bmax: any;
walkableSlopeAngle: number;
walkableHeight: number;
walkableClimb: number;
walkableRadius: number;
maxEdgeLen: number;
maxSimplificationError: number;
minRegionArea: number;
mergeRegionArea: number;
maxVertsPerPoly: number;
detailSampleDist: number;
detailSampleMaxError: number;
}
export class Vec3 {
new ();
new (x: number, y: number, z: number);
x: number;
y: number;
z: number;
}
export class Triangle {
new ();
getPoint(n: number): Vec3;
}
export class DebugNavMesh {
new ();
getTriangleCount(): number;
getTriangle(n: number): Triangle;
}
// eslint-disable-next-line @typescript-eslint/class-name-casing
export class dtNavMesh {
}
// eslint-disable-next-line @typescript-eslint/class-name-casing
export class dtObstacleRef {
}
export class NavmeshData {
new ();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dataPointer: any;
size: number;
}
export class NavPath {
getPointCount(): number;
getPoint(n: number): Vec3;
}
// eslint-disable-next-line @typescript-eslint/class-name-casing
export class dtCrowdAgentParams {
new ();
radius: number;
height: number;
maxAcceleration: number;
maxSpeed: number;
collisionQueryRange: number;
pathOptimizationRange: number;
separationWeight: number;
updateFlags: number;
obstacleAvoidanceType: number;
queryFilterType: number;
userData: unknown;
}
export class NavMesh {
new ();
destroy(): void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
build(positions: any, positionCount: number, indices: any, indexCount: number, config: rcConfig): void;
buildFromNavmeshData(data: NavmeshData): void;
getNavmeshData(): NavmeshData;
freeNavmeshData(data: NavmeshData): void;
getDebugNavMesh(): DebugNavMesh;
getClosestPoint(position: Vec3): Vec3;
getRandomPointAround(position: Vec3, maxRadius: number): Vec3;
moveAlong(position: Vec3, destination: Vec3): Vec3;
getNavMesh(): dtNavMesh;
computePath(start: Vec3, end: Vec3): NavPath;
setDefaultQueryExtent(extent: Vec3): void;
getDefaultQueryExtent(): Vec3;
addCylinderObstacle(position: Vec3, radius: number, height: number): dtObstacleRef;
addBoxObstacle(position: Vec3, extent: Vec3, angle: number): dtObstacleRef;
removeObstacle(obstacle: dtObstacleRef): void;
update(): void;
}
export class Crowd {
new (maxAgents: number, maxAgentRadius: number, nav: dtNavMesh);
destroy(): void;
addAgent(position: Vec3, params: dtCrowdAgentParams): number;
removeAgent(idx: number): void;
update(dt: number): void;
getAgentPosition(idx: number): Vec3;
getAgentVelocity(idx: number): Vec3;
getAgentNextTargetPath(idx: number): Vec3;
getAgentState(idx: number): number;
overOffmeshConnection(idx: number): boolean;
agentGoto(idx: number, destination: Vec3): void;
agentTeleport(idx: number, destination: Vec3): void;
getAgentParameters(idx: number): dtCrowdAgentParams;
setAgentParameters(idx: number, params: dtCrowdAgentParams): void;
setDefaultQueryExtent(extent: Vec3): void;
getDefaultQueryExtent(): Vec3;
getCorners(idx: number): NavPath;
}
}
39 changes: 39 additions & 0 deletions src/libraries/recast-detour/recast.js

Large diffs are not rendered by default.

0 comments on commit d5b053d

Please sign in to comment.