From a6f693598d3a795571d762d1b9915638502b201b Mon Sep 17 00:00:00 2001 From: Alex Foster <123afoster@gmail.com> Date: Sat, 20 Jan 2024 23:15:22 -0800 Subject: [PATCH] move part skinlist generation to meshgroup --- src/engine/model/animmodel.cpp | 14 ++++++++++++++ src/engine/model/animmodel.h | 20 +++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/engine/model/animmodel.cpp b/src/engine/model/animmodel.cpp index 485194bc..7530a41e 100644 --- a/src/engine/model/animmodel.cpp +++ b/src/engine/model/animmodel.cpp @@ -512,6 +512,20 @@ std::vector::iterator> animmodel::meshgroup::getm return meshlist; } +std::vector animmodel::meshgroup::getskins(std::string_view meshname) +{ + std::vector skinlist; + for(uint i = 0; i < meshes.size(); i++) + { + auto &m = *(meshes[i]); + if(!std::strcmp(meshname.data(), "*") || (m.name && !std::strcmp(m.name, meshname.data()))) + { + skinlist.push_back(i); + } + } + return skinlist; +} + void animmodel::meshgroup::calcbb(vec &bbmin, vec &bbmax, const matrix4x3 &t) const { auto rendermeshes = getrendermeshes(); diff --git a/src/engine/model/animmodel.h b/src/engine/model/animmodel.h index df0c3ad6..2eea6bb6 100644 --- a/src/engine/model/animmodel.h +++ b/src/engine/model/animmodel.h @@ -364,7 +364,17 @@ class animmodel : public model virtual void render(const AnimState *as, float pitch, const vec &axis, const vec &forward, dynent *d, part *p) = 0; virtual void preload() = 0; + /** + * Returns a list of Mesh iterators corresponding to a given name + * The iterators may be invalidated by other method calls. + */ std::vector::iterator> getmeshes(std::string_view meshname); + /** + * Returns a list of indices corresponding to locations in animmodel::part::skins. + * These indices are invalidated if animmodel::skins is modified after calling. + */ + std::vector getskins(std::string_view meshname); + void calcbb(vec &bbmin, vec &bbmax, const matrix4x3 &t) const; void genBIH(const std::vector &skins, std::vector &bih, const matrix4x3 &t); void genshadowmesh(std::vector &tris, const matrix4x3 &t) const; @@ -963,14 +973,10 @@ struct modelcommands { return skinlist; } - for(uint i = 0; i < mdl.meshes->meshes.size(); i++) + std::vector skinindices = mdl.meshes->getskins(meshname); + for(size_t i : skinindices) { - auto &m = *(mdl.meshes->meshes[i]); - if(!std::strcmp(meshname.data(), "*") || (m.name && !std::strcmp(m.name, meshname.data()))) - { - std::vector::iterator itr = mdl.skins.begin() + i; - skinlist.push_back(itr); - } + skinlist.push_back(mdl.skins.begin() + i); } return skinlist; }