Fixes in preparation for rigged model rendering

This commit is contained in:
Jack Andersen 2016-09-04 12:47:48 -10:00
parent 03225d3616
commit 668c4f7eee
12 changed files with 89 additions and 46 deletions

View File

@ -1274,16 +1274,16 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath,
{ {
EVNT evnt; EVNT evnt;
evnt.fromYAMLStream(reader); evnt.fromYAMLStream(reader);
anim.m_anim->evnt = evntYamlPath;
hecl::ProjectPath evntYamlOut = cookedOut.getWithExtension(_S(".evnt")); hecl::ProjectPath evntCookedOut = evntYamlPath.getCookedPath(SpecEntMP1);
athena::io::FileWriter w(evntYamlOut.getAbsolutePath(), true, false); athena::io::FileWriter w(evntCookedOut.getAbsolutePath(), true, false);
if (w.hasError()) if (w.hasError())
Log.report(logvisor::Fatal, _S("unable to open '%s' for writing"), Log.report(logvisor::Fatal, _S("unable to open '%s' for writing"),
evntYamlOut.getRelativePath().c_str()); evntCookedOut.getRelativePath().c_str());
evnt.write(w); evnt.write(w);
ancs.animationSet.animResources.back().evntId = evntYamlPath; ancs.animationSet.animResources.back().evntId = evntYamlPath;
anim.m_anim->evnt = evntYamlPath;
} }
} }

View File

@ -156,7 +156,8 @@ const hecl::Database::DataSpecEntry* SpecBase::overrideDataSpec(const hecl::Proj
return nullptr; return nullptr;
if (hecl::IsPathBlend(path)) if (hecl::IsPathBlend(path))
{ {
if (hecl::StringUtils::EndsWith(path.getAuxInfo(), _S(".CSKR"))) if (hecl::StringUtils::EndsWith(path.getAuxInfo(), _S(".CSKR")) ||
hecl::StringUtils::EndsWith(path.getAuxInfo(), _S(".ANIM")))
return oldEntry; return oldEntry;
hecl::BlenderConnection& conn = btok.getBlenderConnection(); hecl::BlenderConnection& conn = btok.getBlenderConnection();

View File

@ -26,7 +26,7 @@ class CAnimFormatUnion
union union
{ {
EAnimFormat x0_format; EAnimFormat x0_format;
intptr_t _align = 0; u8 _align[16];
}; };
u8 x4_storage[std::max(sizeof(CAnimSource), sizeof(CFBStreamedCompression))]; u8 x4_storage[std::max(sizeof(CAnimSource), sizeof(CFBStreamedCompression))];
static void SubConstruct(u8* storage, EAnimFormat fmt, static void SubConstruct(u8* storage, EAnimFormat fmt,

View File

@ -57,10 +57,11 @@ CAnimData::CAnimData(ResId id,
x1fc_transMgr(transMgr), x1fc_transMgr(transMgr),
x204_charIdx(charIdx), x204_charIdx(charIdx),
x208_defaultAnim(defaultAnim), x208_defaultAnim(defaultAnim),
x220_25_loop(loop),
x224_pose(layout->GetSegIdList().GetList().size()), x224_pose(layout->GetSegIdList().GetList().size()),
x2fc_poseBuilder(layout) x2fc_poseBuilder(layout)
{ {
x220_25_loop = loop;
if (iceModel) if (iceModel)
xe4_iceModelData = *iceModel; xe4_iceModelData = *iceModel;
@ -391,13 +392,13 @@ void CAnimData::PrimitiveSetToTokenVector(const std::set<CPrimitive>& primSet,
void CAnimData::GetAnimationPrimitives(const CAnimPlaybackParms& parms, std::set<CPrimitive>& primsOut) const void CAnimData::GetAnimationPrimitives(const CAnimPlaybackParms& parms, std::set<CPrimitive>& primsOut) const
{ {
std::shared_ptr<IMetaAnim> animA = std::shared_ptr<IMetaAnim> animA =
GetAnimationManager()->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x0_animA)); x100_animMgr->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x0_animA));
animA->GetUniquePrimitives(primsOut); animA->GetUniquePrimitives(primsOut);
if (parms.x4_animB != -1) if (parms.x4_animB != -1)
{ {
std::shared_ptr<IMetaAnim> animB = std::shared_ptr<IMetaAnim> animB =
GetAnimationManager()->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x4_animB)); x100_animMgr->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x4_animB));
animB->GetUniquePrimitives(primsOut); animB->GetUniquePrimitives(primsOut);
} }
} }
@ -405,12 +406,12 @@ void CAnimData::GetAnimationPrimitives(const CAnimPlaybackParms& parms, std::set
void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans) void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans)
{ {
if (parms.x0_animA == x40c_playbackParms.x0_animA || if (parms.x0_animA == x40c_playbackParms.x0_animA ||
(parms.x4_animB != x40c_playbackParms.x4_animB && (parms.x4_animB == x40c_playbackParms.x4_animB &&
parms.x8_blendWeight == x40c_playbackParms.x8_blendWeight && parms.x8_blendWeight == x40c_playbackParms.x8_blendWeight &&
parms.x8_blendWeight != 1.f) || parms.x8_blendWeight != 1.f) ||
parms.x4_animB == -1) parms.x4_animB == -1)
{ {
if (x220_29_) if (x220_29_animationJustStarted)
return; return;
} }
@ -430,9 +431,9 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans)
u32 animIdxB = xc_charInfo.GetAnimationIndex(parms.x4_animB); u32 animIdxB = xc_charInfo.GetAnimationIndex(parms.x4_animB);
std::shared_ptr<CAnimTreeNode> treeA = std::shared_ptr<CAnimTreeNode> treeA =
GetAnimationManager()->GetAnimationTree(animIdxA, CMetaAnimTreeBuildOrders::NoSpecialOrders()); x100_animMgr->GetAnimationTree(animIdxA, CMetaAnimTreeBuildOrders::NoSpecialOrders());
std::shared_ptr<CAnimTreeNode> treeB = std::shared_ptr<CAnimTreeNode> treeB =
GetAnimationManager()->GetAnimationTree(animIdxB, CMetaAnimTreeBuildOrders::NoSpecialOrders()); x100_animMgr->GetAnimationTree(animIdxB, CMetaAnimTreeBuildOrders::NoSpecialOrders());
blendNode = std::make_shared<CAnimTreeBlend>(false, treeA, treeB, parms.x8_blendWeight, blendNode = std::make_shared<CAnimTreeBlend>(false, treeA, treeB, parms.x8_blendWeight,
CAnimTreeBlend::CreatePrimitiveName(treeA, treeB, CAnimTreeBlend::CreatePrimitiveName(treeA, treeB,
@ -440,10 +441,10 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans)
} }
else else
{ {
blendNode = GetAnimationManager()->GetAnimationTree(animIdxA, CMetaAnimTreeBuildOrders::NoSpecialOrders()); blendNode = x100_animMgr->GetAnimationTree(animIdxA, CMetaAnimTreeBuildOrders::NoSpecialOrders());
} }
if (!noTrans) if (!noTrans && x1f8_animRoot)
x1f8_animRoot = x1fc_transMgr->GetTransitionTree(x1f8_animRoot, blendNode); x1f8_animRoot = x1fc_transMgr->GetTransitionTree(x1f8_animRoot, blendNode);
else else
x1f8_animRoot = blendNode; x1f8_animRoot = blendNode;
@ -451,7 +452,7 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans)
x220_24_animating = parms.xc_animating; x220_24_animating = parms.xc_animating;
CalcPlaybackAlignmentParms(parms, blendNode); CalcPlaybackAlignmentParms(parms, blendNode);
ResetPOILists(); ResetPOILists();
x220_29_ = true; x220_29_animationJustStarted = true;
} }
SAdvancementDeltas CAnimData::DoAdvance(float dt, bool& b1, CRandom16& random, bool advTree) SAdvancementDeltas CAnimData::DoAdvance(float dt, bool& b1, CRandom16& random, bool advTree)
@ -476,9 +477,9 @@ SAdvancementDeltas CAnimData::DoAdvance(float dt, bool& b1, CRandom16& random, b
return {}; return {};
} }
if (x220_29_) if (x220_29_animationJustStarted)
{ {
x220_29_ = false; x220_29_animationJustStarted = false;
b1 = true; b1 = true;
} }
@ -512,7 +513,7 @@ SAdvancementDeltas CAnimData::DoAdvance(float dt, bool& b1, CRandom16& random, b
if (remTime.EpsilonZero()) if (remTime.EpsilonZero())
{ {
x220_24_animating = false; x220_24_animating = false;
x1dc_ = zeus::CVector3f::skZero; x1dc_alignPos = zeus::CVector3f::skZero;
x220_28_ = false; x220_28_ = false;
x220_26_ = false; x220_26_ = false;
} }
@ -555,7 +556,7 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus::
SAdvancementResults results; SAdvancementResults results;
std::shared_ptr<IAnimReader> simplified; std::shared_ptr<IAnimReader> simplified;
if (x104_) if (!x104_)
{ {
results = x1f8_animRoot->VAdvanceView(time); results = x1f8_animRoot->VAdvanceView(time);
simplified = x1f8_animRoot->VSimplified(); simplified = x1f8_animRoot->VSimplified();
@ -587,14 +588,14 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus::
} }
case EUserEventType::AlignTargetPos: case EUserEventType::AlignTargetPos:
{ {
x1dc_ = zeus::CVector3f::skZero; x1dc_alignPos = zeus::CVector3f::skZero;
x220_28_ = false; x220_28_ = false;
x220_26_ = false; x220_26_ = false;
break; break;
} }
case EUserEventType::AlignTargetRot: case EUserEventType::AlignTargetRot:
{ {
x1e8_ = zeus::CQuaternion::skNoRotation; x1e8_alignRot = zeus::CQuaternion::skNoRotation;
x220_27_ = false; x220_27_ = false;
break; break;
} }
@ -606,11 +607,11 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus::
offset += results.x8_deltas.x0_posDelta; offset += results.x8_deltas.x0_posDelta;
if (x220_26_) if (x220_26_)
offset += x1dc_ * time; offset += x1dc_alignPos * time;
zeus::CQuaternion rot = results.x8_deltas.xc_rotDelta * x1e8_; zeus::CQuaternion rot = results.x8_deltas.xc_rotDelta * x1e8_alignRot;
quat = quat * rot; quat = quat * rot;
x1dc_ = rot.transform(x1dc_); x1dc_alignPos = rot.transform(x1dc_alignPos);
time = results.x0_remTime; time = results.x0_remTime;
} }

View File

@ -95,8 +95,8 @@ class CAnimData
zeus::CAABox x108_aabb; zeus::CAABox x108_aabb;
CParticleDatabase x120_particleDB; CParticleDatabase x120_particleDB;
ResId x1d8_selfId; ResId x1d8_selfId;
zeus::CVector3f x1dc_; zeus::CVector3f x1dc_alignPos;
zeus::CQuaternion x1e8_; zeus::CQuaternion x1e8_alignRot;
std::shared_ptr<CAnimTreeNode> x1f8_animRoot; std::shared_ptr<CAnimTreeNode> x1f8_animRoot;
std::shared_ptr<CTransitionManager> x1fc_transMgr; std::shared_ptr<CTransitionManager> x1fc_transMgr;
@ -119,7 +119,7 @@ class CAnimData
bool x220_26_ : 1; bool x220_26_ : 1;
bool x220_27_ : 1; bool x220_27_ : 1;
bool x220_28_ : 1; bool x220_28_ : 1;
bool x220_29_ : 1; bool x220_29_animationJustStarted : 1;
bool x220_30_poseBuilt : 1; bool x220_30_poseBuilt : 1;
bool x220_31_poseCached : 1; bool x220_31_poseCached : 1;
}; };

View File

@ -146,7 +146,7 @@ bool CCharAnimTime::operator <(const CCharAnimTime& other) const
{ {
if (m_type == Type::Infinity) if (m_type == Type::Infinity)
return m_time < 0.f && other.m_time > 0.f; return m_time < 0.f && other.m_time > 0.f;
return m_time < 0.f; return m_time < other.m_time;
} }
} }

View File

@ -350,6 +350,7 @@ CFBStreamedAnimReader::CFBStreamedAnimReader(const TSubAnimTypeToken<CFBStreamed
x7c_totals(source), x104_bitstreamData(source->GetBitstreamPointer()), x108_bitLoader(x104_bitstreamData), x7c_totals(source), x104_bitstreamData(source->GetBitstreamPointer()), x108_bitLoader(x104_bitstreamData),
x114_segIdToIndex(x7c_totals.x10_nextSel ? x7c_totals.x14_a : x7c_totals.x3c_b) x114_segIdToIndex(x7c_totals.x10_nextSel ? x7c_totals.x14_a : x7c_totals.x3c_b)
{ {
x7c_totals.SetTime(x108_bitLoader, CCharAnimTime());
PostConstruct(time); PostConstruct(time);
} }

View File

@ -7,6 +7,7 @@
#include "zeus/CQuaternion.hpp" #include "zeus/CQuaternion.hpp"
#include "CParticleData.hpp" #include "CParticleData.hpp"
#include "CToken.hpp" #include "CToken.hpp"
#include "CAllFormatsAnimSource.hpp"
namespace urde namespace urde
{ {
@ -66,7 +67,41 @@ public:
}; };
template <class T> template <class T>
using TSubAnimTypeToken = TLockedToken<T>; class TSubAnimTypeToken : public TLockedToken<CAllFormatsAnimSource>
{
};
template <>
class TSubAnimTypeToken<CAnimSource> : public TLockedToken<CAllFormatsAnimSource>
{
public:
TSubAnimTypeToken<CAnimSource>(const TLockedToken<CAllFormatsAnimSource>& token)
: TLockedToken<CAllFormatsAnimSource>(token) {}
const CAnimSource* GetObj() const
{
const CAllFormatsAnimSource* source = TLockedToken<CAllFormatsAnimSource>::GetObj();
return &source->GetAsCAnimSource();
}
const CAnimSource* operator->() const {return GetObj();}
const CAnimSource& operator*() const {return *GetObj();}
};
template <>
class TSubAnimTypeToken<CFBStreamedCompression> : public TLockedToken<CAllFormatsAnimSource>
{
public:
TSubAnimTypeToken<CFBStreamedCompression>(const TLockedToken<CAllFormatsAnimSource>& token)
: TLockedToken<CAllFormatsAnimSource>(token) {}
const CFBStreamedCompression* GetObj() const
{
const CAllFormatsAnimSource* source = TLockedToken<CAllFormatsAnimSource>::GetObj();
return &source->GetAsCFBStreamedCompression();
}
const CFBStreamedCompression* operator->() const {return GetObj();}
const CFBStreamedCompression& operator*() const {return *GetObj();}
};
class IAnimReader class IAnimReader
{ {

View File

@ -177,6 +177,9 @@ class CModel
boo::IGraphicsBufferS* m_ibo; boo::IGraphicsBufferS* m_ibo;
boo::IVertexFormat* m_vtxFmt; boo::IVertexFormat* m_vtxFmt;
u32 m_weightVecCount;
u32 m_skinBankCount;
public: public:
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;

View File

@ -619,7 +619,7 @@ std::unique_ptr<CBooModel> CModel::MakeNewInstance(int shaderIdx)
if (shaderIdx >= x18_matSets.size()) if (shaderIdx >= x18_matSets.size())
shaderIdx = 0; shaderIdx = 0;
return std::make_unique<CBooModel>(m_selfToken, &x8_surfaces, x18_matSets[shaderIdx], return std::make_unique<CBooModel>(m_selfToken, &x8_surfaces, x18_matSets[shaderIdx],
m_vtxFmt, m_vbo, m_ibo, 0, 0, m_aabb); m_vtxFmt, m_vbo, m_ibo, m_weightVecCount, m_skinBankCount, m_aabb);
} }
CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* store, CObjectReference* selfRef) CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* store, CObjectReference* selfRef)
@ -655,6 +655,8 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* stor
athena::io::MemoryReader r(hmdlMetadata, hmdlSz); athena::io::MemoryReader r(hmdlMetadata, hmdlSz);
hmdlMeta.read(r); hmdlMeta.read(r);
} }
m_weightVecCount = hmdlMeta.weightCount;
m_skinBankCount = hmdlMeta.bankCount;
const u8* vboData = MemoryFromPartData(dataCur, secSizeCur); const u8* vboData = MemoryFromPartData(dataCur, secSizeCur);
const u8* iboData = MemoryFromPartData(dataCur, secSizeCur); const u8* iboData = MemoryFromPartData(dataCur, secSizeCur);

View File

@ -61,12 +61,12 @@ enum class EGameplayResult
class CGameGlobalObjects class CGameGlobalObjects
{ {
CMemoryCardSys x0_memoryCardSys; CMemoryCardSys x0_memoryCardSys;
IFactory& x20_resFactory; IFactory& x4_resFactory;
CSimplePool& x114_simplePool; CSimplePool& xcc_simplePool;
CCharacterFactoryBuilder x14c_charFactoryBuilder; CCharacterFactoryBuilder xec_charFactoryBuilder;
CAiFuncMap x188_aiFuncMap; CAiFuncMap x110_aiFuncMap;
CGameState x1a8_gameState; CGameState x134_gameState;
CInGameTweakManager x1c0_tweakManager; CInGameTweakManager x150_tweakManager;
std::unique_ptr<CBooRenderer> m_renderer; std::unique_ptr<CBooRenderer> m_renderer;
void LoadStringTable() void LoadStringTable()
@ -82,21 +82,21 @@ class CGameGlobalObjects
public: public:
CGameGlobalObjects(IFactory& resFactory, CGameGlobalObjects(IFactory& resFactory,
CSimplePool& objStore) CSimplePool& objStore)
: x20_resFactory(resFactory), x114_simplePool(objStore) : x4_resFactory(resFactory), xcc_simplePool(objStore)
{ {
g_MemoryCardSys = &x0_memoryCardSys; g_MemoryCardSys = &x0_memoryCardSys;
g_ResFactory = &x20_resFactory; g_ResFactory = &x4_resFactory;
g_SimplePool = &x114_simplePool; g_SimplePool = &xcc_simplePool;
g_CharFactoryBuilder = &x14c_charFactoryBuilder; g_CharFactoryBuilder = &xec_charFactoryBuilder;
g_AiFuncMap = &x188_aiFuncMap; g_AiFuncMap = &x110_aiFuncMap;
g_GameState = &x1a8_gameState; g_GameState = &x134_gameState;
g_TweakManager = &x1c0_tweakManager; g_TweakManager = &x150_tweakManager;
} }
void PostInitialize() void PostInitialize()
{ {
LoadStringTable(); LoadStringTable();
m_renderer.reset(AllocateRenderer(x114_simplePool, x20_resFactory)); m_renderer.reset(AllocateRenderer(xcc_simplePool, x4_resFactory));
} }
}; };

2
hecl

@ -1 +1 @@
Subproject commit 42679f2a3ae651a7c070688969a8a8430791256e Subproject commit 29c77ef93ca9c5102c01e4f81ef3b5b7675150dd