2016-04-09 23:19:17 +00:00
|
|
|
#include "CSkinRules.hpp"
|
2016-04-12 22:28:08 +00:00
|
|
|
#include "CToken.hpp"
|
2017-08-21 05:46:59 +00:00
|
|
|
#include "Graphics/CModel.hpp"
|
|
|
|
#include "CPoseAsTransforms.hpp"
|
2016-04-09 23:19:17 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CSkinRules::CSkinRules(CInputStream& in)
|
|
|
|
{
|
2016-04-12 22:28:08 +00:00
|
|
|
u32 bankCount = in.readUint32Big();
|
|
|
|
x0_skinBanks.reserve(bankCount);
|
|
|
|
for (u32 i=0 ; i<bankCount ; ++i)
|
|
|
|
x0_skinBanks.emplace_back(in);
|
2017-08-21 05:46:59 +00:00
|
|
|
|
|
|
|
u32 virtualBoneCount = in.readUint32Big();
|
|
|
|
m_virtualBones.reserve(virtualBoneCount);
|
|
|
|
for (u32 i=0 ; i<virtualBoneCount ; ++i)
|
|
|
|
m_virtualBones.emplace_back(in);
|
|
|
|
|
|
|
|
u32 poolSz = in.readUint32Big();
|
|
|
|
m_poolToSkinIdx.reserve(poolSz);
|
|
|
|
for (u32 i=0 ; i<poolSz ; ++i)
|
|
|
|
m_poolToSkinIdx.push_back(in.readUint32Big());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSkinRules::TransformVerticesCPU(std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vnOut,
|
|
|
|
const CPoseAsTransforms& pose, const CModel& model) const
|
|
|
|
{
|
|
|
|
vnOut.resize(m_poolToSkinIdx.size());
|
|
|
|
for (size_t i=0 ; i<m_poolToSkinIdx.size() ; ++i)
|
|
|
|
{
|
|
|
|
const CVirtualBone& vb = m_virtualBones[m_poolToSkinIdx[i]];
|
|
|
|
zeus::CVector3f origVertex = model.GetPoolVertex(i);
|
|
|
|
zeus::CVector3f vertex;
|
|
|
|
zeus::CVector3f origNormal = model.GetPoolNormal(i);
|
|
|
|
zeus::CVector3f normal;
|
|
|
|
for (const SSkinWeighting& w : vb.GetWeights())
|
|
|
|
{
|
|
|
|
const zeus::CTransform& xf = pose.GetRestToAccumTransform(w.m_id);
|
|
|
|
vertex += (xf * origVertex) * w.m_weight;
|
|
|
|
normal += (xf.basis.inverted().transposed() * origVertex) * w.m_weight;
|
|
|
|
}
|
|
|
|
vnOut[i] = std::make_pair(vertex, normal);
|
|
|
|
}
|
2016-04-12 22:28:08 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 19:32:57 +00:00
|
|
|
CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params,
|
|
|
|
CObjectReference* selfRef)
|
2016-04-12 22:28:08 +00:00
|
|
|
{
|
|
|
|
return TToken<CSkinRules>::GetIObjObjectFor(std::make_unique<CSkinRules>(in));
|
2016-04-09 23:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|