2020-01-15 04:07:48 -08:00
|
|
|
#include "Runtime/Character/CCharLayoutInfo.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CToken.hpp"
|
2016-04-09 16:19:17 -07:00
|
|
|
|
2021-04-10 01:42:06 -07:00
|
|
|
namespace metaforce {
|
2016-04-09 16:19:17 -07:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
zeus::CVector3f CCharLayoutInfo::GetFromParentUnrotated(const CSegId& id) const {
|
|
|
|
const CCharLayoutNode::Bone& bone = x0_node->GetBoneMap()[id];
|
2019-10-26 18:24:08 -07:00
|
|
|
|
|
|
|
if (x0_node->GetBoneMap().HasElement(bone.x0_parentId)) {
|
|
|
|
const CCharLayoutNode::Bone& parent = x0_node->GetBoneMap()[bone.x0_parentId];
|
|
|
|
return bone.x4_origin - parent.x4_origin;
|
|
|
|
} else {
|
2018-12-07 21:30:43 -08:00
|
|
|
return bone.x4_origin;
|
|
|
|
}
|
2016-04-13 16:07:18 -07:00
|
|
|
}
|
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
zeus::CVector3f CCharLayoutInfo::GetFromRootUnrotated(const CSegId& id) const {
|
|
|
|
const CCharLayoutNode::Bone& bone = x0_node->GetBoneMap()[id];
|
|
|
|
return bone.x4_origin;
|
2016-09-05 22:52:51 -07:00
|
|
|
}
|
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
CSegId CCharLayoutInfo::GetSegIdFromString(std::string_view name) const {
|
2019-10-26 18:14:43 -07:00
|
|
|
const auto it = x18_segIdMap.find(name);
|
|
|
|
|
|
|
|
if (it == x18_segIdMap.cend()) {
|
2018-12-07 21:30:43 -08:00
|
|
|
return {};
|
2019-10-26 18:14:43 -07:00
|
|
|
}
|
2016-09-02 20:47:57 -07:00
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
return it->second;
|
2016-09-02 20:47:57 -07:00
|
|
|
}
|
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
void CCharLayoutNode::Bone::read(CInputStream& in) {
|
|
|
|
x0_parentId = CSegId(in);
|
2022-02-17 23:37:54 -08:00
|
|
|
x4_origin = in.Get<zeus::CVector3f>();
|
2016-04-09 16:19:17 -07:00
|
|
|
|
2022-02-17 23:37:54 -08:00
|
|
|
const u32 chCount = in.ReadLong();
|
2018-12-07 21:30:43 -08:00
|
|
|
x10_children.reserve(chCount);
|
2019-10-26 18:21:55 -07:00
|
|
|
for (u32 i = 0; i < chCount; ++i) {
|
2018-12-07 21:30:43 -08:00
|
|
|
x10_children.emplace_back(in);
|
2019-10-26 18:21:55 -07:00
|
|
|
}
|
2016-04-09 16:19:17 -07:00
|
|
|
}
|
|
|
|
|
2022-02-17 23:37:54 -08:00
|
|
|
CCharLayoutNode::CCharLayoutNode(CInputStream& in) : x0_boneMap(in.ReadLong()) {
|
2019-10-26 18:21:55 -07:00
|
|
|
const u32 cap = x0_boneMap.GetCapacity();
|
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
for (u32 i = 0; i < cap; ++i) {
|
2022-02-17 23:37:54 -08:00
|
|
|
const u32 thisId = in.ReadLong();
|
2018-12-07 21:30:43 -08:00
|
|
|
Bone& bone = x0_boneMap[thisId];
|
|
|
|
bone.read(in);
|
|
|
|
}
|
2016-04-09 16:19:17 -07:00
|
|
|
}
|
|
|
|
|
2018-12-07 21:30:43 -08:00
|
|
|
CCharLayoutInfo::CCharLayoutInfo(CInputStream& in) : x0_node(std::make_shared<CCharLayoutNode>(in)), x8_segIdList(in) {
|
2022-02-21 22:59:47 -08:00
|
|
|
const u32 mapCount = in.ReadLong();
|
2019-10-26 18:19:54 -07:00
|
|
|
|
2022-02-21 22:59:47 -08:00
|
|
|
for (u32 i = 0; i < mapCount; ++i) {
|
2022-02-17 23:37:54 -08:00
|
|
|
std::string key = in.Get<std::string>();
|
2019-10-26 18:19:54 -07:00
|
|
|
x18_segIdMap.emplace(std::move(key), in);
|
2018-12-07 21:30:43 -08:00
|
|
|
}
|
2016-04-09 16:19:17 -07:00
|
|
|
}
|
|
|
|
|
2016-09-02 12:32:57 -07:00
|
|
|
CFactoryFnReturn FCharLayoutInfo(const SObjectTag&, CInputStream& in, const CVParamTransfer&,
|
2018-12-07 21:30:43 -08:00
|
|
|
CObjectReference* selfRef) {
|
|
|
|
return TToken<CCharLayoutInfo>::GetIObjObjectFor(std::make_unique<CCharLayoutInfo>(in));
|
2016-04-09 16:19:17 -07:00
|
|
|
}
|
|
|
|
|
2021-04-10 01:42:06 -07:00
|
|
|
} // namespace metaforce
|