From 32a8287fc126c2f244c1e92eb6a1dfc6d6389293 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 12 Feb 2024 12:56:34 +0900 Subject: [PATCH] [ruamoko] Add some functions to get joints Still not very useful, but the internal format for iqm is proving to be rather limiting. --- libs/ruamoko/rua_model.c | 78 +++++++++++++++++++++++++++++++++++----- ruamoko/include/scene.h | 3 ++ ruamoko/lib/scene.r | 3 ++ 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/libs/ruamoko/rua_model.c b/libs/ruamoko/rua_model.c index bda727e56..dfe55b591 100644 --- a/libs/ruamoko/rua_model.c +++ b/libs/ruamoko/rua_model.c @@ -36,6 +36,7 @@ # include #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} }; diff --git a/ruamoko/include/scene.h b/ruamoko/include/scene.h index daf9347c2..0958f8d7c 100644 --- a/ruamoko/include/scene.h +++ b/ruamoko/include/scene.h @@ -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 diff --git a/ruamoko/lib/scene.r b/ruamoko/lib/scene.r index 2bd14512a..662013ffb 100644 --- a/ruamoko/lib/scene.r +++ b/ruamoko/lib/scene.r @@ -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;