Skip to content

Commit

Permalink
fix: parcel and react-scripts support, add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-mason committed Sep 23, 2023
1 parent 9d0f6d8 commit 9b8ea41
Show file tree
Hide file tree
Showing 32 changed files with 15,345 additions and 9,043 deletions.
8 changes: 5 additions & 3 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"updateInternalDependencies": "patch",
"ignore": [
"navmesh-website",
"node-cjs-recast-navigation-example",
"node-esm-recast-navigation-example",
"vite-recast-navigation-three-example"
"node-cjs-example",
"node-esm-example",
"parcel-example",
"react-scripts-example",
"vite-example"
],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
Expand Down
5 changes: 5 additions & 0 deletions .changeset/cool-olives-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@recast-navigation/wasm': patch
---

fix: parcel and react-scripts support
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist
.vscode
.vercel
emsdk
.parcel-cache
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "node-cjs-recast-navigation-example",
"name": "node-cjs-example",
"private": true,
"version": "1.0.0",
"description": "example of using recast-navigation in node",
"scripts": {
"start": "node src/index.cjs"
"start": "node index.cjs"
},
"author": "",
"license": "ISC",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "node-esm-recast-navigation-example",
"name": "node-esm-example",
"private": true,
"type": "module",
"version": "1.0.0",
"description": "example of using recast-navigation in node",
"scripts": {
"start": "node src/index.js"
"start": "node index.mjs"
},
"author": "",
"license": "ISC",
Expand Down
6 changes: 0 additions & 6 deletions examples/node-esm-recast-navigation-example/.prettierrc.json

This file was deleted.

8 changes: 8 additions & 0 deletions examples/parcel-example/index.html
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>
72 changes: 72 additions & 0 deletions examples/parcel-example/index.jsx
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 />);
16 changes: 16 additions & 0 deletions examples/parcel-example/package.json
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"
}
}
9 changes: 9 additions & 0 deletions examples/parcel-example/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#root,
canvas {
width: 100%;
height: 100vh;
}

body {
margin: 0;
}
24 changes: 24 additions & 0 deletions examples/react-scripts-example/package.json
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"
]
}
43 changes: 43 additions & 0 deletions examples/react-scripts-example/public/index.html
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>
72 changes: 72 additions & 0 deletions examples/react-scripts-example/src/index.jsx
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 />);
9 changes: 9 additions & 0 deletions examples/react-scripts-example/src/styles.css
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.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "vite-recast-navigation-three-example",
"name": "vite-example",
"private": true,
"type": "module",
"scripts": {
Expand Down
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.

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build:navmesh-website": "(cd apps/navmesh-website && yarn build)",
"test": "concurrently --kill-others-on-fail \"yarn test:unit-tests\" \"yarn test:node-smoke-test\"",
"test:unit-tests": "yarn workspaces foreach -t --include @recast-navigation/core run test",
"test:node-smoke-test": "(cd ./examples/node-cjs-recast-navigation-example && yarn start) && (cd ./examples/node-esm-recast-navigation-example && yarn start)",
"test:node-smoke-test": "(cd ./examples/node-cjs-example && yarn start) && (cd ./examples/node-esm-example && yarn start)",
"change": "yarn changeset",
"release": "yarn build && yarn test",
"publish": "changeset publish",
Expand Down
2 changes: 1 addition & 1 deletion packages/recast-navigation-wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ set(EMCC_ARGS
-s EXPORTED_RUNTIME_METHODS=["UTF8ToString","addFunction"]
-s EXPORT_NAME="Recast"
-s MODULARIZE=1
-s ENVIRONMENT='web,node'
-s ENVIRONMENT='web'
-s NO_EXIT_RUNTIME=1
-s NO_FILESYSTEM=1
-s FILESYSTEM=0
Expand Down
8 changes: 5 additions & 3 deletions packages/recast-navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.cjs"
"require": "./index.cjs",
"types": "./index.d.ts"
},
"./three": {
"import": "./three.mjs",
"require": "./index.cjs"
"require": "./index.cjs",
"types": "./three.d.ts"
}
},
"files": [
Expand All @@ -48,7 +50,7 @@
"README.md"
],
"scripts": {
"clean": "(rm index.js index.d.ts three.js three.d.ts || true)",
"clean": "(rm index.mjs index.cjs index.d.ts three.mjs three.cjs three.d.ts || true)",
"build": "yarn clean && rollup --config rollup.config.js --bundleConfigAsCjs",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
Expand Down

0 comments on commit 9b8ea41

Please sign in to comment.