# Realism
**The High-Performance, Scoped Scene Graph for Modern Rust Engines.**
[](https://crates.io/crates/realism)
[](LICENSE)
`realism` is a data-oriented scene management library designed for engines requiring high-density entity counts and seamless world-scale streaming. It provides the high-performance "glue" between simulation and rendering hardware.
---
## โก Performance Matrix (Latest Benchmarks)
*Benchmarks performed on **Intel Core i5-11400F**, **Intel Arc A380**, **16GB DDR4 RAM**.*
| **Transform Propagation** | **1.36 ms** | SIMD Vectorized (4x Batch) |
| **Spatial Selection (Visible)** | **760 ยตs** | Dynamic Octree (65k Cull) |
| **Entity Spawn/Despawn** | **O(1)** | Generational Dense List |
| **Component Access** | **O(1)** | Cache-Optimized Sparse Set |
---
## ๐ Core Value Propositions
* **โก SIMD-Accelerated Math**: Leveraging Nightly Rust's `portable_simd`, Realism batches transform composition to process 100,000+ entities with unparalleled speed.
* **๐ World-Scale Streaming**: Integrated async chunk management for seamless world loading/unloading, built-in memory monitoring, and thread-safe asset integration.
* **๐ณ Dynamic Spatial Index**: A loose/dynamic Octree handles frustum culling and spatial queries, ensuring only visible data reaches your GPU.
* **๐๏ธ Engine Agnostic Architecture**:
* **Generic Physics Bridge**: Decoupled traits for Rapier, Jolt, or custom physics synchronization.
* **Render Extraction**: Extracts a pure command stream (`RenderCommand`) ready for Vulkan, WGPU, or Dx12.
* **๐ฆ Industrial-Grade Serialization**: Native JSON and binary support for world snapshots and modular prefabs.
---
## โ๏ธ Installation
Add to your `Cargo.toml`. To enable SIMD optimizations, use a **Nightly Rust** toolchain.
```toml
[dependencies]
realism = "0.1.0"
glam = "0.29"
```
---
## ๐ API Usage Examples
### 1. Basic Scene Setup
```rust
use realism::Scene;
use realism::transform::Transform;
use glam::Vec3;
let mut scene = Scene::new();
// Spawn a hierarchy: Parent (0, 10, 0) -> Child (5, 0, 0)
let parent = scene.spawn_with_transform(Transform::from_xyz(0.0, 10.0, 0.0));
let child = scene.spawn_with_transform(Transform::from_xyz(5.0, 0.0, 0.0));
scene.attach(child, parent);
// SIMD Propagation computes World Matrices for the entire hierarchy in batches of 4
scene.propagate_transforms();
let world_pos = scene.transform(child).unwrap().cached_world_transform.w_axis.truncate();
assert_eq!(world_pos, Vec3::new(5.0, 10.0, 0.0));
```
### 2. Physics & Render Extraction
```rust
// 1. Sync transforms with your physical world (Rapier, Jolt, etc.)
scene.sync_physics(&mut physics_engine);
// 2. Extract visible command stream for the current frame
let view_proj = camera.view_projection();
let draw_calls = scene.extract(Some(view_proj));
renderer.draw(draw_calls);
```
### 3. World-Scale Streaming
```rust
use realism::streaming::{ChunkManager, ChunkLoader};
let mut manager = ChunkManager::new(500.0, 1000.0); // Load radius, Unload radius
manager.update(camera.position());
for id in manager.chunks_to_load() {
loader.load_chunk_async(id, format!("assets/chunks/{}.json", id));
}
// Poll background thread results and integrate into Scene
let loaded = loader.poll();
realism::streaming::integrate_chunks(&mut scene, &mut manager, loaded);
```
---
## ๐ก๏ธ Architecture
For a deep dive into the internal sparse set storage, Octree heuristics, and SIMD batching logic, refer to the [Internal Guide](docs/ARCHITECTURE.md).
## ๐ License
Licensed under Apache License, Version 2.0.