https://github.com/danielesteban/r3f-voxels-pathfinder
https://github.com/danielesteban/r3f-voxels-pathfinder
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/danielesteban/r3f-voxels-pathfinder
- Owner: danielesteban
- License: mit
- Created: 2024-06-26T20:43:10.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-07T22:21:48.000Z (about 2 years ago)
- Last Synced: 2025-02-28T11:56:23.919Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 85 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
r3f-voxels-pathfinder
==
### Examples
* [Example](https://codesandbox.io/p/sandbox/r3f-voxels-pathfinder-jm3y5r)
### Installation
```bash
npm install r3f-voxels-pathfinder
```
### Basic usage
```jsx
import { Suspense, useRef } from 'react';
import { Canvas } from '@react-three/fiber';
import { Voxels, VoxelsApi } from 'r3f-voxels';
import { Pathfinder, PathfinderApi } from 'r3f-voxels-pathfinder';
import { Vector3 } from 'three';
const Scene = () => {
const voxels = useRef(null!);
const pathfinder = useRef(null!);
useLayoutEffect(() => {
for (let i = 0; i < 16; i++) {
voxels.current.setVoxel(new Vector3(i, 0, 0), 1);
}
console.log(
pathfinder.current.getPath(
new Vector3(0, 0, 0),
new Vector3(10, 0, 0)
)
);
}, []);
return (
);
};
const App = () => (
);
```
### Api
```ts
type PathfinderApi = {
addObstacle: (position: Vector3) => void;
removeObstacle: (position: Vector3) => void;
getPath: (from: Vector3, to: Vector3, height?: number) => Vector3[];
ground: (position: Vector3, height?: number, minY?: number) => boolean;
};
```