Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
model_api.c
Go to the documentation of this file.
1#include "model.h"
2
6
8 s32 i;
9
10 for (i = 0; i < MAX_ANIMATED_MODELS; i++) {
11 AnimatedModel* anim = (*gCurrentMeshAnimationListPtr)[i];
12
13 if (anim->animModelID >= 0) {
15 }
16 }
17}
18
20 Matrix4f sp18;
21 Matrix4f sp58;
22 Matrix4f sp98;
23 Matrix4f spD8;
24 Matrix4f sp118;
25 Matrix4f sp158;
26 Matrix4f sp198;
27 Matrix4f sp1D8;
28 s32 i = 0;
29 Matrix4f* sp218 = &sp58;
30
31 for (; i < MAX_ANIMATED_MODELS; i++) {
32 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[i];
33
34 if (model->animModelID >= 0) {
35 guTranslateF(sp18, model->pos.x, model->pos.y, model->pos.z);
36 guRotateF(*sp218, model->rot.x, 1.0f, 0.0f, 0.0f);
37 guRotateF(sp98, model->rot.y, 0.0f, 1.0f, 0.0f);
38 guRotateF(spD8, model->rot.z, 0.0f, 0.0f, 1.0f);
39 guScaleF(sp1D8, model->scale.x, model->scale.y, model->scale.z);
40 guMtxCatF(spD8, *sp218, sp158);
41 guMtxCatF(sp158, sp98, sp118);
42 guMtxCatF(sp1D8, sp118, sp158);
43 guMtxCatF(sp158, sp18, sp198);
44 guMtxF2L(sp198, &model->mtx);
45 render_animated_model(model->animModelID, &model->mtx);
46 }
47 }
48}
49
50// split here?
51
52API_CALLABLE(InitAnimatedModels) {
55 } else {
57 }
58
59 return ApiStatus_DONE2;
60}
61
62API_CALLABLE(LoadAnimatedModel) {
63 Bytecode* args = script->ptrReadPos;
64 s32 index = evt_get_variable(script, *args++);
65 StaticAnimatorNode** var1 = (StaticAnimatorNode**) evt_get_variable(script, *args++);
66 AnimatedModel* animModel = (*gCurrentMeshAnimationListPtr)[index];
67 s32 animModelID = create_model_animator(0);
68
69 load_model_animator_tree(animModelID, var1);
70 animModel->animModelID = animModelID;
71 animModel->pos.x = 0;
72 animModel->pos.y = 0;
73 animModel->pos.z = 0;
74 animModel->rot.x = 0;
75 animModel->rot.y = 0;
76 animModel->rot.z = 0;
77 animModel->scale.x = 1.0f;
78 animModel->scale.y = 1.0f;
79 animModel->scale.z = 1.0f;
80 animModel->curAnimData = NULL;
81 guMtxIdent(&animModel->mtx);
82
83 return ApiStatus_DONE2;
84}
85
86API_CALLABLE(LoadAnimatedMesh) {
87 Bytecode* args = script->ptrReadPos;
88 s32 index = evt_get_variable(script, *args++);
89 StaticAnimatorNode** tree = (StaticAnimatorNode**) evt_get_variable(script, *args++);
90 AnimatedModel* animModel = (*gCurrentMeshAnimationListPtr)[index];
91 s32 animModelID = create_model_animator(0);
92
93 load_mesh_animator_tree(animModelID, tree);
94 animModel->animModelID = animModelID;
95 animModel->pos.x = 0;
96 animModel->pos.y = 0;
97 animModel->pos.z = 0;
98 animModel->rot.x = 0;
99 animModel->rot.y = 0;
100 animModel->rot.z = 0;
101 animModel->scale.x = 1.0f;
102 animModel->scale.y = 1.0f;
103 animModel->scale.z = 1.0f;
104 animModel->curAnimData = NULL;
105 guMtxIdent(&animModel->mtx);
106
107 return ApiStatus_DONE2;
108}
109
110API_CALLABLE(PlayModelAnimation) {
111 Bytecode* args = script->ptrReadPos;
112 s32 index = evt_get_variable(script, *args++);
113 s16* var2 = (s16*) evt_get_variable(script, *args++);
114 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
115
116 model->curAnimData = var2;
117 play_model_animation(model->animModelID, var2);
118
119 return ApiStatus_DONE2;
120}
121
122API_CALLABLE(PlayModelAnimationStartingFrom) {
123 Bytecode* args = script->ptrReadPos;
124 s32 index = evt_get_variable(script, *args++);
125 s16* var2 = (s16*) evt_get_variable(script, *args++);
126 s32 var3 = evt_get_variable(script, *args++);
127 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
128
129 model->curAnimData = var2;
131
132 return ApiStatus_DONE2;
133}
134
135API_CALLABLE(ChangeModelAnimation) {
136 Bytecode* args = script->ptrReadPos;
137 s32 index = evt_get_variable(script, *args++);
138 s16* var2 = (s16*) evt_get_variable(script, *args++);
139 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
140
141 if (model->curAnimData == var2) {
142 return ApiStatus_DONE2;
143 }
144
145 model->curAnimData = var2;
146 play_model_animation(model->animModelID, var2);
147 return ApiStatus_DONE2;
148}
149
150API_CALLABLE(SetAnimatedModelRootPosition) {
151 Bytecode* args = script->ptrReadPos;
152 s32 index = evt_get_variable(script, *args++);
153 f32 x = evt_get_float_variable(script, *args++);
154 f32 y = evt_get_float_variable(script, *args++);
155 f32 z = evt_get_float_variable(script, *args++);
156 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
157
158 model->pos.x = x;
159 model->pos.y = y;
160 model->pos.z = z;
161
162 return ApiStatus_DONE2;
163}
164
165API_CALLABLE(GetAnimatedModelRootPosition) {
166 Bytecode* args = script->ptrReadPos;
167 s32 index = evt_get_variable(script, *args++);
168 s32 outX = *args++;
169 s32 outY = *args++;
170 s32 outZ = *args++;
171 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
172
173 evt_set_float_variable(script, outX, model->pos.x);
174 evt_set_float_variable(script, outY, model->pos.y);
175 evt_set_float_variable(script, outZ, model->pos.z);
176
177 return ApiStatus_DONE2;
178}
179
180API_CALLABLE(AddAnimatedModelRootPosition) {
181 Bytecode* args = script->ptrReadPos;
182 s32 index = evt_get_variable(script, *args++);
183 f32 x = evt_get_float_variable(script, *args++);
184 f32 y = evt_get_float_variable(script, *args++);
185 f32 z = evt_get_float_variable(script, *args++);
186 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
187
188 model->pos.x += x;
189 model->pos.y += y;
190 model->pos.z += z;
191
192 return ApiStatus_DONE2;
193}
194
195API_CALLABLE(SetAnimatedModelRootRotation) {
196 Bytecode* args = script->ptrReadPos;
197 s32 index = evt_get_variable(script, *args++);
198 f32 x = evt_get_float_variable(script, *args++);
199 f32 y = evt_get_float_variable(script, *args++);
200 f32 z = evt_get_float_variable(script, *args++);
201 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
202
203 model->rot.x = x;
204 model->rot.y = y;
205 model->rot.z = z;
206
207 return ApiStatus_DONE2;
208}
209
210API_CALLABLE(SetAnimatedModelRootScale) {
211 Bytecode* args = script->ptrReadPos;
212 s32 index = evt_get_variable(script, *args++);
213 f32 x = evt_get_float_variable(script, *args++);
214 f32 y = evt_get_float_variable(script, *args++);
215 f32 z = evt_get_float_variable(script, *args++);
216 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[index];
217
218 model->scale.x = x;
219 model->scale.y = y;
220 model->scale.z = z;
221
222 return ApiStatus_DONE2;
223}
224
225API_CALLABLE(SetAnimatedModelRenderMode) {
226 Bytecode* args = script->ptrReadPos;
227 s32 index = evt_get_variable(script, *args++);
228 s32 renderMode = evt_get_float_variable(script, *args++);
229
230 get_animator_by_index((*gCurrentMeshAnimationListPtr)[index]->animModelID)->renderMode = renderMode;
231 return ApiStatus_DONE2;
232}
233
234API_CALLABLE(DeleteAnimatedModel) {
235 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[evt_get_variable(script, *script->ptrReadPos)];
236
238 model->animModelID = -1;
239 return ApiStatus_DONE2;
240}
241
242API_CALLABLE(SetAnimatorFlags) {
243 Bytecode* args = script->ptrReadPos;
244 s32 index = evt_get_variable(script, *args++);
245 s32 a1 = *args++;
246 s32 enable = evt_get_variable(script, *args++);
247 ModelAnimator* animMesh = get_animator_by_index((*gCurrentMeshAnimationListPtr)[index]->animModelID);
248
249 if (enable) {
250 animMesh->flags |= a1;
251 } else {
252 animMesh->flags &= ~a1;
253 }
254
255 return ApiStatus_DONE2;
256}
257
259 s32 i;
260
263 } else {
265 }
266
267 for (i = 0; i < MAX_ANIMATED_MODELS; i++) {
268 AnimatedModel* model = heap_malloc(sizeof(*model));
269
270 (*gCurrentMeshAnimationListPtr)[i] = model;
272 (*gCurrentMeshAnimationListPtr)[i]->animModelID = -1;
273 }
274
276}
277
285
286API_CALLABLE(GetAnimatedNodePosition) {
287 Bytecode* args = script->ptrReadPos;
288 s32 listIndex = evt_get_variable(script, *args++);
289 s32 treeIndex = evt_get_variable(script, *args++);
290 s32 outX = *args++;
291 s32 outY = *args++;
292 s32 outZ = *args++;
293 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[listIndex];
295 f32 x, y, z;
296
297 guMtxXFML(&model->mtx, node->pos.x, node->pos.y, node->pos.z, &x, &y, &z);
298 evt_set_variable(script, outX, x);
299 evt_set_variable(script, outY, y);
300 evt_set_variable(script, outZ, z);
301
302 return ApiStatus_DONE2;
303}
304
305API_CALLABLE(GetAnimatedNodeRotation) {
306 Bytecode* args = script->ptrReadPos;
307 s32 listIndex = evt_get_variable(script, *args++);
308 s32 treeIndex = evt_get_variable(script, *args++);
309 s32 outX = *args++;
310 s32 outY = *args++;
311 s32 outZ = *args++;
312 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[listIndex];
314
315 evt_set_variable(script, outX, node->rot.x);
316 evt_set_variable(script, outY, node->rot.y);
317 evt_set_variable(script, outZ, node->rot.z);
318
319 return ApiStatus_DONE2;
320}
321
322API_CALLABLE(GetAnimatedPositionByTreeIndex) {
323 Bytecode* args = script->ptrReadPos;
324 s32 listIndex = evt_get_variable(script, *args++);
325 s32 treeIndex = evt_get_variable(script, *args++);
326 s32 outX = *args++;
327 s32 outY = *args++;
328 s32 outZ = *args++;
329 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[listIndex];
331 f32 x, y, z;
332
333 guMtxXFML(&model->mtx, node->pos.x, node->pos.y, node->pos.z, &x, &y, &z);
334 evt_set_variable(script, outX, x);
335 evt_set_variable(script, outY, y);
336 evt_set_variable(script, outZ, z);
337
338 return ApiStatus_DONE2;
339}
340
341API_CALLABLE(GetAnimatedRotationByTreeIndex) {
342 Bytecode* args = script->ptrReadPos;
343 s32 listIndex = evt_get_variable(script, *args++);
344 s32 treeIndex = evt_get_variable(script, *args++);
345 s32 outX = *args++;
346 s32 outY = *args++;
347 s32 outZ = *args++;
348 AnimatedModel* model = (*gCurrentMeshAnimationListPtr)[listIndex];
350
351 evt_set_variable(script, outX, node->rot.x);
352 evt_set_variable(script, outY, node->rot.y);
353 evt_set_variable(script, outZ, node->rot.z);
354
355 return ApiStatus_DONE2;
356}
357
358API_CALLABLE(SetAnimatedNodeFlags) {
359 Bytecode* args = script->ptrReadPos;
360 s32 listIndex = evt_get_variable(script, *args++);
361 s32 id = evt_get_variable(script, *args++);
362 s32 flags = *args++;
363 s32 set = evt_get_variable(script, *args++);
364 ModelAnimator* animator = get_animator_by_index((*gCurrentMeshAnimationListPtr)[listIndex]->animModelID);
365 AnimatorNode* node = get_animator_node_with_id(animator, id);
366
367 if (set) {
368 node->flags |= flags;
369 } else {
370 node->flags &= ~flags;
371 }
372
373 return ApiStatus_DONE2;
374}
AnimatedModel * AnimatedModelList[16]
f32 Matrix4f[4][4]
s8 flags
Definition demo_api.c:15
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define guScaleF
#define ASSERT(condition)
@ CONTEXT_WORLD
Definition enums.h:3529
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
s32 create_worker_world(WorldArgs, WorldArgs)
void play_model_animation(s32, s16 *)
Definition animator.c:1101
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
f32 evt_set_float_variable(Evt *script, Bytecode var, f32 value)
Definition evt.c:1977
s32 evt_set_variable(Evt *script, Bytecode var, s32 value)
Definition evt.c:1847
void load_mesh_animator_tree(s32 index, StaticAnimatorNode **tree)
Definition animator.c:1198
s32 create_model_animator(s16 *animPos)
Definition animator.c:318
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
void load_model_animator_tree(s32, StaticAnimatorNode **)
Definition animator.c:1171
void * heap_malloc(s32 size)
Definition heap.c:34
void render_animated_model(s32 animatorID, Mtx *rootTransform)
Definition animator.c:765
AnimatorNode * get_animator_node_with_id(ModelAnimator *animator, s32 id)
Definition animator.c:1028
void delete_model_animator(ModelAnimator *animator)
Definition animator.c:297
void play_model_animation_starting_from(s32 index, s16 *animPos, s32 framesToSkip)
Definition animator.c:1113
ModelAnimator * get_animator_by_index(s32 animModelID)
Definition animator.c:1041
void update_model_animator_with_transform(s32 animatorID, Mtx *mtx)
Definition animator.c:546
AnimatorNode * get_animator_node_for_tree_index(ModelAnimator *animator, s32 treeIndex)
Definition animator.c:1024
void update_animated_models(void)
Definition model_api.c:7
void init_model_animators(void)
Definition model_api.c:278
AnimatedModelList * gCurrentMeshAnimationListPtr
Definition script_list.c:29
AnimatedModelList gBattleMeshAnimationList
Definition script_list.c:27
void reset_model_animators(void)
Definition model_api.c:258
AnimatedModelList gWorldMeshAnimationList
Definition script_list.c:28
void render_animated_models(void)
Definition model_api.c:19
ApiStatus SetAnimatorFlags(Evt *script, b32 isInitialCall)
ApiStatus GetAnimatedNodePosition(Evt *script, b32 isInitialCall)
ApiStatus SetAnimatedModelRenderMode(Evt *script, b32 isInitialCall)
ApiStatus PlayModelAnimation(Evt *script, b32 isInitialCall)
ApiStatus PlayModelAnimationStartingFrom(Evt *script, b32 isInitialCall)
ApiStatus GetAnimatedRotationByTreeIndex(Evt *script, b32 isInitialCall)
ApiStatus LoadAnimatedModel(Evt *script, b32 isInitialCall)
ApiStatus SetAnimatedNodeFlags(Evt *script, b32 isInitialCall)
ApiStatus LoadAnimatedMesh(Evt *script, b32 isInitialCall)
ApiStatus GetAnimatedModelRootPosition(Evt *script, b32 isInitialCall)
ApiStatus InitAnimatedModels(Evt *script, b32 isInitialCall)
ApiStatus AddAnimatedModelRootPosition(Evt *script, b32 isInitialCall)
ApiStatus SetAnimatedModelRootScale(Evt *script, b32 isInitialCall)
ApiStatus SetAnimatedModelRootPosition(Evt *script, b32 isInitialCall)
ApiStatus ChangeModelAnimation(Evt *script, b32 isInitialCall)
ApiStatus GetAnimatedNodeRotation(Evt *script, b32 isInitialCall)
ApiStatus SetAnimatedModelRootRotation(Evt *script, b32 isInitialCall)
ApiStatus DeleteAnimatedModel(Evt *script, b32 isInitialCall)
ApiStatus GetAnimatedPositionByTreeIndex(Evt *script, b32 isInitialCall)
#define MAX_ANIMATED_MODELS
Definition macros.h:85
GameStatus * gGameStatusPtr
Definition main_loop.c:32