metaforce/Runtime/Graphics/CSkinnedModel.cpp

96 lines
3.7 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");
CSkinnedModel::CSkinnedModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules,
const TLockedToken<CCharLayoutInfo>& layoutInfo)
: 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"));
}
}
CSkinnedModel::CSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo)
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})) {}
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,
2021-06-07 19:29:18 +00:00
const std::optional<CVertexMorphEffect>& morphEffect, const float* morphMagnitudes) {
2022-02-01 00:06:54 +00:00
// TODO
// 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;
// }
// } 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;
// }
// }
// }
2016-08-21 20:39:18 +00:00
}
void CSkinnedModel::Draw(TVectorRef verts, TVectorRef norms, const CModelFlags& drawFlags) {
2021-04-03 16:48:39 +00:00
OPTICK_EVENT();
x4_model->Draw(verts, norms, drawFlags);
// PostDrawFunc();
}
void CSkinnedModel::Draw(const CModelFlags& drawFlags) {
if (x35_disableWorkspaces) {
const auto mtx = CGraphics::g_GXModelMatrix;
CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf);
x4_model->Draw(drawFlags);
CGraphics::SetModelMatrix(mtx);
} else if (x24_vertWorkspace.empty()) {
x4_model->Draw(drawFlags);
} else {
x4_model->Draw(&x24_vertWorkspace, &x2c_normalWorkspace, drawFlags);
// PostDrawFunc();
}
}
void CSkinnedModel::DoDrawCallback(const FCustomDraw& func) const {
if (x35_disableWorkspaces) {
const auto mtx = CGraphics::g_GXModelMatrix;
CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf);
func(x4_model->GetPositions(), x4_model->GetNormals());
CGraphics::SetModelMatrix(mtx);
} else if (x24_vertWorkspace.empty()) {
func(x4_model->GetPositions(), x4_model->GetNormals());
} else {
func(&x24_vertWorkspace, &x2c_normalWorkspace);
// PostDrawFunc();
}
}
2018-12-08 05:30:43 +00:00
CMorphableSkinnedModel::CMorphableSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules,
CAssetId layoutInfo)
: CSkinnedModel(store, model, skinRules, layoutInfo) {}
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