You are viewing the documentation for Deformable v0.1.0, an older version. Read the latest, v0.9.0

C API Reference

Scene

The scene, and everything it takes or returns: materials, objects, glue, driven vertices, steps and outputs.

On this page

A DeformableScene holds a set of objects and steps them through time. Its calls come first, then the values they take and return, in the order a host meets them: materials and material regions, objects, glue, driven vertices, steps and the outputs of a step.

DeformableScene

Opaque handle · deformable.h

c
typedef struct DeformableScene DeformableScene;

One scene a host drives frame by frame: its materials and objects, the glue, driven vertices and forces between steps, the frame step and the outputs a host reads back.

deformable_scene_create makes an empty scene and deformable_scene_destroy frees it. Materials and objects are uint32_t handles counting up from 0 in creation order.

Lengths cross in host units (multiplied by the scale on the way in, divided by it on the way out); time, forces, gravity, masses and material values pass in simulation units. A scene may move between threads, but calls on one scene must not overlap; deformable_scene_step runs the scene’s own worker threads, and its results do not depend on their count.

Each array a per-frame output call lends is owned by the scene and stays valid until the next call of the same function on it or its destruction, so a frame’s outputs can be read side by side without a copy.

Example

c
DeformableScene *scene = NULL;
CHECK(deformable_scene_create(&scene));
DeformableVector3 z_up = {0.0, 0.0, -9.81};
CHECK(deformable_scene_set_gravity(scene, z_up));
DeformableStepReport report;
CHECK(deformable_scene_step(scene, 0.0, 10, NULL, &report));
CHECK(deformable_scene_step(scene, 1.0 / 24, 10, NULL, &report));
deformable_scene_destroy(scene);

See also Guide: Set up the scene · Rust Scene · Python Scene

deformable_scene_create

Function · deformable.h

c
DeformableStatus deformable_scene_create(DeformableScene **scene);

Creates an empty scene: gravity (0, -9.81, 0), scale 1, and as many worker threads as the machine runs in parallel, at most 16.

Parameters

Errors

  • Only the statuses every call can give, which the conventions describe.

See also Guide: Set up the scene · Rust Scene::new

deformable_scene_destroy

Function · deformable.h

c
void deformable_scene_destroy(DeformableScene *scene);

Destroys a scene with everything it holds; NULL is ignored. The arrays it lent become invalid, and it must not be used again.

Parameters

  • scene (DeformableScene *)The scene to destroy, or NULL. No other call may be using it.

See also Guide: Set up the scene · Python Scene.close

deformable_scene_set_scale

Function · deformable.h

c
DeformableStatus deformable_scene_set_scale(
    DeformableScene *scene,
    double scale);

Sets the factor from the host length unit to the simulation unit, from 0.001 to 1,000.

A new scene has scale 1: a host unit is a simulation unit, which reads as a metre under the default gravity, and a scene modelled in centimetres sets 0.01. Positions, driven targets and glue plane offsets are multiplied by the scale on the way in, and positions and velocities divided by it on the way out; time, forces, gravity, node masses and material values pass unscaled. The scale applies to later calls: stored state is not rescaled.

The scene lives in a world box that reaches 1,000 simulation units from the origin along each axis. An awake island that leaves it in a step becomes static for good: its nodes stop where they are. Choose the scale so that the scene stays inside.

Parameters

  • scene (DeformableScene *)The scene to change.
  • scale (double)The length of one host unit in simulation units, from 0.001 to 1,000.

Errors

See also Guide: Set up the scene · Rust Scene::set_scale · Python Scene.set_scale

deformable_scene_set_gravity

Function · deformable.h

c
DeformableStatus deformable_scene_set_gravity(
    DeformableScene *scene,
    DeformableVector3 gravity);

Sets the gravity acceleration, in simulation units: the scale does not apply to it.

A new scene has (0, -9.81, 0): y points up, and a simulation unit reads as a metre. A z-up scene sets (0, 0, -9.81).

Parameters

Errors

See also Guide: Set up the scene · Rust Scene::set_gravity · Python Scene.set_gravity

deformable_scene_set_worker_count

Function · deformable.h

c
DeformableStatus deformable_scene_set_worker_count(
    DeformableScene *scene,
    size_t count);

Sets the number of threads a step uses, the calling thread included; results do not depend on it.

A new scene has as many as the machine runs in parallel, at most 16. Any count from 1 up is accepted, but a step never runs more threads than the machine runs in parallel.

Parameters

  • scene (DeformableScene *)The scene to change.
  • count (size_t)The thread count, at least 1.

Errors

See also Guide: Set up the scene · Rust Scene::set_worker_count · Python Scene.set_worker_count

deformable_scene_add_material

Function · deformable.h

c
DeformableStatus deformable_scene_add_material(
    DeformableScene *scene,
    const DeformableMaterialParameters *parameters,
    uint32_t *material);

Creates a material and writes its handle to material; handles count up from 0 in creation order.

Each value is clamped to its range (see DeformableMaterialParameters), a toughness of 0 or below makes the material unbreakable, and the damping coefficient alpha is youngs_damping / youngs_modulus of the clamped values, at full double precision.

Parameters

Errors

See also Guide: Add and change a material · Rust Scene::add_material · Python Scene.add_material

deformable_scene_set_material

Function · deformable.h

c
DeformableStatus deformable_scene_set_material(
    DeformableScene *scene,
    uint32_t material,
    const DeformableMaterialParameters *parameters);

Rewrites the values of material as deformable_scene_add_material makes them.

The objects using the material get their materials again at the next step that advances the time with at least one substep, before its substeps: their nodes take the new toughness and the masses of a new density, with their velocities kept (see deformable_scene_node_masses), their islands rebuild and nothing wakes.

Parameters

Errors

See also Guide: Add and change a material · Rust Scene::set_material · Python Scene.set_material

deformable_scene_add_object

Function · deformable.h

c
DeformableStatus deformable_scene_add_object(
    DeformableScene *scene,
    const DeformableTetrahedralMeshView *mesh,
    const DeformableTetrahedronMaterials *materials,
    const DeformableObjectOptions *options,
    uint32_t *object);

Creates an object from a tetrahedral mesh and writes its handle to object; handles count up from 0 in creation order.

The mesh is in world space and host units, and its positions are the object’s rest shape: one node per vertex, and one tetrahedron for each of its tetrahedrons, with its material. Every tetrahedron must be positively oriented, as the tools make them; the check runs in simulation units, after the scale. Nothing is created when a check fails or the license refuses the call; the trial counts the tetrahedrons of the enabled objects with this one’s, none when it is created disabled. The object is glued at the next step that advances the time with at least one substep.

Parameters

Errors

See also Guide: Add an object · Rust Scene::add_object · Python Scene.add_object

deformable_scene_set_object_material

Function · deformable.h

c
DeformableStatus deformable_scene_set_object_material(
    DeformableScene *scene,
    uint32_t object,
    const DeformableTetrahedronMaterials *materials);

Gives the tetrahedrons of object new materials at the next step that advances the time with at least one substep, before its substeps.

Their nodes then take the new toughness and the masses of the new densities, with their velocities kept (see deformable_scene_node_masses), the object’s islands rebuild and nothing wakes. A later call before that step replaces this one.

Parameters

Errors

See also Guide: Change an object · Rust Scene::set_object_material · Python Scene.set_object_material

deformable_scene_remove_object

Function · deformable.h

c
DeformableStatus deformable_scene_remove_object(
    DeformableScene *scene,
    uint32_t object);

Deletes object at once, with its contacts, glue, driven vertices, queued forces and pending material change.

Its handle becomes unknown to every call and is never given to another object, so the other objects keep theirs. Its tetrahedrons stop counting toward the trial limit.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to delete.

Errors

See also Guide: Change an object · Rust Scene::remove_object · Python Scene.remove_object

deformable_scene_set_object_disabled

Function · deformable.h

c
DeformableStatus deformable_scene_set_object_disabled(
    DeformableScene *scene,
    uint32_t object,
    uint8_t disabled);

Disables object or enables it again.

Disabling frees the object’s contacts and glue at once, and takes it out of its islands at the next step that runs a substep; its nodes keep their state, it keeps its outputs, and forces on it are ignored while it is disabled. Its driving waits too: its driven vertices hold still, and the deformable_scene_drive calls made for it take effect at the first step after it is enabled, where a vertex they release leaves with its last driven velocity. Enabling it again returns its nodes with their stored state, but not its glue: an object that is disabled when the next step glues new objects gets no glue either. Setting the state the object already has does nothing. A disabled object does not count toward the trial’s limit; enabled again, it counts from the next step, which fails with DEFORMABLE_STATUS_TRIAL_LIMIT_EXCEEDED while the enabled objects pass the limit.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to disable or enable.
  • disabled (uint8_t)Not 0 disables the object, 0 enables it.

Errors

See also Guide: Change an object · Rust Scene::set_object_disabled · Python Scene.set_object_disabled

deformable_scene_set_self_collision

Function · deformable.h

c
DeformableStatus deformable_scene_set_self_collision(
    DeformableScene *scene,
    uint32_t object,
    uint8_t enabled);

Sets or clears the self-collision of object: whether its colliders test its own faces against each other.

Each island of the object takes the change when it is next rebuilt. The self_collision field of DeformableObjectOptions gives the setting an object starts with.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to change.
  • enabled (uint8_t)Not 0 turns self-collision on, 0 off.

Errors

See also Guide: Change an object · Rust Scene::set_self_collision · Python Scene.set_self_collision

deformable_scene_set_never_sleep

Function · deformable.h

c
DeformableStatus deformable_scene_set_never_sleep(
    DeformableScene *scene,
    uint32_t object,
    uint32_t node,
    uint8_t enabled);

Sets or clears the never-sleep flag of node node of object: an island that holds a tetrahedron of a never-sleep node never sleeps.

Setting the flag on a frozen node wakes the node: its island and the islands around it rebuild at the next step. On an awake node the flag takes effect when its island is next rebuilt, and clearing it does nothing else.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object that holds the node.
  • node (uint32_t)The node, an index into the object’s nodes.
  • enabled (uint8_t)Not 0 sets the flag, 0 clears it.

Errors

See also Guide: Change an object · Rust Scene::set_never_sleep · Python Scene.set_never_sleep

deformable_scene_set_glue_all

Function · deformable.h

c
DeformableStatus deformable_scene_set_glue_all(
    DeformableScene *scene,
    const DeformableGlueParameters *parameters);

Turns glue all on with parameters, or off with NULL, the setting of a new scene.

With glue all on, each new object is glued to every other enabled object where their tetrahedrons overlap. The glue is made by the next step that advances the time with at least one substep, from the positions the objects have then; the new objects are those added since the last such step. Objects that only touch are not glued, and glue made before stays when glue all is turned off. A spring constant of 0 means 4,905, and a damping coefficient of 0 means 2,452.5.

Parameters

Errors

See also Guide: Glue objects together · Rust Scene::set_glue_all · Python Scene.set_glue_all

deformable_scene_add_glue_region

Function · deformable.h

c
DeformableStatus deformable_scene_add_glue_region(
    DeformableScene *scene,
    const DeformableConvexRegion *region,
    const uint32_t *members,
    size_t member_count,
    const DeformableGlueParameters *parameters);

Adds a glue region: each new member is glued to every other enabled member through their tetrahedrons with a vertex inside region.

The glue is made by the next step that advances the time with at least one substep, from the positions the objects have then; the new members are those added since the last such step, and the region stays for every later such step. The planes are in host units: their offsets are multiplied by the scale when the region is added, their normals are not. A region with no plane holds every point. A spring constant of 0 means 4,905, and a damping coefficient of 0 means 2,452.5.

Parameters

Errors

See also Guide: Glue objects together · Rust Scene::add_glue_region · Python Scene.add_glue_region

deformable_scene_drive

Function · deformable.h

c
DeformableStatus deformable_scene_drive(
    DeformableScene *scene,
    uint32_t object,
    const DeformableDrivenVertex *vertices,
    size_t vertex_count);

Drives the listed vertices of object to their targets from the next step on, in place of the vertices it drove before.

Each listed vertex moves in equal substeps to reach its target, to within rounding, at the end of the next step, whatever the forces on it, then holds the target until a later call for the object. Vertices driven before but not listed are released with their last driven velocity, so a host can throw them; an empty list releases them all. A vertex released by a step that ends with DEFORMABLE_STEP_OUTCOME_SUBSTEP_TOO_LARGE gets that velocity too, and the next step that runs a substep starts from it. On a disabled object the call waits until the object is enabled, and takes effect at the first step after that (see deformable_scene_set_object_disabled). A call that fails changes nothing.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object whose vertices to drive.
  • vertices (const DeformableDrivenVertex *)Each vertex to drive, with its target in host units. May be NULL when vertex_count is 0.
  • vertex_count (size_t)The number of vertices; 0 releases every driven vertex of the object.

Errors

Example

c
DeformableStepReport report;
for (int frame = 0; frame <= 24; frame++) {
    DeformableDrivenVertex lifted = {0, mesh.positions[0]};
    lifted.target.y += 0.01 * frame;
    CHECK(deformable_scene_drive(scene, object, &lifted, 1));
    CHECK(deformable_scene_step(scene, frame / 24.0, 10, NULL,
                                &report));
}

See also Guide: Drive vertices · Rust Scene::drive · Python Scene.drive

deformable_scene_add_force

Function · deformable.h

c
DeformableStatus deformable_scene_add_force(
    DeformableScene *scene,
    uint32_t object,
    uint32_t node,
    DeformableVector3 force);

Queues force on node node of object for the substeps of the next step call; calls on one node add up.

The next step call that returns a report uses up the queue, whether it runs substeps or not, and deformable_scene_skip_to drops it, so a lasting force is queued again before each step. When a substep applies it, a force on a frozen node wakes the node’s connected piece, or for an object with glue the nodes within the material’s wake_up_radius of it, even a zero force; on a node that is not solved, such as a driven one, the force is kept and acts at once on the node’s first solve. Forces on a disabled object are ignored.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object that holds the node.
  • node (uint32_t)The node, an index into the object’s nodes.
  • force (DeformableVector3)The force, in simulation units: the scale does not apply to it.

Errors

Example

c
// A push along x on every node, for the next step.
DeformableVector3 push = {5.0, 0.0, 0.0};
for (uint32_t node = 0; node < mesh.position_count; node++) {
    CHECK(deformable_scene_add_force(scene, object, node,
                                     push));
}

See also Guide: Add forces · Rust Scene::add_force · Python Scene.add_force

deformable_scene_step

Function · deformable.h

c
DeformableStatus deformable_scene_step(
    DeformableScene *scene,
    double time,
    uint32_t substeps,
    const DeformableCancelFlag *cancel,
    DeformableStepReport *report);

Advances the scene to time, in seconds, in substeps equally long substeps, and writes what it did to report.

A host calls it once per frame with the frame’s time. The first call only records the time, so make it at the start frame. A later call runs its substeps when time has passed, substeps is not 0 and a substep is at most 0.04 s; otherwise the outcome says which of these stopped it. A cancel flag set from another thread stops the step between two substeps, after at least one, with the outcome DEFORMABLE_STEP_OUTCOME_CANCELLED: the time then stands at the last substep run, so the next call goes on from there.

Every call that succeeds uses up the forces deformable_scene_add_force queued. The license is checked at every call, so a scene larger than the trial allows steps only while a license is active.

Parameters

  • scene (DeformableScene *)The scene to step.
  • time (double)The frame’s time, in seconds. It may not be before the last time a step or deformable_scene_skip_to recorded.
  • substeps (uint32_t)How many substeps to run, all of one length; at 24 frames per second, 10 is a good start.
  • cancel (const DeformableCancelFlag *)Stops the step between two substeps when another thread sets it. May be NULL.
  • report (DeformableStepReport *)Out. Receives how many substeps ran, and what the call did: whether they ran, and if not, why.

Errors

Example

c
DeformableStepReport report;
for (int frame = 0; frame < 3; frame++) {
    CHECK(deformable_scene_step(scene, frame / 24.0, 10, NULL,
                                &report));
    unsigned substeps = report.substeps_run;
    printf("%d %u\n", (int)report.outcome, substeps);
}
// 1 0 (the first call), then 0 10 (stepped) twice.

See also Guide: Step · Rust Scene::step · Python Scene.step

deformable_scene_skip_to

Function · deformable.h

c
DeformableStatus deformable_scene_skip_to(
    DeformableScene *scene,
    double time);

Records time as the last time without creating glue, applying driven vertices or stepping, and drops the forces deformable_scene_add_force queued.

A host calls it in place of deformable_scene_step while its scene is paused or disabled: the next step goes on from time as if no time had passed. Before the first step it records nothing, so the next step is still a first call.

Parameters

  • scene (DeformableScene *)The scene whose time to record.
  • time (double)The time to record, in seconds. It may not be before the last time recorded.

Errors

See also Guide: Pause · Rust Scene::skip_to · Python Scene.skip_to

deformable_scene_node_positions

Function · deformable.h

c
DeformableStatus deformable_scene_node_positions(
    DeformableScene *scene,
    uint32_t object,
    const DeformableVector3 **positions,
    size_t *count);

Lends the current node positions of object, in host units.

The first nodes are the vertices of the mesh the object was made from, in order. Fracture clones nodes and adds them after, so the node count grows as the object breaks. The array is owned by the scene and stays valid until the next call of this function on it or its destruction.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to read.
  • positions (const DeformableVector3 **)Out. Receives a pointer to count positions, one per node.
  • count (size_t *)Out. Receives the number of nodes.

Errors

Example

c
const DeformableVector3 *positions;
size_t count;
CHECK(deformable_scene_node_positions(scene, object,
                                      &positions, &count));
// Before any fracture, one node per mesh vertex.
printf("%zu nodes, %zu vertices\n", count, mesh.position_count);

See also Guide: Read the outputs · Rust Scene::node_positions · Python Scene.node_positions

deformable_scene_node_velocities

Function · deformable.h

c
DeformableStatus deformable_scene_node_velocities(
    DeformableScene *scene,
    uint32_t object,
    const DeformableVector3 **velocities,
    size_t *count);

Lends the current node velocities of object, in host units per second (divided by the scale), in the order of deformable_scene_node_positions. The array is owned by the scene and stays valid until the next call of this function on it or its destruction.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to read.
  • velocities (const DeformableVector3 **)Out. Receives a pointer to count velocities, one per node.
  • count (size_t *)Out. Receives the number of nodes.

Errors

See also Guide: Read the outputs · Rust Scene::node_velocities · Python Scene.node_velocities

deformable_scene_node_masses

Function · deformable.h

c
DeformableStatus deformable_scene_node_masses(
    DeformableScene *scene,
    uint32_t object,
    const double **masses,
    size_t *count);

Lends the lumped node masses of object, in simulation units, in the order of deformable_scene_node_positions.

Each node, driven or not, takes a quarter of the mass (density times volume) of every tetrahedron it belongs to. A density that deformable_scene_set_material or deformable_scene_set_object_material changes reaches the masses at the next step that advances the time with at least one substep: each of its tetrahedrons gives its nodes the quarter of the new mass in place of the old one, and the velocities stay as they were, so the momentum changes with the mass. Fracture moves a tetrahedron’s quarter to the clone that takes it. The array is owned by the scene and stays valid until the next call of this function on it or its destruction.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to read.
  • masses (const double **)Out. Receives a pointer to count masses, one per node.
  • count (size_t *)Out. Receives the number of nodes.

Errors

See also Guide: Read the outputs · Rust Scene::node_masses · Python Scene.node_masses

deformable_scene_tetrahedron_nodes

Function · deformable.h

c
DeformableStatus deformable_scene_tetrahedron_nodes(
    DeformableScene *scene,
    uint32_t object,
    const uint32_t (**tetrahedrons)[4],
    size_t *count);

Lends the current four nodes of each tetrahedron of object, as indices into its nodes (the order of deformable_scene_node_positions), in mesh order.

Fracture never deletes or reorders tetrahedrons: tetrahedron i stays tetrahedron i of the mesh. It moves tetrahedrons onto cloned nodes instead, which these indices follow. The array is owned by the scene and stays valid until the next call of this function on it or its destruction.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to read.
  • tetrahedrons (const uint32_t (**)[4])Out. Receives a pointer to count groups of four node indices, one per tetrahedron.
  • count (size_t *)Out. Receives the tetrahedron count.

Errors

Example

c
const uint32_t (*tetrahedrons)[4];
size_t count;
CHECK(deformable_scene_tetrahedron_nodes(scene, object,
                                         &tetrahedrons, &count));
// Before any fracture, the nodes are those of the mesh.
printf("%zu tetrahedrons, %zu in the mesh\n", count,
       mesh.tetrahedron_count);

See also Guide: Read the outputs · Rust Scene::tetrahedron_nodes · Python Scene.tetrahedron_nodes

deformable_scene_tetrahedron_states

Function · deformable.h

c
DeformableStatus deformable_scene_tetrahedron_states(
    DeformableScene *scene,
    uint32_t object,
    const DeformableTetrahedronState **states,
    size_t *count);

Lends the output record of each tetrahedron of object, in mesh order: its corners in host units, its island id or 0, its strain measure and its flags. The array is owned by the scene and stays valid until the next call of this function on it or its destruction.

Parameters

  • scene (DeformableScene *)The scene that holds the object.
  • object (uint32_t)The object to read.
  • states (const DeformableTetrahedronState **)Out. Receives a pointer to count records, one per tetrahedron.
  • count (size_t *)Out. Receives the number of tetrahedrons.

Errors

Example

c
const DeformableTetrahedronState *states;
size_t count, index, broken = 0;
CHECK(deformable_scene_tetrahedron_states(scene, object,
                                          &states, &count));
for (index = 0; index < count; index++) {
    if (states[index].flags & DEFORMABLE_NODE_REPLACED) broken++;
}
printf("%zu tetrahedrons sit on a cloned node\n", broken);

See also Guide: Read the outputs · Rust Scene::tetrahedron_states · Python Scene.tetrahedron_states

deformable_scene_face_events

Function · deformable.h

c
DeformableStatus deformable_scene_face_events(
    DeformableScene *scene,
    uint32_t object,
    const DeformableFaceEvent **events,
    size_t *count);

Lends the exposed-face events of object from the last step: one for each tetrahedron that fracture changed in it.

Every step that succeeds replaces them, so a step without fracture leaves none. The array is owned by the scene and stays valid until the next call of this function on it or its destruction.

Parameters

Errors

Example

c
const DeformableFaceEvent *events;
size_t count, index;
CHECK(deformable_scene_face_events(scene, object, &events,
                                   &count));
for (index = 0; index < count; index++) {
    printf("tetrahedron %zu\n", (size_t)events[index].tetrahedron);
}

See also Guide: Find the faces a crack opened · Rust Scene::face_events · Python Scene.face_events

deformable_scene_awake_tetrahedron_count

Function · deformable.h

c
DeformableStatus deformable_scene_awake_tetrahedron_count(
    const DeformableScene *scene,
    size_t *count);

Writes the number of tetrahedrons in awake islands, over the whole scene, counted at each call, to count.

Sleeping tetrahedrons do not count, nor do static ones: those whose four nodes are all driven, and those of an island that left the world box (see deformable_scene_set_scale). Nor do those of islands waiting to be rebuilt at the next step that runs a substep, as after a material change, a disable or a fracture. A tetrahedron counts once a step has put it in an island, so a new object counts from the next step that runs substeps.

Parameters

  • scene (const DeformableScene *)The scene whose tetrahedrons are counted.
  • count (size_t *)Out. Receives the number of awake tetrahedrons.

Errors

  • Only the statuses every call can give, which the conventions describe.

See also Guide: Measure a scene · Rust Scene::awake_tetrahedron_count · Python Scene.awake_tetrahedron_count

deformable_scene_statistics

Function · deformable.h

c
DeformableStatus deformable_scene_statistics(
    const DeformableScene *scene,
    DeformableSceneStatistics *statistics);

Writes the solver, contact and island counters of the scene, for measuring it, to statistics: the solves since the scene was created, and the live contacts and the islands it holds now.

Parameters

Errors

  • Only the statuses every call can give, which the conventions describe.

See also Guide: Measure a scene · Rust Scene::statistics · Python Scene.statistics

DeformableMaterialParameters

Struct · deformable.h

c
typedef struct DeformableMaterialParameters {
    double youngs_modulus;
    double poissons_ratio;
    double density;
    double toughness;
    double youngs_damping;
    double yield_strain;
    double maximum_yield;
    double creep_fraction;
    double wake_up_radius;
    double friction;
} DeformableMaterialParameters;

The values of a material, as a host gives them to deformable_scene_add_material and deformable_scene_set_material, which clamp each one to its range and refuse a NaN or infinite one.

deformable_material_parameters_default writes the defaults below, and deformable_material_preset_find the values of a named material such as "steel".

Fields

  • youngs_modulus (double)Young’s modulus, in pascals in simulation units: the higher, the stiffer. Default 8e5, clamped to [1e3, 1e10].
  • poissons_ratio (double)Poisson’s ratio, unitless: how much the material bulges sideways when it is squeezed. Default 0, clamped to [-0.90001, 0.490001].
  • density (double)Mass per unit volume, in simulation units: a tetrahedron weighs its density times its volume. Default 2500, clamped to [0, 1e4].
  • toughness (double)The fracture threshold: a node can split once half the largest eigenvalue of its separation tensor exceeds the lowest toughness among its tetrahedrons. 0 or less makes the material unbreakable. Default 2e5, clamped to [0, 1e8].
  • youngs_damping (double)Stiffness-proportional damping; the engine’s damping coefficient is youngs_damping / youngs_modulus. Default 0, clamped to [0, 1e9].
  • yield_strain (double)The elastic strain norm above which plastic flow starts. Default 0, clamped to [0, 1].
  • maximum_yield (double)The bound on the plastic strain norm; 0 resets the plastic strain every solve. Default 0, clamped to [0, 1].
  • creep_fraction (double)The share of the elastic strain added to the plastic strain once per solve, not per second, while the elastic strain norm exceeds yield_strain; 0 turns plasticity off. Default 0, clamped to [0, 1].
  • wake_up_radius (double)How far, in simulation units, an impact on this material wakes the sleeping nodes of an object that has glue; an object without glue wakes its whole connected piece instead. Default 1.2, clamped to [1, 1000].
  • friction (double)The Coulomb friction coefficient; a contact uses the lower of its two materials’ coefficients. Default 0.6, clamped to [0, 1].

Example

c
DeformableMaterialParameters rubber;
CHECK(deformable_material_parameters_default(&rubber));
rubber.youngs_modulus = 1e6;
rubber.poissons_ratio = 0.45;
uint32_t handle;
CHECK(deformable_scene_add_material(scene, &rubber, &handle));

See also Guide: Materials · Rust MaterialParameters · Python MaterialParameters

deformable_material_parameters_default

Function · deformable.h

c
DeformableStatus deformable_material_parameters_default(
    DeformableMaterialParameters *parameters);

Writes the values a new material starts from, the defaults DeformableMaterialParameters lists, to parameters.

Parameters

Errors

  • Only the statuses every call can give, which the conventions describe.

See also Guide: Material values · Python MaterialParameters.default

deformable_material_preset_count

Function · deformable.h

c
size_t deformable_material_preset_count(void);

The number of material presets the library ships: deformable_material_preset reads each one by its index, in the library’s order, by family from the softest solids to the metals.

Density is in kilograms per cubic metre, with one simulation unit a metre. The values are chosen for each material and checked on a cube about one unit across, dropped onto a floor, and on a cantilever: whether the preset shatters, breaks from a fall or survives both, whether it bounces or keeps a dent, and how far it sags. An unbreakable_ preset is its namesake with toughness 0, and a few other presets are unbreakable too. Every value lies inside its clamp range, and every preset keeps the default wake_up_radius.

The names of the presets, by family:

  • Soft solids: sponge, foam, snow, jelly, rubber, unbreakable_rubber, hard_rubber.
  • Living and wooden: flesh, bone, plant, straw, cork, tree, wood, plywood, cardboard.
  • Building materials and stone: drywall, plaster, asphalt, clay, brick, concrete, reinforced_concrete, sandstone, stone, granite.
  • Glass and ceramics: glass, safety_glass, ceramic, diamond.
  • Plastics and carbon: plastic, rigid_foam, carbon_fiber, graphite.
  • Metals: wire, stiff_wire, steel, sheet_metal, foil, rebar, unbreakable_rebar, lead, iron.

See also Guide: Use a preset · Rust MaterialParameters::presets · Python MaterialParameters.presets

deformable_material_preset

Function · deformable.h

c
DeformableStatus deformable_material_preset(
    size_t index,
    const char **name,
    DeformableMaterialParameters *parameters);

Writes the name and values of material preset index, in the library’s order, to name and parameters.

Parameters

  • index (size_t)The preset’s index, counted from 0 and below the count deformable_material_preset_count gives.
  • name (const char **)Out. Receives the preset’s name, in lowercase with underscores between words, such as "unbreakable_rubber": a static NUL-terminated string the host never frees.
  • parameters (DeformableMaterialParameters *)Out. Receives the preset’s values.

Errors

Example

c
size_t count = deformable_material_preset_count();
for (size_t index = 0; index < count; index++) {
    const char *name;
    DeformableMaterialParameters parameters;
    CHECK(deformable_material_preset(index, &name, &parameters));
    puts(name);
}

See also Guide: Use a preset · Rust MaterialParameters::presets · Python MaterialParameters.presets

deformable_material_preset_find

Function · deformable.h

c
DeformableStatus deformable_material_preset_find(
    const char *name,
    DeformableMaterialParameters *parameters);

Looks a material preset up by its name and writes its values to parameters.

The name must match a preset’s exactly, case included: "steel" is a preset, "Steel" is not.

Parameters

  • name (const char *)The preset’s name, a NUL-terminated string such as "concrete" or "unbreakable_rubber".
  • parameters (DeformableMaterialParameters *)Out. Receives the preset’s values.

Errors

Example

c
DeformableMaterialParameters steel;
CHECK(deformable_material_preset_find("steel", &steel));
uint32_t handle;
CHECK(deformable_scene_add_material(scene, &steel, &handle));

See also Guide: Use a preset · Rust MaterialParameters::preset · Python MaterialParameters.preset

DeformableMaterialRegion

Struct · deformable.h

c
typedef struct DeformableMaterialRegion {
    DeformablePolygonMeshView mesh;
    DeformableAffineTransform to_mesh_space;
} DeformableMaterialRegion;

A material region: a polygon mesh in its own object space, and its map into the object space of a tetrahedral mesh, for deformable_material_region_indices.

A region with no polygons holds every tetrahedron.

Fields

  • mesh (DeformablePolygonMeshView)The region’s mesh, normally a closed convex polyhedron with outward faces, such as a unit cube: the region is what lies behind all of its face planes. Borrowed for the call only.
  • to_mesh_space (DeformableAffineTransform)Maps the region’s points into the tetrahedral mesh’s object space: the region’s world matrix times the inverse of the object’s.

Example

c
// The unit cube moved 0.5 along x: it holds the right half of mesh.
DeformableMaterialRegion region = {0};
region.mesh = polygons;
region.to_mesh_space = (DeformableAffineTransform){
    {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}, {0.5, 0, 0}};
DeformableMaterialRegionIndices *indices = NULL;
CHECK(deformable_material_region_indices(&mesh, &region, 1, &indices));
deformable_material_region_indices_destroy(indices);

See also Guide: Give part of an object another material · Rust MaterialRegion · Python MaterialRegion

DeformableMaterialRegionIndices

Opaque handle · deformable.h

c
typedef struct DeformableMaterialRegionIndices
    DeformableMaterialRegionIndices;

The material-region indices deformable_material_region_indices makes, one per tetrahedron: read them with deformable_material_region_indices_values and free them with deformable_material_region_indices_destroy.

See also Guide: Give part of an object another material

deformable_material_region_indices_values

Function · deformable.h

c
DeformableStatus deformable_material_region_indices_values(
    const DeformableMaterialRegionIndices *indices,
    const uint32_t **values,
    size_t *count);

Lends the indices of indices: one per tetrahedron of the mesh, in mesh order, valid until indices is destroyed.

Parameters

Errors

  • Only the statuses every call can give, which the conventions describe.

deformable_material_region_indices_destroy

Function · deformable.h

c
void deformable_material_region_indices_destroy(
    DeformableMaterialRegionIndices *indices);

Destroys material-region indices; NULL is ignored. The values they lent become invalid.

Parameters

deformable_material_region_indices

Function · deformable.h

c
DeformableStatus deformable_material_region_indices(
    const DeformableTetrahedralMeshView *mesh,
    const DeformableMaterialRegion *regions,
    size_t region_count,
    DeformableMaterialRegionIndices **indices);

Finds which material region holds each tetrahedron of mesh: 0 when none does, or 1 plus the index in regions of the region that does.

A region holds a tetrahedron when the tetrahedron’s centroid lies behind or on every face plane of the region’s mesh, mapped by to_mesh_space. Where regions overlap, the one whose mesh has the smallest signed volume before the map wins, whatever their order in regions; regions of equal volume may be tried in another order than theirs. A region with no polygons holds every tetrahedron. Each face plane is taken from the mapped polygon, so any invertible map, a non-uniform scale or a zero diagonal included, keeps the region exactly where the map puts it.

The host turns the indices into the DEFORMABLE_MATERIAL_ASSIGNMENT_PER_TETRAHEDRON materials of deformable_scene_add_object or deformable_scene_set_object_material: 0 is the object’s material, and each other index the material of the region one below it in regions.

Parameters

Returns

DEFORMABLE_STATUS_OK, and the handle in indices: read the indices, one per tetrahedron in mesh order, with deformable_material_region_indices_values.

Errors

Example

c
// The unit cube with x halved: it holds the left half of mesh.
DeformableMaterialRegion region = {0};
region.mesh = polygons;
region.to_mesh_space = (DeformableAffineTransform){
    {{{0.5, 0, 0}, {0, 1, 0}, {0, 0, 1}}}, {0, 0, 0}};
DeformableMaterialRegionIndices *indices = NULL;
CHECK(deformable_material_region_indices(&mesh, &region, 1, &indices));
deformable_material_region_indices_destroy(indices);

See also Guide: Give part of an object another material · Rust material_region_indices · Python material_region_indices

DeformableTetrahedronMaterials

Struct · deformable.h

c
typedef struct DeformableTetrahedronMaterials {
    DeformableMaterialAssignment assignment;
    uint32_t material;
    const uint32_t *materials;
    size_t material_count;
} DeformableTetrahedronMaterials;

The materials of an object’s tetrahedrons, for deformable_scene_add_object and deformable_scene_set_object_material: one material for all of them, or one per tetrahedron.

A list of another count than the mesh’s tetrahedron count gives DEFORMABLE_STATUS_LENGTH_MISMATCH, and a handle that names no material of the scene gives DEFORMABLE_STATUS_UNKNOWN_MATERIAL.

Fields

Example

c
DeformableTetrahedronMaterials uniform = {0};
uniform.assignment = DEFORMABLE_MATERIAL_ASSIGNMENT_UNIFORM;
uniform.material = material;
CHECK(deformable_scene_set_object_material(scene, object,
                                           &uniform));

See also Guide: Add an object · Rust TetrahedronMaterials

DeformableMaterialAssignment

Enum · deformable.h

c
typedef int32_t DeformableMaterialAssignment;

How DeformableTetrahedronMaterials gives the tetrahedrons their materials.

Values

  • DEFORMABLE_MATERIAL_ASSIGNMENT_UNIFORM (0)The struct’s material for every tetrahedron; materials is not read.
  • DEFORMABLE_MATERIAL_ASSIGNMENT_PER_TETRAHEDRON (1)materials[i] for tetrahedron i, in mesh order: the form material regions take; material is not read.

See also Guide: Add an object

DeformableObjectOptions

Struct · deformable.h

c
typedef struct DeformableObjectOptions {
    uint8_t self_collision;
    uint8_t disabled;
} DeformableObjectOptions;

The per-object settings a host gives when it creates an object with deformable_scene_add_object; booleans are 0 or not 0.

deformable_object_options_default writes the defaults: self-collision on and the object enabled. deformable_scene_set_self_collision and deformable_scene_set_object_disabled change them later.

Fields

  • self_collision (uint8_t)The object’s colliders test its own faces against each other. Default 1.
  • disabled (uint8_t)The object is created disabled: it takes no part in the scene until deformable_scene_set_object_disabled enables it, and it gets no glue if it is still disabled when the next step glues new objects. Default 0.

Example

c
DeformableObjectOptions options;
CHECK(deformable_object_options_default(&options));
options.self_collision = 0;
DeformableTetrahedronMaterials uniform = {0};
uniform.material = material;
uint32_t cube;
CHECK(deformable_scene_add_object(scene, &mesh, &uniform,
                                  &options, &cube));

See also Guide: Add an object · Rust ObjectOptions · Python ObjectOptions

deformable_object_options_default

Function · deformable.h

c
DeformableStatus deformable_object_options_default(
    DeformableObjectOptions *options);

Writes the object defaults to options: self-collision on (self_collision 1) and the object enabled (disabled 0).

Parameters

Errors

  • Only the statuses every call can give, which the conventions describe.

See also Python ObjectOptions.default

DeformableGlueParameters

Struct · deformable.h

c
typedef struct DeformableGlueParameters {
    double spring_constant;
    double damping_coefficient;
} DeformableGlueParameters;

The spring and damping of glue, for deformable_scene_set_glue_all and deformable_scene_add_glue_region.

Glue holds two overlapping tetrahedrons at the overlap volume they had when it was made, as a spring with a damper; the library scales the spring by the mass of the lighter of the two glued islands. A spring constant of 0 means 4,905, and a damping coefficient of 0 means 2,452.5.

Fields

  • spring_constant (double)The spring constant; 0 means 4,905.
  • damping_coefficient (double)The damping coefficient; 0 means 2,452.5.

Example

c
// A stiffer spring than the default, with the default damping.
DeformableGlueParameters glue = {2e4, 0.0};
CHECK(deformable_scene_set_glue_all(scene, &glue));

See also Guide: Glue objects together · Rust GlueParameters · Python GlueParameters

DeformableDrivenVertex

Struct · deformable.h

c
typedef struct DeformableDrivenVertex {
    uint32_t vertex;
    DeformableVector3 target;
} DeformableDrivenVertex;

A vertex of an object driven to a target, in host units, for deformable_scene_drive.

Fields

  • vertex (uint32_t)The vertex, an index into the object’s nodes.
  • target (DeformableVector3)Where the vertex is at the end of the next step, in host units. It holds the target until a later deformable_scene_drive call for the object moves or releases it.

Example

c
// Vertex 0, lifted 0.1 above where the mesh has it.
DeformableDrivenVertex lifted = {0, mesh.positions[0]};
lifted.target.y += 0.1;
CHECK(deformable_scene_drive(scene, object, &lifted, 1));

See also Guide: Drive vertices · Rust DrivenVertex · Python DrivenVertex

DeformableStepReport

Struct · deformable.h

c
typedef struct DeformableStepReport {
    uint32_t substeps_run;
    DeformableStepOutcome outcome;
} DeformableStepReport;

The result of a deformable_scene_step call: how many substeps ran, and what the call did.

Fields

See also Guide: Step · Rust StepReport · Python StepReport

DeformableStepOutcome

Enum · deformable.h

c
typedef int32_t DeformableStepOutcome;

What a deformable_scene_step call did.

Values

  • DEFORMABLE_STEP_OUTCOME_STEPPED (0)The substeps ran.
  • DEFORMABLE_STEP_OUTCOME_FIRST_CALL (1)The first call only records the time.
  • DEFORMABLE_STEP_OUTCOME_NO_TIME_ELAPSED (2)The time equals the last time; nothing is stepped.
  • DEFORMABLE_STEP_OUTCOME_NO_SUBSTEPS (3)Zero substeps were asked for; the time advances without a step.
  • DEFORMABLE_STEP_OUTCOME_SUBSTEP_TOO_LARGE (4)A substep would be longer than 0.04 s. The time advances, and the step’s new glue, material changes and driven-vertex changes are made, but no substep runs; a vertex released now gets its last driven velocity, and the next step that runs a substep starts from it.
  • DEFORMABLE_STEP_OUTCOME_CANCELLED (5)The cancel flag stopped the step after substeps_run substeps; the time advances by as many substeps, so the next step goes on from there. The queued forces are used up and do not reach the substeps that remain.

See also Guide: Step · Rust StepOutcome · Python StepOutcome

DeformableSceneStatistics

Struct · deformable.h

c
typedef struct DeformableSceneStatistics {
    uint64_t systems;
    uint64_t conjugate_gradient_updates;
    size_t contacts;
    size_t islands;
} DeformableSceneStatistics;

The solver, contact and island counters of a scene, for measuring it, as deformable_scene_statistics writes them; nothing in the scene uses them.

Fields

  • systems (uint64_t)The linear systems solved since the scene was created: one per contact island, and one per awake island outside every contact island, in each substep.
  • conjugate_gradient_updates (uint64_t)The conjugate gradient solution updates, summed over every solve since the scene was created.
  • contacts (size_t)The live contacts, glue contacts included.
  • islands (size_t)The islands it holds: awake, asleep and static (driven, or out of the world box), those waiting to be rebuilt at the next step included.

See also Guide: Measure a scene · Rust SceneStatistics · Python SceneStatistics

DeformableTetrahedronState

Struct · deformable.h

c
typedef struct DeformableTetrahedronState {
    DeformableVector3 corners[4];
    uint32_t island;
    double strain_measure;
    uint32_t flags;
} DeformableTetrahedronState;

The output record of one tetrahedron, as deformable_scene_tetrahedron_states lends it.

Fields

  • corners (DeformableVector3[4])The current corner positions in host units, in the order of the tetrahedron’s nodes.
  • island (uint32_t)The id of the tetrahedron’s island, the group of tetrahedrons solved together, or 0 while it has none.
  • strain_measure (double)The squared norm of the total co-rotated strain, plastic part included, measured with the tetrahedron’s stored rotation: ε_xx² + ε_yy² + ε_zz² + 2(γ_yz² + γ_xz² + γ_xy²), with no square root taken.
  • flags (uint32_t)Bit k (0 to 3) is set once face k, opposite corner k, has been reported exposed, and stays set; bit DEFORMABLE_NODE_REPLACED is set while a fracture has moved the tetrahedron onto a cloned node.

See also Guide: Read the outputs · Rust TetrahedronState · Python TetrahedronState

deformable_tetrahedron_state_face_centroid

Function · deformable.h

c
DeformableStatus deformable_tetrahedron_state_face_centroid(
    const DeformableTetrahedronState *state,
    uint32_t face,
    DeformableVector3 *centroid);

Writes the centroid of the face face, the one opposite corner face, of state to centroid, in the unit of the corners.

Parameters

Errors

See also Guide: Find the faces a crack opened · Rust TetrahedronState::face_centroid · Python TetrahedronState.face_centroid

deformable_tetrahedron_state_face_normal

Function · deformable.h

c
DeformableStatus deformable_tetrahedron_state_face_normal(
    const DeformableTetrahedronState *state,
    uint32_t face,
    DeformableVector3 *normal);

Writes the outward unit normal of the face face, the one opposite corner face, of state to normal, for a positively oriented tetrahedron; a face of zero area gives the zero vector.

Parameters

Errors

See also Guide: Find the faces a crack opened · Rust TetrahedronState::face_normal · Python TetrahedronState.face_normal

DeformableFaceEvent

Struct · deformable.h

c
typedef struct DeformableFaceEvent {
    uint32_t tetrahedron;
    uint8_t exposed_faces;
} DeformableFaceEvent;

An exposed-face event: a tetrahedron fracture changed in the last step and the faces it now shares with no other tetrahedron.

The mask holds every exposed face of the tetrahedron, not only those the step opened: the faces on the surface of the rest mesh, which deformable_boundary_faces gives, count too. A tetrahedron that a later fracture changes again gets a new event, with the faces reported before still set.

Fields

  • tetrahedron (uint32_t)The tetrahedron’s index in its object’s mesh.
  • exposed_faces (uint8_t)Bit k is set when face k, opposite corner k, is shared with no other tetrahedron.

See also Guide: Find the faces a crack opened · Rust FaceEvent · Python FaceEvent

DEFORMABLE_NODE_REPLACED

Constant · deformable.h

c
#define DEFORMABLE_NODE_REPLACED 0x10u

The bit of the flags of a DeformableTetrahedronState set while one of the tetrahedron’s nodes is no longer the node it was created with: a fracture moved the tetrahedron onto a clone of that node. It is worked out again for every read, not kept like the face bits.

See also Guide: Read the outputs · Rust NODE_REPLACED · Python NODE_REPLACED