-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parcel and react-scripts support, add examples
- Loading branch information
1 parent
9d0f6d8
commit 9b8ea41
Showing
32 changed files
with
15,345 additions
and
9,043 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@recast-navigation/wasm': patch | ||
--- | ||
|
||
fix: parcel and react-scripts support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ dist | |
.vscode | ||
.vercel | ||
emsdk | ||
.parcel-cache |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...js-recast-navigation-example/package.json → examples/node-cjs-example/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...sm-recast-navigation-example/package.json → examples/node-esm-example/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> </head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./index.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { OrbitControls } from '@react-three/drei'; | ||
import { Canvas } from '@react-three/fiber'; | ||
import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { init } from 'recast-navigation'; | ||
import { NavMeshHelper, threeToSoloNavMesh } from 'recast-navigation/three'; | ||
import { suspend } from 'suspend-react'; | ||
import { Mesh } from 'three'; | ||
import './styles.css'; | ||
|
||
const NavMesh = ({ children }) => { | ||
const group = useRef(); | ||
const [navMesh, setNavMesh] = useState(); | ||
|
||
const navMeshHelper = useMemo(() => { | ||
if (!navMesh) return null; | ||
|
||
return new NavMeshHelper({ navMesh }); | ||
}, [navMesh]); | ||
|
||
useEffect(() => { | ||
const meshes = []; | ||
|
||
group.current.traverse((object) => { | ||
if (object instanceof Mesh) { | ||
meshes.push(object); | ||
} | ||
}); | ||
|
||
const { success, navMesh } = threeToSoloNavMesh(meshes); | ||
|
||
if (!success) return; | ||
|
||
setNavMesh(navMesh); | ||
|
||
return () => { | ||
setNavMesh(undefined); | ||
navMesh.destroy(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<group> | ||
<group ref={group}>{children}</group> | ||
|
||
{navMeshHelper && <primitive object={navMeshHelper} />} | ||
</group> | ||
); | ||
}; | ||
|
||
function App() { | ||
suspend(() => init(), []); | ||
|
||
return ( | ||
<Canvas camera={{ position: [10, 10, 10] }}> | ||
<NavMesh> | ||
<mesh> | ||
<boxGeometry args={[10, 0.2, 10]} /> | ||
<meshBasicMaterial color="#333" /> | ||
</mesh> | ||
</NavMesh> | ||
|
||
<ambientLight intensity={0.5} /> | ||
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} /> | ||
<pointLight position={[-10, -10, -10]} /> | ||
|
||
<OrbitControls /> | ||
</Canvas> | ||
); | ||
} | ||
|
||
createRoot(document.getElementById('root')).render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "parcel-example", | ||
"packageManager": "yarn@3.5.0", | ||
"scripts": { | ||
"start": "parcel index.html" | ||
}, | ||
"dependencies": { | ||
"@react-three/drei": "^9.84.2", | ||
"@react-three/fiber": "^8.14.2", | ||
"recast-navigation": "workspace:^", | ||
"three": "^0.156.1" | ||
}, | ||
"devDependencies": { | ||
"parcel": "^2.9.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#root, | ||
canvas { | ||
width: 100%; | ||
height: 100vh; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "react-scripts-example", | ||
"private": true, | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"@react-three/drei": "^9.83.9", | ||
"@react-three/fiber": "^8.12.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "5.0.1", | ||
"recast-navigation": "0.9.2", | ||
"suspend-react": "^0.1.3", | ||
"three": "^0.156.1" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start" | ||
}, | ||
"browserslist": [ | ||
">1%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<!-- | ||
manifest.json provides metadata used when your web app is added to the | ||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
</head> | ||
|
||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { OrbitControls } from '@react-three/drei'; | ||
import { Canvas } from '@react-three/fiber'; | ||
import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { init } from 'recast-navigation'; | ||
import { NavMeshHelper, threeToSoloNavMesh } from 'recast-navigation/three'; | ||
import { suspend } from 'suspend-react'; | ||
import { Mesh } from 'three'; | ||
import './styles.css'; | ||
|
||
const NavMesh = ({ children }) => { | ||
const group = useRef(); | ||
const [navMesh, setNavMesh] = useState(); | ||
|
||
const navMeshHelper = useMemo(() => { | ||
if (!navMesh) return null; | ||
|
||
return new NavMeshHelper({ navMesh }); | ||
}, [navMesh]); | ||
|
||
useEffect(() => { | ||
const meshes = []; | ||
|
||
group.current.traverse((object) => { | ||
if (object instanceof Mesh) { | ||
meshes.push(object); | ||
} | ||
}); | ||
|
||
const { success, navMesh } = threeToSoloNavMesh(meshes); | ||
|
||
if (!success) return; | ||
|
||
setNavMesh(navMesh); | ||
|
||
return () => { | ||
setNavMesh(undefined); | ||
navMesh.destroy(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<group> | ||
<group ref={group}>{children}</group> | ||
|
||
{navMeshHelper && <primitive object={navMeshHelper} />} | ||
</group> | ||
); | ||
}; | ||
|
||
function App() { | ||
suspend(() => init(), []); | ||
|
||
return ( | ||
<Canvas camera={{ position: [10, 10, 10] }}> | ||
<NavMesh> | ||
<mesh> | ||
<boxGeometry args={[10, 0.2, 10]} /> | ||
<meshBasicMaterial color="#333" /> | ||
</mesh> | ||
</NavMesh> | ||
|
||
<ambientLight intensity={0.5} /> | ||
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} /> | ||
<pointLight position={[-10, -10, -10]} /> | ||
|
||
<OrbitControls /> | ||
</Canvas> | ||
); | ||
} | ||
|
||
createRoot(document.getElementById('root')).render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#root, | ||
canvas { | ||
width: 100%; | ||
height: 100vh; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ast-navigation-three-example/package.json → examples/vite-example/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions
6
examples/vite-recast-navigation-three-example/.prettierrc.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.