From 668c4f7eee158b5a216b4e45fb4a7a95031c774d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 4 Sep 2016 12:47:48 -1000 Subject: [PATCH] Fixes in preparation for rigged model rendering --- DataSpec/DNAMP1/ANCS.cpp | 8 ++--- DataSpec/SpecBase.cpp | 3 +- Runtime/Character/CAllFormatsAnimSource.hpp | 2 +- Runtime/Character/CAnimData.cpp | 39 +++++++++++---------- Runtime/Character/CAnimData.hpp | 6 ++-- Runtime/Character/CCharAnimTime.cpp | 2 +- Runtime/Character/CFBStreamedAnimReader.cpp | 1 + Runtime/Character/IAnimReader.hpp | 37 ++++++++++++++++++- Runtime/Graphics/CModel.hpp | 3 ++ Runtime/Graphics/CModelBoo.cpp | 4 ++- Runtime/MP1/MP1.hpp | 28 +++++++-------- hecl | 2 +- 12 files changed, 89 insertions(+), 46 deletions(-) diff --git a/DataSpec/DNAMP1/ANCS.cpp b/DataSpec/DNAMP1/ANCS.cpp index 7cef0da9a..8b7f94ec4 100644 --- a/DataSpec/DNAMP1/ANCS.cpp +++ b/DataSpec/DNAMP1/ANCS.cpp @@ -1274,16 +1274,16 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath, { EVNT evnt; evnt.fromYAMLStream(reader); - anim.m_anim->evnt = evntYamlPath; - hecl::ProjectPath evntYamlOut = cookedOut.getWithExtension(_S(".evnt")); - athena::io::FileWriter w(evntYamlOut.getAbsolutePath(), true, false); + hecl::ProjectPath evntCookedOut = evntYamlPath.getCookedPath(SpecEntMP1); + athena::io::FileWriter w(evntCookedOut.getAbsolutePath(), true, false); if (w.hasError()) Log.report(logvisor::Fatal, _S("unable to open '%s' for writing"), - evntYamlOut.getRelativePath().c_str()); + evntCookedOut.getRelativePath().c_str()); evnt.write(w); ancs.animationSet.animResources.back().evntId = evntYamlPath; + anim.m_anim->evnt = evntYamlPath; } } diff --git a/DataSpec/SpecBase.cpp b/DataSpec/SpecBase.cpp index caf9d0f08..1d780e32f 100644 --- a/DataSpec/SpecBase.cpp +++ b/DataSpec/SpecBase.cpp @@ -156,7 +156,8 @@ const hecl::Database::DataSpecEntry* SpecBase::overrideDataSpec(const hecl::Proj return nullptr; 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; hecl::BlenderConnection& conn = btok.getBlenderConnection(); diff --git a/Runtime/Character/CAllFormatsAnimSource.hpp b/Runtime/Character/CAllFormatsAnimSource.hpp index e3962e183..c0d94aea0 100644 --- a/Runtime/Character/CAllFormatsAnimSource.hpp +++ b/Runtime/Character/CAllFormatsAnimSource.hpp @@ -26,7 +26,7 @@ class CAnimFormatUnion union { EAnimFormat x0_format; - intptr_t _align = 0; + u8 _align[16]; }; u8 x4_storage[std::max(sizeof(CAnimSource), sizeof(CFBStreamedCompression))]; static void SubConstruct(u8* storage, EAnimFormat fmt, diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index 5e4200ea1..ee15a0d3d 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -57,10 +57,11 @@ CAnimData::CAnimData(ResId id, x1fc_transMgr(transMgr), x204_charIdx(charIdx), x208_defaultAnim(defaultAnim), - x220_25_loop(loop), x224_pose(layout->GetSegIdList().GetList().size()), x2fc_poseBuilder(layout) { + x220_25_loop = loop; + if (iceModel) xe4_iceModelData = *iceModel; @@ -391,13 +392,13 @@ void CAnimData::PrimitiveSetToTokenVector(const std::set& primSet, void CAnimData::GetAnimationPrimitives(const CAnimPlaybackParms& parms, std::set& primsOut) const { std::shared_ptr animA = - GetAnimationManager()->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x0_animA)); + x100_animMgr->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x0_animA)); animA->GetUniquePrimitives(primsOut); if (parms.x4_animB != -1) { std::shared_ptr animB = - GetAnimationManager()->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x4_animB)); + x100_animMgr->GetMetaAnimation(xc_charInfo.GetAnimationIndex(parms.x4_animB)); animB->GetUniquePrimitives(primsOut); } } @@ -405,12 +406,12 @@ void CAnimData::GetAnimationPrimitives(const CAnimPlaybackParms& parms, std::set void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans) { 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 != 1.f) || parms.x4_animB == -1) { - if (x220_29_) + if (x220_29_animationJustStarted) return; } @@ -430,9 +431,9 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans) u32 animIdxB = xc_charInfo.GetAnimationIndex(parms.x4_animB); std::shared_ptr treeA = - GetAnimationManager()->GetAnimationTree(animIdxA, CMetaAnimTreeBuildOrders::NoSpecialOrders()); + x100_animMgr->GetAnimationTree(animIdxA, CMetaAnimTreeBuildOrders::NoSpecialOrders()); std::shared_ptr treeB = - GetAnimationManager()->GetAnimationTree(animIdxB, CMetaAnimTreeBuildOrders::NoSpecialOrders()); + x100_animMgr->GetAnimationTree(animIdxB, CMetaAnimTreeBuildOrders::NoSpecialOrders()); blendNode = std::make_shared(false, treeA, treeB, parms.x8_blendWeight, CAnimTreeBlend::CreatePrimitiveName(treeA, treeB, @@ -440,10 +441,10 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans) } 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); else x1f8_animRoot = blendNode; @@ -451,7 +452,7 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans) x220_24_animating = parms.xc_animating; CalcPlaybackAlignmentParms(parms, blendNode); ResetPOILists(); - x220_29_ = true; + x220_29_animationJustStarted = true; } 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 {}; } - if (x220_29_) + if (x220_29_animationJustStarted) { - x220_29_ = false; + x220_29_animationJustStarted = false; b1 = true; } @@ -512,7 +513,7 @@ SAdvancementDeltas CAnimData::DoAdvance(float dt, bool& b1, CRandom16& random, b if (remTime.EpsilonZero()) { x220_24_animating = false; - x1dc_ = zeus::CVector3f::skZero; + x1dc_alignPos = zeus::CVector3f::skZero; x220_28_ = false; x220_26_ = false; } @@ -555,7 +556,7 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus:: SAdvancementResults results; std::shared_ptr simplified; - if (x104_) + if (!x104_) { results = x1f8_animRoot->VAdvanceView(time); simplified = x1f8_animRoot->VSimplified(); @@ -587,14 +588,14 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus:: } case EUserEventType::AlignTargetPos: { - x1dc_ = zeus::CVector3f::skZero; + x1dc_alignPos = zeus::CVector3f::skZero; x220_28_ = false; x220_26_ = false; break; } case EUserEventType::AlignTargetRot: { - x1e8_ = zeus::CQuaternion::skNoRotation; + x1e8_alignRot = zeus::CQuaternion::skNoRotation; x220_27_ = false; break; } @@ -606,11 +607,11 @@ void CAnimData::AdvanceAnim(CCharAnimTime& time, zeus::CVector3f& offset, zeus:: offset += results.x8_deltas.x0_posDelta; 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; - x1dc_ = rot.transform(x1dc_); + x1dc_alignPos = rot.transform(x1dc_alignPos); time = results.x0_remTime; } diff --git a/Runtime/Character/CAnimData.hpp b/Runtime/Character/CAnimData.hpp index c9bf19bbe..b2b6bced9 100644 --- a/Runtime/Character/CAnimData.hpp +++ b/Runtime/Character/CAnimData.hpp @@ -95,8 +95,8 @@ class CAnimData zeus::CAABox x108_aabb; CParticleDatabase x120_particleDB; ResId x1d8_selfId; - zeus::CVector3f x1dc_; - zeus::CQuaternion x1e8_; + zeus::CVector3f x1dc_alignPos; + zeus::CQuaternion x1e8_alignRot; std::shared_ptr x1f8_animRoot; std::shared_ptr x1fc_transMgr; @@ -119,7 +119,7 @@ class CAnimData bool x220_26_ : 1; bool x220_27_ : 1; bool x220_28_ : 1; - bool x220_29_ : 1; + bool x220_29_animationJustStarted : 1; bool x220_30_poseBuilt : 1; bool x220_31_poseCached : 1; }; diff --git a/Runtime/Character/CCharAnimTime.cpp b/Runtime/Character/CCharAnimTime.cpp index 0d36aad19..4d56fa12e 100644 --- a/Runtime/Character/CCharAnimTime.cpp +++ b/Runtime/Character/CCharAnimTime.cpp @@ -146,7 +146,7 @@ bool CCharAnimTime::operator <(const CCharAnimTime& other) const { if (m_type == Type::Infinity) return m_time < 0.f && other.m_time > 0.f; - return m_time < 0.f; + return m_time < other.m_time; } } diff --git a/Runtime/Character/CFBStreamedAnimReader.cpp b/Runtime/Character/CFBStreamedAnimReader.cpp index ffd5a85f2..65dc2fc57 100644 --- a/Runtime/Character/CFBStreamedAnimReader.cpp +++ b/Runtime/Character/CFBStreamedAnimReader.cpp @@ -350,6 +350,7 @@ CFBStreamedAnimReader::CFBStreamedAnimReader(const TSubAnimTypeTokenGetBitstreamPointer()), x108_bitLoader(x104_bitstreamData), x114_segIdToIndex(x7c_totals.x10_nextSel ? x7c_totals.x14_a : x7c_totals.x3c_b) { + x7c_totals.SetTime(x108_bitLoader, CCharAnimTime()); PostConstruct(time); } diff --git a/Runtime/Character/IAnimReader.hpp b/Runtime/Character/IAnimReader.hpp index d49ec6095..0f8d9d670 100644 --- a/Runtime/Character/IAnimReader.hpp +++ b/Runtime/Character/IAnimReader.hpp @@ -7,6 +7,7 @@ #include "zeus/CQuaternion.hpp" #include "CParticleData.hpp" #include "CToken.hpp" +#include "CAllFormatsAnimSource.hpp" namespace urde { @@ -66,7 +67,41 @@ public: }; template -using TSubAnimTypeToken = TLockedToken; +class TSubAnimTypeToken : public TLockedToken +{ +}; + +template <> +class TSubAnimTypeToken : public TLockedToken +{ +public: + TSubAnimTypeToken(const TLockedToken& token) + : TLockedToken(token) {} + + const CAnimSource* GetObj() const + { + const CAllFormatsAnimSource* source = TLockedToken::GetObj(); + return &source->GetAsCAnimSource(); + } + const CAnimSource* operator->() const {return GetObj();} + const CAnimSource& operator*() const {return *GetObj();} +}; + +template <> +class TSubAnimTypeToken : public TLockedToken +{ +public: + TSubAnimTypeToken(const TLockedToken& token) + : TLockedToken(token) {} + + const CFBStreamedCompression* GetObj() const + { + const CAllFormatsAnimSource* source = TLockedToken::GetObj(); + return &source->GetAsCFBStreamedCompression(); + } + const CFBStreamedCompression* operator->() const {return GetObj();} + const CFBStreamedCompression& operator*() const {return *GetObj();} +}; class IAnimReader { diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index f7858d4a2..65734170d 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -177,6 +177,9 @@ class CModel boo::IGraphicsBufferS* m_ibo; boo::IVertexFormat* m_vtxFmt; + u32 m_weightVecCount; + u32 m_skinBankCount; + public: using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 82fd6a251..31bf3b0d2 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -619,7 +619,7 @@ std::unique_ptr CModel::MakeNewInstance(int shaderIdx) if (shaderIdx >= x18_matSets.size()) shaderIdx = 0; return std::make_unique(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&& in, u32 /* dataLen */, IObjectStore* store, CObjectReference* selfRef) @@ -655,6 +655,8 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor athena::io::MemoryReader r(hmdlMetadata, hmdlSz); hmdlMeta.read(r); } + m_weightVecCount = hmdlMeta.weightCount; + m_skinBankCount = hmdlMeta.bankCount; const u8* vboData = MemoryFromPartData(dataCur, secSizeCur); const u8* iboData = MemoryFromPartData(dataCur, secSizeCur); diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 32b617fc3..4904493af 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -61,12 +61,12 @@ enum class EGameplayResult class CGameGlobalObjects { CMemoryCardSys x0_memoryCardSys; - IFactory& x20_resFactory; - CSimplePool& x114_simplePool; - CCharacterFactoryBuilder x14c_charFactoryBuilder; - CAiFuncMap x188_aiFuncMap; - CGameState x1a8_gameState; - CInGameTweakManager x1c0_tweakManager; + IFactory& x4_resFactory; + CSimplePool& xcc_simplePool; + CCharacterFactoryBuilder xec_charFactoryBuilder; + CAiFuncMap x110_aiFuncMap; + CGameState x134_gameState; + CInGameTweakManager x150_tweakManager; std::unique_ptr m_renderer; void LoadStringTable() @@ -82,21 +82,21 @@ class CGameGlobalObjects public: CGameGlobalObjects(IFactory& resFactory, CSimplePool& objStore) - : x20_resFactory(resFactory), x114_simplePool(objStore) + : x4_resFactory(resFactory), xcc_simplePool(objStore) { g_MemoryCardSys = &x0_memoryCardSys; - g_ResFactory = &x20_resFactory; - g_SimplePool = &x114_simplePool; - g_CharFactoryBuilder = &x14c_charFactoryBuilder; - g_AiFuncMap = &x188_aiFuncMap; - g_GameState = &x1a8_gameState; - g_TweakManager = &x1c0_tweakManager; + g_ResFactory = &x4_resFactory; + g_SimplePool = &xcc_simplePool; + g_CharFactoryBuilder = &xec_charFactoryBuilder; + g_AiFuncMap = &x110_aiFuncMap; + g_GameState = &x134_gameState; + g_TweakManager = &x150_tweakManager; } void PostInitialize() { LoadStringTable(); - m_renderer.reset(AllocateRenderer(x114_simplePool, x20_resFactory)); + m_renderer.reset(AllocateRenderer(xcc_simplePool, x4_resFactory)); } }; diff --git a/hecl b/hecl index 42679f2a3..29c77ef93 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 42679f2a3ae651a7c070688969a8a8430791256e +Subproject commit 29c77ef93ca9c5102c01e4f81ef3b5b7675150dd