Soft sphere
Arguments are center x/y/z, radius, segments (default 16) and optional construction settings. The sphere is a closed surface shell rather than a tetrahedral solid. Pressure and stiffness must be tuned together for size and mass; excessive pressure in a soft shell can overinflate it.
Example#
ball = jolt_soft_body_create_sphere(0, 0, 3, 0.5, 24);
if (!is_undefined(ball)) {
ball.set_mass(2);
ball.set_stiffness(0.6);
ball.set_pressure(100);
ball.set_renderer(o_control_bbmod_renderer.renderer);
}Usage and limits#
Set mass, stiffness, pressure, damping, friction, gravity factor, collision thickness and layer on the created object. Use spatial attachments for anchors and set_grab_enabled(true) for Carry. Creation returns undefined on error; check before calling methods. Register BBMOD rendering once and destroy the object in Clean Up.
API reference#
Public function and method signatures. Call methods on the returned instance; parameters with defaults are optional.
Related guides#
- Migrating existing code
- Choosing a Soft Body
- Volumetric soft box
- Closed model import
- Cloth model and named anchors
- Spatial attachments
- Separate visual mesh
- Local force and impulse
- Wind
- Carrying Soft Bodies
Verified operation contracts#
These contracts distinguish units, return values, errors and lifetime according to the current implementation. Check results: false, 0 and undefined can mean different things for different methods.
| Symbol / owner | Signature | Operation contract |
|---|---|---|
| jolt_soft_body_create_sphere | jolt_soft_body_create_sphere(x,y,z,radius,segments=16,settings=undefined) | Returns JoltBBMODSphere or undefined in a running world. Radius .05..100 m; integer segments 8..64, default 16. This selects geodesic subdivision, not an exact particle count: 10*4^ceil(log2(segments/4))+2. Options mass=2, stiffness=.8, pressure=1000, damping=.1, friction=.5, gravity_factor=1, collision_thickness=.02, default layer. Thickness cannot exceed radius. |
| JoltBBMODSphere.add_force | JoltBBMODSphere.add_force(x,y,z) | Finite world force components x/y/z in N; Boolean. Submits total force to the native soft body, not a local particle selection. Use jolt_soft_body_force for a local effect. |
| JoltBBMODSphere.destroy | JoltBBMODSphere.destroy() | Boolean, repeatedly true after successful destruction. Removes physics first, then renderer registration, owned meshes/materials, attachments, wind and force helpers. Borrowed materials and host bodies are not destroyed. |
| JoltBBMODSphere.draw | JoltBBMODSphere.draw() | Renders current deformed geometry if live and visible; no return value. draw aliases render. Do not additionally call these manually when registered with a renderer. |
| JoltBBMODSphere.get_collision_thickness | JoltBBMODSphere.get_collision_thickness() | Current particle radius in m; undefined for an invalid wrapper, inspect native errors separately. |
| JoltBBMODSphere.get_damping | JoltBBMODSphere.get_damping() | Linear damping: current numeric value in 1/s. Failure: undefined (invalid wrapper); inspect native errors separately; an invalid object is not a zero measurement. |
| JoltBBMODSphere.get_friction | JoltBBMODSphere.get_friction() | Friction coefficient: current numeric value in dimensionless units. Failure: undefined (invalid wrapper); inspect native errors separately; an invalid object is not a zero measurement. |
| JoltBBMODSphere.get_gravity_factor | JoltBBMODSphere.get_gravity_factor() | Gravity multiplier: current numeric value in dimensionless units. Failure: undefined (invalid wrapper); inspect native errors separately; an invalid object is not a zero measurement. |
| JoltBBMODSphere.get_layer | JoltBBMODSphere.get_layer() | Returns a numeric layer handle, not a JoltLayer; undefined for an invalid wrapper. |
| JoltBBMODSphere.get_mass | JoltBBMODSphere.get_mass() | Total mass: current numeric value in kg. Failure: undefined; an invalid object is not a zero measurement. |
| JoltBBMODSphere.get_native_handle | JoltBBMODSphere.get_native_handle() | Valid soft-body handle, otherwise 0. Not a JoltBody handle for rigid-body methods. |
| JoltBBMODSphere.get_position | JoltBBMODSphere.get_position() | World mean particle position {x, y, z} in m, not a rigid transform; undefined for an invalid wrapper. |
| JoltBBMODSphere.get_pressure | JoltBBMODSphere.get_pressure() | Internal pressure of a closed surface: current numeric value in N/m². Failure: undefined; an invalid object is not a zero measurement. Open model cloth has no pressure; nonzero settings are rejected. |
| JoltBBMODSphere.get_stretch | JoltBBMODSphere.get_stretch() | Stretch stiffness: current numeric value in dimensionless units. Failure: undefined; an invalid object is not a zero measurement. |
| JoltBBMODSphere.get_vertex_position | JoltBBMODSphere.get_vertex_position(index) | Integer index 0 ≤ index < vertex_count. Returns world {x, y, z} in m, undefined for an invalid index/wrapper. |
| JoltBBMODSphere.get_volume | JoltBBMODSphere.get_volume() | Volume in m³ from current deformation; open model cloth returns 0. undefined for invalid object or read failure. |
| JoltBBMODSphere.is_valid | JoltBBMODSphere.is_valid() | Boolean based on the wrapper, handle and original managed world. Not a native existence query for every particle; do not mix raw destruction with managed ownership. |
| JoltBBMODSphere.render | JoltBBMODSphere.render() | Renders current deformed geometry if live and visible; no return value. draw aliases render. Do not additionally call these manually when registered with a renderer. |
| JoltBBMODSphere.set_collision_thickness | JoltBBMODSphere.set_collision_thickness(v) | Particle collision radius in m, finite ≥0. Upper bound: Sphere radius, half the smallest Box dimension, half the shortest model edge. Boolean; default 0.02 Sphere/Box, model 0.01 or a smaller edge-adjusted value when omitted from options. |
| JoltBBMODSphere.set_damping | JoltBBMODSphere.set_damping(v) | Linear damping: finite number 0..1000 1/s; default 0.1 Sphere, 0.5 Box, 0.2 closed model / 0.1 model cloth. Returns true on acceptance, false for an invalid input or object. Updates the live object. |
| JoltBBMODSphere.set_debug | JoltBBMODSphere.set_debug(v) | Enables diagnostic drawing, default false; returns true. Does not change physics or object lifetime. |
| JoltBBMODSphere.set_friction | JoltBBMODSphere.set_friction(v) | Friction coefficient: finite number 0..1000 ; default 0.5. Returns true on acceptance, false for an invalid input or object. Updates the live object. |
| JoltBBMODSphere.set_gravity_factor | JoltBBMODSphere.set_gravity_factor(v) | Gravity multiplier: finite number 0..1000 ; default 1. Returns true on acceptance, false for an invalid input or object. Updates the live object. |
| JoltBBMODSphere.set_layer | JoltBBMODSphere.set_layer(layer) | JoltLayer or positive integer layer handle; the layer must exist in this world. Boolean. Does not modify the layer collision matrix. |
| JoltBBMODSphere.set_mass | JoltBBMODSphere.set_mass(v) | Total mass: finite number 0.01..1000000 kg; default 2 (Sphere/Box), 2 closed model / 1 model cloth. Returns true on acceptance, false for an invalid input or object. Updates the live object. |
| JoltBBMODSphere.set_material | JoltBBMODSphere.set_material(material) | BBMOD_BaseMaterial or undefined for an automatic owned two-sided material. Boolean; user material is borrowed and not destroyed, a previous owned material is released. |
| JoltBBMODSphere.set_pressure | JoltBBMODSphere.set_pressure(v) | Internal pressure of a closed surface: finite number 0..1000000 N/m²; default 1000 Sphere, 50 closed model, 0 open model cloth. Returns true on acceptance, false for an invalid input or object. Updates the live object. Open model cloth has no pressure; nonzero settings are rejected. |
| JoltBBMODSphere.set_renderer | JoltBBMODSphere.set_renderer(renderer) | Live BBMOD_BaseRenderer or undefined to detach. Boolean; registers/unregisters this same object, do not additionally register it by hand. Requires a live soft body. |
| JoltBBMODSphere.set_stretch | JoltBBMODSphere.set_stretch(v) | Stretch stiffness: finite number 0..1 ; default 0.8 Sphere/closed model, 0.3 Box, 0.9 model cloth. Returns true on acceptance, false for an invalid input or object. Updates the live object. |
| JoltBBMODSphere.set_visible | JoltBBMODSphere.set_visible(value) | Input coerced to Boolean, default true. Returns Boolean success. Hides rendering without disabling physics. |
| JoltBBMODSphere.update_mesh | JoltBBMODSphere.update_mesh(force=false) | Boolean success; force=false uses the physics revision cache. force=true forces an update even after manual native stepping. Positions are already world-space; do not apply the body transform again. |