@spatial-engine/react 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @spatial-engine/react
|
|
2
|
+
|
|
3
|
+
React hooks specifically designed for [React Three Fiber](https://docs.pmnd.rs/react-three-fiber) scenes that interface with [`@spatial-engine/core`](https://www.npmjs.com/package/@spatial-engine/core) and [`@spatial-engine/three`](https://www.npmjs.com/package/@spatial-engine/three).
|
|
4
|
+
|
|
5
|
+
The hooks safely setup and manage pool lifecycles across React renders natively ensuring the core Data-Oriented arrays remain stable and don't leak memory.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @spatial-engine/react @spatial-engine/core @spatial-engine/three @react-three/fiber three react
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @spatial-engine/react @spatial-engine/core @spatial-engine/three @react-three/fiber three react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
- Provides React-safe lifecycles for complex DOD memory pools.
|
|
17
|
+
- Automatically initializes and clears arrays safely mapped exactly within the `useFrame` game loop.
|
|
18
|
+
- Simple, un-intimidating hooks (`useSpatialEngine`, `useOctree`) making extreme performance approachable in R3F.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Using `useSpatialEngine`
|
|
23
|
+
Manages a paired `AABBPool` and `RayPool` across renders.
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { useSpatialEngine } from '@spatial-engine/react';
|
|
27
|
+
import { useFrame } from '@react-three/fiber';
|
|
28
|
+
|
|
29
|
+
function Scene() {
|
|
30
|
+
const engine = useSpatialEngine({ aabbCapacity: 1024, rayCapacity: 64 });
|
|
31
|
+
|
|
32
|
+
useFrame(() => {
|
|
33
|
+
engine.reset(); // free all allocations safely each frame (zero GC impact)
|
|
34
|
+
|
|
35
|
+
// dynamically re-populate your aabbPool and rayPool for this tick...
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Using `useOctree`
|
|
41
|
+
Manages an entire `Octree`, alongside an `OctreeNodePool`, and `AABBPool` tied safely within a lifecycle context.
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { useOctree } from '@spatial-engine/react';
|
|
45
|
+
import { useFrame, useThree } from '@react-three/fiber';
|
|
46
|
+
|
|
47
|
+
function Scene() {
|
|
48
|
+
const { octree, aabbPool, reset } = useOctree({
|
|
49
|
+
nodeCapacity: 1024,
|
|
50
|
+
objectCapacity: 1024
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
useFrame(() => {
|
|
54
|
+
reset(); // reset DOD pools each frame
|
|
55
|
+
|
|
56
|
+
// insert/update objects into the octree here natively mapping external models ...
|
|
57
|
+
|
|
58
|
+
// Native query without memory allocations
|
|
59
|
+
const hits = octree.queryBox(-5, -5, -5, 5, 5, 5);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Use Cases
|
|
65
|
+
- Building interactive pointer/ray mechanics across thousands of objects smoothly.
|
|
66
|
+
- Connecting external R3F `useFrame` mechanics perfectly safely over the Spatial Engine lifecycle context.
|
|
67
|
+
- Frustum culling heavy geometries smoothly out of view in React Three scenarios.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spatial-engine/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "React Three Fiber adapter for @spatial-engine/core",
|
|
5
5
|
"author": "Francisco Rueda Esquivel",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@spatial-engine/core": "0.0.
|
|
40
|
-
"@spatial-engine/three": "0.0.
|
|
39
|
+
"@spatial-engine/core": "0.0.2",
|
|
40
|
+
"@spatial-engine/three": "0.0.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=18.0.0",
|