Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @recast-navigation/playcanvas package #438

Merged
merged 34 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cdb2d95
Add PlayCanvas integration to Recast Navigation
marklundin Sep 30, 2024
ac2c638
feat: remove the 'three' entrypoint from 'recast-navigation'
isaac-mason Oct 4, 2024
01ce88c
chore: align @recast-navigation/playcanvas version with other packages
isaac-mason Oct 4, 2024
f1667f8
fix: add playcanvas as dev dependency of @react-navigation/playcanvas
isaac-mason Oct 4, 2024
620be91
feat: simplify three examples
isaac-mason Oct 4, 2024
609f755
feat: avoid cloning meshes and geometry in getPositionsAndIndices
isaac-mason Oct 4, 2024
dcfa4dc
fix: changesets config
isaac-mason Oct 4, 2024
7bdbad4
feat: playcanvas lib changes, fix type errors
isaac-mason Oct 5, 2024
fd85b46
feat: add playcanvas example
isaac-mason Oct 5, 2024
7b7d247
feat: refactor playcanvas off mesh connections helper
isaac-mason Oct 5, 2024
dab8f6e
chore: update README.md
isaac-mason Oct 5, 2024
61ab4cb
feat: change three debug helpers to take required params as standalon…
isaac-mason Oct 6, 2024
e13870d
fix: test package.json scripts
isaac-mason Oct 6, 2024
86a9c6c
fix: build package.json scripts
isaac-mason Oct 6, 2024
b1bf2f2
chore: rename playcanvas example package
isaac-mason Oct 6, 2024
48f0625
feat: align playcanvas helpers with three helpers
isaac-mason Oct 6, 2024
49891ca
feat: move common three and playcanvas debug drawer code into @recast…
isaac-mason Oct 6, 2024
9950f7b
fix: remove react plugin from vite examples
isaac-mason Oct 6, 2024
760c17d
chore: stop using concurrently in scripts
isaac-mason Oct 9, 2024
5574b50
chore: fix test:bundlers-smoke-test script
isaac-mason Oct 9, 2024
092ff70
chore: rename basic three vite example
isaac-mason Oct 9, 2024
6ed4773
chore: bump vite and vitest
isaac-mason Oct 9, 2024
afb84e3
fix: playcanvas example
isaac-mason Oct 9, 2024
42c0bdd
chore: update test:packages script
isaac-mason Oct 9, 2024
f7ded1b
chore: don't build examples in ci
isaac-mason Oct 9, 2024
3f32040
chore: update README.md
isaac-mason Oct 9, 2024
338f92b
feat: refactor playcanvas OffMeshConnectionsHelper
isaac-mason Oct 9, 2024
4d6851a
feat: refactor playcanvas helpers
isaac-mason Oct 9, 2024
c58686f
chore: bump three version
isaac-mason Oct 9, 2024
5731dfc
chore: update changeset
isaac-mason Oct 15, 2024
046c046
chore: update README.md
isaac-mason Oct 15, 2024
98d0b25
chore: update README.md
isaac-mason Oct 15, 2024
7a0d214
chore: update README.md
isaac-mason Oct 15, 2024
e250c41
fix: typedoc docs
isaac-mason Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: change three debug helpers to take required params as standalon…
…e constructor arguments
isaac-mason committed Oct 6, 2024
commit 61ab4cb64f34c1db507722d2b4aba578114d0720
5 changes: 5 additions & 0 deletions .changeset/thin-planes-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@recast-navigation/three': minor
---

feat: change three debug helpers to take required params as standalone constructor arguments
26 changes: 13 additions & 13 deletions apps/navmesh-website/src/features/recast/crowd/recast-agent.tsx
Original file line number Diff line number Diff line change
@@ -69,20 +69,20 @@ export const RecastAgent = forwardRef<RecastAgentRef, RecastAgentProps>(
maxAgentRadius: agentRadius,
});

const { point: agentPosition } = navMeshQuery.findClosestPoint({ x: 0, y: 0, z: 0 });

const agent = crowd.addAgent(
agentPosition,
{
radius: agentRadius,
height: agentHeight,
maxAcceleration: agentMaxAcceleration,
maxSpeed: agentMaxSpeed,
}
);
const { point: agentPosition } = navMeshQuery.findClosestPoint({
x: 0,
y: 0,
z: 0,
});

const agent = crowd.addAgent(agentPosition, {
radius: agentRadius,
height: agentHeight,
maxAcceleration: agentMaxAcceleration,
maxSpeed: agentMaxSpeed,
});

const crowdHelper = new CrowdHelper({
crowd,
const crowdHelper = new CrowdHelper(crowd, {
agentMaterial: new MeshStandardMaterial({ color: 'red' }),
});

2 changes: 1 addition & 1 deletion examples/three-parcel-example/index.js
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ const init = async () => {
const { success, navMesh } = threeToSoloNavMesh([mesh]);

if (success) {
const navMeshHelper = new NavMeshHelper({ navMesh });
const navMeshHelper = new NavMeshHelper(navMesh);

scene.add(navMeshHelper);
}
2 changes: 1 addition & 1 deletion examples/three-vite-wasm-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ const init = async () => {
const { success, navMesh } = threeToSoloNavMesh([mesh]);

if (success) {
const navMeshHelper = new NavMeshHelper({ navMesh });
const navMeshHelper = new NavMeshHelper(navMesh);

scene.add(navMeshHelper);
}
24 changes: 10 additions & 14 deletions packages/recast-navigation-three/README.md
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ This package provides helpers for visualizing various recast-navigation objects
```ts
import { NavMeshHelper } from '@recast-navigation/three';

const navMeshHelper = new NavMeshHelper({ navMesh });
const navMeshHelper = new NavMeshHelper(navMesh);

scene.add(navMeshHelper);

@@ -131,9 +131,9 @@ navMeshHelper.update();
```ts
import { OffMeshConnectionsHelper } from '@recast-navigation/three';

const offMeshConnectionsHelper = new OffMeshConnectionsHelper({
offMeshConnections,
});
const offMeshConnectionsHelper = new OffMeshConnectionsHelper(
offMeshConnections
);

scene.add(offMeshConnectionsHelper);
```
@@ -145,7 +145,7 @@ Visualises obstacles in a `TileCache`.
```ts
import { TileCacheHelper } from '@recast-navigation/three';

const tileCacheHelper = new TileCacheHelper({ tileCache });
const tileCacheHelper = new TileCacheHelper(tileCache);

scene.add(tileCacheHelper);

@@ -160,7 +160,7 @@ Visualises agents in a `Crowd`.
```ts
import { CrowdHelper } from '@recast-navigation/three';

const crowdHelper = new CrowdHelper({ crowd });
const crowdHelper = new CrowdHelper(crowd);

scene.add(crowdHelper);

@@ -175,8 +175,7 @@ You can optionally provide custom materials to the helpers.
```ts
// NavMeshHelper
const navMeshMaterial = new THREE.MeshBasicMaterial({ color: 'red' });
const navMeshHelper = new NavMeshHelper({
navMesh,
const navMeshHelper = new NavMeshHelper(navMesh, {
navMeshMaterial,
});

@@ -190,24 +189,21 @@ const offMeshConnectionExitCircleMaterial = new THREE.MeshBasicMaterial({
const offMeshConnectionLineMaterial = new THREE.LineBasicMaterial({
color: 'white',
});
const offMeshConnectionsHelper = new OffMeshConnectionsHelper({
offMeshConnections,
const offMeshConnectionsHelper = new OffMeshConnectionsHelper(offMeshConnections, {
entryCircleMaterial: offMeshConnectionEntryCircleMaterial,
exitCircleMaterial: offMeshConnectionExitCircleMaterial,
lineMaterial: offMeshConnectionLineMaterial,
});

// TileCacheHelper
const obstacleMaterial = new THREE.MeshBasicMaterial({ color: 'blue' });
const tileCacheHelper = new TileCacheHelper({
tileCache,
const tileCacheHelper = new TileCacheHelper(tileCache, {
obstacleMaterial,
});

// CrowdHelper
const agentMaterial = new THREE.MeshBasicMaterial({ color: 'red' });
const crowdHelper = new CrowdHelper({
crowd,
const crowdHelper = new CrowdHelper(crowd, {
agentMaterial,
});
```
5 changes: 2 additions & 3 deletions packages/recast-navigation-three/src/helpers/crowd-helper.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import {
} from 'three';

export type CrowdHelperParams = {
crowd: Crowd;
agentMaterial?: Material;
};

@@ -20,13 +19,13 @@ export class CrowdHelper extends Object3D {

agentMaterial: Material;

constructor({ crowd, agentMaterial }: CrowdHelperParams) {
constructor(crowd: Crowd, params?: CrowdHelperParams) {
super();

this.recastCrowd = crowd;

this.agentMaterial =
agentMaterial ?? new MeshBasicMaterial({ color: 'red' });
params?.agentMaterial ?? new MeshBasicMaterial({ color: 'red' });

this.update();
}
25 changes: 13 additions & 12 deletions packages/recast-navigation-three/src/helpers/nav-mesh-helper.ts
Original file line number Diff line number Diff line change
@@ -9,28 +9,27 @@ import {
} from 'three';

export type NavMeshHelperParams = {
navMesh: NavMesh;
navMeshMaterial?: Material;
};

export class NavMeshHelper extends Object3D {
navMesh: NavMesh;

navMeshMaterial: Material;

mesh: Mesh;

geometry: BufferGeometry;
navMeshMaterial: Material;

navMeshGeometry: BufferGeometry;

constructor({ navMesh, navMeshMaterial }: NavMeshHelperParams) {
constructor(navMesh: NavMesh, params?: NavMeshHelperParams) {
super();

this.navMesh = navMesh;

this.geometry = new BufferGeometry();
this.navMeshGeometry = new BufferGeometry();

this.navMeshMaterial = navMeshMaterial
? navMeshMaterial
this.navMeshMaterial = params?.navMeshMaterial
? params.navMeshMaterial
: new MeshBasicMaterial({
color: 'orange',
transparent: true,
@@ -40,7 +39,7 @@ export class NavMeshHelper extends Object3D {

this.update();

this.mesh = new Mesh(this.geometry, this.navMeshMaterial);
this.mesh = new Mesh(this.navMeshGeometry, this.navMeshMaterial);

this.add(this.mesh);
}
@@ -53,11 +52,13 @@ export class NavMeshHelper extends Object3D {
update() {
const [positions, indices] = this.navMesh.getDebugNavMesh();

this.geometry.setAttribute(
this.navMeshGeometry.setAttribute(
'position',
new BufferAttribute(Float32Array.from(positions), 3)
);
this.geometry.setIndex(new BufferAttribute(Uint32Array.from(indices), 1));
this.geometry.computeVertexNormals();
this.navMeshGeometry.setIndex(
new BufferAttribute(Uint32Array.from(indices), 1)
);
this.navMeshGeometry.computeVertexNormals();
}
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import {
} from 'three';

export type OffMeshConnectionsHelperParams = {
offMeshConnections?: OffMeshConnectionParams[];
entryCircleMaterial?: Material;
exitCircleMaterial?: Material;
lineMaterial?: LineBasicMaterial;
@@ -28,23 +27,22 @@ export class OffMeshConnectionsHelper extends Object3D {

lineMaterial: LineBasicMaterial;

constructor({
offMeshConnections,
entryCircleMaterial,
exitCircleMaterial,
lineMaterial,
}: OffMeshConnectionsHelperParams) {
constructor(
offMeshConnections: OffMeshConnectionParams[],
params?: OffMeshConnectionsHelperParams
) {
super();

this.offMeshConnections = offMeshConnections ?? [];

this.entryCircleMaterial =
entryCircleMaterial ?? new MeshBasicMaterial({ color: 'green' });
params?.entryCircleMaterial ?? new MeshBasicMaterial({ color: 'green' });

this.exitCircleMaterial =
exitCircleMaterial ?? new MeshBasicMaterial({ color: 'blue' });
params?.exitCircleMaterial ?? new MeshBasicMaterial({ color: 'blue' });

this.lineMaterial = lineMaterial ?? new LineBasicMaterial({ color: 'red' });
this.lineMaterial =
params?.lineMaterial ?? new LineBasicMaterial({ color: 'red' });

this.update();
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ import {
} from 'three';

export type TileCacheHelperParams = {
tileCache: TileCache;
obstacleMaterial?: Material;
};

@@ -21,13 +20,13 @@ export class TileCacheHelper extends Object3D {

obstacleMaterial: Material;

constructor({ tileCache, obstacleMaterial }: TileCacheHelperParams) {
constructor(tileCache: TileCache, params?: TileCacheHelperParams) {
super();

this.tileCache = tileCache;

this.obstacleMaterial = obstacleMaterial
? obstacleMaterial
this.obstacleMaterial = params?.obstacleMaterial
? params.obstacleMaterial
: new MeshBasicMaterial({
color: 'red',
wireframe: true,
13 changes: 4 additions & 9 deletions packages/recast-navigation/.storybook/common/debug.tsx
Original file line number Diff line number Diff line change
@@ -38,36 +38,31 @@ export const Debug = ({
const navMeshHelper = useMemo(() => {
if (!navMesh) return null;

return new NavMeshHelper({
navMesh,
return new NavMeshHelper(navMesh, {
navMeshMaterial,
});
}, [navMesh, navMeshMaterial]);

const tileCacheHelper = useMemo(() => {
if (!tileCache) return null;

return new TileCacheHelper({
tileCache,
return new TileCacheHelper(tileCache, {
obstacleMaterial,
});
}, [tileCache, obstacleMaterial]);

const crowdHelper = useMemo(() => {
if (!crowd) return null;

return new CrowdHelper({
crowd,
return new CrowdHelper(crowd, {
agentMaterial,
});
}, [crowd, agentMaterial]);

const offMeshConnectionsHelper = useMemo(() => {
if (!offMeshConnections) return null;

return new OffMeshConnectionsHelper({
offMeshConnections,
});
return new OffMeshConnectionsHelper(offMeshConnections);
}, [offMeshConnections]);

useFrame(() => {
Original file line number Diff line number Diff line change
@@ -136,15 +136,20 @@ export const ThreePathfinding = () => {
y: 0,
z: 1.5,
};
const startGroupId = pathfinding.getGroup(ZONE, start, true);
const startGroupId = pathfinding.getGroup(ZONE, start as Vector3);

const end = {
x: 1.5,
y: 0,
z: -1.5,
};

const path = pathfinding.findPath(start, end, ZONE, startGroupId);
const path = pathfinding.findPath(
start as Vector3,
end as Vector3,
ZONE,
startGroupId
);

setNavMeshGeometry(geometry);
setPath(path);
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@ import {
NavMesh,
NavMeshQuery,
OffMeshConnectionParams,
QueryFilter,
Raw,
QueryFilter
} from '@recast-navigation/core';
import { threeToSoloNavMesh } from '@recast-navigation/three';
import React, { useEffect, useState } from 'react';
@@ -297,7 +296,7 @@ function computeSmoothPath(
const targetPos = new Vector3().copy(closestEnd);

const polys = [...findPathResult.polys.getHeapView()];
let smoothPath: Vector3[] = [];
const smoothPath: Vector3[] = [];

smoothPath.push(iterPos.clone());

Original file line number Diff line number Diff line change
@@ -3,10 +3,9 @@ import {
Detour,
NavMesh,
NavMeshQuery,
Raw,
TileCache,
statusDetail,
statusToReadableString,
statusToReadableString
} from '@recast-navigation/core';
import { threeToTileCache } from '@recast-navigation/three';
import React, { useEffect, useState } from 'react';