metaforce/Runtime/Character/CSkinRules.cpp

73 lines
2.4 KiB
C++
Raw Normal View History

#include "Runtime/Character/CSkinRules.hpp"
#include "Runtime/CToken.hpp"
#include "Runtime/Character/CPoseAsTransforms.hpp"
#include "Runtime/Graphics/CModel.hpp"
2016-04-09 23:19:17 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
2016-04-09 23:19:17 +00:00
2022-02-01 00:06:54 +00:00
static u32 ReadCount(CInputStream& in) {
2022-02-21 00:03:38 +00:00
s32 result = in.ReadLong();
if (result == -1) {
return in.ReadLong();
}
u8 junk[784];
u32 iVar2 = 0;
for (u32 i = 0; i < (result * 3); i += iVar2) {
iVar2 = ((result * 3) - i);
iVar2 = 192 < iVar2 ? 192 : iVar2;
in.Get(junk, iVar2 * 4);
2022-02-01 00:06:54 +00:00
}
return result;
}
2022-02-01 00:06:54 +00:00
CSkinRules::CSkinRules(CInputStream& in) {
u32 weightCount = in.ReadLong();
2022-02-01 00:06:54 +00:00
x0_bones.reserve(weightCount);
for (int i = 0; i < weightCount; ++i) {
x0_bones.emplace_back(in);
2018-12-08 05:30:43 +00:00
}
2022-02-01 00:06:54 +00:00
x10_vertexCount = ReadCount(in);
x14_normalCount = ReadCount(in);
}
2022-02-01 00:06:54 +00:00
// void CSkinRules::TransformVerticesCPU(std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vnOut,
// const CPoseAsTransforms& pose, const CModel& model) const {
// OPTICK_EVENT();
// 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() * origNormal) * w.m_weight;
// }
// vnOut[i] = std::make_pair(vertex, normal.normalized());
// }
// }
CFactoryFnReturn FSkinRulesFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params,
2018-12-08 05:30:43 +00:00
CObjectReference* selfRef) {
return TToken<CSkinRules>::GetIObjObjectFor(std::make_unique<CSkinRules>(in));
2016-04-09 23:19:17 +00:00
}
2022-02-01 00:06:54 +00:00
auto StreamInSkinWeighting(CInputStream& in) {
rstl::reserved_vector<SSkinWeighting, 3> weights;
u32 weightCount = in.ReadLong();
2022-02-01 00:06:54 +00:00
for (int i = 0; i < std::min(3u, weightCount); ++i) {
weights.emplace_back(in);
}
for (int i = 3; i < weightCount; ++i) {
SSkinWeighting{in};
}
return weights;
}
CVirtualBone::CVirtualBone(CInputStream& in)
: x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.ReadLong()) {}
2021-04-10 08:42:06 +00:00
} // namespace metaforce