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

C API Reference

Render surfaces

Embed a render surface in a tetrahedral mesh, and deform it with the simulation every frame.

On this page

A render surface is the mesh a host draws. deformable_embed_surface prepares it once against the rest mesh of an object, and the DeformableSurfaceEmbedding it returns deforms it with the simulated nodes every frame. A breakable surface gets inner faces, which lie on tetrahedron faces inside the object and stay hidden until a crack exposes them. With a splinter cage it takes the splinter path instead: it is cut into bricks, one per cell of the cage, and caps close the cuts.

DeformableClipMode

Enum · deformable.h

c
typedef int32_t DeformableClipMode;

How deformable_embed_surface prepares a render surface against the rest mesh: whether it cuts the surface along the tetrahedron faces, and which inner faces it adds.

An inner face lies on a tetrahedron face inside the object, hidden until a crack exposes it. With a splinter cage (the splinter_cage of DeformablePreparationParameters), the two modes other than DEFORMABLE_CLIP_MODE_ASSIGN_ONLY take the splinter path instead.

Values

  • DEFORMABLE_CLIP_MODE_ASSIGN_ONLY (0)Each vertex follows the tetrahedron it lies in, or the nearest one by its weights when it lies outside the mesh; nothing is cut and no inner face is made. For objects that bend but never break.
  • DEFORMABLE_CLIP_MODE_CLIP_WITH_INNER_FACES (2)Breakable: the surface is cut along the tetrahedron faces, and the part of each interior tetrahedron face inside the surface becomes an inner face. A polygon wholly outside the mesh is kept whole on the nearest tetrahedron by its weights.
  • DEFORMABLE_CLIP_MODE_TETRAHEDRAL_MESH_BOUNDARY (3)The tetrahedral mesh is the surface: each polygon follows the tetrahedron its centre lies in, uncut, and every interior tetrahedron face becomes an inner face. For showing the tetrahedrons themselves.

See also Guide: Prepare the surface · Rust ClipMode · Python ClipMode

DeformablePreparationParameters

Struct · deformable.h

c
typedef struct DeformablePreparationParameters {
    DeformableClipMode clip_mode;
    double uv_scale;
    const DeformablePolygonMeshView *splinter_cage;
} DeformablePreparationParameters;

The settings of deformable_embed_surface: how it cuts the surface, the scale of the planar UVs it makes, and an optional splinter cage.

Fields

  • clip_mode (DeformableClipMode)How the surface is cut, and which inner faces it gets.
  • uv_scale (double)Scale of the planar UVs of inner and cap faces; the random offsets of inner faces are not scaled. 1 is a good start.
  • splinter_cage (const DeformablePolygonMeshView *)The splinter cage in the surface’s space, already moved by the host’s splinter transform, or NULL. With vertices and a clip mode other than DEFORMABLE_CLIP_MODE_ASSIGN_ONLY, the surface takes the splinter path: it is cut into one brick per cage cell, and the cuts are capped. When no cell holds a part of the surface, the surface is prepared as without a cage. DEFORMABLE_CLIP_MODE_ASSIGN_ONLY ignores the cage, but its polygons are still checked.

Example

c
// A surface that bends with the object but never breaks.
DeformablePreparationParameters parameters = {0};
parameters.clip_mode = DEFORMABLE_CLIP_MODE_ASSIGN_ONLY;
parameters.uv_scale = 1.0;
DeformableSurfaceMeshView surface = {0};
surface.mesh = polygons;
DeformableSurfaceEmbedding *embedding = NULL;
CHECK(deformable_embed_surface(&mesh, &surface, &parameters,
                               &embedding));
deformable_surface_embedding_destroy(embedding);

See also Guide: Prepare the surface · Rust PreparationParameters · Python PreparationParameters

DeformableSkinningOptions

Struct · deformable.h

c
typedef struct DeformableSkinningOptions {
    uint8_t show_inner_faces;
    uint8_t start_splintered;
} DeformableSkinningOptions;

The per-frame skinning options: which hidden faces deformable_surface_embedding_deform shows. A zeroed struct turns both off.

Fields

  • show_inner_faces (uint8_t)Not 0: shows every inner face and cap, exposed or not, so no face is hidden: useful to inspect the preparation.
  • start_splintered (uint8_t)Not 0: with splinter data, shows the caps from the start instead of once a tetrahedron of theirs is flagged, as for an object that starts out split.

Example

c
DeformablePreparationParameters parameters = {0};
parameters.clip_mode = DEFORMABLE_CLIP_MODE_CLIP_WITH_INNER_FACES;
DeformableSurfaceMeshView surface = {0};
surface.mesh = polygons;
DeformableSurfaceEmbedding *embedding = NULL;
CHECK(deformable_embed_surface(&mesh, &surface, &parameters,
                               &embedding));
const DeformableTetrahedronState *states;
size_t count;
CHECK(deformable_scene_tetrahedron_states(scene, object,
                                          &states, &count));
DeformableAffineTransform identity = {
    {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}, {0, 0, 0}};
// Every inner face shown, to inspect the preparation.
DeformableSkinningOptions options = {1, 0};
DeformableDeformedSurface *deformed = NULL;
CHECK(deformable_deformed_surface_create(&deformed));
CHECK(deformable_surface_embedding_deform(embedding, states, count,
                                          &identity, &options,
                                          deformed));
deformable_deformed_surface_destroy(deformed);
deformable_surface_embedding_destroy(embedding);

See also Guide: Skin it every frame · Rust SkinningOptions · Python SkinningOptions

DeformableDeformedSurface

Opaque handle · deformable.h

c
typedef struct DeformableDeformedSurface DeformableDeformedSurface;

A skinned surface in the object space of the host’s shape: float positions per output vertex, unit float normals per corner (none when the surface has none) and the faces to hide.

Made with deformable_deformed_surface_create and refilled by every deformable_surface_embedding_deform into it: keep one per surface across frames, so its buffers are allocated once. One deform may fill it at a time: give each thread that skins its own. Read it with deformable_deformed_surface_view and free it with deformable_deformed_surface_destroy.

See also Guide: Skin it every frame · Rust DeformedSurface · Python DeformedSurface

deformable_deformed_surface_create

Function · deformable.h

c
DeformableStatus deformable_deformed_surface_create(
    DeformableDeformedSurface **deformed);

Creates an empty skinned surface for deformable_surface_embedding_deform to fill. Make one per surface and reuse it every frame: each deform into it replaces its contents and reuses its buffers.

Parameters

Errors

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

deformable_deformed_surface_view

Function · deformable.h

c
DeformableStatus deformable_deformed_surface_view(
    const DeformableDeformedSurface *deformed,
    DeformableDeformedSurfaceView *view);

Lends the arrays of a skinned surface: the positions, the corner normals and the faces to hide.

Parameters

Errors

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

deformable_deformed_surface_destroy

Function · deformable.h

c
void deformable_deformed_surface_destroy(
    DeformableDeformedSurface *deformed);

Destroys a skinned surface; NULL is ignored. Views of it become invalid.

Parameters

DeformableDeformedSurfaceView

Struct · deformable.h

c
typedef struct DeformableDeformedSurfaceView {
    const float (*positions)[3];
    size_t position_count;
    const float (*normals)[3];
    size_t normal_count;
    const uint8_t *hidden_faces;
    size_t face_count;
} DeformableDeformedSurfaceView;

The arrays of a skinned surface, as deformable_deformed_surface_view lends them: owned by it, in the object space of the host’s shape.

Fields

  • positions (const float (*)[3])The deformed position of each output vertex, mapped by the inverse world transform.
  • position_count (size_t)The number of output vertices.
  • normals (const float (*)[3])The deformed normal of each corner, embed(p + n) - embed(p) mapped by the linear part of the inverse world transform and made unit length, a zero vector left zero; none when the surface has no normals.
  • normal_count (size_t)The number of corner normals: the corner count, or 0 without normals.
  • hidden_faces (const uint8_t *)1 for each face the host hides (an inner face or cap not shown yet), 0 for the others.
  • face_count (size_t)The number of faces.

See also Guide: Skin it every frame · Rust DeformedSurface · Python DeformedSurface

DeformableSurfaceEmbedding

Opaque handle · deformable.h

c
typedef struct DeformableSurfaceEmbedding DeformableSurfaceEmbedding;

A prepared surface in rest space, made by deformable_embed_surface: the output surface, the tetrahedron and barycentric weights each output vertex follows, the flag word of each corner, the weights of the corner normals, and on the splinter path each vertex’s cell tetrahedron. Read it with deformable_surface_embedding_view, skin it with deformable_surface_embedding_deform and free it with deformable_surface_embedding_destroy.

An input vertex becomes one output vertex for each flag word and tetrahedron among its corners, so the surface can open along the cracks. A vertex outside the rest mesh follows the nearest tetrahedron by its weights (the one whose smallest barycentric weight is largest), with weights that extrapolate. Reading and skinning never change the embedding, so any number of threads may use one embedding at the same time.

See also Guide: The prepared surface · Rust SurfaceEmbedding · Python SurfaceEmbedding

deformable_surface_embedding_view

Function · deformable.h

c
DeformableStatus deformable_surface_embedding_view(
    const DeformableSurfaceEmbedding *embedding,
    DeformableSurfaceEmbeddingView *view);

Lends the arrays of a surface embedding: the prepared surface in rest space, the flag word of each corner, the source face of each face, and the tetrahedron and weights each vertex follows.

Parameters

Errors

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

See also Python SurfaceEmbedding.arrays

deformable_surface_embedding_deform

Function · deformable.h

c
DeformableStatus deformable_surface_embedding_deform(
    const DeformableSurfaceEmbedding *embedding,
    const DeformableTetrahedronState *states,
    size_t state_count,
    const DeformableAffineTransform *world_transform,
    const DeformableSkinningOptions *options,
    DeformableDeformedSurface *deformed);

Skins the surface on the current tetrahedron states into deformed, in the object space of the host’s shape: positions and unit normals in float, mapped by the inverse of world_transform, and the faces to hide.

Each output vertex follows its tetrahedron by its weights. On the splinter path it switches to its cell tetrahedron once its cell has broken loose: once that tetrahedron or its own has a state flag word other than 0, or the two sit in different islands. Each corner normal is mapped by the linear part of the inverse, then made unit length; a zero one stays zero. A face is hidden while it is an inner face whose tetrahedron face no fracture has exposed, or a cap whose brick tetrahedron and the own tetrahedron of its first corner both still have a state flag word of 0, unless options say to show it. The states are not checked: a NaN or infinite corner gives NaN or infinite positions. Skinning never changes the embedding, so several threads may skin one embedding at the same time, each into its own deformed surface.

Parameters

Errors

Example

c
DeformablePreparationParameters parameters = {0}; // assign only
DeformableSurfaceMeshView surface = {0};
surface.mesh = polygons;
DeformableSurfaceEmbedding *embedding = NULL;
CHECK(deformable_embed_surface(&mesh, &surface, &parameters,
                               &embedding));
DeformableDeformedSurface *deformed = NULL;
CHECK(deformable_deformed_surface_create(&deformed));
// Every frame, after the step:
const DeformableTetrahedronState *states;
size_t count;
CHECK(deformable_scene_tetrahedron_states(scene, object,
                                          &states, &count));
DeformableAffineTransform identity = {
    {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}, {0, 0, 0}};
DeformableSkinningOptions options = {0, 0};
CHECK(deformable_surface_embedding_deform(embedding, states, count,
                                          &identity, &options,
                                          deformed));
deformable_deformed_surface_destroy(deformed);
deformable_surface_embedding_destroy(embedding);

See also Guide: Skin it every frame · Rust SurfaceEmbedding::deform · Python SurfaceEmbedding.deform

deformable_surface_embedding_destroy

Function · deformable.h

c
void deformable_surface_embedding_destroy(
    DeformableSurfaceEmbedding *embedding);

Destroys a surface embedding; NULL is ignored. Views of it become invalid.

Parameters

See also Python SurfaceEmbedding.close

DeformableSurfaceEmbeddingView

Struct · deformable.h

c
typedef struct DeformableSurfaceEmbeddingView {
    DeformableSurfaceMeshView surface;
    const uint32_t *corner_flags;
    size_t corner_flag_count;
    const int32_t *source_faces;
    size_t source_face_count;
    const uint32_t *vertex_tetrahedrons;
    size_t vertex_tetrahedron_count;
    const double (*vertex_weights)[4];
    size_t vertex_weight_count;
    const double (*normal_weights)[4];
    size_t normal_weight_count;
    const uint32_t *brick_tetrahedrons;
    size_t brick_tetrahedron_count;
    const uint32_t *vertex_cell_tetrahedrons;
    size_t vertex_cell_tetrahedron_count;
} DeformableSurfaceEmbeddingView;

The arrays of a surface embedding, as deformable_surface_embedding_view lends them: owned by the embedding and valid until it is destroyed.

Fields

  • surface (DeformableSurfaceMeshView)The prepared surface in rest space: output vertices, polygons and per-corner channels. It can have more vertices than the input, as a vertex is split where a crack can open; with DEFORMABLE_CLIP_MODE_ASSIGN_ONLY it keeps one vertex per input vertex a polygon uses. Build the render mesh from it once.
  • corner_flags (const uint32_t *)The flag word of each corner of surface, in corner order: bits 0 to 28 the controlling tetrahedron, bits 29 and 30 the tetrahedron face of an inner face, bit 31 set on the corners of inner faces. On the splinter path, the tetrahedron is that of the corner’s brick, the face bits are not set, and bit 31 marks the corners of caps.
  • corner_flag_count (size_t)The number of corner flag words: the corner count of surface.
  • source_faces (const int32_t *)The input face each output face was cut from, in face order; -1 for inner faces and caps.
  • source_face_count (size_t)The number of output faces.
  • vertex_tetrahedrons (const uint32_t *)The controlling tetrahedron of each output vertex, the one it follows.
  • vertex_tetrahedron_count (size_t)The number of output vertices.
  • vertex_weights (const double (*)[4])The barycentric weights of each output vertex in its tetrahedron; some are negative for a vertex outside it.
  • vertex_weight_count (size_t)The number of vertex weights: one per output vertex.
  • normal_weights (const double (*)[4])The barycentric weights of p + n for each corner, the tip of its normal n at its position p, in its vertex’s tetrahedron; none when the surface has no normals.
  • normal_weight_count (size_t)The number of normal weights: the corner count, or 0 without normals.
  • brick_tetrahedrons (const uint32_t *)The controlling tetrahedron of each brick of the splinter path, one brick per cage cell that holds a part of the surface; none without splinter data.
  • brick_tetrahedron_count (size_t)The number of bricks.
  • vertex_cell_tetrahedrons (const uint32_t *)The cell tetrahedron of each output vertex on the splinter path, the one it follows once its cell has broken loose; none without splinter data.
  • vertex_cell_tetrahedron_count (size_t)The number of cell tetrahedrons: one per output vertex, or 0 without splinter data.

See also Guide: The prepared surface · Python SurfaceEmbeddingArrays

deformable_embed_surface

Function · deformable.h

c
DeformableStatus deformable_embed_surface(
    const DeformableTetrahedralMeshView *rest,
    const DeformableSurfaceMeshView *surface,
    const DeformablePreparationParameters *parameters,
    DeformableSurfaceEmbedding **embedding);

Prepares a render surface against the rest mesh of an object: cuts it as the clip mode says, adds inner faces with random planar UVs times uv_scale, takes the splinter path when a splinter cage is given, then embeds each output vertex in a tetrahedron by barycentric weights.

The prepared surface keeps every channel the input has, with opaque white as the colour of inner faces. With DEFORMABLE_CLIP_MODE_CLIP_WITH_INNER_FACES and on the splinter path, a polygon of fewer than 3 corners is left out. The random stream that turns and offsets the UVs of inner faces has a fixed seed, so equal input gives equal UVs. The call copies what it needs: the inputs may be freed once it returns.

Parameters

Returns

DEFORMABLE_STATUS_OK, and the prepared surface with its embedding in embedding: read it with deformable_surface_embedding_view, and skin it every frame with deformable_surface_embedding_deform.

Errors

Example

c
DeformablePreparationParameters parameters = {0};
parameters.clip_mode = DEFORMABLE_CLIP_MODE_CLIP_WITH_INNER_FACES;
parameters.uv_scale = 1.0;
DeformableSurfaceMeshView surface = {0};
surface.mesh = polygons;
DeformableSurfaceEmbedding *embedding = NULL;
CHECK(deformable_embed_surface(&mesh, &surface, &parameters,
                               &embedding));
deformable_surface_embedding_destroy(embedding);

See also Guide: Prepare the surface · Rust embed_surface · Python embed_surface