From ab346f1b4295006e12d893e800fd549be758ec88 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 13 Oct 2025 23:10:39 -0500 Subject: [PATCH] feat(model): add CM2Model::SetGeometryVisible --- src/model/CM2Model.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++ src/model/CM2Model.hpp | 2 ++ 2 files changed, 58 insertions(+) diff --git a/src/model/CM2Model.cpp b/src/model/CM2Model.cpp index 64408cc..d474f75 100644 --- a/src/model/CM2Model.cpp +++ b/src/model/CM2Model.cpp @@ -1524,6 +1524,58 @@ void CM2Model::SetBoneSequenceDeferred(uint16_t a2, M2Data* data, uint16_t boneI // TODO } +void CM2Model::SetGeometryVisible(uint32_t start, uint32_t end, int32_t visible) { + // Waiting for load + + if (!this->m_loaded) { + auto modelCall = STORM_NEW(CM2ModelCall); + + modelCall->type = 1; + modelCall->modelCallNext = nullptr; + modelCall->time = this->m_scene->m_time; + modelCall->args[0] = start; + modelCall->args[1] = end; + modelCall->args[2] = visible; + + *this->m_modelCallTail = modelCall; + this->m_modelCallTail = &modelCall->modelCallNext; + + return; + } + + // No skin sections + + if (!this->m_shared->skinProfile->skinSections.Count()) { + return; + } + + // Update visibility + + bool visibilityChanged = false; + + for (uint32_t i = 0; i < this->m_shared->skinProfile->skinSections.Count(); i++) { + auto& skinSection = this->m_shared->skinProfile->skinSections[i]; + auto modelSkinSection = &this->m_skinSections[i]; + + // Out of range + if (skinSection.skinSectionId < start || skinSection.skinSectionId > end) { + continue; + } + + // No change + if (*modelSkinSection == 0 && visible == 0 || *modelSkinSection == 1 && visible == 1) { + continue; + } + + *modelSkinSection = visible; + visibilityChanged = true; + } + + if (visibilityChanged) { + this->UnoptimizeVisibleGeometry(); + } +} + void CM2Model::SetIndices() { // TODO } @@ -1736,6 +1788,10 @@ void CM2Model::UnlinkFromCallbackList() { } } +void CM2Model::UnoptimizeVisibleGeometry() { + // TODO +} + void CM2Model::UnsetBoneSequence(uint32_t boneId, int32_t a3, int32_t a4) { // TODO } diff --git a/src/model/CM2Model.hpp b/src/model/CM2Model.hpp index fba4c20..2eda9ca 100644 --- a/src/model/CM2Model.hpp +++ b/src/model/CM2Model.hpp @@ -172,6 +172,7 @@ class CM2Model { void SetAnimating(int32_t animating); void SetBoneSequence(uint32_t boneId, uint32_t sequenceId, uint32_t a4, uint32_t time, float a6, int32_t a7, int32_t a8); void SetBoneSequenceDeferred(uint16_t a2, M2Data* data, uint16_t boneIndex, uint32_t time, float a6, M2SequenceFallback fallback, int32_t a8, int32_t a9, int32_t a10); + void SetGeometryVisible(uint32_t start, uint32_t end, int32_t visible); void SetIndices(); void SetLightingCallback(void (*lightingCallback)(CM2Model*, CM2Lighting*, void*), void* lightingArg); void SetLoadedCallback(void (*loadedCallback)(CM2Model*, void*), void* loadedArg); @@ -185,6 +186,7 @@ class CM2Model { int32_t Sub8269C0(uint32_t boneId, uint16_t boneIndex); void Sub826E60(uint32_t* a2, uint32_t* a3); void UnlinkFromCallbackList(); + void UnoptimizeVisibleGeometry(); void UnsetBoneSequence(uint32_t boneId, int32_t a3, int32_t a4); void UpdateLoaded(); void WaitForLoad(const char* a2);