mk_box_buildfunction
mk_geometry_counts mk_box_build(const mk_box_params *, mk_geometry_buffer *)Build box.
| Parameter | Type | Description |
|---|---|---|
| const mk_box_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
#include <modkit/geometry.h>37 functions · 13 structs · 1 enums · 13 typedefs · 1 macros
Reusable shape geometry (the three.js BufferGeometry analog).
A geometry is a reusable shape: a vertex buffer (+ optional index buffer), its layout, counts, and topology. It is decoupled from how it's shaded pair any geometry with any pipeline/material and a transform via mk_draw_desc/mk_mesh. Two layers:Low-level builders (mk_*_sizes / mk_*_build): the single source of truth for primitive shape math. They fill caller-owned arrays (sokol_shape style), so they're allocation-agnostic and reusable the draw3d immediate API and the high-level constructors below both call these.High-level handles (mk_geometry_create + mk_geometry_box/sphere/...): upload a built shape to a GPU buffer and hand back a reusable mk_geometry_t. Generator vertex format (mk_geometry_vertex / mk_geometry_vertex_layout): POSITION f32x3, NORMAL f32x3, TANGENT f32x4, TEXCOORD0 f32x2, TEXCOORD1 f32x2, COLOR0 u8x4 normalized. One format serves the unlit, lit, and PBR materials. The tangent (xyz + sign in .w) is for normal mapping; primitive builders fill it (mk_geometry_create computes it for the built-in shapes), the model loader supplies glTF/MikkTSpace tangents. TEXCOORD1 (u1,v1) is a second UV set for KHR_texture_transform maps authored on UV1 (e.g. a baked occlusion atlas); primitive builders default it to (u,v) only the glTF loader ever fills it with real second-UV-set data.
mk_box_buildfunctionmk_geometry_counts mk_box_build(const mk_box_params *, mk_geometry_buffer *)Build box.
| Parameter | Type | Description |
|---|---|---|
| const mk_box_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_box_sizesfunctionmk_geometry_counts mk_box_sizes(const mk_box_params *)Perform the box sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_box_params * | — |
Returns The resulting value.
mk_capsule_buildfunctionmk_geometry_counts mk_capsule_build(const mk_capsule_params *, mk_geometry_buffer *)Build capsule.
| Parameter | Type | Description |
|---|---|---|
| const mk_capsule_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_capsule_sizesfunctionmk_geometry_counts mk_capsule_sizes(const mk_capsule_params *)Perform the capsule sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_capsule_params * | — |
Returns The resulting value.
mk_cone_buildfunctionmk_geometry_counts mk_cone_build(const mk_cone_params *, mk_geometry_buffer *)Build cone.
| Parameter | Type | Description |
|---|---|---|
| const mk_cone_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_cone_sizesfunctionmk_geometry_counts mk_cone_sizes(const mk_cone_params *)Perform the cone sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_cone_params * | — |
Returns The resulting value.
mk_cylinder_buildfunctionmk_geometry_counts mk_cylinder_build(const mk_cylinder_params *, mk_geometry_buffer *)Build cylinder.
| Parameter | Type | Description |
|---|---|---|
| const mk_cylinder_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_cylinder_sizesfunctionmk_geometry_counts mk_cylinder_sizes(const mk_cylinder_params *)Perform the cylinder sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_cylinder_params * | — |
Returns The resulting value.
mk_geometry_applyfunctionvoid mk_geometry_apply(mk_geometry_t, struct mk_draw_desc *out)Apply geometry.
| Parameter | Type | Description |
|---|---|---|
| mk_geometry_t | — |
out | struct mk_draw_desc * | Value for out. |
mk_geometry_boundsfunctionbool mk_geometry_bounds(mk_geometry_t, mk_aabb *out_bounds)Perform the geometry bounds operation.
| Parameter | Type | Description |
|---|---|---|
| mk_geometry_t | — |
out_bounds | mk_aabb * | Receives the bounds. |
Returns True when the operation succeeds.
mk_geometry_boxfunctionmk_geometry_t mk_geometry_box(const mk_box_params *)Primitive constructors build + upload, return a static geometry.
| Parameter | Type | Description |
|---|---|---|
| const mk_box_params * | — |
Returns The resulting handle or value.
mk_geometry_capsulefunctionmk_geometry_t mk_geometry_capsule(const mk_capsule_params *)Perform the geometry capsule operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_capsule_params * | — |
Returns The resulting handle or value.
mk_geometry_conefunctionmk_geometry_t mk_geometry_cone(const mk_cone_params *)Perform the geometry cone operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_cone_params * | — |
Returns The resulting handle or value.
mk_geometry_createfunctionmk_geometry_t mk_geometry_create(const mk_geometry_desc *desc)Create a static geometry from raw data.
| Parameter | Type | Description |
|---|---|---|
desc | const mk_geometry_desc * | Configuration descriptor. |
Returns The resulting handle or value.
mk_geometry_cylinderfunctionmk_geometry_t mk_geometry_cylinder(const mk_cylinder_params *)Perform the geometry cylinder operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_cylinder_params * | — |
Returns The resulting handle or value.
mk_geometry_destroyfunctionvoid mk_geometry_destroy(mk_geometry_t)Destroy the geometry.
| Parameter | Type | Description |
|---|---|---|
| mk_geometry_t | — |
mk_geometry_gridfunctionmk_geometry_t mk_geometry_grid(const mk_grid_params *)Perform the geometry grid operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_grid_params * | — |
Returns The resulting handle or value.
mk_geometry_index_countfunctionuint32_t mk_geometry_index_count(mk_geometry_t)Perform the geometry index count operation.
| Parameter | Type | Description |
|---|---|---|
| mk_geometry_t | — |
Returns The resulting value.
mk_geometry_is_validfunctionbool mk_geometry_is_valid(mk_geometry_t g)Test whether the geometry is valid.
| Parameter | Type | Description |
|---|---|---|
g | mk_geometry_t | Value for g. |
Returns True when the condition holds.
mk_geometry_pinfunctionbool mk_geometry_pin(mk_geometry_t g)Perform the geometry pin operation.
| Parameter | Type | Description |
|---|---|---|
g | mk_geometry_t | Value for g. |
Returns True when the operation succeeds.
mk_geometry_planefunctionmk_geometry_t mk_geometry_plane(const mk_plane_params *)Perform the geometry plane operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_plane_params * | — |
Returns The resulting handle or value.
mk_geometry_spherefunctionmk_geometry_t mk_geometry_sphere(const mk_sphere_params *)Perform the geometry sphere operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_sphere_params * | — |
Returns The resulting handle or value.
mk_geometry_system_initfunctionvoid mk_geometry_system_init(void)Initialize the geometry system.
mk_geometry_system_shutdownfunctionvoid mk_geometry_system_shutdown(void)Perform the geometry system shutdown operation.
mk_geometry_topologyfunctionmk_topology_t mk_geometry_topology(mk_geometry_t)Perform the geometry topology operation.
| Parameter | Type | Description |
|---|---|---|
| mk_geometry_t | — |
Returns The resulting handle or value.
mk_geometry_torusfunctionmk_geometry_t mk_geometry_torus(const mk_torus_params *)Perform the geometry torus operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_torus_params * | — |
Returns The resulting handle or value.
mk_geometry_unpinfunctionvoid mk_geometry_unpin(mk_geometry_t g)Perform the geometry unpin operation.
| Parameter | Type | Description |
|---|---|---|
g | mk_geometry_t | Value for g. |
mk_geometry_vertex_countfunctionuint32_t mk_geometry_vertex_count(mk_geometry_t)Perform the geometry vertex count operation.
| Parameter | Type | Description |
|---|---|---|
| mk_geometry_t | — |
Returns The resulting value.
mk_geometry_vertex_layoutfunctionmk_layout_t mk_geometry_vertex_layout(void)The layout the builders emit and the default 3D materials expect.
Returns The resulting handle or value.
mk_grid_buildfunctionmk_geometry_counts mk_grid_build(const mk_grid_params *, mk_geometry_buffer *)Build grid.
| Parameter | Type | Description |
|---|---|---|
| const mk_grid_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_grid_sizesfunctionmk_geometry_counts mk_grid_sizes(const mk_grid_params *)Perform the grid sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_grid_params * | — |
Returns The resulting value.
mk_plane_buildfunctionmk_geometry_counts mk_plane_build(const mk_plane_params *, mk_geometry_buffer *)Build plane.
| Parameter | Type | Description |
|---|---|---|
| const mk_plane_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_plane_sizesfunctionmk_geometry_counts mk_plane_sizes(const mk_plane_params *)Perform the plane sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_plane_params * | — |
Returns The resulting value.
mk_sphere_buildfunctionmk_geometry_counts mk_sphere_build(const mk_sphere_params *, mk_geometry_buffer *)Build sphere.
| Parameter | Type | Description |
|---|---|---|
| const mk_sphere_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_sphere_sizesfunctionmk_geometry_counts mk_sphere_sizes(const mk_sphere_params *)Perform the sphere sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_sphere_params * | — |
Returns The resulting value.
mk_torus_buildfunctionmk_geometry_counts mk_torus_build(const mk_torus_params *, mk_geometry_buffer *)Build torus.
| Parameter | Type | Description |
|---|---|---|
| const mk_torus_params * | — |
| mk_geometry_buffer * | — |
Returns The resulting value.
mk_torus_sizesfunctionmk_geometry_counts mk_torus_sizes(const mk_torus_params *)Perform the torus sizes operation.
| Parameter | Type | Description |
|---|---|---|
| const mk_torus_params * | — |
Returns The resulting value.
mk_box_paramsstructData for box params.
| Field | Type | Description |
|---|---|---|
w | float | Width; zero selects the unit default. |
h | float | Height; zero selects the unit default. |
d | float | Depth; zero selects the unit default. |
color | uint32_t | RGBA color; zero selects opaque white. |
mk_capsule_paramsstructData for capsule params.
| Field | Type | Description |
|---|---|---|
radius | float | Cap and body radius. |
height | float | Total capsule height. |
segments | int | Radial segments; zero selects the automatic default. |
color | uint32_t | RGBA color; zero selects opaque white. |
mk_cone_paramsstructData for cone params.
| Field | Type | Description |
|---|---|---|
radius | float | Base radius; zero selects the unit default. |
height | float | Height; zero selects the unit default. |
segments | int | Radial segments; zero selects the automatic default. |
color | uint32_t | RGBA color; zero selects opaque white. |
mk_cylinder_paramsstructData for cylinder params.
| Field | Type | Description |
|---|---|---|
radius | float | Radius; zero selects the unit default. |
height | float | Height; zero selects the unit default. |
segments | int | Radial segments; zero selects the automatic default. |
color | uint32_t | RGBA color; zero selects opaque white. |
mk_geometry_bufferstructData for geometry buffer.
| Field | Type | Description |
|---|---|---|
vertices | mk_geometry_vertex * | caller-owned, >= counts.vertices |
vertex_cap | uint32_t | The vertex cap. |
indices | uint16_t * | caller-owned, >= counts.indices |
index_cap | uint32_t | The index cap. |
base_vertex | uint32_t | added to every emitted index |
mk_geometry_countsstructData for geometry counts.
| Field | Type | Description |
|---|---|---|
vertices | uint32_t | Number of vertices. |
indices | uint32_t | Number of indices. |
mk_geometry_descstructData for geometry desc.
| Field | Type | Description |
|---|---|---|
name | const char * | debug, NULL ok |
vertices | const void * | vertex bytes |
vertex_size | uint32_t | total bytes |
layout | const mk_layout_t * | NULL => mk_geometry_vertex_layout(). |
indices | const uint16_t * | NULL => non-indexed. |
index_count | uint32_t | The index count. |
topology | mk_topology_t | 0 => TRIANGLES |
bounds | const mk_aabb * | optional; default vertex format is computed |
mk_geometry_tstructData for geometry.
| Field | Type | Description |
|---|---|---|
id | uint32_t | The ID. |
mk_geometry_vertexstructData for geometry vertex.
| Field | Type | Description |
|---|---|---|
x | float | Position X coordinate. |
y | float | Position Y coordinate. |
z | float | Position Z coordinate. |
nx | float | Normal X component. |
ny | float | Normal Y component. |
nz | float | Normal Z component. |
tx | float | Tangent X component. |
ty | float | Tangent Y component. |
tz | float | Tangent Z component. |
tw | float | Tangent handedness sign. |
u | float | Primary texture U coordinate. |
v | float | Primary texture V coordinate. |
u1 | float | Secondary texture U coordinate; defaults to u when unavailable. |
v1 | float | Secondary texture V coordinate; defaults to v when unavailable. |
abgr | uint32_t | Packed ABGR vertex color. |
mk_grid_paramsstructData for grid params.
| Field | Type | Description |
|---|---|---|
size | float | Total grid width and depth. |
divisions | int | Number of cells per axis. |
color | uint32_t | Packed RGBA line color. |
mk_plane_paramsstructData for plane params.
| Field | Type | Description |
|---|---|---|
width | float | Width; zero selects the unit default. |
depth | float | Depth; zero selects the unit default. |
x_div | int | Subdivisions along X; zero selects the automatic default. |
z_div | int | Subdivisions along Z; zero selects the automatic default. |
color | uint32_t | RGBA color; zero selects opaque white. |
mk_sphere_paramsstructData for sphere params.
| Field | Type | Description |
|---|---|---|
radius | float | The radius. |
segments | int | The segments. |
color | uint32_t | The color. |
mk_torus_paramsstructData for torus params.
| Field | Type | Description |
|---|---|---|
major_r | float | Distance from the center to the tube center. |
minor_r | float | Tube radius. |
major_seg | int | Segments around the major ring. |
minor_seg | int | Segments around the tube. |
color | uint32_t | RGBA color; zero selects opaque white. |
mk_topologyenumPrimitive topology.
Note: bgfx encodes topology in the pipeline STATE word (MK_STATE_PT_*), not the buffer this is advisory. A LINES geometry (grid) must be drawn with a lines-state pipeline/material.
| Value | Description |
|---|---|
MK_TOPOLOGY_TRIANGLES | Selects triangles. |
MK_TOPOLOGY_LINES | Selects lines. |
mk_box_paramstypedeftypedef struct mk_box_params mk_box_paramsData for box params.
mk_capsule_paramstypedeftypedef struct mk_capsule_params mk_capsule_paramsData for capsule params.
mk_cone_paramstypedeftypedef struct mk_cone_params mk_cone_paramsData for cone params.
mk_cylinder_paramstypedeftypedef struct mk_cylinder_params mk_cylinder_paramsData for cylinder params.
mk_geometry_buffertypedeftypedef struct mk_geometry_buffer mk_geometry_bufferData for geometry buffer.
mk_geometry_countstypedeftypedef struct mk_geometry_counts mk_geometry_countsData for geometry counts.
mk_geometry_desctypedeftypedef struct mk_geometry_desc mk_geometry_descData for geometry desc.
mk_geometry_vertextypedeftypedef struct mk_geometry_vertex mk_geometry_vertexData for geometry vertex.
mk_grid_paramstypedeftypedef struct mk_grid_params mk_grid_paramsData for grid params.
LINES
mk_plane_paramstypedeftypedef struct mk_plane_params mk_plane_paramsData for plane params.
mk_sphere_paramstypedeftypedef struct mk_sphere_params mk_sphere_paramsData for sphere params.
mk_topology_ttypedeftypedef enum mk_topology mk_topology_tPrimitive topology.
Note: bgfx encodes topology in the pipeline STATE word (MK_STATE_PT_*), not the buffer this is advisory. A LINES geometry (grid) must be drawn with a lines-state pipeline/material.
mk_torus_paramstypedeftypedef struct mk_torus_params mk_torus_paramsData for torus params.
MK_GEOMETRY_INVALIDdefineMK_GEOMETRY_INVALIDInvalid sentinel for geometry.