Turns an image (its alpha) into a concave shape made of convex polygons (at most 8 vertices each) and writes it as .dnshape bytes (integer vertices, origin at the image centre, y up). Register the bytes as a mesh of a world or a session. It is an editor-time tool: nothing in it runs during a simulation. Every decision is made with integers, so the same image and parameters give the same bytes on every platform. The editors' bakers (3. Concepts) call these functions.
Function
Description
detphys_bake_abi_version
Version of this header (DETPHYS_BAKE_ABI_VERSION)
detphys_bake_params_default
Default parameters (1000 units per m = mm, 128 px per m, alpha 128 or more is inside, 8 vertices per piece, Steiner, tolerance 1 px)
Bake an alpha image (1 byte per pixel), an RGBA image (alpha is the 4th byte) or the bytes of a PNG file (rows top-down; up to 16384 x 16384 px). params may be NULL (the defaults). Always return a result (NULL only when memory runs out)
detphys_bake_status
DETPHYS_OK, DETPHYS_BAKE_ERR_IMAGE (−20, the image could not be read), DETPHYS_BAKE_ERR_SHAPE (−21, no shape could be made) or DETPHYS_ERR_ARGUMENT / DETPHYS_ERR_INTERNAL
detphys_bake_error
Why the bake failed (English, one sentence; empty on success)
detphys_bake_data
The .dnshape bytes (NULL when the bake failed). Valid until the result is destroyed
The simplified outline, for previews (loops and vertices in vertex units)
detphys_bake_png_alpha
Reads the alpha of a PNG without baking it (call with alpha = NULL to get the size first)
detphys_bake_result_destroy
Frees a result
Struct
Description
detphys_bake_params
Units per m, pixels per m, alpha threshold, most vertices per piece (3–8), decomposition (DETPHYS_BAKE_STEINER = default, DETPHYS_BAKE_HM = Hertel-Mehlhorn), simplification tolerance (px), smallest bulge of a vertex (mm), smallest island (px), Steiner snap distance (mm)
detphys_bake_stats
Image size, pieces and their vertices, outline loops and vertices, holes filled, specks dropped, vertices removed, Steiner points, bounds, the tolerance used and the largest distance from the traced outline (mm)