Tiny3D
Loading...
Searching...
No Matches
t3dmodel.h File Reference
#include "t3d.h"
Include dependency graph for t3dmodel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  T3DMaterialAxis
 
struct  T3DMaterialTexture
 
struct  T3DMaterial
 
struct  T3DObjectPart
 
struct  T3DObject
 
struct  T3DBvhNode
 
struct  T3DBvh
 
struct  T3DChunkBone
 
struct  T3DChunkSkeleton
 
struct  T3DAnimChannelMapping
 
struct  T3DChunkAnim
 
union  T3DChunkOffset
 
struct  T3DModel
 
struct  T3DModelIter
 
struct  T3DModelDrawConf
 
struct  T3DModelState
 

Macros

#define T3D_ALPHA_MODE_DEFAULT   0
 
#define T3D_ALPHA_MODE_OPAQUE   1
 
#define T3D_ALPHA_MODE_CUTOUT   2
 
#define T3D_ALPHA_MODE_TRANSP   3
 
#define T3D_FOG_MODE_DEFAULT   0
 
#define T3D_FOG_MODE_DISABLED   1
 
#define T3D_FOG_MODE_ACTIVE   2
 

Typedefs

typedef void(* T3DModelTileCb) (void *userData, rdpq_texparms_t *tileParams, rdpq_tile_t tile)
 
typedef bool(* T3DModelFilterCb) (void *userData, const T3DObject *obj)
 
typedef void(* T3DModelDynTextureCb) (void *userData, const T3DMaterial *material, rdpq_texparms_t *tileParams, rdpq_tile_t tile)
 

Enumerations

enum  T3DModelChunkType {
  T3D_CHUNK_TYPE_VERTICES = 'V' , T3D_CHUNK_TYPE_INDICES = 'I' , T3D_CHUNK_TYPE_MATERIAL = 'M' , T3D_CHUNK_TYPE_OBJECT = 'O' ,
  T3D_CHUNK_TYPE_SKELETON = 'S' , T3D_CHUNK_TYPE_ANIM = 'A' , T3D_CHUNK_TYPE_BVH = 'B'
}
 

Functions

T3DModelt3d_model_load (const char *path)
 
static T3DModelState t3d_model_state_create ()
 
void t3d_model_free (T3DModel *model)
 
void t3d_model_draw_custom (const T3DModel *model, T3DModelDrawConf conf)
 
static void t3d_model_draw (const T3DModel *model)
 
void t3d_model_draw_object (const T3DObject *object, const T3DMat4FP *boneMatrices)
 
void t3d_model_draw_material (T3DMaterial *mat, T3DModelState *state)
 
static T3DVertPacked * t3d_model_get_vertices (const T3DModel *model)
 
void t3d_model_make_object_vert_placeholder (const T3DModel *model, T3DObject *object, uint8_t segmentId)
 
static const T3DChunkSkeletont3d_model_get_skeleton (const T3DModel *model)
 
static uint32_t t3d_model_get_animation_count (const T3DModel *model)
 
void t3d_model_get_animations (const T3DModel *model, T3DChunkAnim **anims)
 
T3DChunkAnimt3d_model_get_animation (const T3DModel *model, const char *name)
 
T3DObjectt3d_model_get_object (const T3DModel *model, const char *name)
 
static T3DObjectt3d_model_get_object_by_index (const T3DModel *model, uint32_t index)
 
T3DMaterialt3d_model_get_material (const T3DModel *model, const char *name)
 
static T3DModelIter t3d_model_iter_create (const T3DModel *model, enum T3DModelChunkType chunkType)
 
bool t3d_model_iter_next (T3DModelIter *iter)
 
static const T3DBvht3d_model_bvh_get (const T3DModel *model)
 
void t3d_model_bvh_query_frustum (const T3DBvh *bvh, const T3DFrustum *frustum)
 

Detailed Description

Function Documentation

◆ t3d_model_bvh_get()

static const T3DBvh * t3d_model_bvh_get ( const T3DModel * model)
inlinestatic

Returns the BVH of a model. Note that this is optional and may return NULL. To create one, pass '–bvh' to the gltf importer.

Parameters
modelmodel
Returns
pointer to the BVH or NULL if not found

◆ t3d_model_bvh_query_frustum()

void t3d_model_bvh_query_frustum ( const T3DBvh * bvh,
const T3DFrustum * frustum )

Queries the BVH of a model with a frustum. Note that the BVH is in model space, so the frustum may need to be transformed before. This will mark all objects in the BVH as visible via the 'isVisible' flag. Note that you need to first set all to false before calling this.

Parameters
bvhBVH to check
frustumfrustum to check against
Returns

◆ t3d_model_draw()

static void t3d_model_draw ( const T3DModel * model)
inlinestatic

Draws a model with default settings. This call can be recorded into a display list.

Parameters
modelmodel to draw

◆ t3d_model_draw_custom()

void t3d_model_draw_custom ( const T3DModel * model,
T3DModelDrawConf conf )

Draws a model with a custom configuration. This call can be recorded into a display list.

Parameters
modelmodel to draw
confcustom configuration

◆ t3d_model_draw_material()

void t3d_model_draw_material ( T3DMaterial * mat,
T3DModelState * state )

Draws/Applies a material of an object. This can be called before 't3d_model_draw_object'.
This will set up the texture, CC, and other RDP and t3d settings of the material.
NOTE: if you want to use this to record individual objects into a display list,
make sure to pass NULL for 'state', otherwise you may only record partial state changes.
For complete recordings, create a state via 't3d_model_state_create' and pass it to each call.

Parameters
matmaterial to apply
statestate for material settings, used to minimized changes across materials

◆ t3d_model_draw_object()

void t3d_model_draw_object ( const T3DObject * object,
const T3DMat4FP * boneMatrices )

Draws an object in a model directly.
This will only handle the mesh part, and not any material or texture settings.
As in, it will load vertices (optionally a bone matrix) and then draw the triangles.
If you want to change material settings, you can use 't3d_model_draw_material' before this.
Take a look at 't3d_model_iter_create' for an example of how to use it.

Parameters
objectobject to draw
boneMatricesmatrices in the case of skinned meshes, set to NULL for non-skinned

◆ t3d_model_free()

void t3d_model_free ( T3DModel * model)

Free model and any related resources (e.g. textures)

Parameters
model

◆ t3d_model_get_animation()

T3DChunkAnim * t3d_model_get_animation ( const T3DModel * model,
const char * name )

Returns an animation definition by name. Note: if you want to create an animation instance, use 't3d_anim_create'.

Parameters
model
nameanimation name
Returns
pointer to the animation or NULL if not found

◆ t3d_model_get_animation_count()

static uint32_t t3d_model_get_animation_count ( const T3DModel * model)
inlinestatic

Returns the number of animations in the model.

Parameters
model
Returns

◆ t3d_model_get_animations()

void t3d_model_get_animations ( const T3DModel * model,
T3DChunkAnim ** anims )

Stores the pointers to all animations inside the model into anims. Make sure to use t3d_model_get_animation_count to allocate enough memory.

Parameters
model
animsarray to store the pointers to

◆ t3d_model_get_material()

T3DMaterial * t3d_model_get_material ( const T3DModel * model,
const char * name )

Returns a material by name.

Parameters
modelmodel
namematerial name
Returns
material or NULL if not found

◆ t3d_model_get_object()

T3DObject * t3d_model_get_object ( const T3DModel * model,
const char * name )

Returns an object by name.

Parameters
modelmodel
nameobject name
Returns
object or NULL if not found

◆ t3d_model_get_object_by_index()

static T3DObject * t3d_model_get_object_by_index ( const T3DModel * model,
uint32_t index )
inlinestatic

Returns an object by index. Note that no bounds checking is done, so make sure the index is valid.

Parameters
modelmodel
indexobject index
Returns
object, invalid pointer if OOB!

◆ t3d_model_get_skeleton()

static const T3DChunkSkeleton * t3d_model_get_skeleton ( const T3DModel * model)
inlinestatic

Returns the first/main skeleton of a model. If the model contains multiple skeletons, data must be manually traversed instead.

Parameters
modelmodel
Returns
pointer to the skeleton or NULL if not found

◆ t3d_model_get_vertices()

static T3DVertPacked * t3d_model_get_vertices ( const T3DModel * model)
inlinestatic

Returns the global vertex buffer of a model. For the amount of vertices, see 'model->totalVertCount'. Since vertices are interleaved, the max index is 'totalVertCount / 2'. For easy access, use functions like 't3d_vertbuffer_get_pos' and similar.

Note that this is shared for all parts of the model. If you need to change specific vertices, you must iterate over the parts.

Parameters
model
Returns
pointer to the vertex buffer

◆ t3d_model_iter_create()

static T3DModelIter t3d_model_iter_create ( const T3DModel * model,
enum T3DModelChunkType chunkType )
inlinestatic

Creates an iterator to manually traverse the chunks contained in a file.
This can be used to manually iterate and draw objects.

Note that the iterator does not need to be freed,
you can simply discard it, or call this function again to rewind it.
the model it points to must however outlive the iterator.

As an example, here is how to do a custom draw of all objects in a file:

T3DModelIter it = t3d_model_iter_create(itemModel, T3D_CHUNK_TYPE_OBJECT);
while(t3d_model_iter_next(&it)) {
// (Apply materials here before the draw)
t3d_model_draw_object(it.object, NULL);
}
Definition t3dmodel.h:171
static T3DModelIter t3d_model_iter_create(const T3DModel *model, enum T3DModelChunkType chunkType)
Definition t3dmodel.h:438
Parameters
modelmodel to iterate
chunkTypetype of chunk to iterate (e.g. T3D_CHUNK_TYPE_OBJECT)
Returns
iterator

◆ t3d_model_iter_next()

bool t3d_model_iter_next ( T3DModelIter * iter)

Advances the iterator to the next chunk.
A pointer to the chunk is stored in 'iter->chunk'.
If it reached the end, this function will return false and set 'iter->chunk' to NULL.

Depending on the type you passed in via 't3d_model_iter_create', you either have to cast it,
or directly use one of the typed accessors like 'iter.object' for T3D_CHUNK_TYPE_OBJECT.

Parameters
iteriterator to advance
Returns
true if it found a chunk, false if it reached the end

◆ t3d_model_load()

T3DModel * t3d_model_load ( const char * path)

Loads a model from a file. If you no longer need the model, call 't3d_model_free'

Parameters
pathFS path
Returns
pointer to the model (that you now own)

◆ t3d_model_make_object_vert_placeholder()

void t3d_model_make_object_vert_placeholder ( const T3DModel * model,
T3DObject * object,
uint8_t segmentId )

Modifies an object to replace absolute vertex addresses with relative addressing. This can be used for switching out vertex buffers for effects or dynamic meshes, while still being able to record a mesh.

Internally this works by replacing the pointers with segments (see 't3d_segment_address'). In order to draw anything, you have to point the segment to a vertex buffer before drawing.

See the '04_dynamic' example for a full demo.

Parameters
modelmodel containing the object
objectobject to patch
segmentIdsegment id to use (1-7)

◆ t3d_model_state_create()

static T3DModelState t3d_model_state_create ( )
inlinestatic

Creates a new draw state with default values.

Returns