Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
model.h
Go to the documentation of this file.
1#ifndef _MODEL_H_
2#define _MODEL_H_
3
4#include "common.h"
5
6typedef union ModelNodePropertyData {
7 s32 s;
8 f32 f;
9 void* p;
11
12// In memory this is a list of ModelNodeProperty, but due to the way it uses
13// the fields (storing into the "type" field) we decided to make a struct for this
14typedef struct ModelBoundingBox {
15 /* 0x00 */ s32 key; // MODEL_PROP_KEY_BOUNDING_BOX
16 /* 0x04 */ s32 halfSizeX;
17 /* 0x08 */ f32 minX;
18 /* 0x0C */ char unk_0C[0x04];
19 /* 0x10 */ s32 halfSizeY;
20 /* 0x14 */ f32 minY;
21 /* 0x18 */ char unk_18[0x04];
22 /* 0x1C */ s32 halfSizeZ;
23 /* 0x20 */ f32 minZ;
24 /* 0x24 */ char unk_24[0x8];
25 /* 0x2C */ f32 maxX;
26 /* 0x30 */ char unk_30[0x8];
27 /* 0x38 */ f32 maxY;
28 /* 0x3C */ char unk_3C[0x8];
29 /* 0x44 */ f32 maxZ;
30} ModelBoundingBox; // size = 0x48?
31
32typedef struct ModelNodeProperty {
33 /* 0x0 */ s32 key;
34 /* 0x4 */ s32 dataType;
36} ModelNodeProperty; // size = 0xC;
37
38typedef struct ModelGroupData {
39 /* 0x00 */ Mtx* transformMatrix;
40 /* 0x04 */ Lightsn* lightingGroup;
41 /* 0x08 */ s32 numLights;
42 /* 0x0C */ s32 numChildren;
43 /* 0x10 */ struct ModelNode** childList;
44} ModelGroupData; // size = 0x14
45
46typedef struct ModelDisplayData {
47 /* 0x0 */ Gfx* displayList;
48 /* 0x4 */ char unk_04[0x4];
49} ModelDisplayData; // size = 0x8
50
51typedef struct ModelNode {
52 /* 0x00 */ s32 type; /* 2 = model */
54 /* 0x08 */ s32 numProperties;
56 /* 0x10 */ struct ModelGroupData* groupData;
57} ModelNode; // size = 0x14
58
59typedef struct Model {
60 /* 0x00 */ u16 flags;
61 /* 0x02 */ u16 modelID;
62 /* 0x04 */ Mtx* bakedMtx; // pointer to stack-allocated copy of matrix supplied by the shape file for this model
63 /* 0x08 */ ModelNode* modelNode;
65 /* 0x10 */ Mtx* finalMtx; // the matrix actually used while building the display list
66 /* 0x14 */ char unk_14[4];
67 /* 0x18 */ Mtx savedMtx;
68 /* 0x58 */ Matrix4f userTransformMtx; // provided for user code to apply an additional multiplicative transformation
69 /* 0x98 */ Vec3f center;
70 /* 0xA4 */ u8 texPannerID;
71 /* 0xA5 */ u8 customGfxIndex;
72 /* 0xA6 */ s8 renderMode;
73 /* 0xA7 */ u8 matrixFreshness;
74 /* 0xA8 */ u8 textureID;
75 /* 0xA9 */ s8 textureVariation;
76 /* 0xAA */ char unk_AA[6];
77} Model; // size = 0xB0
78
79typedef struct ModelTransformGroup {
80 /* 0x00 */ u16 flags;
81 /* 0x02 */ u16 groupModelID;
82 /* 0x04 */ Mtx* bakedMtx; // would point to copy of matrix from shape file, but seems to always be NULL.
84 /* 0x0C */ Mtx* finalMtx; // the matrix actually used while building the display list
85 /* 0x10 */ Mtx savedMtx;
86 /* 0x50 */ Matrix4f userTransformMtx; // provided for user code to apply an additional multiplicative transformation
87 /* 0x90 */ Vec3f center;
88 /* 0x9C */ u8 minChildModelIndex;
89 /* 0x9D */ u8 maxChildModelIndex;
90 /* 0x9E */ u8 renderMode;
91 /* 0x9F */ u8 matrixFreshness;
92} ModelTransformGroup; // size = 0xA0
93
96
97typedef struct ModelIDList {
98 u16 count;
99 u16 list[VLA];
101
102typedef struct ModelLocalVertexCopy {
103 /* 0x00 */ s32 numVertices;
104 /* 0x04 */ Vtx* minVertexAddr;
105 /* 0x08 */ Gfx* gfxCopy[2];
106 /* 0x10 */ Vtx* vtxCopy[2];
107 /* 0x18 */ s32 selector;
108} ModelLocalVertexCopy; // size = 0x1C
109
111
112typedef struct ModelTreeInfo {
113 /* 0x00 */ u8 modelIndex;
114 /* 0x01 */ u8 treeDepth;
115 /* 0x02 */ u8 textureID;
116 /* 0x03 */ char unk_03;
117} ModelTreeInfo; // size = 0x04
118
119typedef struct TextureHandle {
120 /* 0x00 */ Gfx* gfx;
122 /* 0x34 */ IMG_PTR raster;
123 /* 0x38 */ PAL_PTR palette;
124 /* 0x3C */ IMG_PTR auxRaster;
125 /* 0x40 */ PAL_PTR auxPalette;
126} TextureHandle; // size = 0x44
127
128typedef struct ModelBlueprint {
129 /* 0x0 */ s16 flags;
130 /* 0x2 */ char unk_02[0x2];
131 /* 0x4 */ ModelNode* mdlNode;
133 /* 0xC */ Mtx* mtx;
134} ModelBlueprint; // size = 0x10
135
136typedef void(*ModelCustomGfxBuilderFunc)(s32 index);
137
138typedef Gfx* ModelCustomGfxList[32];
140
150
157
162
163typedef enum ExtraTileTypes {
164 EXTRA_TILE_NONE = 0, // texture contains only a single tile
165 EXTRA_TILE_MIPMAPS = 1, // texture contais mipmaps
166 EXTRA_TILE_AUX_SAME_AS_MAIN = 2, // texture contains main and aux images with identical fmt and size
167 EXTRA_TILE_AUX_INDEPENDENT = 3, // texture contains main and aux images with independent fmt and size
168 EXTRA_TILE_4 = 4, // only use-case may be a mistake? unused and mostly unimplemented
170
171#define SHAPE_SIZE_LIMIT 0x8000
172
173typedef struct ShapeFileHeader {
174 /* 0x00 */ ModelNode* root;
175 /* 0x04 */ Vtx_t* vertexTable;
176 /* 0x08 */ char** modelNames;
177 /* 0x0C */ char** colliderNames;
178 /* 0x10 */ char** zoneNames;
179 /* 0x14 */ unsigned char pad_14[0xC];
180} ShapeFileHeader; // size = 0x20
181
182typedef struct ShapeFile {
184 /* 0x20 */ u8 data[SHAPE_SIZE_LIMIT - sizeof(ShapeFileHeader)];
185} ShapeFile; // size = variable
186
188
191
192void mdl_set_depth_tint_params(u8 primR, u8 primG, u8 primB, u8 primA, u8 fogR, u8 fogG, u8 fogB, s32 fogStart, s32 fogEnd);
193void mdl_set_remap_tint_params(u8 primR, u8 primG, u8 primB, u8 envR, u8 envG, u8 envB);
194void mdl_get_remap_tint_params(u8* primR, u8* primG, u8* primB, u8* envR, u8* envG, u8* envB);
195
196void init_model_data(void);
197void update_model_animator(s32);
198void update_model_animator_with_transform(s32 animatorID, Mtx* mtx);
199void set_mdl_custom_gfx_set(Model*, s32, u32);
201void load_texture_variants(u32 romOffset, s32 textureID, s32 baseOffset, s32 size);
205void animator_update_model_transforms(ModelAnimator* animator, Mtx* rootTransform);
206void render_animated_model(s32 animatorID, Mtx* rootTransform);
207void animator_node_update_model_transform(ModelAnimator* animator, f32 (*flipMtx)[4], AnimatorNode* node,
208 Mtx* rootTransform);
209void init_worker_list(void);
210ModelAnimator* get_animator_by_index(s32 animModelID);
211void reset_animator_list(void);
215void render_animated_model_with_vertices(s32 animatorID, Mtx* rootTransform, s32 segment, void* baseAddr);
216void appendGfx_animator(ModelAnimator* animator);
217ModelAnimator* set_animator_render_callback(s32 animModelID, void* callbackArg, void (*callbackFunc)(void*));
219s32 step_mesh_animator(ModelAnimator* animator);
220
222void mdl_make_local_vertex_copy(s32 arg0, u16 treeIdx, s32);
223void play_model_animation_starting_from(s32 index, s16* animPos, s32 framesToSkip);
224
225void mdl_set_shroud_tint_params(u8 r, u8 g, u8 b, u8 a);
226
227#endif
#define PAL_PTR
#define IMG_PTR
f32 Matrix4f[4][4]
ModelNodeProperty * propertyList
Definition model.h:55
ModelNode * baseModelNode
Definition model.h:83
u8 matrixFreshness
Definition model.h:73
void mdl_set_shroud_tint_params(u8 r, u8 g, u8 b, u8 a)
Definition model.c:3906
void render_animated_model_with_vertices(s32 animatorID, Mtx *rootTransform, s32 segment, void *baseAddr)
Definition animator.c:795
Vtx * vtxCopy[2]
Definition model.h:106
Mtx * transformMatrix
Definition model.h:39
void reset_animator_list(void)
Definition animator.c:252
char unk_04[0x4]
Definition model.h:48
ModelNode * root
Definition model.h:174
char unk_3C[0x8]
Definition model.h:28
u8 data[0x8000 - sizeof(ShapeFileHeader)]
Definition model.h:184
void init_model_data(void)
Definition model.c:2431
ModelAnimator * set_animator_render_callback(s32 animModelID, void *callbackArg, void(*callbackFunc)(void *))
Definition animator.c:1045
void render_animated_model(s32 animatorID, Mtx *rootTransform)
Definition animator.c:765
char ** modelNames
Definition model.h:176
void mdl_make_local_vertex_copy(s32 arg0, u16 treeIdx, s32)
Definition model.c:4041
ModelLocalVertexCopy * ModelLocalVertexCopyList[16]
Definition model.h:110
ModelCustomGfxBuilderFunc ModelCustomGfxBuilderList[32]
Definition model.h:139
Mtx * finalMtx
Definition model.h:65
u16 * palette
Definition model.h:123
u16 list[]
Definition model.h:99
ShapeFileHeader header
Definition model.h:183
AnimatorNode * get_animator_node_with_id(ModelAnimator *animator, s32 id)
Definition animator.c:1028
ModelNode * mdlNode
Definition model.h:131
Mtx * mtx
Definition model.h:133
#define SHAPE_SIZE_LIMIT
Definition model.h:171
void(* ModelCustomGfxBuilderFunc)(s32 index)
Definition model.h:136
void animator_node_update_model_transform(ModelAnimator *animator, f32(*flipMtx)[4], AnimatorNode *node, Mtx *rootTransform)
Definition animator.c:732
char unk_30[0x8]
Definition model.h:26
void reload_mesh_animator_tree(ModelAnimator *animator)
Definition animator.c:1258
void delete_model_animator_nodes(ModelAnimator *animator)
Definition animator.c:284
char unk_24[0x8]
Definition model.h:24
void delete_model_animator(ModelAnimator *animator)
Definition animator.c:297
struct ModelNode ** childList
Definition model.h:43
s8 renderMode
Definition model.h:72
void play_model_animation_starting_from(s32 index, s16 *animPos, s32 framesToSkip)
Definition animator.c:1113
u8 modelIndex
Definition model.h:113
ModelGroupData * groupData
Definition model.h:64
char unk_18[0x04]
Definition model.h:21
Vec3f center
Definition model.h:69
s8 textureVariation
Definition model.h:75
void set_custom_gfx_builders(s32 customGfxIndex, ModelCustomGfxBuilderFunc pre, ModelCustomGfxBuilderFunc post)
Definition model.c:3849
void delete_model_animator_node(AnimatorNode *node)
Definition animator.c:269
ModelAnimator * get_animator_by_index(s32 animModelID)
Definition animator.c:1041
void mdl_get_remap_tint_params(u8 *primR, u8 *primG, u8 *primB, u8 *envR, u8 *envG, u8 *envB)
Definition model.c:3954
Gfx * gfxCopy[2]
Definition model.h:105
char unk_02[0x2]
Definition model.h:130
Gfx * displayList
Definition model.h:47
s32 numProperties
Definition model.h:54
void load_texture_variants(u32 romOffset, s32 textureID, s32 baseOffset, s32 size)
Definition model.c:2173
ModelNode * modelNode
Definition model.h:63
u8 * raster
Definition model.h:122
char unk_03
Definition model.h:116
s32 numLights
Definition model.h:41
u8 * auxRaster
Definition model.h:124
Lightsn * lightingGroup
Definition model.h:40
s32 type
Definition model.h:52
Model * ModelList[256]
Definition model.h:94
Mtx * bakedMtx
Definition model.h:62
u8 textureID
Definition model.h:74
unsigned char pad_14[0xC]
Definition model.h:179
void mdl_set_remap_tint_params(u8 primR, u8 primG, u8 primB, u8 envR, u8 envG, u8 envB)
Definition model.c:3945
u16 flags
Definition model.h:60
void appendGfx_animator(ModelAnimator *animator)
Definition animator.c:826
Gfx * gfx
Definition model.h:120
void set_mdl_custom_gfx_set(Model *, s32, u32)
Definition model.c:3832
Vtx_t * vertexTable
Definition model.h:175
char unk_14[4]
Definition model.h:66
s32 step_mesh_animator(ModelAnimator *animator)
Definition animator.c:1274
u8 texPannerID
Definition model.h:70
ModelTransformGroup * ModelTransformGroupList[4]
Definition model.h:95
ModelTreeInfoList * gCurrentModelTreeNodeInfo
Definition model.c:107
void update_model_animator(s32)
Definition animator.c:482
s32 numChildren
Definition model.h:42
s32 step_model_animator(ModelAnimator *animator)
Definition animator.c:610
ModelNodePropertyData data
Definition model.h:35
void update_model_animator_with_transform(s32 animatorID, Mtx *mtx)
Definition animator.c:546
u16 * auxPalette
Definition model.h:125
Matrix4f userTransformMtx
Definition model.h:86
u8 customGfxIndex
Definition model.h:71
char ** colliderNames
Definition model.h:177
ModelList * gCurrentModels
Definition model.c:106
Matrix4f userTransformMtx
Definition model.h:68
u16 count
Definition model.h:98
void init_worker_list(void)
Definition worker.c:24
ModelDisplayData * displayData
Definition model.h:53
ModelGroupData * groupData
Definition model.h:132
char unk_AA[6]
Definition model.h:76
ModelNodeProperty * get_model_property(ModelNode *node, ModelPropertyKeys key)
Definition model.c:2285
u16 modelID
Definition model.h:61
char ** zoneNames
Definition model.h:178
char unk_0C[0x04]
Definition model.h:18
TextureHeader header
Definition model.h:121
ExtraTileTypes
Definition model.h:163
@ EXTRA_TILE_AUX_INDEPENDENT
Definition model.h:167
@ EXTRA_TILE_NONE
Definition model.h:164
@ EXTRA_TILE_MIPMAPS
Definition model.h:165
@ EXTRA_TILE_AUX_SAME_AS_MAIN
Definition model.h:166
@ EXTRA_TILE_4
Definition model.h:168
ModelTreeInfo ModelTreeInfoList[0x200]
Definition model.h:187
void animator_update_model_transforms(ModelAnimator *animator, Mtx *rootTransform)
Definition animator.c:710
ShapeTypes
Definition model.h:151
@ SHAPE_TYPE_SPECIAL_GROUP
Definition model.h:155
@ SHAPE_TYPE_ROOT
Definition model.h:154
@ SHAPE_TYPE_MODEL
Definition model.h:152
@ SHAPE_TYPE_GROUP
Definition model.h:153
struct ModelGroupData * groupData
Definition model.h:56
AnimatorNode * get_animator_node_for_tree_index(ModelAnimator *animator, s32 treeIndex)
Definition animator.c:1024
Gfx * ModelCustomGfxList[32]
Definition model.h:138
ModelPropertyKeys
Definition model.h:141
@ MODEL_PROP_KEY_CAMERA_DATA
Definition model.h:143
@ MODEL_PROP_KEY_BOUNDING_BOX
Definition model.h:147
@ MODEL_PROP_KEY_SPECIAL
Definition model.h:145
@ MODEL_PROP_KEY_62
Definition model.h:148
@ MODEL_PROP_KEY_GROUP_INFO
Definition model.h:146
@ MODEL_PROP_KEY_TEXTURE_NAME
Definition model.h:144
@ MODEL_PROP_KEY_RENDER_MODE
Definition model.h:142
Mtx savedMtx
Definition model.h:67
GroupTypes
Definition model.h:158
@ GROUP_TYPE_1
Definition model.h:160
@ GROUP_TYPE_0
Definition model.h:159
void mdl_set_depth_tint_params(u8 primR, u8 primG, u8 primB, u8 primA, u8 fogR, u8 fogG, u8 fogB, s32 fogStart, s32 fogEnd)
Definition model.c:3920
Definition model.h:59
#define VLA
Definition macros.h:516
#define MAX_MODEL_TRANSFORM_GROUPS
Definition macros.h:89
#define MAX_MODELS
Definition macros.h:88