scenix-math 0.2.0

Custom no_std 3D math primitives for the scenix rendering library.
Documentation
# scenix

> Italian: scenix - scene, the stage on which everything appears.

[![CI](https://github.com/AarambhDevHub/scenix/actions/workflows/ci.yml/badge.svg)](https://github.com/AarambhDevHub/scenix/actions)
[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](#license)

scenix v0.2.0 is the Scene Graph release of a renderer-agnostic 3D scene library for Rust.

This release ships the GPU-free foundation plus a working scene graph:

- `scenix-math`: vectors, matrices, quaternions, transforms, rays, bounds, planes, and coordinate helpers.
- `scenix-core`: typed IDs, color, errors, and shared traits.
- `scenix-input`: pointer and keyboard state.
- `scenix-scene`: scene node hierarchy, transform propagation, traversal, fog, sprites, and LOD helpers.
- `scenix`: facade crate re-exporting the default APIs.

Meshes, materials, renderer, loaders, WASM integration, and `animato` integration are planned in later roadmap milestones.

## Installation

Most users should start with the facade crate:

```toml
[dependencies]
scenix = "0.2"
```

Use the focused crates directly when you only need one layer:

```toml
[dependencies]
scenix-math = "0.2"
scenix-core = "0.2"
scenix-input = "0.2"
scenix-scene = "0.2"
```

For `no_std` math with portable trigonometry:

```toml
[dependencies]
scenix-math = { version = "0.2", default-features = false, features = ["libm"] }
scenix-core = { version = "0.2", default-features = false }
scenix-input = { version = "0.2", default-features = false }
scenix-scene = { version = "0.2", default-features = false }
```

## Quick Start

### Scene Graph

```rust
use scenix::{SceneGraph, SceneNode, Transform, Vec3};

let mut scene = SceneGraph::new();
let root = scene.add(SceneNode::group("root"));
let child = scene
    .add_child(
        root,
        SceneNode::new("child")
            .transform(Transform::from_translation(Vec3::new(1.0, 2.0, 3.0))),
    )
    .unwrap();

scene.update_world_transforms();

assert_eq!(scene.parent(child), Some(root));
assert_eq!(
    scene.world_matrix(child).unwrap().mul_vec3(Vec3::ZERO),
    Vec3::new(1.0, 2.0, 3.0)
);
```

### Vector And Quaternion Math

```rust
use scenix::{Quat, Vec3};

let right = Vec3::X;
let up = Vec3::Y;
let forward = right.cross(up);

let rotation = Quat::from_axis_angle(Vec3::Y, core::f32::consts::FRAC_PI_2);
let rotated = rotation.mul_vec3(Vec3::X);

assert_eq!(forward, Vec3::Z);
assert!((rotated.z + 1.0).abs() < 1.0e-5);
```

### Matrices And Transforms

```rust
use scenix::{Mat4, Quat, Transform, Vec3};

let transform = Transform::from_translation(Vec3::new(1.0, 2.0, 3.0))
    .rotate_by(Quat::from_axis_angle(Vec3::Y, 0.5))
    .scale_by(Vec3::new(2.0, 2.0, 2.0));

let matrix = transform.to_mat4();
let projection = Mat4::perspective(core::f32::consts::FRAC_PI_3, 16.0 / 9.0, 0.1, 1000.0);

assert_eq!(matrix.mul_vec3(Vec3::ZERO), Vec3::new(1.0, 2.0, 3.0));
assert_eq!(projection.to_cols_array()[15], 0.0);
```

### Ray Intersections

```rust
use scenix::{Aabb, Ray3, Vec3};

let ray = Ray3::new(Vec3::new(0.0, 0.0, 5.0), Vec3::NEG_Z);
let bounds = Aabb::new(Vec3::new(-1.0, -1.0, -1.0), Vec3::new(1.0, 1.0, 1.0));

let hit_t = ray.intersect_aabb(bounds).unwrap();
assert_eq!(ray.at(hit_t), Vec3::new(0.0, 0.0, 1.0));
```

### Color And IDs

```rust
use scenix::{Color, MaterialId, NodeId};

let node = NodeId::new(42);
let material = MaterialId::new(7);
let color = Color::from_hex(0xFF_80_00).to_linear();

assert_eq!(node.get(), 42);
assert_eq!(material.get(), 7);
assert_eq!(color.a, 1.0);
```

### Input State

```rust
use scenix::{KeyCode, KeyboardState, PointerButton, PointerState, Vec2};

let mut keyboard = KeyboardState::new();
keyboard.on_key_down(KeyCode::KeyW);
assert!(keyboard.is_pressed(KeyCode::KeyW));

let mut pointer = PointerState::new();
pointer.set_position(Vec2::new(100.0, 50.0));
pointer.on_button_down(PointerButton::Left);
assert!(pointer.is_pressed(PointerButton::Left));
```

## Feature Flags

| Feature | Default | Description |
|---------|---------|-------------|
| `std` | yes | Enables standard-library conveniences such as `std::error::Error` and `Named`. |
| `scene` | yes | Enables the `scenix-scene` graph API from the facade crate. |
| `libm` | no | Uses `libm` for portable `no_std` trigonometry in `scenix-math`. |
| `serde` | no | Derives `Serialize` and `Deserialize` for public data types. |
| `approx` | no | Implements `approx` traits for math types. |
| `gpu` | no | Enables the `GpuUpload` trait in `scenix-core`. |

## Workspace Layout

```text
scenix/
├── crates/
│   ├── scenix-math/
│   ├── scenix-core/
│   ├── scenix-input/
│   ├── scenix-scene/
│   └── scenix/
├── ARCHITECTURE.md
├── ROADMAP.md
├── CHANGELOG.md
└── README.md
```

## Running Checks

```sh
cargo fmt --check
cargo clippy --workspace --all-features -- -D warnings
cargo test --workspace
cargo test --workspace --all-features
cargo test -p scenix-math -p scenix-core -p scenix-input -p scenix-scene --no-default-features
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps
cargo bench --workspace --no-run
```

## Roadmap

The long-term design remains the full scenix workspace described in [ARCHITECTURE.md](./ARCHITECTURE.md). Version `0.2.0` adds the scene graph on top of the Foundation APIs. Upcoming milestones add mesh primitives, materials, lights, cameras, textures, renderer, loaders, raycasting, helpers, `animato`, and WASM integration.

See [ROADMAP.md](./ROADMAP.md) for the full versioned plan.

## License

Licensed under either of:

- [MIT License]./LICENSE-MIT
- [Apache License, Version 2.0]./LICENSE-APACHE

at your option.