CommandBuilders Module
Factory functions for constructing protobuf SimulationCommand messages from simple F# values.
These builders hide the nested proto message hierarchy (Shape → AddBody → SimulationCommand).
Use batchAdd to send the resulting commands.
Functions and values
| Function or value |
Description
|
|
Bouncy material preset: moderate friction (0.4), high recovery (8.0), stiff spring (60 Hz, 0.5 damping).
|
Full Usage:
makeBoxCmd id pos halfExtents mass
Parameters:
string
-
Unique body ID. Use nextId "box" for auto-generated IDs.
pos : float * float * float
-
World-space position (x, y, z). Position is the box center.
For a box resting on the ground, set Y to its half-height.
halfExtents : float * float * float
-
Half-dimensions (hx, hy, hz) in meters. (0.5, 0.5, 0.5) = 1m cube.
Reference: crate=(0.5,0.5,0.5), brick=(0.2,0.1,0.05), die=(0.05,0.05,0.05), domino=(0.1,0.3,0.02).
mass : float
-
Mass in kg. Use 0 for static walls/floors. Reference: die=0.03, brick=3, crate=20.
Returns: SimulationCommand
A SimulationCommand ready for batchAdd.
|
Builds an
Example
val crate: obj
val wall: obj
|
Full Usage:
makeCapsuleCmd id pos radius length mass
Parameters:
string
-
Unique body ID. Use nextId "capsule" for auto-generated IDs.
pos : float * float * float
-
World-space position (x, y, z). Position is the capsule center.
radius : float
-
Capsule radius in meters. Reference: limb=0.05, pipe=0.1, barrel=0.25. Typical range: 0.01–0.5.
length : float
-
Capsule length (cylinder portion, excluding caps) in meters. Total height = length + 2×radius.
Reference: finger=0.05, limb=0.3, pole=2.0. Typical range: 0.1–3.0.
mass : float
-
Mass in kg. Use 0 for static. Reference: limb=2, pipe=5, log=50.
Returns: SimulationCommand
A SimulationCommand ready for batchAdd.
|
Builds an
Example
val capsule: obj
|
Full Usage:
makeColor r g b a
Parameters:
float
-
Red channel 0.0–1.0.
g : float
-
Green channel 0.0–1.0.
b : float
-
Blue channel 0.0–1.0.
a : float
-
Alpha channel 0.0–1.0. 1.0 = fully opaque.
Returns: Color
A Color message to assign to a body's color field.
|
Creates a
|
Full Usage:
makeCylinderCmd id pos radius length mass
Parameters:
string
-
Unique body ID. Use nextId "cylinder" for auto-generated IDs.
pos : float * float * float
-
World-space position (x, y, z). Position is the cylinder center.
radius : float
-
Cylinder radius in meters. Reference: coin=0.01, can=0.03, barrel=0.25. Typical range: 0.01–1.0.
length : float
-
Cylinder length (height) in meters. Reference: coin=0.002, can=0.12, barrel=0.9. Typical range: 0.01–3.0.
mass : float
-
Mass in kg. Use 0 for static. Reference: coin=0.01, can=0.35, barrel=50.
Returns: SimulationCommand
A SimulationCommand ready for batchAdd.
|
Builds an
Example
val cyl: obj
|
Full Usage:
makeImpulseCmd bodyId impulse
Parameters:
string
-
Target body ID. Must match an existing body.
impulse : float * float * float
-
Impulse vector (x, y, z) in Newton-seconds. Effect scales inversely with mass.
Typical: (0, 5, 0) gentle nudge, (0, 50, 0) strong launch, (10, 0, 0) horizontal push,
(0, 0, -30) bowling-ball break shot.
Returns: SimulationCommand
A SimulationCommand ready for batchAdd.
|
Builds an
Example
val launch: obj
val push: obj
|
Full Usage:
makeMaterialProperties friction maxRecovery springFreq springDamping
Parameters:
float
-
Coulomb friction coefficient. 0=frictionless ice, 0.5=wood, 1.0=rubber. Typical range: 0.0–2.0.
maxRecovery : float
-
Maximum recovery velocity in m/s. Higher = bouncier collisions. Typical: 1.0–10.0.
springFreq : float
-
Contact spring frequency in Hz. Higher = stiffer contact. Typical: 30–120.
springDamping : float
-
Contact spring damping ratio. 1.0 = critically damped. Typical: 0.5–2.0.
Returns: MaterialProperties
A MaterialProperties message to assign to a body's material field.
|
Creates a
|
Full Usage:
makeSetBodyPoseCmd bodyId pos
Parameters:
string
pos : float * float * float
Returns: SimulationCommand
|
Builds a
|
Full Usage:
makeSphereCmd id pos radius mass
Parameters:
string
-
Unique body ID. Use nextId "sphere" for auto-generated IDs like "sphere-1".
pos : float * float * float
-
World-space position (x, y, z). Y is up; ground at Y=0. Example: (0.0, 5.0, 0.0).
Space bodies at least 2× radius apart to avoid overlap.
radius : float
-
Sphere radius in meters. Reference: marble=0.01, bowling ball=0.11,
beach ball=0.2, boulder=0.5. Typical range: 0.01–1.0.
mass : float
-
Mass in kg. Use 0 for static. Reference: marble=0.005, beach ball=0.1,
bowling ball=6.35, boulder=200. Typical range: 0.01–200.
Returns: SimulationCommand
A SimulationCommand ready for batchAdd.
|
Builds an
Example
val cmd: obj
|
Full Usage:
makeTorqueCmd bodyId torque
Parameters:
string
-
Target body ID. Must match an existing body.
torque : float * float * float
-
Torque vector (x, y, z) in Newton-meters. The axis determines rotation direction;
magnitude determines strength. Typical: (0, 5, 0) gentle Y-spin, (0, 50, 0) fast spin,
(10, 10, 0) diagonal tumble. Heavier bodies need proportionally larger torques.
Returns: SimulationCommand
A SimulationCommand ready for batchAdd.
|
Builds an
Example
val spin: obj
val tumble: obj
|
|
Slippery/ice-like material preset: near-zero friction (0.01), moderate recovery (2.0), standard spring (30 Hz, 1.0 damping).
|
|
Sticky/high-friction material preset: friction 2.0, low recovery (0.5), stiff spring (30 Hz, 1.0 damping).
|
PhysicsSandbox