scena3d 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SCENA contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # SCENA — SCenes & ENvironment Assets
2
+
3
+ **SCENA** is a 3D world-building library on top of [three.js](https://threejs.org): seeded procedural props, terrain, sky, lighting and scattering — with **gameplay metadata** (steering obstacles, exact height queries) that game libraries like [GAMA](https://github.com/pariharshyamu/gama) understand.
4
+
5
+ three.js renders. GAMA makes it a game. **SCENA gives it a world.**
6
+
7
+ ## Principles
8
+
9
+ - **Seeded determinism.** Same seed, same tree — forests are reproducible, diffable and network-syncable. `Math.random` appears nowhere in the library.
10
+ - **Playable before assets exist.** Every generator produces a coherent flat-shaded low-poly visual out of the box; real models come later, if ever.
11
+ - **Props know their gameplay.** A tree isn't just a mesh — it reports its obstacle footprint. `scatter()` returns world-space obstacles that plug straight into GAMA's `ObstacleAvoidance`; the terrain exposes its exact height function for spawning, ground-clamping and navmesh baking.
12
+ - **A matched set.** One palette system (`meadow`, `autumn`, `dusk`) themes every prop, the terrain bands, the sky and the fog together.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install scena3d three
18
+ ```
19
+
20
+ ## A world in ten lines
21
+
22
+ ```ts
23
+ import { createTerrain, createSky, createLightingRig, applyFog,
24
+ createTree, createRock, scatter, PALETTES } from 'scena3d';
25
+
26
+ const terrain = createTerrain({ seed: 20, size: 90, amplitude: 5 });
27
+ scene.add(terrain.mesh, createSky().mesh, createLightingRig('golden-hour').group);
28
+ applyFog(scene, 'haze');
29
+
30
+ const forest = scatter({
31
+ seed: 21,
32
+ area: { min: { x: -40, z: -40 }, max: { x: 40, z: 40 } },
33
+ surface: terrain.heightAt, // exact — never disagrees with the mesh
34
+ density: 0.05,
35
+ items: [
36
+ { create: (rng) => createTree({ seed: rng.int(1, 1e9) }), weight: 4 },
37
+ { create: (rng) => createRock({ seed: rng.int(1, 1e9) }) },
38
+ ],
39
+ mask: (_x, _z, y) => y < 3.6, // keep the peaks bare
40
+ keepOut: [{ center: { x: 0, z: 0 }, radius: 9 }], // the camp clearing
41
+ });
42
+ scene.add(forest.group); // InstancedMeshes — a few draw calls
43
+ ```
44
+
45
+ ## The GAMA handshake
46
+
47
+ ```ts
48
+ import { MotionAgent, ObstacleAvoidance, FollowPath } from 'gama3d';
49
+
50
+ agent.addBehavior(new FollowPath(patrolPath, 1.5));
51
+ agent.addBehavior(new ObstacleAvoidance(() => forest.obstacles), 2.5); // ← SCENA metadata
52
+ game.onUpdate(() => { // ← SCENA ground truth
53
+ agent.owner.position.y = terrain.heightAt(agent.position.x, agent.position.z);
54
+ });
55
+ ```
56
+
57
+ Neither library imports the other — the obstacle shape (`{ center, radius }`) is structural. Run the full demo (`npm run dev`, expects a sibling `../gama` clone): terrain, forest, a lamp-lit camp, wardens patrolling between the trees, and a flock overhead.
58
+
59
+ ## API
60
+
61
+ | Area | Exports |
62
+ |---|---|
63
+ | Props | `createTree`, `createRock`, `createCrate`, `createFence`, `createLamp` — each returns `{ object, obstacleRadius }` |
64
+ | Environment | `createTerrain` (with `heightAt(x, z)`), `createSky`, `createLightingRig('day' \| 'golden-hour' \| 'overcast' \| 'night')`, `applyFog('clear' \| 'haze' \| 'thick' \| 'eerie')` |
65
+ | Scattering | `scatter({ seed, area, surface, density \| count, items, mask, minSpacing, keepOut })` → `{ group, placements, obstacles, count }` |
66
+ | Core | `Rng` (seeded), `valueNoise2`/`fractalNoise2`, `PALETTES`, `collectObstacles` |
67
+
68
+ Scatter placement uses density noise for natural clumping and clearings, a spatial hash for minimum spacing, and per-item visual variants; rendering merges everything into `InstancedMesh`es (one draw call per prop part).
69
+
70
+ ## Roadmap
71
+
72
+ - [x] Seeded props with obstacle metadata (tree, rock, crate, fence, lamp)
73
+ - [x] Instanced `scatter()` with masks, keep-out, spacing and clumping
74
+ - [x] Noise terrain with exact `heightAt` and height/slope color bands
75
+ - [x] Sky dome, lighting rigs, fog presets, three theme palettes
76
+ - [ ] Kits: dungeon/village pieces with shared snap dimensions
77
+ - [ ] Declarative scene manifests (JSON → scene), Blender marker conventions (`spawn_*`, `route_*`, `nav_*`)
78
+ - [ ] Water, day-night cycle driving sun + sky together
79
+ - [ ] Buildings/ruins generators; LOD tiers for scatter
80
+ - [ ] CC0 asset-pack adapters (Kenney/Quaternius) and a KTX2/Draco pipeline
81
+ - [ ] Docs site with live playground (reusing GAMA's runner)
82
+
83
+ ## Development
84
+
85
+ ```bash
86
+ npm install
87
+ npm test # 21 vitest unit tests (determinism, metadata, scatter rules)
88
+ npm run typecheck
89
+ npm run build # tsup → dist (ESM + CJS + d.ts)
90
+ npm run dev # the SCENA × GAMA forest demo (needs ../gama sibling clone)
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT