Gama C Library
Gama C API Documentation
mesh.h File Reference
#include "mtl.h"
#include "position.h"
#include <float.h>

Go to the source code of this file.

Data Structures

struct  gm3MeshFace
 Represents a single face (triangle) in a 3D mesh. More...
struct  gm3Tex
 Represents a 2D texture coordinate. More...
struct  gm3Mesh
 Represents a 3D mesh composed of vertices, faces, normals, and texture coordinates. More...
struct  gm3BakedMeshHeader
 Header for the baked mesh binary format. More...

Macros

#define GM3_BAKED_MESH_MAGIC   0x474D334D
 Magic number for the baked mesh binary format: "GM3M".

Functions

void gm3_mesh_free (gm3Mesh *m)
 Frees all dynamically allocated memory associated with a gm3Mesh struct.
int gm3_mesh_center (gm3Mesh *m)
 Centers the mesh geometry around the origin (0,0,0).
int gm3_mesh_serialize (const gm3Mesh *mesh, void **data, size_t *size)
 Serializes a gm3Mesh into a binary buffer.
int gm3_mesh_deserialize (gm3Mesh *mesh, const void *data, size_t size)
 Deserializes a gm3Mesh from a binary buffer.

Macro Definition Documentation

◆ GM3_BAKED_MESH_MAGIC

#define GM3_BAKED_MESH_MAGIC   0x474D334D

Magic number for the baked mesh binary format: "GM3M".

Function Documentation

◆ gm3_mesh_center()

int gm3_mesh_center ( gm3Mesh * m)

Centers the mesh geometry around the origin (0,0,0).

This function calculates the bounding box of the mesh and translates all vertices so that the center of the bounding box is at the origin.

Parameters
mA pointer to the gm3Mesh to center.
Returns
0 on success, -1 if the mesh is NULL.

◆ gm3_mesh_deserialize()

int gm3_mesh_deserialize ( gm3Mesh * mesh,
const void * data,
size_t size )

Deserializes a gm3Mesh from a binary buffer.

This function reconstructs a gm3Mesh from a binary buffer created by gm3_mesh_serialize. The deserialized mesh will have its internal arrays dynamically allocated.

Parameters
meshA pointer to the gm3Mesh to fill with deserialized data.
dataA pointer to the binary buffer containing the serialized data.
sizeThe size of the binary buffer.
Returns
0 on success, -1 on failure (e.g., invalid magic, buffer too small, memory allocation failure).

◆ gm3_mesh_free()

void gm3_mesh_free ( gm3Mesh * m)

Frees all dynamically allocated memory associated with a gm3Mesh struct.

Parameters
mA pointer to the gm3Mesh to free.

◆ gm3_mesh_serialize()

int gm3_mesh_serialize ( const gm3Mesh * mesh,
void ** data,
size_t * size )

Serializes a gm3Mesh into a binary buffer.

This function converts the mesh data into a compact binary format, suitable for baking into a file or memory. The caller is responsible for freeing *data.

Parameters
meshA pointer to the gm3Mesh to serialize.
dataA pointer to a void* that will be allocated and filled with the serialized data.
sizeA pointer to a size_t that will store the size of the serialized data.
Returns
0 on success, -1 on memory allocation failure.