/dice

Beautiful 3D dice roller built for Owlbear Rodeo

Primary LanguageTypeScriptGNU General Public License v3.0GPL-3.0

Owlbear Rodeo Dice

Quick (Textual) Roll Specifier

This version supports entering a string like 3d6-2 and it chooses 3 six-sided dice and sets the modifier to -2. Textual roll specifier

It uses peggy to parse the specifier, according to a grammar in the RollSpecifier.tsx file.

const diceRollGrammar = `{
function parseRoll(rolls, sides, modifier) {
var total = 0;
var theRolls = [];
var resultObject = {sides: parseInt(sides), modifier: modifier, rolls: theRolls};
for (var i = 0; i < rolls; i++) {
const roll = Math.floor(Math.random() * sides) + 1;
theRolls.push(roll);
total += roll;
}
resultObject.total = total + modifier;
return resultObject;
}
}
start = dice_roll
dice_roll
= _ rolls:number _ "d"i _ sides:dice_sides _ modifier:modifier? _
{ return parseRoll(rolls, sides, modifier || 0); }
dice_sides
= "2" / "4" / "6" / "8" / "10" / "12" / "20"
modifier
= "+" _ n:number
{ return n; }
/ "-" _ n:number
{ return -n; }
number "number"
= digits:[0-9]+
{ return parseInt(digits.join(''), 10); }
_ "whitespace"
= [ \\t\\r\\n]*
`;

Beautiful 3D dice extension for d20 based systems

Example

Installing

The extension can be installed from the store page.

How it Works

This project uses React for UI, Three.js for rendering and Rapier for physics.

The physics simulation is used to both generate the animation for the roll as well as the final roll values.

Wait is it really random if physics is used to determine the result? How do I know the dice rolls are fair?

Short answer yes, the dice are fair. Long answer here's a statistical analysis of the rolling methodology.

In order to sync rolls over the network efficiently we rely on the fact the Rapier is a deterministic physics engine. This means that across two different computers we'll get the same result given the same initial parameters.

So we only need to make sure that all the initial parameters are synced and then each client can run its own simulation and end up with the correct animation.

To try out the dice roller outside of Owlbear Rodeo you can head to https://dice.owlbear.rodeo/.

Building

This project uses Yarn as a package manager.

To install all the dependencies run:

yarn

To run in a development mode run:

yarn dev

To make a production build run:

yarn build

Project Structure

All source files can be found in the src folder.

If you'd like to create a new dice set with the existing dice styles edit the diceSets.ts file in the sets folder.

If you'd like to add a new dice style the 3D models for the dice are split across four folders: materials, meshes, colliders and previews.

The materials folder contains the PBR materials for each dice style.

The meshes folder contains the 3D geometry used for the dice.

The colliders folder contains the simplified collider geometry for the dice.

The previews folder contains 2D image previews for each dice.

All the code specific for the Owlbear Rodeo extension is in the plugin folder.

License

GNU GPLv3

Contributing

This project is provided as an example of how to use the Owlbear Rodeo SDK. As such it is unlikely that we will accept pull requests for new features.

Instead we encourage you to fork this repository and build the dice roller of your dreams.

Copyright (C) 2023 Owlbear Rodeo