# Nightshade Editor

An interactive editor and scene inspector for the [Nightshade](https://github.com/matthewjberger/nightshade) game engine.

<img width="1238" height="1346" alt="image" src="https://github.com/user-attachments/assets/dcfab536-f067-4988-b3f5-d8839444aaea" />

## Installation

### From crates.io

```bash
cargo install nightshade-editor
```

### From source

```bash
git clone https://github.com/matthewjberger/nightshade.git
cd nightshade
cargo build --release -p nightshade-editor
```

## Usage

Run the editor:

```bash
nightshade-editor
```

Or use the justfile:

```bash
just run
```

## Features

### Scene Management
- **Scene tree** - Hierarchical view of entities with parent-child relationships
- **Component inspector** - View and edit entity components
- **Entity selection** - Click entities to inspect their properties

### Rendering
- **3D viewport** - WGPU-based renderer with WebGPU support
- **Fly camera controls** - WASD movement with mouse look
- **Grid and skybox** - Scene navigation helpers
- **Alpha blending** - Support for opaque, mask, and blend (OIT) transparency modes
- **Material editing** - Edit base color, alpha mode, and alpha cutoff in real-time
- **SDF text rendering** - Signed distance field text with outline support
- **HUD overlays** - Screen-space UI elements

### Tools
- **Mesh spawning** - Create cubes, spheres, planes, and cylinders
- **Line rendering** - GPU-accelerated line primitives with frustum culling
- **3D text** - Spawn text objects with customizable properties
- **Stress testing** - Tools for performance profiling (5K text lattice, 10K meshes, 20K lines)

### Post-Processing
- **Render graph system** - Modular pass-based rendering pipeline
- **Grayscale effect** - Example compute shader post-process

### Performance
- **FPS counter** - Frame rate display
- **Entity count** - Total entities in scene
- **Line count** - Line primitive usage

## Controls

| Input | Action |
|-------|--------|
| **Middle mouse** | Orbit camera |
| **Shift + Middle mouse** | Pan camera |
| **Scroll wheel** | Zoom |
| **Numpad 0** | Toggle fly camera mode (WASD + right-click look) |
| **Numpad 1/3/7** | Front / Right / Top view |
| **Numpad 5** | Toggle orthographic / perspective |
| **G / R / S** | Grab / Rotate / Scale selected entity |
| **X** | Delete selected entity |
| **Tab** | Toggle local / world coordinate space |
| **Q** | Exit editor |

## Architecture

The editor is built on top of the Nightshade engine and demonstrates:

- **ECS pattern** using [freecs](https://github.com/matthewjberger/freecs)
- **Data-oriented design** with component-based architecture
- **WGPU rendering** with custom render graph
- **egui integration** for immediate-mode UI
- **Cross-platform support** (native and WASM)

## Development

### Building for WASM

```bash
trunk serve --open --config apps/editor/Trunk.toml
```

### Running tests

```bash
cargo test --all
```

### Linting

```bash
cargo clippy --all --tests -- -D warnings
```

## License

Licensed under the [MIT License](https://github.com/matthewjberger/nightshade/blob/main/LICENSE).

## Links

- [Nightshade Engine](https://github.com/matthewjberger/nightshade)
- [Documentation](https://docs.rs/nightshade)
- [Crates.io](https://crates.io/crates/nightshade-editor)
