2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Graphics/CSkinnedModel.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/Character/CSkinRules.hpp"
|
|
|
|
#include "Runtime/Graphics/CVertexMorphEffect.hpp"
|
|
|
|
|
|
|
|
#include <logvisor/logvisor.hpp>
|
2016-04-05 01:51:25 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
|
|
|
static logvisor::Module Log("metaforce::CSkinnedModel");
|
2016-04-05 01:51:25 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
CSkinnedModel::CSkinnedModel(const TLockedToken<CModel>& model, const TLockedToken<CSkinRules>& skinRules,
|
|
|
|
const TLockedToken<CCharLayoutInfo>& layoutInfo)
|
2020-02-24 07:36:40 +00:00
|
|
|
: 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"));
|
2020-02-24 07:36:40 +00:00
|
|
|
}
|
|
|
|
if (!x10_skinRules) {
|
2020-04-11 22:51:39 +00:00
|
|
|
Log.report(logvisor::Fatal, FMT_STRING("bad skin token provided to CSkinnedModel"));
|
2020-02-24 07:36:40 +00:00
|
|
|
}
|
|
|
|
if (!x1c_layoutInfo) {
|
2020-04-11 22:51:39 +00:00
|
|
|
Log.report(logvisor::Fatal, FMT_STRING("bad character layout token provided to CSkinnedModel"));
|
2020-02-24 07:36:40 +00:00
|
|
|
}
|
2016-04-05 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
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}),
|
2022-02-25 07:45:25 +00:00
|
|
|
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
|
2022-02-25 07:45:25 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
void CSkinnedModel::Draw(TVectorRef verts, TVectorRef norms, const CModelFlags& drawFlags) {
|
2021-04-03 16:48:39 +00:00
|
|
|
OPTICK_EVENT();
|
2022-02-25 07:45:25 +00:00
|
|
|
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();
|
|
|
|
}
|
2016-04-05 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CMorphableSkinnedModel::CMorphableSkinnedModel(IObjectStore& store, CAssetId model, CAssetId skinRules,
|
2022-02-25 07:45:25 +00:00
|
|
|
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
|