@spatial-engine/core 0.0.1

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.
@@ -0,0 +1,84 @@
1
+ /**
2
+ * LiDAR Web Worker
3
+ *
4
+ * Handles heavy raycasting (LiDAR sweep logic) off the main thread.
5
+ *
6
+ * Protocol
7
+ * --------
8
+ * 1. Main thread sends one `LidarInitMessage` to set up shared buffers and
9
+ * world bounds. The worker replies with `{ type: 'ready' }`.
10
+ *
11
+ * 2. For each sweep the main thread:
12
+ * a. Writes up-to-date object AABB data into `aabbsSab`
13
+ * (6 floats per object: minX, minY, minZ, maxX, maxY, maxZ).
14
+ * b. Sends a `LidarSweepMessage` with the current `objectCount`.
15
+ *
16
+ * 3. The worker reads the transforms, inserts/updates objects in its local
17
+ * Octree, casts every ray from `raysSab`, and writes results to
18
+ * `resultsSab` (2 floats per ray: objectIndex, t; –1/–1 for a miss).
19
+ * It then replies with `{ type: 'done', rayCount }`.
20
+ *
21
+ * SharedArrayBuffer layout
22
+ * ------------------------
23
+ * aabbsSab : Float32Array – objectCapacity × AABB_STRIDE (6) floats
24
+ * nodesSab : Float32Array – nodeCapacity × NODE_STRIDE floats
25
+ * raysSab : Float32Array – rayCount × RAY_STRIDE (6) floats
26
+ * resultsSab: Float32Array – rayCount × 2 floats
27
+ * [objectIndex (float), t (float)] per ray
28
+ */
29
+ /** Sent once from the main thread to initialise the shared buffers. */
30
+ interface LidarInitMessage {
31
+ type: 'init';
32
+ /** SharedArrayBuffer for AABB data (objectCapacity × 6 floats). Written by the main thread. */
33
+ aabbsSab: SharedArrayBuffer;
34
+ /** SharedArrayBuffer for Octree node data (nodeCapacity × NODE_STRIDE floats). Managed by the worker. */
35
+ nodesSab: SharedArrayBuffer;
36
+ /** SharedArrayBuffer for ray data (rayCount × 6 floats). Written by the main thread (or set once). */
37
+ raysSab: SharedArrayBuffer;
38
+ /** SharedArrayBuffer for raycast results (rayCount × 2 floats). Written by the worker. */
39
+ resultsSab: SharedArrayBuffer;
40
+ /** Maximum number of objects the AABBPool can hold. */
41
+ objectCapacity: number;
42
+ /** Maximum number of Octree nodes the NodePool can hold. */
43
+ nodeCapacity: number;
44
+ /** Number of rays in the LiDAR sweep. */
45
+ rayCount: number;
46
+ /** World-space bounds for the root octree node. */
47
+ worldMinX: number;
48
+ worldMinY: number;
49
+ worldMinZ: number;
50
+ worldMaxX: number;
51
+ worldMaxY: number;
52
+ worldMaxZ: number;
53
+ }
54
+ /** Sent each frame to trigger a LiDAR sweep. */
55
+ interface LidarSweepMessage {
56
+ type: 'sweep';
57
+ /** Number of active objects whose AABB data has been written to `aabbsSab`. */
58
+ objectCount: number;
59
+ }
60
+ type LidarWorkerInMessage = LidarInitMessage | LidarSweepMessage;
61
+ /** Posted by the worker after initialisation succeeds. */
62
+ interface LidarReadyMessage {
63
+ type: 'ready';
64
+ }
65
+ /** Posted by the worker after a sweep finishes. */
66
+ interface LidarDoneMessage {
67
+ type: 'done';
68
+ /** Number of rays that were cast (equals the `rayCount` given in `init`). */
69
+ rayCount: number;
70
+ }
71
+ type LidarWorkerOutMessage = LidarReadyMessage | LidarDoneMessage;
72
+ /**
73
+ * Stateful LiDAR sweep processor.
74
+ *
75
+ * Exported for direct use in tests and advanced integrations. The bottom of
76
+ * this module wires it to the Web Worker global scope automatically when the
77
+ * script runs inside a worker.
78
+ */
79
+ declare function createLidarProcessor(): {
80
+ init(msg: LidarInitMessage): LidarReadyMessage;
81
+ sweep(msg: LidarSweepMessage): LidarDoneMessage;
82
+ };
83
+
84
+ export { type LidarDoneMessage, type LidarInitMessage, type LidarReadyMessage, type LidarSweepMessage, type LidarWorkerInMessage, type LidarWorkerOutMessage, createLidarProcessor };
@@ -0,0 +1,84 @@
1
+ /**
2
+ * LiDAR Web Worker
3
+ *
4
+ * Handles heavy raycasting (LiDAR sweep logic) off the main thread.
5
+ *
6
+ * Protocol
7
+ * --------
8
+ * 1. Main thread sends one `LidarInitMessage` to set up shared buffers and
9
+ * world bounds. The worker replies with `{ type: 'ready' }`.
10
+ *
11
+ * 2. For each sweep the main thread:
12
+ * a. Writes up-to-date object AABB data into `aabbsSab`
13
+ * (6 floats per object: minX, minY, minZ, maxX, maxY, maxZ).
14
+ * b. Sends a `LidarSweepMessage` with the current `objectCount`.
15
+ *
16
+ * 3. The worker reads the transforms, inserts/updates objects in its local
17
+ * Octree, casts every ray from `raysSab`, and writes results to
18
+ * `resultsSab` (2 floats per ray: objectIndex, t; –1/–1 for a miss).
19
+ * It then replies with `{ type: 'done', rayCount }`.
20
+ *
21
+ * SharedArrayBuffer layout
22
+ * ------------------------
23
+ * aabbsSab : Float32Array – objectCapacity × AABB_STRIDE (6) floats
24
+ * nodesSab : Float32Array – nodeCapacity × NODE_STRIDE floats
25
+ * raysSab : Float32Array – rayCount × RAY_STRIDE (6) floats
26
+ * resultsSab: Float32Array – rayCount × 2 floats
27
+ * [objectIndex (float), t (float)] per ray
28
+ */
29
+ /** Sent once from the main thread to initialise the shared buffers. */
30
+ interface LidarInitMessage {
31
+ type: 'init';
32
+ /** SharedArrayBuffer for AABB data (objectCapacity × 6 floats). Written by the main thread. */
33
+ aabbsSab: SharedArrayBuffer;
34
+ /** SharedArrayBuffer for Octree node data (nodeCapacity × NODE_STRIDE floats). Managed by the worker. */
35
+ nodesSab: SharedArrayBuffer;
36
+ /** SharedArrayBuffer for ray data (rayCount × 6 floats). Written by the main thread (or set once). */
37
+ raysSab: SharedArrayBuffer;
38
+ /** SharedArrayBuffer for raycast results (rayCount × 2 floats). Written by the worker. */
39
+ resultsSab: SharedArrayBuffer;
40
+ /** Maximum number of objects the AABBPool can hold. */
41
+ objectCapacity: number;
42
+ /** Maximum number of Octree nodes the NodePool can hold. */
43
+ nodeCapacity: number;
44
+ /** Number of rays in the LiDAR sweep. */
45
+ rayCount: number;
46
+ /** World-space bounds for the root octree node. */
47
+ worldMinX: number;
48
+ worldMinY: number;
49
+ worldMinZ: number;
50
+ worldMaxX: number;
51
+ worldMaxY: number;
52
+ worldMaxZ: number;
53
+ }
54
+ /** Sent each frame to trigger a LiDAR sweep. */
55
+ interface LidarSweepMessage {
56
+ type: 'sweep';
57
+ /** Number of active objects whose AABB data has been written to `aabbsSab`. */
58
+ objectCount: number;
59
+ }
60
+ type LidarWorkerInMessage = LidarInitMessage | LidarSweepMessage;
61
+ /** Posted by the worker after initialisation succeeds. */
62
+ interface LidarReadyMessage {
63
+ type: 'ready';
64
+ }
65
+ /** Posted by the worker after a sweep finishes. */
66
+ interface LidarDoneMessage {
67
+ type: 'done';
68
+ /** Number of rays that were cast (equals the `rayCount` given in `init`). */
69
+ rayCount: number;
70
+ }
71
+ type LidarWorkerOutMessage = LidarReadyMessage | LidarDoneMessage;
72
+ /**
73
+ * Stateful LiDAR sweep processor.
74
+ *
75
+ * Exported for direct use in tests and advanced integrations. The bottom of
76
+ * this module wires it to the Web Worker global scope automatically when the
77
+ * script runs inside a worker.
78
+ */
79
+ declare function createLidarProcessor(): {
80
+ init(msg: LidarInitMessage): LidarReadyMessage;
81
+ sweep(msg: LidarSweepMessage): LidarDoneMessage;
82
+ };
83
+
84
+ export { type LidarDoneMessage, type LidarInitMessage, type LidarReadyMessage, type LidarSweepMessage, type LidarWorkerInMessage, type LidarWorkerOutMessage, createLidarProcessor };
@@ -0,0 +1,7 @@
1
+ import {
2
+ createLidarProcessor
3
+ } from "./chunk-JF4RVZK3.js";
4
+ export {
5
+ createLidarProcessor
6
+ };
7
+ //# sourceMappingURL=lidar-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@spatial-engine/core",
3
+ "version": "0.0.1",
4
+ "description": "High-performance spatial partitioning and query library using Data-Oriented Design",
5
+ "author": "Francisco Rueda Esquivel",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/franruedaesq/spatial-engine.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "keywords": [
13
+ "octree",
14
+ "spatial",
15
+ "aabb",
16
+ "raycast",
17
+ "lidar",
18
+ "data-oriented-design",
19
+ "float32array",
20
+ "3d",
21
+ "webworker",
22
+ "sharedarraybuffer",
23
+ "zero-gc"
24
+ ],
25
+ "type": "module",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/index.cjs"
34
+ },
35
+ "./lidar-worker": {
36
+ "types": "./dist/lidar-worker.d.ts",
37
+ "import": "./dist/lidar-worker.js",
38
+ "require": "./dist/lidar-worker.cjs"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist"
43
+ ],
44
+ "devDependencies": {},
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "typecheck": "tsc --noEmit"
48
+ }
49
+ }