@spatial-engine/three 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.
Files changed (2) hide show
  1. package/README.md +52 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @spatial-engine/three
2
+
3
+ Bridges [`@spatial-engine/core`](https://www.npmjs.com/package/@spatial-engine/core) with [Three.js](https://threejs.org/).
4
+
5
+ Provides `ThreeSynchronizer`, which automatically computes a `THREE.Mesh` or `THREE.Group`'s world-space bounding box and keeps the corresponding AABB exactly synchronized in the core DOD spatial octree without GC memory leaks.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @spatial-engine/three @spatial-engine/core three
11
+ # or
12
+ pnpm add @spatial-engine/three @spatial-engine/core three
13
+ ```
14
+
15
+ ## Features
16
+ - **Zero GC Sync** — computes world-space bounding boxes directly into the pre-allocated Data-Oriented Design (DOD) cache-friendly arrays.
17
+ - **Compatible with all Three.js Objects** — Works effortlessly with single `Mesh` components or deep `Group` tree hierarchies.
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { AABBPool, OctreeNodePool, Octree } from '@spatial-engine/core';
23
+ import { ThreeSynchronizer } from '@spatial-engine/three';
24
+ import { Mesh, BoxGeometry, MeshBasicMaterial } from 'three';
25
+
26
+ // 1. Setup Data-Oriented core pools
27
+ const nodePool = new OctreeNodePool(512);
28
+ const aabbPool = new AABBPool(512);
29
+ const octree = new Octree(nodePool, aabbPool);
30
+ octree.setBounds(-100, -100, -100, 100, 100, 100);
31
+
32
+ // 2. Setup Three.js Meshes
33
+ const mesh = new Mesh(new BoxGeometry(2, 2, 2), new MeshBasicMaterial());
34
+
35
+ // 3. Connect them via synchronizer
36
+ const sync = new ThreeSynchronizer(mesh, octree, aabbPool);
37
+
38
+ function animate() {
39
+ // Update your Three.js objects
40
+ mesh.position.x += 0.1;
41
+ mesh.updateMatrixWorld();
42
+
43
+ // Call sync() each frame after updating position/scale
44
+ // This computes world AABB and repositions it instantly in the octree
45
+ sync.sync();
46
+ }
47
+ ```
48
+
49
+ ## Use Cases
50
+ - High performance custom raycasting bypassing Three.js's standard `Raycaster` allocations.
51
+ - Culling thousands of Three.js objects outside a specific region or box.
52
+ - Simulating robotic sensors or environment scans over complex Three.js loaded geometries safely synchronized onto the `Octree`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spatial-engine/three",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Three.js adapter for @spatial-engine/core",
5
5
  "author": "Francisco Rueda Esquivel",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@spatial-engine/core": "0.0.1"
37
+ "@spatial-engine/core": "0.0.2"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "three": ">=0.150.0"