3D dice rendering and physics library
Project description
pydice3d
Physics-based 3D polyhedral dice simulation library for Python
Pydice3d simulates and renders polyhedral dice as used in tabletop RPGs. It handles physics, geometry, rendering, and audio, exposing a single entry point — DiceSimulation — that any application can drive with a few lines of code.
The library has no dependency on any GUI toolkit. Anything that can provide an OpenGL 3.3 context (GTK, Qt, Pygame, SDL, etc.) can host it.
Supported dice
d4, d6, d8, d10, d12, d20, d100 (percentile, paired d10), and Fudge/FATE dice (df).
Quick start
Headless (no rendering)
from pydice3d.simulation import DiceSimulation
sim = DiceSimulation()
sim.roll({"d6": 2, "d20": 1})
while not sim.is_done:
sim.step()
print(sim.result.as_dict()) # {"d6": [3, 5], "d20": [17]}
With OpenGL rendering
from pydice3d.simulation import DiceSimulation, RollResult
from pydice3d.renderer import Renderer
sim = DiceSimulation(on_result=lambda r: print(r.summary()))
sim.resize(viewport_w, viewport_h)
sim.roll({"d6": 3}, theme="dark")
renderer = Renderer(sim.scene, sim.dice_types)
# inside the render loop:
sim.step() # advance physics, update scene
renderer.draw(sim.scene, sim.view_projection(),
sim.camera_position(), width, height)
Architecture
The library is split into clearly separated layers. Public API surface is intentionally small. For more details, check the architecture file.
pydice3d/
├── simulation.py # Entry point. Orchestrates everything.
├── physics.py # PyBullet world, bodies, collision events
├── spawner.py # Spawn and launch dice into the scene
├── dice.py # Dice entity: physics body + mesh
├── dice_state.py # Per-die lifecycle (SPAWNED → ROLLING → SETTLING → RESTING)
├── dice_mesh.py # Polyhedron geometry (vertices, faces, normals, face values)
├── results.py # Roll result aggregation and completion monitoring
├── scene.py # CPU-side render data, model matrices, themes
├── renderer.py # OpenGL renderer (VAO/VBO, shaders, MSDF glyph atlas)
├── shaders.py # GLSL source and shader utilities
├── camera.py # Orbital camera, view/projection matrices
├── math_utils.py # Quaternion and vector math
└── audio.py # Collision and rolling audio engine
Data flow per frame
PhysicsWorld.step()
└─ DiceState.update_status() # lifecycle transitions
└─ RollMonitor.tick() # detect completion
└─ RenderScene.update() # write model matrices from orientations
└─ Renderer.draw() # GPU draw calls
Entry point contract
DiceSimulation Renderer are the only classes a frontend needs to import from the library.
Demonstration application
The repository includes a GTK4-based demo (exemples/gtk) used for manual testing, physics tuning, and visual validation. It is not required for using the library and is not part of the public API.
Status
Active development. The project is feature-complete for the initial release. The architecture and APIs have reached a point of stability. Future updates are expected to focus primarily on bug fixes, testing, performance improvements, and incremental enhancements rather than disruptive changes.
Bug reports, suggestions, and pull requests are welcome.
License
AGPL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydice3d-1.0.0.tar.gz.
File metadata
- Download URL: pydice3d-1.0.0.tar.gz
- Upload date:
- Size: 166.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2ebabfca9c6536876ab6650e829f3a5ec3dabeffe6e13a3879e362236943d75
|
|
| MD5 |
bccc9c0c99f8d9146f34fe3903705da5
|
|
| BLAKE2b-256 |
abdafc65e465a0fa273c12c4bf5df022199a9ce013689ae65496bfd0dd03541f
|
File details
Details for the file pydice3d-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pydice3d-1.0.0-py3-none-any.whl
- Upload date:
- Size: 179.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1b807fa3ae1e2c050c259c4452aa80f762b4d7b9040f2060ae39a5ee0cded54
|
|
| MD5 |
ee1502f057eba8c33695ef00e1d7aec8
|
|
| BLAKE2b-256 |
dbbbe9285b987168663fb57b11c165dede5130f2363664acd943f552c746e385
|