UNPKG

@planarally/dice

Version:

3D dice rolling functionality for babylon.js.

72 lines (71 loc) 2.28 kB
import { type EngineOptions } from "@babylonjs/core/Engines/thinEngine"; import { Vector3 } from "@babylonjs/core/Maths/math"; import { Scene } from "@babylonjs/core/scene"; import type { DiceSystem, Part, RollResult, Status, WithStatus } from "../core/types"; import type { DieOptions } from "./options"; import "@babylonjs/core/Loading"; import "@babylonjs/core/Materials/standardMaterial"; import "@babylonjs/core/Materials/PBR/pbrMaterial"; import "@babylonjs/core/Physics/physicsEngineComponent"; import "@babylonjs/core/Physics/v1/physicsEngineComponent"; export declare class DiceThrower { private loaded; scene: Scene; tresholds: { angular: number; linear: number; }; physics: { friction: number; mass: number; restitution: number; }; freezeOnDecision: boolean; clearAfter: number; private activeDiceSystem; private meshMap; private activeRolls; constructor(options: { scene?: Scene; canvas?: HTMLCanvasElement; tresholds?: { linear: number; angular: number; }; physics?: { mass: number; friction: number; restitution: number; }; freezeOnDecision?: boolean; clearAfter?: number; antialias?: boolean; engineOptions?: EngineOptions; }); /** * Loads the physics engine * * This NEEDS to be run before any dice throwing can happen. */ loadPhysics(gravity?: Vector3): Promise<void>; loadMeshes(meshUrl: string, scene?: Scene): Promise<void>; loadSystem(diceSystem: DiceSystem<Part, unknown>): Promise<void>; startRenderLoop(): void; private checkSolutions; rollString<Q>(inputString: string, rollOptions?: Q): Promise<RollResult<Part>>; rollParts<Q>(parts: WithStatus<Part, Status>[], rollOptions?: Q): Promise<RollResult<Part>>; throwDice(rolls: { name: string; options?: Omit<DieOptions, "key">; pickVector?: Vector3; }[], defaultOptions?: DieOptions): Promise<{ results: { faceId: number; dieName: string; }[]; key: string; }>; private createDie; remove(key: string): void; removeAll(): void; }