metaforce/Runtime/Graphics/CSkinnedModel.cpp

69 lines
2.9 KiB
C++
Raw Normal View History

#include "Runtime/Graphics/CSkinnedModel.hpp"
#include "Runtime/Character/CSkinRules.hpp"
#include "Runtime/Graphics/CVertexMorphEffect.hpp"
#include <logvisor/logvisor.hpp>
2021-04-10 08:42:06 +00:00
namespace metaforce {
static logvisor::Module Log("metaforce::CSkinnedModel");
2018-12-08 05:30:43 +00:00
CSkinnedModel::CSkinnedModel(TLockedToken<CModel> model, TLockedToken<CSkinRules> skinRules,
TLockedToken<CCharLayoutInfo> layoutInfo, int shaderIdx, int drawInsts)
: x4_model(std::move(model)), x10_skinRules(std::move(skinRules)), x1c_layoutInfo(std::move(layoutInfo)) {
if (!x4_model) {
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Fatal, FMT_STRING("bad model token provided to CSkinnedModel"));
}
if (!x10_skinRules) {
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Fatal, FMT_STRING("bad skin token provided to CSkinnedModel"));
}
if (!x1c_layoutInfo) {
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Fatal, FMT_STRING("bad character layout token provided to CSkinnedModel"));
}
m_modelInst = x4_model->MakeNewInstance(shaderIdx, drawInsts);
}
2018-12-08 05:30:43 +00:00
CSkinnedModel::CSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo,
2016-09-12 04:53:28 +00:00
int shaderIdx, int drawInsts)
2018-12-08 05:30:43 +00:00
: CSkinnedModel(store.GetObj(SObjectTag{FOURCC('CMDL'), model}), store.GetObj(SObjectTag{FOURCC('CSKR'), skinRules}),
store.GetObj(SObjectTag{FOURCC('CINF'), layoutInfo}), shaderIdx, drawInsts) {}
2016-04-15 03:02:21 +00:00
2018-12-08 05:30:43 +00:00
void CSkinnedModel::Calculate(const CPoseAsTransforms& pose, const CModelFlags& drawFlags,
const std::optional<CVertexMorphEffect>& morphEffect,
2018-12-08 05:30:43 +00:00
const float* morphMagnitudes) {
if (morphEffect || g_PointGenFunc) {
if (boo::ObjToken<boo::IGraphicsBufferD> vertBuf = m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr)) {
x10_skinRules->TransformVerticesCPU(m_vertWorkspace, pose, *x4_model);
if (morphEffect)
morphEffect->MorphVertices(m_vertWorkspace, morphMagnitudes, x10_skinRules, pose);
if (g_PointGenFunc)
g_PointGenFunc(g_PointGenCtx, m_vertWorkspace);
x4_model->ApplyVerticesCPU(vertBuf, m_vertWorkspace);
m_modifiedVBO = true;
}
2018-12-08 05:30:43 +00:00
} else {
if (boo::ObjToken<boo::IGraphicsBufferD> vertBuf =
m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose)) {
if (m_modifiedVBO) {
x4_model->RestoreVerticesCPU(vertBuf);
m_modifiedVBO = false;
}
}
2018-12-08 05:30:43 +00:00
}
2016-08-21 20:39:18 +00:00
}
2018-12-08 05:30:43 +00:00
void CSkinnedModel::Draw(const CModelFlags& drawFlags) const {
2021-04-03 16:48:39 +00:00
OPTICK_EVENT();
2018-12-08 05:30:43 +00:00
if (m_modelInst->TryLockTextures())
m_modelInst->DrawSurfaces(drawFlags);
}
2018-12-08 05:30:43 +00:00
CMorphableSkinnedModel::CMorphableSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules,
CAssetId layoutInfo, int shaderIdx, int drawInsts)
: CSkinnedModel(store, model, skinRules, layoutInfo, shaderIdx, drawInsts) {}
2016-04-15 03:02:21 +00:00
2017-03-26 05:53:04 +00:00
CSkinnedModel::FPointGenerator CSkinnedModel::g_PointGenFunc = nullptr;
void* CSkinnedModel::g_PointGenCtx = nullptr;
2021-04-10 08:42:06 +00:00
} // namespace metaforce