mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-24 20:51:35 +00:00
[ruamoko] Add some functions to get joints
Still not very useful, but the internal format for iqm is proving to be rather limiting.
This commit is contained in:
parent
3d26aafbea
commit
32a8287fc1
3 changed files with 75 additions and 9 deletions
|
@ -36,6 +36,7 @@
|
|||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "QF/iqm.h"
|
||||
#include "QF/model.h"
|
||||
#include "QF/progs.h"
|
||||
|
||||
|
@ -80,7 +81,9 @@ rua__model_handle_get (rua_model_resources_t *res, int index, const char *name)
|
|||
qfZoneScoped (true);
|
||||
rua_model_t *handle = 0;
|
||||
|
||||
handle = PR_RESGET(res->model_map, index);
|
||||
if (index) {
|
||||
handle = PR_RESGET(res->model_map, index);
|
||||
}
|
||||
if (!handle) {
|
||||
PR_RunError (res->pr, "invalid model handle passed to %s", name + 3);
|
||||
}
|
||||
|
@ -136,11 +139,12 @@ alloc_handle (rua_model_resources_t *res, model_t *model)
|
|||
return rua_model_handle_index (res, handle);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Model_Load (progs_t *pr, void *_res)
|
||||
#define bi(x) static void bi_##x (progs_t *pr, void *_res)
|
||||
|
||||
bi (Model_Load)
|
||||
{
|
||||
qfZoneScoped (true);
|
||||
__auto_type res = (rua_model_resources_t *) _res;
|
||||
auto res = (rua_model_resources_t *) _res;
|
||||
const char *path = P_GSTRING (pr, 0);
|
||||
model_t *model;
|
||||
|
||||
|
@ -164,16 +168,13 @@ Model_GetModel (progs_t *pr, int handle)
|
|||
return h->model;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Model_Unload (progs_t *pr, void *_res)
|
||||
bi (Model_Unload)
|
||||
{
|
||||
qfZoneScoped (true);
|
||||
__auto_type res = (rua_model_resources_t *) _res;
|
||||
auto res = (rua_model_resources_t *) _res;
|
||||
int handle = P_INT (pr, 0);
|
||||
rua_model_t *h = rua_model_handle_get (res, handle);
|
||||
|
||||
if (!h)
|
||||
PR_RunError (pr, "invalid model handle passed to Qclose");
|
||||
Mod_UnloadModel (h->model);
|
||||
*h->prev = h->next;
|
||||
if (h->next)
|
||||
|
@ -181,12 +182,71 @@ bi_Model_Unload (progs_t *pr, void *_res)
|
|||
rua_model_handle_free (res, h);
|
||||
}
|
||||
|
||||
bi (Model_NumJoints)
|
||||
{
|
||||
auto res = (rua_model_resources_t *) _res;
|
||||
int handle = P_INT (pr, 0);
|
||||
auto h = rua_model_handle_get (res, handle);
|
||||
auto model = h->model;
|
||||
|
||||
R_INT (pr) = 0;
|
||||
if (model->type == mod_iqm) {
|
||||
auto iqm = (iqm_t *) model->aliashdr;
|
||||
R_INT (pr) = iqm->num_joints;
|
||||
}
|
||||
}
|
||||
|
||||
bi (Model_GetJoints)
|
||||
{
|
||||
auto res = (rua_model_resources_t *) _res;
|
||||
int handle = P_INT (pr, 0);
|
||||
auto h = rua_model_handle_get (res, handle);
|
||||
auto model = h->model;
|
||||
auto iqm = (iqm_t *) model->aliashdr;
|
||||
auto joints = (iqmjoint *) P_GPOINTER (pr, 1);
|
||||
|
||||
if (model->type != mod_iqm || !iqm->num_joints) {
|
||||
R_INT (pr) = 0;
|
||||
return;
|
||||
}
|
||||
memcpy (joints, iqm->joints, iqm->num_joints * sizeof (iqmjoint));
|
||||
for (int i = 0; i < iqm->num_joints; i++) {
|
||||
char *name = iqm->text + joints[i].name;
|
||||
joints[i].name = PR_SetString (pr, name);
|
||||
}
|
||||
R_INT (pr) = 1;
|
||||
}
|
||||
|
||||
bi (Model_NumFrames)
|
||||
{
|
||||
auto res = (rua_model_resources_t *) _res;
|
||||
int handle = P_INT (pr, 0);
|
||||
auto h = rua_model_handle_get (res, handle);
|
||||
auto model = h->model;
|
||||
|
||||
R_INT (pr) = 0;
|
||||
if (model->type == mod_iqm) {
|
||||
auto iqm = (iqm_t *) model->aliashdr;
|
||||
R_INT (pr) = iqm->num_frames;
|
||||
} else if (model->type == mod_alias) {
|
||||
auto hdr = model->aliashdr;
|
||||
if (!hdr) {
|
||||
hdr = Cache_Get (&model->cache);
|
||||
}
|
||||
R_INT (pr) = hdr->mdl.numframes;
|
||||
}
|
||||
}
|
||||
|
||||
#undef bi
|
||||
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
||||
#define p(type) PR_PARAM(type)
|
||||
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
||||
static builtin_t builtins[] = {
|
||||
bi(Model_Load, 1, p(string)),
|
||||
bi(Model_Unload, 1, p(ptr)),
|
||||
bi(Model_NumJoints, 1, p(ptr)),
|
||||
bi(Model_GetJoints, 1, p(ptr)),
|
||||
bi(Model_NumFrames, 1, p(ptr)),
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -65,5 +65,8 @@ void Light_EnableSun (lightingdata_t ldata);
|
|||
|
||||
model_t Model_Load (string path);
|
||||
void Model_Unload (model_t model);
|
||||
int Model_NumJoints (model_t model);
|
||||
void Model_GetJoints (model_t model, void *j);
|
||||
int Model_NumFrames (model_t model);
|
||||
|
||||
#endif//__ruamoko_scene_h
|
||||
|
|
|
@ -46,3 +46,6 @@ void Light_EnableSun (lightingdata_t ldata) = #0;
|
|||
|
||||
model_t Model_Load (string path) = #0;
|
||||
void Model_Unload (model_t model) = #0;
|
||||
int Model_NumJoints (model_t model) = #0;
|
||||
void Model_GetJoints (model_t model, void *j) = #0;
|
||||
int Model_NumFrames (model_t model) = #0;
|
||||
|
|
Loading…
Reference in a new issue