diff --git a/include/reign.h b/include/reign.h index 029bdaa..5984a64 100644 --- a/include/reign.h +++ b/include/reign.h @@ -214,6 +214,7 @@ bool RE_instance_load(struct RE_instance *instance, const char *name); bool RE_instance_load_motion(struct RE_instance *instance, const char *name); bool RE_instance_load_next_motion(struct RE_instance *instance, const char *name); bool RE_instance_free_next_motion(struct RE_instance *instance); +bool RE_instance_set_mesh_show(struct RE_instance *instance, const char *mesh_name, bool show); bool RE_instance_set_vertex_pos(struct RE_instance *instance, int index, float x, float y, float z); int RE_instance_get_bone_index(struct RE_instance *instance, const char *name); bool RE_instance_trans_local_pos_to_world_pos_by_bone(struct RE_instance *instance, int bone, vec3 offset, vec3 out); diff --git a/src/3d/3d_internal.h b/src/3d/3d_internal.h index a5287e7..9d390a2 100644 --- a/src/3d/3d_internal.h +++ b/src/3d/3d_internal.h @@ -50,8 +50,10 @@ struct model { }; struct mesh { + char *name; uint32_t flags; bool is_transparent; + bool hidden; GLuint vao; GLuint attr_buffer; GLuint index_buffer; diff --git a/src/3d/model.c b/src/3d/model.c index c53c57a..cbef051 100644 --- a/src/3d/model.c +++ b/src/3d/model.c @@ -317,6 +317,7 @@ static void add_mesh(struct model *model, struct pol_mesh *m, uint32_t material_ } model->meshes = xrealloc_array(model->meshes, model->nr_meshes, model->nr_meshes + 1, sizeof(struct mesh)); struct mesh *mesh = &model->meshes[model->nr_meshes++]; + mesh->name = xstrdup(m->name); mesh->flags = m->flags; mesh->material = material; if (re_plugin_version == RE_REIGN_PLUGIN) @@ -393,6 +394,7 @@ static void add_mesh(struct model *model, struct pol_mesh *m, uint32_t material_ static void destroy_mesh(struct mesh *mesh) { + free(mesh->name); glDeleteVertexArrays(1, &mesh->vao); glDeleteBuffers(1, &mesh->attr_buffer); if (mesh->index_buffer) diff --git a/src/3d/reign.c b/src/3d/reign.c index 1c415be..276292a 100644 --- a/src/3d/reign.c +++ b/src/3d/reign.c @@ -502,6 +502,19 @@ bool RE_instance_free_next_motion(struct RE_instance *instance) return true; } +bool RE_instance_set_mesh_show(struct RE_instance *instance, const char *mesh_name, bool show) +{ + if (!instance || !instance->model) + return false; + for (int i = 0; i < instance->model->nr_meshes; i++) { + if (!strcmp(instance->model->meshes[i].name, mesh_name)) { + instance->model->meshes[i].hidden = !show; + return true; + } + } + return false; +} + bool RE_instance_set_vertex_pos(struct RE_instance *instance, int index, float x, float y, float z) { if (!instance) diff --git a/src/3d/renderer.c b/src/3d/renderer.c index 8abfa92..d649cb6 100644 --- a/src/3d/renderer.c +++ b/src/3d/renderer.c @@ -362,6 +362,8 @@ static void render_model(struct RE_instance *inst, struct RE_renderer *r, enum d for (int i = 0; i < model->nr_meshes; i++) { struct mesh *mesh = &model->meshes[i]; + if (mesh->hidden) + continue; struct material *material = &model->materials[mesh->material]; bool is_transparent = mesh->is_transparent || inst->alpha < 1.0f; if (phase != (is_transparent ? DRAW_TRANSPARENT : DRAW_OPAQUE)) diff --git a/src/hll/ReignEngine.c b/src/hll/ReignEngine.c index 8ec90e7..f5a8ee4 100644 --- a/src/hll/ReignEngine.c +++ b/src/hll/ReignEngine.c @@ -1891,7 +1891,11 @@ static bool TapirEngine_GetInstancePathLine(int plugin, int instance, struct pag } //bool TapirEngine_CreateInstancePathLineList(int PluginNumber, int InstanceNumber, int PathInstanceNumber); -//bool TapirEngine_SetInstanceMeshShow(int PluginNumber, int InstanceNumber, struct string *pIMeshName, bool Show); + +static bool TapirEngine_SetInstanceMeshShow(int plugin, int instance, struct string *mesh_name, bool show) +{ + return RE_instance_set_mesh_show(get_instance(plugin, instance), mesh_name->text, show); +} static bool TapirEngine_SetDrawOption(int plugin_number, int draw_option, int param) { @@ -2303,7 +2307,7 @@ HLL_LIBRARY(ReignEngine, REIGN_EXPORTS, HLL_EXPORT(OptimizeInstancePathLine, TapirEngine_OptimizeInstancePathLine), \ HLL_EXPORT(GetInstancePathLine, TapirEngine_GetInstancePathLine), \ HLL_TODO_EXPORT(CreateInstancePathLineList, TapirEngine_CreateInstancePathLineList), \ - HLL_TODO_EXPORT(SetInstanceMeshShow, TapirEngine_SetInstanceMeshShow), \ + HLL_EXPORT(SetInstanceMeshShow, TapirEngine_SetInstanceMeshShow), \ HLL_EXPORT(SetDrawOption, TapirEngine_SetDrawOption), \ HLL_EXPORT(GetDrawOption, TapirEngine_GetDrawOption), \ HLL_TODO_EXPORT(SetDebugMode, TapirEngine_SetDebugMode), \