LibT2FS 0.1
C API for accessing TEngine data in memory.
Loading...
Searching...
No Matches
Models API

Example usage:

Assuming you are already read through the Core Basics and have an open T2FSContext object, in this example called ctx.

int error;
uint32_t modelCount;
// Get the amount of models
modelCount = t2fs_model_count(&ctx);
// The model context is needed to support the differences between games
// and game platforms. This will set the right function pointers in the
// context to match current loaded game.
t2fs_model_context_init(&ctx, &modelCtx);
// Iterate over all models
for (uint32_t modelId=0; modelId<modelCount; ++modelId) {
// First we need to read the data from file and decompress/de-interleave
// when needed. This will allocate memory on the heap and will keep
// a pointer to it internally (inside the T2FSNode).
T2FSNode *modelNode;
error = t2fs_model_load_data_node(&modelCtx, modelId, &modelNode);
if (error) {
// Do not continue, return or do whatever your code needs.
// ..
}
// Now that we have the model data in memory, we can read the amount
// of variations this model has. Some examples of variations:
// - Model of a building that has multiple states, like first
// variation is the full building, on second variation the building
// is half destroyed and on third variation the building is completely
// destroyed.
// - For character models different stuff for different games has been
// observed. Variations can be slightly different character, total
// different character or maybe first variation is a character and
// other are just weapons.
uint32_t variations = t2fs_model_get_variation_count(&modelCtx, modelNode);
// Iterate over all variations and create useful T2FSModels for them.
for (uint32_t var=0; var<variations; ++var) {
T2FSModel model;
// Init the model so we can later safely call t2fs_model_free()
t2fs_model_init(&model);
// This will fill the T2FSModel, it most likely will allocate memory
// so always call t2fs_model_free() when you are done with it. The
// data the T2FSModel holds after calling this will be all new
// allocated memory, so no pointers to the model node data. So when
// you only need one variation, it's ok to unload the node after this.
error = t2fs_model_make(&modelCtx, modelNode, var, &model);
if (error) {
// Do not continue, return or do whatever your code needs but
// do not forget to unload the model node data and free the model
// first!
t2fs_model_free(&model);
// ..
}
// Now we have a valid T2FSModel we can do stuff with.
// .. do your stuff here .. for that have a look at s_T2FSModel
// After you are done with the T2FSModel, it should be free'd.
t2fs_model_free(&model);
}
// Free all data that was allocated by t2fs_model_load_data_node()
}
void t2fs_model_init(T2FSModel *mdl)
Init our unified model struct.
uint32_t t2fs_model_count(T2FSContext *ctx)
Get the amount of models present.
void t2fs_model_free(T2FSModel *mdl)
Free all allocated memory for given T2FSModel.
struct s_T2FSModel T2FSModel
struct s_T2FSModelContext T2FSModelContext
helper to unify different games/versions
int t2fs_model_load_data_node(T2FSModelContext *mdlCtx, uint32_t mdlId, T2FSNode **dest)
Loads the model data into memory.
void t2fs_model_context_init(T2FSContext *ctx, T2FSModelContext *mdlCtx)
Initialize T2FSModelContext.
int t2fs_model_make(T2FSModelContext *mdlCtx, T2FSNode *mdlNode, uint32_t varId, T2FSModel *dest)
Convert the model data to our unified struct s_T2FSModel.
uint32_t t2fs_model_get_variation_count(T2FSModelContext *mdlCtx, T2FSNode *mdlNode)
Get the model variation count.
void t2fs_model_unload_data_node(T2FSNode *modelNode)
Unloads the model data node.
struct s_T2FSNode T2FSNode
This is the core object to describe a path inside the tree.
Definition t2fs.h:110