2016-04-05 01:51:25 +00:00
|
|
|
#include "CSkinnedModel.hpp"
|
2016-08-23 03:12:50 +00:00
|
|
|
#include "Character/CSkinRules.hpp"
|
2017-08-21 05:46:59 +00:00
|
|
|
#include "CVertexMorphEffect.hpp"
|
2016-04-05 01:51:25 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
2016-08-31 23:08:09 +00:00
|
|
|
static logvisor::Module Log("urde::CSkinnedModel");
|
2016-04-05 01:51:25 +00:00
|
|
|
|
2016-08-21 20:39:18 +00:00
|
|
|
CSkinnedModel::CSkinnedModel(TLockedToken<CModel> model,
|
|
|
|
TLockedToken<CSkinRules> skinRules,
|
|
|
|
TLockedToken<CCharLayoutInfo> layoutInfo,
|
2016-09-12 04:53:28 +00:00
|
|
|
int shaderIdx, int drawInsts)
|
2016-04-14 21:42:47 +00:00
|
|
|
: x4_model(model), x10_skinRules(skinRules), x1c_layoutInfo(layoutInfo)
|
2016-04-05 01:51:25 +00:00
|
|
|
{
|
2016-08-31 23:08:09 +00:00
|
|
|
if (!model)
|
|
|
|
Log.report(logvisor::Fatal, "bad model token provided to CSkinnedModel");
|
|
|
|
if (!skinRules)
|
|
|
|
Log.report(logvisor::Fatal, "bad skin token provided to CSkinnedModel");
|
|
|
|
if (!layoutInfo)
|
|
|
|
Log.report(logvisor::Fatal, "bad character layout token provided to CSkinnedModel");
|
2016-09-12 04:53:28 +00:00
|
|
|
m_modelInst = model->MakeNewInstance(shaderIdx, drawInsts);
|
2016-04-05 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CSkinnedModel::CSkinnedModel(IObjectStore& store, CAssetId model,
|
|
|
|
CAssetId skinRules, CAssetId layoutInfo,
|
2016-09-12 04:53:28 +00:00
|
|
|
int shaderIdx, int drawInsts)
|
2016-08-21 20:39:18 +00:00
|
|
|
: CSkinnedModel(store.GetObj(SObjectTag{FOURCC('CMDL'), model}),
|
|
|
|
store.GetObj(SObjectTag{FOURCC('CSKR'), skinRules}),
|
|
|
|
store.GetObj(SObjectTag{FOURCC('CINF'), layoutInfo}),
|
2016-09-12 04:53:28 +00:00
|
|
|
shaderIdx, drawInsts)
|
2016-04-15 03:02:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-05 01:51:25 +00:00
|
|
|
void CSkinnedModel::Calculate(const CPoseAsTransforms& pose,
|
2016-08-21 20:39:18 +00:00
|
|
|
const CModelFlags& drawFlags,
|
2018-04-30 03:12:41 +00:00
|
|
|
const std::experimental::optional<CVertexMorphEffect>& morphEffect,
|
2016-08-21 20:39:18 +00:00
|
|
|
const float* morphMagnitudes)
|
|
|
|
{
|
2017-08-21 05:46:59 +00:00
|
|
|
if (morphEffect || g_PointGenFunc)
|
|
|
|
{
|
2018-01-15 07:39:25 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-08-21 05:46:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose);
|
|
|
|
}
|
2016-08-21 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSkinnedModel::Draw(const CModelFlags& drawFlags) const
|
2016-04-05 01:51:25 +00:00
|
|
|
{
|
2016-08-21 20:39:18 +00:00
|
|
|
if (m_modelInst->TryLockTextures())
|
|
|
|
m_modelInst->DrawSurfaces(drawFlags);
|
2016-04-05 01:51:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CMorphableSkinnedModel::CMorphableSkinnedModel(IObjectStore& store, CAssetId model,
|
|
|
|
CAssetId skinRules, CAssetId layoutInfo,
|
2016-09-12 04:53:28 +00:00
|
|
|
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;
|
|
|
|
|
2016-04-05 01:51:25 +00:00
|
|
|
}
|