mirror of https://github.com/AxioDL/metaforce.git
More CModel imps
This commit is contained in:
parent
27bcf57447
commit
7b865683e7
|
@ -20,6 +20,8 @@ namespace urde
|
||||||
|
|
||||||
void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
|
void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
|
||||||
{
|
{
|
||||||
|
//m_modelTest = objStore.GetObj("CMDL_GameCube");
|
||||||
|
|
||||||
//m_partGenDesc = objStore.GetObj({hecl::FOURCC('PART'), 0x972A5CD2});
|
//m_partGenDesc = objStore.GetObj({hecl::FOURCC('PART'), 0x972A5CD2});
|
||||||
m_partGenDesc = objStore.GetObj("BusterSparks");
|
m_partGenDesc = objStore.GetObj("BusterSparks");
|
||||||
m_partGen.reset(new urde::CElementGen(m_partGenDesc,
|
m_partGen.reset(new urde::CElementGen(m_partGenDesc,
|
||||||
|
@ -56,6 +58,11 @@ void ViewManager::ParticleView::resized(const boo::SWindowRect& root, const boo:
|
||||||
|
|
||||||
void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
|
void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
|
||||||
{
|
{
|
||||||
|
if (m_vm.m_modelTest)
|
||||||
|
{
|
||||||
|
CModelFlags flags;
|
||||||
|
m_vm.m_modelTest->Draw(flags);
|
||||||
|
}
|
||||||
if (m_vm.m_partGen)
|
if (m_vm.m_partGen)
|
||||||
{
|
{
|
||||||
m_vm.m_partGen->Update(1.0 / 60.0);
|
m_vm.m_partGen->Update(1.0 / 60.0);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "Runtime/Particle/CElementGen.hpp"
|
#include "Runtime/Particle/CElementGen.hpp"
|
||||||
#include "Runtime/Graphics/CLineRenderer.hpp"
|
#include "Runtime/Graphics/CLineRenderer.hpp"
|
||||||
#include "Runtime/Graphics/CMoviePlayer.hpp"
|
#include "Runtime/Graphics/CMoviePlayer.hpp"
|
||||||
|
#include "Runtime/Graphics/CModel.hpp"
|
||||||
|
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,7 @@ class ViewManager : public specter::IViewManager
|
||||||
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
||||||
};
|
};
|
||||||
std::unique_ptr<ParticleView> m_particleView;
|
std::unique_ptr<ParticleView> m_particleView;
|
||||||
|
urde::TLockedToken<CModel> m_modelTest;
|
||||||
urde::TLockedToken<CGenDescription> m_partGenDesc;
|
urde::TLockedToken<CGenDescription> m_partGenDesc;
|
||||||
std::unique_ptr<CElementGen> m_partGen;
|
std::unique_ptr<CElementGen> m_partGen;
|
||||||
std::unique_ptr<CLineRenderer> m_lineRenderer;
|
std::unique_ptr<CLineRenderer> m_lineRenderer;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "CTimeProvider.hpp"
|
#include "CTimeProvider.hpp"
|
||||||
#if 0
|
|
||||||
#include "Graphics/CGraphics.hpp"
|
#include "Graphics/CGraphics.hpp"
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
|
@ -14,9 +12,7 @@ CTimeProvider::CTimeProvider(const float& time)
|
||||||
|
|
||||||
g_currentTimeProvider = this;
|
g_currentTimeProvider = this;
|
||||||
|
|
||||||
#if 0
|
|
||||||
CGraphics::SetExternalTimeProvider(this);
|
CGraphics::SetExternalTimeProvider(this);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CTimeProvider::~CTimeProvider()
|
CTimeProvider::~CTimeProvider()
|
||||||
|
@ -24,9 +20,7 @@ CTimeProvider::~CTimeProvider()
|
||||||
g_currentTimeProvider = x8_lastProvider;
|
g_currentTimeProvider = x8_lastProvider;
|
||||||
if (g_currentTimeProvider)
|
if (g_currentTimeProvider)
|
||||||
g_currentTimeProvider->x4_first = true;
|
g_currentTimeProvider->x4_first = true;
|
||||||
#if 0
|
CGraphics::SetExternalTimeProvider(g_currentTimeProvider);
|
||||||
CGraphics::SetExternalTimeProvider(g_TimeProvider);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Graphics/CGraphics.hpp"
|
#include "Graphics/CGraphics.hpp"
|
||||||
#include "Graphics/CLight.hpp"
|
#include "Graphics/CLight.hpp"
|
||||||
#include "zeus/Math.hpp"
|
#include "zeus/Math.hpp"
|
||||||
|
#include "CTimeProvider.hpp"
|
||||||
|
|
||||||
#undef near
|
#undef near
|
||||||
#undef far
|
#undef far
|
||||||
|
@ -18,6 +19,7 @@ bool CGraphics::g_InterruptLastFrameUsedAbove = false;
|
||||||
ERglLightBits CGraphics::g_LightActive = ERglLightBits::None;
|
ERglLightBits CGraphics::g_LightActive = ERglLightBits::None;
|
||||||
ERglLightBits CGraphics::g_LightsWereOn = ERglLightBits::None;
|
ERglLightBits CGraphics::g_LightsWereOn = ERglLightBits::None;
|
||||||
zeus::CTransform CGraphics::g_GXModelView;
|
zeus::CTransform CGraphics::g_GXModelView;
|
||||||
|
zeus::CTransform CGraphics::g_GXModelViewInvXpose;
|
||||||
zeus::CTransform CGraphics::g_GXModelMatrix;
|
zeus::CTransform CGraphics::g_GXModelMatrix;
|
||||||
zeus::CTransform CGraphics::g_ViewMatrix;
|
zeus::CTransform CGraphics::g_ViewMatrix;
|
||||||
zeus::CVector3f CGraphics::g_ViewPoint;
|
zeus::CVector3f CGraphics::g_ViewPoint;
|
||||||
|
@ -116,6 +118,8 @@ void CGraphics::SetViewMatrix()
|
||||||
g_GXModelView = g_CameraMatrix * g_GXModelMatrix;
|
g_GXModelView = g_CameraMatrix * g_GXModelMatrix;
|
||||||
/* Load position matrix */
|
/* Load position matrix */
|
||||||
/* Inverse-transpose */
|
/* Inverse-transpose */
|
||||||
|
g_GXModelViewInvXpose = g_GXModelView.inverse();
|
||||||
|
g_GXModelViewInvXpose.m_basis.transpose();
|
||||||
/* Load normal matrix */
|
/* Load normal matrix */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +301,16 @@ void CGraphics::SetViewportResolution(const zeus::CVector2i& res)
|
||||||
g_ViewportResolutionHalf = {res.x / 2, res.y / 2};
|
g_ViewportResolutionHalf = {res.x / 2, res.y / 2};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTimeProvider* CGraphics::g_ExternalTimeProvider = nullptr;
|
||||||
|
float CGraphics::g_DefaultSeconds;
|
||||||
|
|
||||||
|
float CGraphics::GetSecondsMod900()
|
||||||
|
{
|
||||||
|
if (!g_ExternalTimeProvider)
|
||||||
|
return g_DefaultSeconds;
|
||||||
|
return g_ExternalTimeProvider->x0_currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
|
boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
|
||||||
boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;
|
boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;
|
||||||
boo::ITextureR* CGraphics::g_SpareTexture = nullptr;
|
boo::ITextureR* CGraphics::g_SpareTexture = nullptr;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
namespace urde
|
namespace urde
|
||||||
{
|
{
|
||||||
class CLight;
|
class CLight;
|
||||||
|
class CTimeProvider;
|
||||||
|
|
||||||
enum class ERglLight : u8
|
enum class ERglLight : u8
|
||||||
{
|
{
|
||||||
|
@ -172,6 +173,7 @@ public:
|
||||||
static ERglLightBits g_LightActive;
|
static ERglLightBits g_LightActive;
|
||||||
static ERglLightBits g_LightsWereOn;
|
static ERglLightBits g_LightsWereOn;
|
||||||
static zeus::CTransform g_GXModelView;
|
static zeus::CTransform g_GXModelView;
|
||||||
|
static zeus::CTransform g_GXModelViewInvXpose;
|
||||||
static zeus::CTransform g_GXModelMatrix;
|
static zeus::CTransform g_GXModelMatrix;
|
||||||
static zeus::CTransform g_ViewMatrix;
|
static zeus::CTransform g_ViewMatrix;
|
||||||
static zeus::CVector3f g_ViewPoint;
|
static zeus::CVector3f g_ViewPoint;
|
||||||
|
@ -211,6 +213,12 @@ public:
|
||||||
static zeus::CVector3f ProjectModelPointToViewportSpace(const zeus::CVector3f& point);
|
static zeus::CVector3f ProjectModelPointToViewportSpace(const zeus::CVector3f& point);
|
||||||
static void SetViewportResolution(const zeus::CVector2i& res);
|
static void SetViewportResolution(const zeus::CVector2i& res);
|
||||||
|
|
||||||
|
static CTimeProvider* g_ExternalTimeProvider;
|
||||||
|
static float g_DefaultSeconds;
|
||||||
|
static void SetExternalTimeProvider(CTimeProvider* provider)
|
||||||
|
{g_ExternalTimeProvider = provider;}
|
||||||
|
static float GetSecondsMod900();
|
||||||
|
|
||||||
static boo::IGraphicsDataFactory* g_BooFactory;
|
static boo::IGraphicsDataFactory* g_BooFactory;
|
||||||
static boo::IGraphicsCommandQueue* g_BooMainCommandQueue;
|
static boo::IGraphicsCommandQueue* g_BooMainCommandQueue;
|
||||||
static boo::ITextureR* g_SpareTexture;
|
static boo::ITextureR* g_SpareTexture;
|
||||||
|
|
|
@ -18,15 +18,15 @@ class CTexture;
|
||||||
|
|
||||||
struct CModelFlags
|
struct CModelFlags
|
||||||
{
|
{
|
||||||
u8 f1; /* Blend state 3/5 enable additive */
|
u8 m_blendMode = 0; /* Blend state 3/5 enable additive */
|
||||||
u8 f2;
|
u8 m_matSetIdx = 0;
|
||||||
u16 f3; /* Depth state */
|
u16 m_flags = 0; /* Flags */
|
||||||
zeus::CColor color; /* Set into kcolor slot specified by material */
|
zeus::CColor color; /* Set into kcolor slot specified by material */
|
||||||
|
|
||||||
/* depth flags
|
/* Flags
|
||||||
0x4: render without texture lock
|
0x4: render without texture lock
|
||||||
0x8: greater
|
0x8: depth greater
|
||||||
0x10: non-inclusive
|
0x10: depth non-inclusive
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,20 +39,30 @@ struct CBooSurface
|
||||||
CBooSurface* m_next = nullptr;
|
CBooSurface* m_next = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SUnskinnedXf
|
||||||
|
{
|
||||||
|
zeus::CMatrix4f mv;
|
||||||
|
zeus::CMatrix4f mvinv;
|
||||||
|
zeus::CMatrix4f proj;
|
||||||
|
};
|
||||||
|
|
||||||
class CBooModel
|
class CBooModel
|
||||||
{
|
{
|
||||||
|
friend class CModel;
|
||||||
public:
|
public:
|
||||||
|
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
|
||||||
|
using UVAnimation = DataSpec::DNAMP1::MaterialSet::Material::UVAnimation;
|
||||||
struct SShader
|
struct SShader
|
||||||
{
|
{
|
||||||
std::vector<TCachedToken<CTexture>> x0_textures;
|
std::vector<TCachedToken<CTexture>> x0_textures;
|
||||||
std::vector<boo::IShaderPipeline*> m_shaders;
|
std::vector<boo::IShaderPipeline*> m_shaders;
|
||||||
DataSpec::DNAMP1::HMDLMaterialSet m_matSet;
|
MaterialSet m_matSet;
|
||||||
void UnlockTextures();
|
void UnlockTextures();
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<CBooSurface>* x0_surfaces;
|
std::vector<CBooSurface>* x0_surfaces;
|
||||||
const DataSpec::DNAMP1::HMDLMaterialSet* x4_matSet;
|
const MaterialSet* x4_matSet;
|
||||||
const std::vector<boo::IShaderPipeline*>* m_pipelines;
|
const std::vector<boo::IShaderPipeline*>* m_pipelines;
|
||||||
boo::IVertexFormat* m_vtxFmt;
|
boo::IVertexFormat* m_vtxFmt;
|
||||||
boo::IGraphicsBufferS* x8_vbo;
|
boo::IGraphicsBufferS* x8_vbo;
|
||||||
|
@ -65,25 +75,35 @@ private:
|
||||||
bool x40_25_ : 1;
|
bool x40_25_ : 1;
|
||||||
u8 x41_shortNormals;
|
u8 x41_shortNormals;
|
||||||
|
|
||||||
|
struct UVAnimationBuffer
|
||||||
|
{
|
||||||
|
std::vector<zeus::CMatrix4f> m_buffer;
|
||||||
|
std::vector<std::pair<size_t,size_t>> m_ranges;
|
||||||
|
void ProcessAnimation(const UVAnimation& anim);
|
||||||
|
void PadOutBuffer();
|
||||||
|
void Update(const MaterialSet* matSet);
|
||||||
|
} m_uvAnimBuffer;
|
||||||
|
|
||||||
/* urde addition: boo! */
|
/* urde addition: boo! */
|
||||||
boo::GraphicsDataToken m_gfxToken;
|
boo::GraphicsDataToken m_gfxToken;
|
||||||
boo::IGraphicsBufferD* m_uniformBuffer;
|
boo::IGraphicsBufferD* m_unskinnedXfBuffer;
|
||||||
|
boo::IGraphicsBufferD* m_uvMtxBuffer;
|
||||||
std::vector<boo::IShaderDataBinding*> m_shaderDataBindings;
|
std::vector<boo::IShaderDataBinding*> m_shaderDataBindings;
|
||||||
|
|
||||||
|
void BuildGfxToken();
|
||||||
|
void UpdateUniformData() const;
|
||||||
void DrawAlphaSurfaces(const CModelFlags& flags) const;
|
void DrawAlphaSurfaces(const CModelFlags& flags) const;
|
||||||
void DrawNormalSurfaces(const CModelFlags& flags) const;
|
void DrawNormalSurfaces(const CModelFlags& flags) const;
|
||||||
void DrawSurfaces(const CModelFlags& flags) const;
|
void DrawSurfaces(const CModelFlags& flags) const;
|
||||||
void DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const;
|
void DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const;
|
||||||
|
|
||||||
void BuildGfxToken();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
||||||
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
|
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
|
||||||
const zeus::CAABox& aabb,
|
const zeus::CAABox& aabb,
|
||||||
u8 shortNormals, bool texturesLoaded);
|
u8 shortNormals, bool texturesLoaded);
|
||||||
|
|
||||||
static void MakeTexuresFromMats(const DataSpec::DNAMP1::HMDLMaterialSet& matSet,
|
static void MakeTexuresFromMats(const MaterialSet& matSet,
|
||||||
std::vector<TCachedToken<CTexture>>& toksOut,
|
std::vector<TCachedToken<CTexture>>& toksOut,
|
||||||
IObjectStore& store);
|
IObjectStore& store);
|
||||||
|
|
||||||
|
@ -94,7 +114,7 @@ public:
|
||||||
void DrawNormal(const CModelFlags& flags) const;
|
void DrawNormal(const CModelFlags& flags) const;
|
||||||
void Draw(const CModelFlags& flags) const;
|
void Draw(const CModelFlags& flags) const;
|
||||||
|
|
||||||
const DataSpec::DNAMP1::HMDLMaterialSet::Material& GetMaterialByIndex(int idx) const
|
const MaterialSet::Material& GetMaterialByIndex(int idx) const
|
||||||
{
|
{
|
||||||
return x4_matSet->materials.at(idx);
|
return x4_matSet->materials.at(idx);
|
||||||
}
|
}
|
||||||
|
@ -122,6 +142,8 @@ class CModel
|
||||||
void VerifyCurrentShader(int shaderIdx) const;
|
void VerifyCurrentShader(int shaderIdx) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
|
||||||
|
|
||||||
CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store);
|
CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store);
|
||||||
void DrawSortedParts(const CModelFlags& flags) const;
|
void DrawSortedParts(const CModelFlags& flags) const;
|
||||||
void DrawUnsortedParts(const CModelFlags& flags) const;
|
void DrawUnsortedParts(const CModelFlags& flags) const;
|
||||||
|
|
|
@ -9,14 +9,6 @@ namespace urde
|
||||||
static logvisor::Module Log("urde::CModelBoo");
|
static logvisor::Module Log("urde::CModelBoo");
|
||||||
bool CBooModel::g_DrawingOccluders = false;
|
bool CBooModel::g_DrawingOccluders = false;
|
||||||
|
|
||||||
struct SUnskinnedUniforms
|
|
||||||
{
|
|
||||||
zeus::CMatrix4f mv;
|
|
||||||
zeus::CMatrix4f mvinv;
|
|
||||||
zeus::CMatrix4f proj;
|
|
||||||
zeus::CMatrix4f tex[8];
|
|
||||||
};
|
|
||||||
|
|
||||||
CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
||||||
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
|
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
|
||||||
const zeus::CAABox& aabb, u8 shortNormals, bool texturesLoaded)
|
const zeus::CAABox& aabb, u8 shortNormals, bool texturesLoaded)
|
||||||
|
@ -30,7 +22,7 @@ CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
||||||
for (auto it=x0_surfaces->rbegin() ; it != x0_surfaces->rend() ; ++it)
|
for (auto it=x0_surfaces->rbegin() ; it != x0_surfaces->rend() ; ++it)
|
||||||
{
|
{
|
||||||
u32 matId = it->m_data.matIdx;
|
u32 matId = it->m_data.matIdx;
|
||||||
const DataSpec::DNAMP1::HMDLMaterialSet::Material& matData = GetMaterialByIndex(matId);
|
const MaterialSet::Material& matData = GetMaterialByIndex(matId);
|
||||||
if (matData.flags.depthSorting())
|
if (matData.flags.depthSorting())
|
||||||
{
|
{
|
||||||
it->m_next = x3c_firstSortedSurface;
|
it->m_next = x3c_firstSortedSurface;
|
||||||
|
@ -49,14 +41,16 @@ CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
||||||
|
|
||||||
void CBooModel::BuildGfxToken()
|
void CBooModel::BuildGfxToken()
|
||||||
{
|
{
|
||||||
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
m_gfxToken = CGraphics::CommitResources(
|
||||||
|
[&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||||
{
|
{
|
||||||
m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SUnskinnedUniforms), 1);
|
m_unskinnedXfBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex,
|
||||||
boo::IGraphicsBuffer* bufs[] = {m_uniformBuffer};
|
sizeof(SUnskinnedXf), 1);
|
||||||
|
boo::IGraphicsBuffer* bufs[] = {m_unskinnedXfBuffer};
|
||||||
m_shaderDataBindings.reserve(x4_matSet->materials.size());
|
m_shaderDataBindings.reserve(x4_matSet->materials.size());
|
||||||
auto pipelineIt = m_pipelines->begin();
|
auto pipelineIt = m_pipelines->begin();
|
||||||
std::vector<boo::ITexture*> texs;
|
std::vector<boo::ITexture*> texs;
|
||||||
for (const DataSpec::DNAMP1::HMDLMaterialSet::Material& mat : x4_matSet->materials)
|
for (const MaterialSet::Material& mat : x4_matSet->materials)
|
||||||
{
|
{
|
||||||
texs.clear();
|
texs.clear();
|
||||||
texs.reserve(mat.textureIdxs.size());
|
texs.reserve(mat.textureIdxs.size());
|
||||||
|
@ -65,15 +59,17 @@ void CBooModel::BuildGfxToken()
|
||||||
TCachedToken<CTexture>& tex = (*x1c_textures)[idx];
|
TCachedToken<CTexture>& tex = (*x1c_textures)[idx];
|
||||||
texs.push_back(tex.GetObj()->GetBooTexture());
|
texs.push_back(tex.GetObj()->GetBooTexture());
|
||||||
}
|
}
|
||||||
m_shaderDataBindings.push_back(ctx.newShaderDataBinding(*pipelineIt, m_vtxFmt, x8_vbo, nullptr, xc_ibo, 1, bufs,
|
m_shaderDataBindings.push_back(
|
||||||
mat.textureIdxs.size(), texs.data()));
|
ctx.newShaderDataBinding(*pipelineIt, m_vtxFmt,
|
||||||
|
x8_vbo, nullptr, xc_ibo, 1, bufs,
|
||||||
|
mat.textureIdxs.size(), texs.data()));
|
||||||
++pipelineIt;
|
++pipelineIt;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBooModel::MakeTexuresFromMats(const DataSpec::DNAMP1::HMDLMaterialSet& matSet,
|
void CBooModel::MakeTexuresFromMats(const MaterialSet& matSet,
|
||||||
std::vector<TCachedToken<CTexture>>& toksOut,
|
std::vector<TCachedToken<CTexture>>& toksOut,
|
||||||
IObjectStore& store)
|
IObjectStore& store)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +142,7 @@ void CBooModel::DrawNormalSurfaces(const CModelFlags& flags) const
|
||||||
|
|
||||||
void CBooModel::DrawSurfaces(const CModelFlags& flags) const
|
void CBooModel::DrawSurfaces(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
if (!(flags.f3 & 0x4))
|
if (!(flags.m_flags & 0x4))
|
||||||
if (!TryLockTextures())
|
if (!TryLockTextures())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -167,7 +163,7 @@ void CBooModel::DrawSurfaces(const CModelFlags& flags) const
|
||||||
|
|
||||||
void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const
|
void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
const DataSpec::DNAMP1::HMDLMaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx);
|
const MaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx);
|
||||||
if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders)
|
if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -175,18 +171,144 @@ void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) c
|
||||||
CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount);
|
CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBooModel::UVAnimationBuffer::ProcessAnimation(const UVAnimation& anim)
|
||||||
|
{
|
||||||
|
m_buffer.emplace_back();
|
||||||
|
zeus::CMatrix4f& matrixOut = m_buffer.back();
|
||||||
|
switch (anim.mode)
|
||||||
|
{
|
||||||
|
case UVAnimation::Mode::MvInvNoTranslation:
|
||||||
|
{
|
||||||
|
|
||||||
|
matrixOut = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(
|
||||||
|
CGraphics::g_GXModelMatrix).toMatrix4f();
|
||||||
|
matrixOut.vec[3].zeroOut();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::MvInv:
|
||||||
|
{
|
||||||
|
matrixOut = (CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix).toMatrix4f();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::Scroll:
|
||||||
|
{
|
||||||
|
matrixOut.vec[3].x = CGraphics::GetSecondsMod900() * anim.vals[2] + anim.vals[0];
|
||||||
|
matrixOut.vec[3].y = CGraphics::GetSecondsMod900() * anim.vals[3] + anim.vals[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::Rotation:
|
||||||
|
{
|
||||||
|
float angle = CGraphics::GetSecondsMod900() * anim.vals[1] + anim.vals[0];
|
||||||
|
float acos = std::cos(angle);
|
||||||
|
float asin = std::sin(angle);
|
||||||
|
matrixOut.vec[0].x = acos;
|
||||||
|
matrixOut.vec[0].y = asin;
|
||||||
|
matrixOut.vec[1].x = -asin;
|
||||||
|
matrixOut.vec[1].y = acos;
|
||||||
|
matrixOut.vec[3].x = (1.0 - (acos - asin)) * 0.5;
|
||||||
|
matrixOut.vec[3].y = (1.0 - (asin + acos)) * 0.5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::HStrip:
|
||||||
|
{
|
||||||
|
float value = anim.vals[2] * anim.vals[0] * (anim.vals[3] + CGraphics::GetSecondsMod900());
|
||||||
|
matrixOut.vec[3].x = anim.vals[1] * fmod(value, 1.0f) * anim.vals[2];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::VStrip:
|
||||||
|
{
|
||||||
|
float value = anim.vals[2] * anim.vals[0] * (anim.vals[3] + CGraphics::GetSecondsMod900());
|
||||||
|
matrixOut.vec[3].y = anim.vals[1] * fmod(value, 1.0f) * anim.vals[2];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::Model:
|
||||||
|
{
|
||||||
|
matrixOut.vec[0].x = 0.5f;
|
||||||
|
matrixOut.vec[1].y = 0.0f;
|
||||||
|
matrixOut.vec[2].y = 0.5f;
|
||||||
|
matrixOut.vec[3].x = CGraphics::g_GXModelMatrix.m_origin.x * 0.5f;
|
||||||
|
matrixOut.vec[3].y = CGraphics::g_GXModelMatrix.m_origin.y * 0.5f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case UVAnimation::Mode::WhoMustNotBeNamed:
|
||||||
|
{
|
||||||
|
zeus::CTransform texmtx = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix;
|
||||||
|
texmtx.m_origin.zeroOut();
|
||||||
|
/* TODO: Finish */
|
||||||
|
matrixOut = texmtx.toMatrix4f();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBooModel::UVAnimationBuffer::PadOutBuffer()
|
||||||
|
{
|
||||||
|
size_t curEnd = 0;
|
||||||
|
if (m_ranges.size())
|
||||||
|
curEnd = m_ranges.back().first + m_ranges.back().second;
|
||||||
|
|
||||||
|
size_t bufRem = m_buffer.size() % 4;
|
||||||
|
if (bufRem)
|
||||||
|
for (int i=0 ; i<(4-bufRem) ; ++i)
|
||||||
|
m_buffer.emplace_back();
|
||||||
|
size_t newEnd = m_buffer.size() * 64;
|
||||||
|
|
||||||
|
m_ranges.emplace_back(curEnd, newEnd - curEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBooModel::UVAnimationBuffer::Update(const MaterialSet* matSet)
|
||||||
|
{
|
||||||
|
m_buffer.clear();
|
||||||
|
m_ranges.clear();
|
||||||
|
|
||||||
|
size_t bufCount = 0;
|
||||||
|
size_t count = 0;
|
||||||
|
for (const MaterialSet::Material& mat : matSet->materials)
|
||||||
|
{
|
||||||
|
count += mat.uvAnims.size();
|
||||||
|
bufCount += mat.uvAnims.size();
|
||||||
|
bufCount = ROUND_UP_4(bufCount);
|
||||||
|
}
|
||||||
|
m_buffer.reserve(bufCount);
|
||||||
|
m_ranges.reserve(count);
|
||||||
|
|
||||||
|
for (const MaterialSet::Material& mat : matSet->materials)
|
||||||
|
{
|
||||||
|
for (const UVAnimation& anim : mat.uvAnims)
|
||||||
|
ProcessAnimation(anim);
|
||||||
|
PadOutBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBooModel::UpdateUniformData() const
|
||||||
|
{
|
||||||
|
SUnskinnedXf unskinnedXf;
|
||||||
|
unskinnedXf.mv = CGraphics::g_GXModelView.toMatrix4f();
|
||||||
|
unskinnedXf.mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
|
||||||
|
unskinnedXf.proj = CGraphics::GetPerspectiveProjectionMatrix();
|
||||||
|
m_unskinnedXfBuffer->load(&unskinnedXf, sizeof(unskinnedXf));
|
||||||
|
|
||||||
|
((CBooModel*)this)->m_uvAnimBuffer.Update(x4_matSet);
|
||||||
|
m_uvMtxBuffer->load(m_uvAnimBuffer.m_buffer.data(),
|
||||||
|
m_uvAnimBuffer.m_buffer.size() * 64);
|
||||||
|
}
|
||||||
|
|
||||||
void CBooModel::DrawAlpha(const CModelFlags& flags) const
|
void CBooModel::DrawAlpha(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
|
UpdateUniformData();
|
||||||
DrawAlphaSurfaces(flags);
|
DrawAlphaSurfaces(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBooModel::DrawNormal(const CModelFlags& flags) const
|
void CBooModel::DrawNormal(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
|
UpdateUniformData();
|
||||||
DrawNormalSurfaces(flags);
|
DrawNormalSurfaces(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBooModel::Draw(const CModelFlags& flags) const
|
void CBooModel::Draw(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
|
UpdateUniformData();
|
||||||
DrawSurfaces(flags);
|
DrawSurfaces(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +370,7 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store)
|
||||||
for (CBooModel::SShader& matSet : x18_matSets)
|
for (CBooModel::SShader& matSet : x18_matSets)
|
||||||
{
|
{
|
||||||
matSet.m_shaders.reserve(matSet.m_matSet.materials.size());
|
matSet.m_shaders.reserve(matSet.m_matSet.materials.size());
|
||||||
for (const DataSpec::DNAMP1::HMDLMaterialSet::Material& mat : matSet.m_matSet.materials)
|
for (const MaterialSet::Material& mat : matSet.m_matSet.materials)
|
||||||
{
|
{
|
||||||
hecl::Runtime::ShaderTag tag(mat.heclIr,
|
hecl::Runtime::ShaderTag tag(mat.heclIr,
|
||||||
hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount,
|
hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount,
|
||||||
|
@ -296,24 +418,42 @@ void CModel::VerifyCurrentShader(int shaderIdx) const
|
||||||
|
|
||||||
void CModel::DrawSortedParts(const CModelFlags& flags) const
|
void CModel::DrawSortedParts(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
|
VerifyCurrentShader(flags.m_matSetIdx);
|
||||||
|
x28_modelInst->DrawAlpha(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModel::DrawUnsortedParts(const CModelFlags& flags) const
|
void CModel::DrawUnsortedParts(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
|
VerifyCurrentShader(flags.m_matSetIdx);
|
||||||
|
x28_modelInst->DrawNormal(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModel::Draw(const CModelFlags& flags) const
|
void CModel::Draw(const CModelFlags& flags) const
|
||||||
{
|
{
|
||||||
|
VerifyCurrentShader(flags.m_matSetIdx);
|
||||||
|
x28_modelInst->Draw(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModel::Touch(int shaderIdx) const
|
void CModel::Touch(int shaderIdx) const
|
||||||
{
|
{
|
||||||
|
VerifyCurrentShader(shaderIdx);
|
||||||
|
x28_modelInst->TryLockTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CModel::IsLoaded(int shaderIdx) const
|
bool CModel::IsLoaded(int shaderIdx) const
|
||||||
{
|
{
|
||||||
VerifyCurrentShader(shaderIdx);
|
VerifyCurrentShader(shaderIdx);
|
||||||
return false;
|
std::vector<TCachedToken<CTexture>>* texs = x28_modelInst->x1c_textures;
|
||||||
|
bool loaded = true;
|
||||||
|
for (TCachedToken<CTexture>& tex : *texs)
|
||||||
|
{
|
||||||
|
if (!tex.IsLoaded())
|
||||||
|
{
|
||||||
|
loaded = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
|
CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
|
||||||
|
|
|
@ -66,9 +66,9 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
|
||||||
case EGuiModelDrawFlags::Shadeless:
|
case EGuiModelDrawFlags::Shadeless:
|
||||||
{
|
{
|
||||||
CModelFlags flags;
|
CModelFlags flags;
|
||||||
flags.f1 = 0;
|
flags.m_blendMode = 0;
|
||||||
flags.f2 = 0;
|
flags.m_matSetIdx = 0;
|
||||||
flags.f3 = 3;
|
flags.m_flags = 3;
|
||||||
flags.color = zeus::CColor::skWhite;
|
flags.color = zeus::CColor::skWhite;
|
||||||
model->Draw(flags);
|
model->Draw(flags);
|
||||||
break;
|
break;
|
||||||
|
@ -76,9 +76,9 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
|
||||||
case EGuiModelDrawFlags::Opaque:
|
case EGuiModelDrawFlags::Opaque:
|
||||||
{
|
{
|
||||||
CModelFlags flags;
|
CModelFlags flags;
|
||||||
flags.f1 = 1;
|
flags.m_blendMode = 1;
|
||||||
flags.f2 = 0;
|
flags.m_matSetIdx = 0;
|
||||||
flags.f3 = 3;
|
flags.m_flags = 3;
|
||||||
flags.color = moduCol;
|
flags.color = moduCol;
|
||||||
model->Draw(flags);
|
model->Draw(flags);
|
||||||
break;
|
break;
|
||||||
|
@ -86,9 +86,9 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
|
||||||
case EGuiModelDrawFlags::Alpha:
|
case EGuiModelDrawFlags::Alpha:
|
||||||
{
|
{
|
||||||
CModelFlags flags;
|
CModelFlags flags;
|
||||||
flags.f1 = 4;
|
flags.m_blendMode = 4;
|
||||||
flags.f2 = 0;
|
flags.m_matSetIdx = 0;
|
||||||
flags.f3 = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
|
flags.m_flags = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
|
||||||
flags.color = moduCol;
|
flags.color = moduCol;
|
||||||
model->Draw(flags);
|
model->Draw(flags);
|
||||||
break;
|
break;
|
||||||
|
@ -96,9 +96,9 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
|
||||||
case EGuiModelDrawFlags::Additive:
|
case EGuiModelDrawFlags::Additive:
|
||||||
{
|
{
|
||||||
CModelFlags flags;
|
CModelFlags flags;
|
||||||
flags.f1 = 3;
|
flags.m_blendMode = 3;
|
||||||
flags.f2 = 0;
|
flags.m_matSetIdx = 0;
|
||||||
flags.f3 = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
|
flags.m_flags = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
|
||||||
flags.color = moduCol;
|
flags.color = moduCol;
|
||||||
model->Draw(flags);
|
model->Draw(flags);
|
||||||
break;
|
break;
|
||||||
|
@ -106,15 +106,15 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
|
||||||
case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
|
case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
|
||||||
{
|
{
|
||||||
CModelFlags flags;
|
CModelFlags flags;
|
||||||
flags.f1 = 4;
|
flags.m_blendMode = 4;
|
||||||
flags.f2 = 0;
|
flags.m_matSetIdx = 0;
|
||||||
flags.f3 = xf6_31_depthTest;
|
flags.m_flags = xf6_31_depthTest;
|
||||||
flags.color = moduCol;
|
flags.color = moduCol;
|
||||||
model->Draw(flags);
|
model->Draw(flags);
|
||||||
|
|
||||||
flags.f1 = 5;
|
flags.m_blendMode = 5;
|
||||||
flags.f2 = 0;
|
flags.m_matSetIdx = 0;
|
||||||
flags.f3 = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
|
flags.m_flags = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
|
||||||
flags.color = moduCol;
|
flags.color = moduCol;
|
||||||
model->Draw(flags);
|
model->Draw(flags);
|
||||||
break;
|
break;
|
||||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
||||||
Subproject commit c6feb64383aa84fee18afa423e741bfa3dca4a74
|
Subproject commit c5faedae338e1573ee2c97ef606623775df59936
|
2
specter
2
specter
|
@ -1 +1 @@
|
||||||
Subproject commit 66a07ccca4b244a29e2cc82d728cbb0641c6daec
|
Subproject commit 33ce8bc20ba776e5868230aec459cd31c7e6554b
|
Loading…
Reference in New Issue