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: align playcanvas helpers with three helpers
isaac-mason committed Oct 6, 2024
commit 48f0625f6ab598407a68736f06cd9609a6644e0d
39 changes: 20 additions & 19 deletions packages/recast-navigation-playcanvas/src/debug/debug-drawer.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ import {
StandardMaterial,
TYPE_FLOAT32,
VertexBuffer,
VertexFormat
VertexFormat,
} from 'playcanvas';

/**
@@ -61,23 +61,20 @@ export class DebugDrawer extends Entity {
pointMaterial: StandardMaterial;
lineMaterial: StandardMaterial;

private app: AppBase;
private graphicsDevice: GraphicsDevice;
private debugDrawImpl: any; // Replace 'any' with the actual type if available
private currentVertices: VertexData[] = [];
private currentPrimitive: number = 0;

constructor({
app,
triMaterial,
pointMaterial,
lineMaterial,
}: DebugDrawerParams) {
constructor(graphicsDevice: GraphicsDevice, params?: DebugDrawerParams) {
super();

this.app = app;
this.graphicsDevice = graphicsDevice;

this.triMaterial = triMaterial || new StandardMaterial();
if (!triMaterial) {
if (params?.triMaterial) {
this.triMaterial = params.triMaterial;
} else {
this.triMaterial = new StandardMaterial();
this.triMaterial.useLighting = false;
this.triMaterial.diffuse = new Color(1, 1, 1);
this.triMaterial.opacity = 0.4;
@@ -86,14 +83,18 @@ export class DebugDrawer extends Entity {
this.triMaterial.update();
}

this.pointMaterial = pointMaterial || new StandardMaterial();
if (!pointMaterial) {
if (params?.pointMaterial) {
this.pointMaterial = params.pointMaterial;
} else {
this.pointMaterial = new StandardMaterial();
this.pointMaterial.useLighting = false;
this.pointMaterial.update();
}

this.lineMaterial = lineMaterial || new StandardMaterial();
if (!lineMaterial) {
if (params?.lineMaterial) {
this.lineMaterial = params.lineMaterial;
} else {
this.lineMaterial = new StandardMaterial();
this.lineMaterial.useLighting = false;
this.lineMaterial.diffuse = new Color(1, 1, 1);
this.lineMaterial.emissive = new Color(1, 1, 1);
@@ -319,7 +320,7 @@ export class DebugDrawer extends Entity {
}

private endPoints(): void {
const graphicsDevice = this.app.graphicsDevice;
const graphicsDevice = this.graphicsDevice;

const positions: number[] = [];
const colors: number[] = [];
@@ -340,7 +341,7 @@ export class DebugDrawer extends Entity {
}

private endLines(): void {
const graphicsDevice = this.app.graphicsDevice;
const graphicsDevice = this.graphicsDevice;

const positions: number[] = [];
const colors: number[] = [];
@@ -361,7 +362,7 @@ export class DebugDrawer extends Entity {
}

private endTris(): void {
const graphicsDevice = this.app.graphicsDevice;
const graphicsDevice = this.graphicsDevice;

const positions: number[] = [];
const colors: number[] = [];
@@ -383,7 +384,7 @@ export class DebugDrawer extends Entity {

private endQuads(): void {
// Quads are converted to triangles
const graphicsDevice = this.app.graphicsDevice;
const graphicsDevice = this.graphicsDevice;

const positions: number[] = [];
const colors: number[] = [];
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ import {
} from 'playcanvas';

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

@@ -36,17 +35,18 @@ export class CrowdHelper extends GraphNode {
agentMeshData = new Map<number, CrowdAgentData>();

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

this.agentMeshData = new Map();
this.recastCrowd = crowd;
this.graphicsDevice = graphicsDevice;

if (agentMaterial) {
this.agentMaterial = agentMaterial;
if (params?.agentMaterial) {
this.agentMaterial = params.agentMaterial;
} else {
const material = new StandardMaterial();
material.diffuse.set(1, 0, 0);
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import {
} from 'playcanvas';

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

@@ -26,15 +25,17 @@ export class NavMeshHelper extends Entity {
mesh!: Mesh;

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

this.navMesh = navMesh;

// Create material if not provided
this.navMeshMaterial = navMeshMaterial || this.createDefaultMaterial();
this.navMeshMaterial =
params?.navMeshMaterial || this.createDefaultMaterial();

// Update the mesh
this.updateMesh(graphicsDevice);
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ import {
* Parameters for creating OffMeshConnectionsHelper.
*/
export type OffMeshConnectionsHelperParams = {
offMeshConnections?: OffMeshConnectionParams[];
entryCircleMaterial?: Material;
exitCircleMaterial?: Material;
lineMaterial?: Material;
@@ -40,13 +39,16 @@ export class OffMeshConnectionsHelper extends Entity {

lineMaterial: Material;

constructor(params: OffMeshConnectionsHelperParams) {
constructor(
offMeshConnections: OffMeshConnectionParams[],
params?: OffMeshConnectionsHelperParams
) {
super();

this.offMeshConnections = params.offMeshConnections || [];
this.offMeshConnections = offMeshConnections;

// Initialize materials
if (params.entryCircleMaterial) {
if (params?.entryCircleMaterial) {
this.entryCircleMaterial = params.entryCircleMaterial;
} else {
this.entryCircleMaterial = new StandardMaterial();
@@ -62,11 +64,11 @@ export class OffMeshConnectionsHelper extends Entity {
this.entryCircleMaterial.update();
}

if (params.exitCircleMaterial) {
if (params?.exitCircleMaterial) {
this.exitCircleMaterial = params.exitCircleMaterial;
} else {
this.exitCircleMaterial = new StandardMaterial();

if ('diffuse' in this.exitCircleMaterial) {
this.exitCircleMaterial.diffuse = new Color(0, 0, 1); // Blue
}
@@ -76,7 +78,7 @@ export class OffMeshConnectionsHelper extends Entity {
this.exitCircleMaterial.update();
}

if (params.lineMaterial) {
if (params?.lineMaterial) {
this.lineMaterial = params.lineMaterial;
} else {
this.lineMaterial = new StandardMaterial();
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import {
* Parameters for creating TileCacheHelper.
*/
export type TileCacheHelperParams = {
tileCache: TileCache;
obstacleMaterial?: StandardMaterial;
};

@@ -23,14 +22,14 @@ export class TileCacheHelper extends Entity {
obstacleMeshes = new Map<Obstacle, Entity>();
obstacleMaterial: StandardMaterial;

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

this.tileCache = tileCache;

// Initialize obstacleMaterial
if (obstacleMaterial) {
this.obstacleMaterial = obstacleMaterial;
if (params?.obstacleMaterial) {
this.obstacleMaterial = params.obstacleMaterial;
} else {
this.obstacleMaterial = new StandardMaterial();
this.obstacleMaterial.diffuse = new Color(1, 0, 0); // Red color