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
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"updateInternalDependencies": "patch",
"ignore": [
"navmesh-website",
"node-cjs-example",
"node-esm-example",
"parcel-example",
"vite-wasm-example",
"vite-worker-example"
"three-node-cjs-example",
"three-node-esm-example",
"three-vite-example",
"three-vite-worker-example",
"playcanvas-vite-example"
],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
Expand Down
9 changes: 9 additions & 0 deletions .changeset/kind-parrots-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'recast-navigation': minor
---

feat: remove 'three' entrypoint from 'recast-navigation' package

To make way for adding other integration packages without bloating the `recast-navigation` package, the `recast-navigation/three` entrypoint has been removed.

If you are importing from `recast-navigation/three`, simply install and import from `@recast/navigation-three` instead.
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
5 changes: 5 additions & 0 deletions .changeset/wet-toes-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@recast-navigation/generators': patch
---

feat: add mergePositionsAndIndices
5 changes: 5 additions & 0 deletions .changeset/witty-clouds-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@recast-navigation/three': minor
---

feat: avoid cloning meshes and geometry in getPositionsAndIndices
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ enableGlobalCache: false
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.1.cjs

npmRegistryServer: "https://registry.npmjs.org"
3 changes: 1 addition & 2 deletions apps/docs/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "recast-navigation-js",
"entryPoints": [
"../../packages/recast-navigation/src/index.ts",
"../../packages/recast-navigation/src/generators.ts",
"../../packages/recast-navigation/src/three.ts"
"../../packages/recast-navigation/src/generators.ts"
],
"entryPointStrategy": "expand",
"out": "dist/",
Expand Down
6 changes: 3 additions & 3 deletions apps/navmesh-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
"recast-navigation": "workspace:*",
"styled-components": "^6.1.8",
"suspend-react": "^0.1.3",
"three": "^0.167.1",
"three": "^0.169.0",
"tunnel-rat": "^0.1.2",
"zustand": "^4.3.8"
},
"devDependencies": {
"@types/react": "^18.3.1",
"@types/react-dom": "^18.2.8",
"@types/three": "^0.167.1",
"@types/three": "^0.169.0",
"@vitejs/plugin-react": "^4.2.0",
"typescript": "^5.4.3",
"vite": "^5.2.8",
"vite": "^5.4.8",
"vite-plugin-html": "^3.2.1"
}
}
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
Expand Up @@ -2,7 +2,7 @@ import { Line } from '@react-three/drei';
import { useFrame } from '@react-three/fiber';
import { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { Crowd, CrowdAgent, NavMesh, NavMeshQuery } from 'recast-navigation';
import { CrowdHelper } from 'recast-navigation/three';
import { CrowdHelper } from '@recast-navigation/three';
import { MeshStandardMaterial, Vector3, Vector3Tuple } from 'three';

export type RecastAgentRef = {
Expand Down Expand Up @@ -69,20 +69,20 @@ export const RecastAgent = forwardRef<RecastAgentRef, RecastAgentProps>(
maxAgentRadius: agentRadius,
});

const { point: agentPosition } = navMeshQuery.findClosestPoint({ x: 0, y: 0, z: 0 });
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 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' }),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TileCacheGeneratorIntermediates,
TiledNavMeshGeneratorIntermediates,
} from 'recast-navigation/generators';
import { DebugDrawer } from 'recast-navigation/three';
import { DebugDrawer } from '@recast-navigation/three';

export const DebugDrawerOption = {
HEIGHTFIELD_SOLID: 'heightfield solid',
Expand Down
2 changes: 1 addition & 1 deletion apps/navmesh-website/src/pages/editor-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
generateSoloNavMesh,
generateTiledNavMesh,
} from 'recast-navigation/generators';
import { getPositionsAndIndices } from 'recast-navigation/three';
import { getPositionsAndIndices } from '@recast-navigation/three';
import { suspend } from 'suspend-react';
import { Mesh } from 'three';
import { RouterPaths } from '../app';
Expand Down
72 changes: 0 additions & 72 deletions examples/parcel-example/index.jsx

This file was deleted.

14 changes: 14 additions & 0 deletions examples/playcanvas-vite-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<link rel="stylesheet" href="/src/index.css" />
</head>
<body>
<canvas id="app"></canvas>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions examples/playcanvas-vite-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "playcanvas-vite-example",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@recast-navigation/playcanvas": "workspace:^",
"playcanvas": "^2.0.0",
"recast-navigation": "workspace:^"
},
"devDependencies": {
"typescript": "^5.4.3",
"vite": "^5.4.8"
}
}
10 changes: 10 additions & 0 deletions examples/playcanvas-vite-example/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body {
margin: 0;
padding: 0;
}

body,
canvas {
width: 100%;
height: 100vh;
}
80 changes: 80 additions & 0 deletions examples/playcanvas-vite-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { NavMeshHelper, pcToSoloNavMesh } from '@recast-navigation/playcanvas';
import * as pc from 'playcanvas';
import { init as initRecast } from 'recast-navigation';

const init = async () => {
await initRecast();

const canvas = document.querySelector('#app') as HTMLCanvasElement;

const device = await pc.createGraphicsDevice(canvas, {
deviceTypes: [pc.DEVICETYPE_WEBGL2],
});
device.maxPixelRatio = Math.min(window.devicePixelRatio, 2);

const app = new pc.Application(canvas);
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);
app.start();

const resize = () => app.resizeCanvas();
window.addEventListener('resize', resize);

const ground = new pc.Entity('cube');
ground.addComponent('render');
ground.render!.meshInstances = [
new pc.MeshInstance(
pc.Mesh.fromGeometry(
app.graphicsDevice,
new pc.BoxGeometry({ halfExtents: new pc.Vec3(5, 0.2, 5) })
),
new pc.StandardMaterial()
),
];
app.root.addChild(ground);

const obstacle = new pc.Entity('obstacle');
obstacle.addComponent('render', {
type: 'box',
material: new pc.StandardMaterial(),
});
obstacle.setLocalScale(1, 1, 1);
obstacle.setPosition(0, 0.5, 0);
app.root.addChild(obstacle);

const camera = new pc.Entity('camera');
camera.addComponent('camera', {
clearColor: new pc.Color(0.5, 0.6, 0.9),
});
app.root.addChild(camera);
camera.setPosition(5, 5, 5);
camera.lookAt(0, 0, 0);

const light = new pc.Entity('light');
light.addComponent('light');
app.root.addChild(light);
light.setEulerAngles(45, 0, 0);

const recastConfig = {
cs: 0.05,
ch: 0.2,
};

const navMeshMeshInstances = [
...ground.render!.meshInstances,
...obstacle.render!.meshInstances,
];

const { success, navMesh } = pcToSoloNavMesh(
navMeshMeshInstances,
recastConfig
);

if (success) {
const navMeshHelper = new NavMeshHelper(navMesh, app.graphicsDevice);

app.root.addChild(navMeshHelper);
}
};

init();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const THREE = require('three');
const Recast = require('recast-navigation');
const RecastGenerators = require('recast-navigation/generators');
const RecastThree = require('recast-navigation/three');
const RecastThree = require('@recast-navigation/three');

Recast.init().then(() => {
console.log(RecastThree);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node-cjs-example",
"name": "three-node-cjs-example",
"private": true,
"version": "1.0.0",
"description": "example of using recast-navigation in node",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NavMeshQuery, init } from 'recast-navigation';
import { generateSoloNavMesh } from 'recast-navigation/generators';
import * as RecastThree from 'recast-navigation/three';
import * as RecastThree from '@recast-navigation/three';
import { BoxGeometry, Mesh } from 'three';

await init();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node-esm-example",
"name": "three-node-esm-example",
"private": true,
"type": "module",
"version": "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<head> </head>
<body>
<div id="root"></div>
<script type="module" src="./index.jsx"></script>
<script type="module" src="./index.js"></script>
</body>
</html>
Loading
Loading