@jgengine/navbake 0.18.0
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/LICENSE +1 -0
- package/NOTICE +1 -0
- package/README.md +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +27 -0
- package/package.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Apache License 2.0
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
JGengine contributors
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NavMeshData } from "@jgengine/core/nav/navMesh";
|
|
2
|
+
export interface BakeNavMeshOptions {
|
|
3
|
+
positions: readonly number[];
|
|
4
|
+
indices: readonly number[];
|
|
5
|
+
agentRadius: number;
|
|
6
|
+
agentHeight: number;
|
|
7
|
+
maxSlope: number;
|
|
8
|
+
maxClimb: number;
|
|
9
|
+
}
|
|
10
|
+
/** Bake indexed walkable triangles into the engine's serializable nav-mesh format. */
|
|
11
|
+
export declare function bakeNavMesh(options: BakeNavMeshOptions): NavMeshData;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function triangleSlope(positions, a, b, c) {
|
|
2
|
+
const ax = positions[a * 3], ay = positions[a * 3 + 1], az = positions[a * 3 + 2];
|
|
3
|
+
const bx = positions[b * 3], by = positions[b * 3 + 1], bz = positions[b * 3 + 2];
|
|
4
|
+
const cx = positions[c * 3], cy = positions[c * 3 + 1], cz = positions[c * 3 + 2];
|
|
5
|
+
const ux = bx - ax, uy = by - ay, uz = bz - az;
|
|
6
|
+
const vx = cx - ax, vy = cy - ay, vz = cz - az;
|
|
7
|
+
const ny = ux * vz - uz * vx;
|
|
8
|
+
const nx = uy * vz - uz * vy;
|
|
9
|
+
const nz = ux * vy - uy * vx;
|
|
10
|
+
return Math.atan2(Math.hypot(nx, nz), Math.abs(ny)) * 180 / Math.PI;
|
|
11
|
+
}
|
|
12
|
+
/** Bake indexed walkable triangles into the engine's serializable nav-mesh format. */
|
|
13
|
+
export function bakeNavMesh(options) {
|
|
14
|
+
if (options.positions.length % 3 !== 0)
|
|
15
|
+
throw new Error("positions must contain xyz triples");
|
|
16
|
+
if (options.indices.length % 3 !== 0)
|
|
17
|
+
throw new Error("indices must contain triangle triples");
|
|
18
|
+
const polys = [];
|
|
19
|
+
for (let i = 0; i < options.indices.length; i += 3) {
|
|
20
|
+
const a = options.indices[i], b = options.indices[i + 1], c = options.indices[i + 2];
|
|
21
|
+
if (a < 0 || b < 0 || c < 0 || a * 3 + 2 >= options.positions.length || b * 3 + 2 >= options.positions.length || c * 3 + 2 >= options.positions.length)
|
|
22
|
+
continue;
|
|
23
|
+
if (triangleSlope(options.positions, a, b, c) <= Math.max(0, options.maxSlope))
|
|
24
|
+
polys.push([a, b, c]);
|
|
25
|
+
}
|
|
26
|
+
return { verts: Array.from(options.positions), polys, links: [] };
|
|
27
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jgengine/navbake",
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "Deterministic navigation-mesh baking for JGengine scenes.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": { "type": "git", "url": "git+https://github.com/Noisemaker111/jgengine.git", "directory": "packages/navbake" },
|
|
9
|
+
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
10
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" }, "./*": { "types": "./dist/*.d.ts", "default": "./dist/*.js" } },
|
|
11
|
+
"scripts": { "build": "tsgo -p tsconfig.build.json && bun ../../scripts/fix-extensions.ts dist", "check-types": "bun ../../scripts/check-types-preflight.ts && tsgo --noEmit -p tsconfig.json", "test": "bun test src" },
|
|
12
|
+
"dependencies": { "@jgengine/core": "^0.18.0", "recast-navigation": "^0.34.0" },
|
|
13
|
+
"publishConfig": { "access": "public" }
|
|
14
|
+
}
|