Header menu logo PhysicsSandbox

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

bouncyMaterial

Full Usage: bouncyMaterial

Returns: MaterialProperties

Bouncy material preset: moderate friction (0.4), high recovery (8.0), stiff spring (60 Hz, 0.5 damping).

Returns: MaterialProperties

makeBoxCmd id pos halfExtents mass

Full Usage: makeBoxCmd id pos halfExtents mass

Parameters:
    id : 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 AddBody command for a box.

id : 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.

Example

 let crate = makeBoxCmd "crate-1" (0.0, 5.0, 0.0) (0.5, 0.5, 0.5) 20.0
 let wall = makeBoxCmd "wall" (3.0, 1.0, 0.0) (0.1, 1.0, 2.0) 0.0   // static
val crate: obj
val wall: obj

makeCapsuleCmd id pos radius length mass

Full Usage: makeCapsuleCmd id pos radius length mass

Parameters:
    id : 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 AddBody command for a capsule (cylinder with hemispherical caps).

id : 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.

Example

 let capsule = makeCapsuleCmd "cap-1" (0.0, 5.0, 0.0) 0.2 1.0 5.0
 batchAdd session [capsule]
val capsule: obj

makeColor r g b a

Full Usage: makeColor r g b a

Parameters:
    r : 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 Color proto message from RGBA components (each 0.0–1.0).

r : 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.

makeCylinderCmd id pos radius length mass

Full Usage: makeCylinderCmd id pos radius length mass

Parameters:
    id : 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 AddBody command for a cylinder.

id : 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.

Example

 let cyl = makeCylinderCmd "cyl-1" (0.0, 3.0, 0.0) 0.25 0.9 50.0
 batchAdd session [cyl]
val cyl: obj

makeImpulseCmd bodyId impulse

Full Usage: makeImpulseCmd bodyId impulse

Parameters:
    bodyId : 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 ApplyImpulse command — an instantaneous velocity change applied once.

bodyId : 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.

Example

 let launch = makeImpulseCmd "sphere-1" (0.0, 20.0, 0.0)
 let push = makeImpulseCmd "box-1" (15.0, 0.0, 0.0)
val launch: obj
val push: obj

makeMaterialProperties friction maxRecovery springFreq springDamping

Full Usage: makeMaterialProperties friction maxRecovery springFreq springDamping

Parameters:
    friction : 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 MaterialProperties proto message from physical parameters.

friction : 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.

makeSetBodyPoseCmd bodyId pos

Full Usage: makeSetBodyPoseCmd bodyId pos

Parameters:
    bodyId : string
    pos : float * float * float

Returns: SimulationCommand

Builds a SetBodyPose command to update a body's position at runtime.

bodyId : string
pos : float * float * float
Returns: SimulationCommand

makeSphereCmd id pos radius mass

Full Usage: makeSphereCmd id pos radius mass

Parameters:
    id : 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 AddBody command for a sphere.

id : 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.

Example

 let cmd = makeSphereCmd "ball-1" (0.0, 10.0, 0.0) 0.5 1.0
 batchAdd session [cmd]
val cmd: obj

makeTorqueCmd bodyId torque

Full Usage: makeTorqueCmd bodyId torque

Parameters:
    bodyId : 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 ApplyTorque command — a rotational force applied to a body.

bodyId : 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.

Example

 let spin = makeTorqueCmd "box-1" (0.0, 10.0, 0.0)
 let tumble = makeTorqueCmd "sphere-1" (5.0, 0.0, 5.0)
val spin: obj
val tumble: obj

slipperyMaterial

Full Usage: slipperyMaterial

Returns: MaterialProperties

Slippery/ice-like material preset: near-zero friction (0.01), moderate recovery (2.0), standard spring (30 Hz, 1.0 damping).

Returns: MaterialProperties

stickyMaterial

Full Usage: stickyMaterial

Returns: MaterialProperties

Sticky/high-friction material preset: friction 2.0, low recovery (0.5), stiff spring (30 Hz, 1.0 damping).

Returns: MaterialProperties

Type something to start searching.