bevy_symbios_shape
Bevy integration for symbios-shape — a CGA Shape Grammar engine for procedural architecture.
Converts grammar outputs (ShapeModel / Terminal nodes) into Bevy entity hierarchies with procedural or asset-based meshes.
Features
- Plugin:
BevySymbiosShapePluginregistersShapeRegistry,ShapeMeshCache,LastDerivedModel, andSnapPlanesresources, plus an observer forSpawnShapeRequestevents. - Asset routing: Register GLTF scenes and materials by string ID; unregistered terminals fall back to procedural meshes.
- Procedural meshes:
build_profiled_meshgenerates geometry for tapered prisms, triangles, trapezoids, and arbitrary polygons based on the terminal'sFaceProfile. - Coordinate translation:
scope_to_transformhandles the f64→f32 downcast and corner-to-centroid offset betweensymbios-shapescopes and Bevy transforms. - Spawn extension:
commands.spawn_shape(...)derives a grammar and spawns the full terminal hierarchy in one call. - Event-driven spawning: trigger
SpawnShapeRequestand observeSpawnShapeSpawned/SpawnShapeFailedfor decoupled call sites. - Cross-spawn mesh cache:
ShapeMeshCachededuplicates procedural meshes acrossspawn_shapecalls (with hit/miss counters). - Mass properties: terminals whose grammar carries
Mat(id, density)get aTerminalMasscomponent (mass / centroid / inertia) for downstream physics, IK, and LOD. - Snap planes:
RegSnap("label")recordings are surfaced via theSnapPlanesresource. - Spatial queries:
LastDerivedModelplus the re-exportedTerminalQuery/obb_overlapgive downstream systems OBB collision tests against spawned terminals.
Quick start
use *;
use *;
use ;
Modules
| Module | Purpose |
|---|---|
cache |
ShapeMeshCache — persistent procedural mesh cache shared across spawns |
events |
SpawnShapeRequest / SpawnShapeSpawned / SpawnShapeFailed events + observer |
mass |
TerminalMass Component — mass / centroid / inertia from upstream MassProperties |
mesh |
build_profiled_mesh / build_tapered_cuboid — procedural mesh generation |
query |
LastDerivedModel resource holding the most recently derived ShapeModel |
registry |
ShapeRegistry — asset routing table (mesh IDs → scenes, material IDs → materials) |
snap |
SnapPlane / SnapPlanes resource exposing RegSnap recordings |
spawner |
SpawnShapeExt — Commands extension trait for one-call grammar derivation + spawning |
transform |
scope_to_transform — f64 scope to f32 Bevy Transform with corner-to-centroid offset |
Asset registration
Register GLTF scenes and materials before spawning so the grammar can resolve them:
Terminals whose mesh_id is not registered get a procedural mesh colored by a stable hash of the ID. Material fallback order is: registered handle → default_material → generated grey.
Event-driven spawning
For decoupled call sites — e.g. a UI button that requests a building without holding the mesh/material asset registries — trigger [SpawnShapeRequest]:
use Arc;
// Observe the result anywhere:
The plugin's built-in observer performs the derivation and spawn, then triggers SpawnShapeSpawned(root_entity) on success or SpawnShapeFailed(message) on derivation failure.
Cargo features
| Feature | Default | Effect |
|---|---|---|
egui |
off | Pulls in bevy_egui for downstream inspector/editor UIs. |
mutation |
off | Enables the mutation module: MaterialMutationPlugin, TextureConfigStore, and the MutateMaterialsRequest / MaterialTextureMutated event pair. Drives procedural-texture evolution via bevy_symbios_texture and symbios-genetics. |
Enable from Cargo.toml:
[]
= { = "0.5", = ["mutation"] }
Examples
License
MIT