From 7f3929d4ca6b439143aed5df222d729fae35d75d Mon Sep 17 00:00:00 2001 From: parax0 Date: Thu, 28 Apr 2016 00:44:50 -0600 Subject: [PATCH] Fixed grid drawing at incorrect depth, fixed MP2 areas not loading correctly with the AnimSet loader changes --- src/Core/Resource/Factory/CAnimSetLoader.cpp | 75 ++++++++++--------- src/Core/Resource/Factory/CModelLoader.cpp | 10 --- src/Core/Resource/Model/CModel.cpp | 2 +- src/Editor/CGridRenderable.h | 23 ++++++ .../CCharacterEditorViewport.cpp | 4 +- .../CCharacterEditorViewport.h | 2 + src/Editor/Editor.pro | 3 +- .../ModelEditor/CModelEditorViewport.cpp | 6 +- src/Editor/ModelEditor/CModelEditorViewport.h | 2 + 9 files changed, 75 insertions(+), 52 deletions(-) create mode 100644 src/Editor/CGridRenderable.h diff --git a/src/Core/Resource/Factory/CAnimSetLoader.cpp b/src/Core/Resource/Factory/CAnimSetLoader.cpp index af15a4c3..4e27ce9c 100644 --- a/src/Core/Resource/Factory/CAnimSetLoader.cpp +++ b/src/Core/Resource/Factory/CAnimSetLoader.cpp @@ -298,47 +298,50 @@ CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& rANCS) } } - // Load Animation Set - u32 SetStart = rANCS.Tell(); - SetStart = SetStart; - u16 InfoCount = rANCS.ReadShort(); - u32 NumAnims = rANCS.ReadLong(); - - for (u32 iAnim = 0; iAnim < NumAnims; iAnim++) - Loader.LoadAnimation(rANCS); - - u32 NumTransitions = rANCS.ReadLong(); - - for (u32 iTrans = 0; iTrans < NumTransitions; iTrans++) - Loader.LoadTransition(rANCS); - Loader.LoadMetaTransition(rANCS); - - u32 NumAdditiveAnims = rANCS.ReadLong(); - - for (u32 iAnim = 0; iAnim < NumAdditiveAnims; iAnim++) - Loader.LoadAdditiveAnimation(rANCS); - - rANCS.Seek(0x8, SEEK_CUR); - - if (InfoCount > 2) + if (Loader.mVersion <= ePrime) { - u32 NumHalfTransitions = rANCS.ReadLong(); + // Load Animation Set + u32 SetStart = rANCS.Tell(); + SetStart = SetStart; + u16 InfoCount = rANCS.ReadShort(); + u32 NumAnims = rANCS.ReadLong(); - for (u32 iHalf = 0; iHalf < NumHalfTransitions; iHalf++) - Loader.LoadHalfTransition(rANCS); - } + for (u32 iAnim = 0; iAnim < NumAnims; iAnim++) + Loader.LoadAnimation(rANCS); - // Add anims to set - for (u32 iPrim = 0; iPrim < Loader.mAnimPrimitives.size(); iPrim++) - { - SPrimitive& rPrim = Loader.mAnimPrimitives[iPrim]; + u32 NumTransitions = rANCS.ReadLong(); - if (rPrim.Loaded) + for (u32 iTrans = 0; iTrans < NumTransitions; iTrans++) + Loader.LoadTransition(rANCS); + Loader.LoadMetaTransition(rANCS); + + u32 NumAdditiveAnims = rANCS.ReadLong(); + + for (u32 iAnim = 0; iAnim < NumAdditiveAnims; iAnim++) + Loader.LoadAdditiveAnimation(rANCS); + + rANCS.Seek(0x8, SEEK_CUR); + + if (InfoCount > 2) { - CAnimSet::SAnimation Anim; - Anim.Name = rPrim.Name; - Anim.pAnim = gResCache.GetResource(rPrim.AnimID, "ANIM"); - Loader.pSet->mAnims.push_back(Anim); + u32 NumHalfTransitions = rANCS.ReadLong(); + + for (u32 iHalf = 0; iHalf < NumHalfTransitions; iHalf++) + Loader.LoadHalfTransition(rANCS); + } + + // Add anims to set + for (u32 iPrim = 0; iPrim < Loader.mAnimPrimitives.size(); iPrim++) + { + SPrimitive& rPrim = Loader.mAnimPrimitives[iPrim]; + + if (rPrim.Loaded) + { + CAnimSet::SAnimation Anim; + Anim.Name = rPrim.Name; + Anim.pAnim = gResCache.GetResource(rPrim.AnimID, "ANIM"); + Loader.pSet->mAnims.push_back(Anim); + } } } diff --git a/src/Core/Resource/Factory/CModelLoader.cpp b/src/Core/Resource/Factory/CModelLoader.cpp index a85e5513..47f2ef72 100644 --- a/src/Core/Resource/Factory/CModelLoader.cpp +++ b/src/Core/Resource/Factory/CModelLoader.cpp @@ -464,16 +464,6 @@ CModel* CModelLoader::LoadCMDL(IInputStream& rCMDL) { Loader.mMaterials[iSet] = CMaterialLoader::LoadMaterialSet(rCMDL, Loader.mVersion); - // Toggle skinning on materials - if (Loader.mFlags.HasAnyFlags(eSkinnedModel)) - { - for (u32 iMat = 0; iMat < Loader.mMaterials[iSet]->NumMaterials(); iMat++) - { - CMaterial *pMat = Loader.mMaterials[iSet]->MaterialByIndex(iMat); - pMat->SetVertexDescription(pMat->VtxDesc() | FVertexDescription(eBoneIndices | eBoneWeights)); - } - } - if (Loader.mVersion < eCorruptionProto) Loader.mpSectionMgr->ToNextSection(); } diff --git a/src/Core/Resource/Model/CModel.cpp b/src/Core/Resource/Model/CModel.cpp index eb2d1b4b..9b31da73 100644 --- a/src/Core/Resource/Model/CModel.cpp +++ b/src/Core/Resource/Model/CModel.cpp @@ -122,7 +122,7 @@ void CModel::DrawSurface(FRenderOptions Options, u32 Surface, u32 MatSet) SSurface *pSurf = mSurfaces[Surface]; CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID); - if ((!(Options & eEnableOccluders)) && (pMat->Options() & CMaterial::eOccluder)) + if (!Options.HasFlag(eEnableOccluders) && pMat->Options().HasFlag(CMaterial::eOccluder)) return; pMat->SetCurrent(Options); diff --git a/src/Editor/CGridRenderable.h b/src/Editor/CGridRenderable.h new file mode 100644 index 00000000..87bd715d --- /dev/null +++ b/src/Editor/CGridRenderable.h @@ -0,0 +1,23 @@ +#ifndef CGRIDRENDERABLE +#define CGRIDRENDERABLE + +#include +#include + +// Tiny helper to make sure the grid draws at the correct depth. +class CGridRenderable : public IRenderable +{ +public: + void AddToRenderer(CRenderer *pRenderer, const SViewInfo&) + { + pRenderer->AddMesh(this, 0, CAABox::skOne, false, eDrawMesh); + } + + void Draw(FRenderOptions, int, const SViewInfo&) + { + CDrawUtil::DrawGrid(); + } +}; + +#endif // CGRIDRENDERABLE + diff --git a/src/Editor/CharacterEditor/CCharacterEditorViewport.cpp b/src/Editor/CharacterEditor/CCharacterEditorViewport.cpp index cd88cf83..b0fe19cc 100644 --- a/src/Editor/CharacterEditor/CCharacterEditorViewport.cpp +++ b/src/Editor/CharacterEditor/CCharacterEditorViewport.cpp @@ -49,14 +49,14 @@ void CCharacterEditorViewport::Paint() { mpRenderer->BeginFrame(); mCamera.LoadMatrices(); - CDrawUtil::DrawGrid(); + mGrid.AddToRenderer(mpRenderer, mViewInfo); if (mpCharNode) { mpCharNode->AddToRenderer(mpRenderer, mViewInfo); - mpRenderer->RenderBuckets(mViewInfo); } + mpRenderer->RenderBuckets(mViewInfo); mpRenderer->EndFrame(); } diff --git a/src/Editor/CharacterEditor/CCharacterEditorViewport.h b/src/Editor/CharacterEditor/CCharacterEditorViewport.h index 18f95bc1..080cf035 100644 --- a/src/Editor/CharacterEditor/CCharacterEditorViewport.h +++ b/src/Editor/CharacterEditor/CCharacterEditorViewport.h @@ -2,6 +2,7 @@ #define CCHARACTEREDITORVIEWPORT_H #include "Editor/CBasicViewport.h" +#include "Editor/CGridRenderable.h" #include class CCharacterEditorViewport : public CBasicViewport @@ -9,6 +10,7 @@ class CCharacterEditorViewport : public CBasicViewport Q_OBJECT CCharacterNode *mpCharNode; + CGridRenderable mGrid; CRenderer *mpRenderer; u32 mHoverBone; diff --git a/src/Editor/Editor.pro b/src/Editor/Editor.pro index 13b78a05..ebe614b1 100644 --- a/src/Editor/Editor.pro +++ b/src/Editor/Editor.pro @@ -158,7 +158,8 @@ HEADERS += \ WorldEditor/CRepackInfoDialog.h \ CAboutDialog.h \ CharacterEditor/CCharacterEditor.h \ - CharacterEditor/CCharacterEditorViewport.h + CharacterEditor/CCharacterEditorViewport.h \ + CGridRenderable.h # Source Files SOURCES += \ diff --git a/src/Editor/ModelEditor/CModelEditorViewport.cpp b/src/Editor/ModelEditor/CModelEditorViewport.cpp index 77d44cdc..9758becf 100644 --- a/src/Editor/ModelEditor/CModelEditorViewport.cpp +++ b/src/Editor/ModelEditor/CModelEditorViewport.cpp @@ -56,13 +56,15 @@ void CModelEditorViewport::Paint() if (!mpModelNode->Model()) { if (mGridEnabled) - CDrawUtil::DrawGrid(); + mGrid.AddToRenderer(mpRenderer, mViewInfo); + + mpRenderer->RenderBuckets(mViewInfo); } else if (mMode == eDrawMesh) { if (mGridEnabled) - CDrawUtil::DrawGrid(); + mGrid.AddToRenderer(mpRenderer, mViewInfo); mpModelNode->AddToRenderer(mpRenderer, mViewInfo); mpRenderer->RenderBuckets(mViewInfo); diff --git a/src/Editor/ModelEditor/CModelEditorViewport.h b/src/Editor/ModelEditor/CModelEditorViewport.h index f008179e..74636095 100644 --- a/src/Editor/ModelEditor/CModelEditorViewport.h +++ b/src/Editor/ModelEditor/CModelEditorViewport.h @@ -2,6 +2,7 @@ #define CMODELEDITORVIEWPORT_H #include "Editor/CBasicViewport.h" +#include "Editor/CGridRenderable.h" #include class CModelEditorViewport : public CBasicViewport @@ -13,6 +14,7 @@ public: private: EDrawMode mMode; + CGridRenderable mGrid; CModelNode *mpModelNode; CMaterial *mpActiveMaterial; CRenderer *mpRenderer;