mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 07:07:42 +00:00
More CModel imps
This commit is contained in:
@@ -9,14 +9,6 @@ namespace urde
|
||||
static logvisor::Module Log("urde::CModelBoo");
|
||||
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,
|
||||
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
|
||||
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)
|
||||
{
|
||||
u32 matId = it->m_data.matIdx;
|
||||
const DataSpec::DNAMP1::HMDLMaterialSet::Material& matData = GetMaterialByIndex(matId);
|
||||
const MaterialSet::Material& matData = GetMaterialByIndex(matId);
|
||||
if (matData.flags.depthSorting())
|
||||
{
|
||||
it->m_next = x3c_firstSortedSurface;
|
||||
@@ -49,14 +41,16 @@ CBooModel::CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
||||
|
||||
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);
|
||||
boo::IGraphicsBuffer* bufs[] = {m_uniformBuffer};
|
||||
m_unskinnedXfBuffer = ctx.newDynamicBuffer(boo::BufferUse::Vertex,
|
||||
sizeof(SUnskinnedXf), 1);
|
||||
boo::IGraphicsBuffer* bufs[] = {m_unskinnedXfBuffer};
|
||||
m_shaderDataBindings.reserve(x4_matSet->materials.size());
|
||||
auto pipelineIt = m_pipelines->begin();
|
||||
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.reserve(mat.textureIdxs.size());
|
||||
@@ -65,15 +59,17 @@ void CBooModel::BuildGfxToken()
|
||||
TCachedToken<CTexture>& tex = (*x1c_textures)[idx];
|
||||
texs.push_back(tex.GetObj()->GetBooTexture());
|
||||
}
|
||||
m_shaderDataBindings.push_back(ctx.newShaderDataBinding(*pipelineIt, m_vtxFmt, x8_vbo, nullptr, xc_ibo, 1, bufs,
|
||||
mat.textureIdxs.size(), texs.data()));
|
||||
m_shaderDataBindings.push_back(
|
||||
ctx.newShaderDataBinding(*pipelineIt, m_vtxFmt,
|
||||
x8_vbo, nullptr, xc_ibo, 1, bufs,
|
||||
mat.textureIdxs.size(), texs.data()));
|
||||
++pipelineIt;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void CBooModel::MakeTexuresFromMats(const DataSpec::DNAMP1::HMDLMaterialSet& matSet,
|
||||
void CBooModel::MakeTexuresFromMats(const MaterialSet& matSet,
|
||||
std::vector<TCachedToken<CTexture>>& toksOut,
|
||||
IObjectStore& store)
|
||||
{
|
||||
@@ -146,7 +142,7 @@ void CBooModel::DrawNormalSurfaces(const CModelFlags& flags) const
|
||||
|
||||
void CBooModel::DrawSurfaces(const CModelFlags& flags) const
|
||||
{
|
||||
if (!(flags.f3 & 0x4))
|
||||
if (!(flags.m_flags & 0x4))
|
||||
if (!TryLockTextures())
|
||||
return;
|
||||
|
||||
@@ -167,7 +163,7 @@ void CBooModel::DrawSurfaces(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)
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawAlphaSurfaces(flags);
|
||||
}
|
||||
|
||||
void CBooModel::DrawNormal(const CModelFlags& flags) const
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawNormalSurfaces(flags);
|
||||
}
|
||||
|
||||
void CBooModel::Draw(const CModelFlags& flags) const
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawSurfaces(flags);
|
||||
}
|
||||
|
||||
@@ -248,7 +370,7 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store)
|
||||
for (CBooModel::SShader& matSet : x18_matSets)
|
||||
{
|
||||
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,
|
||||
hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount,
|
||||
@@ -296,24 +418,42 @@ void CModel::VerifyCurrentShader(int shaderIdx) const
|
||||
|
||||
void CModel::DrawSortedParts(const CModelFlags& flags) const
|
||||
{
|
||||
VerifyCurrentShader(flags.m_matSetIdx);
|
||||
x28_modelInst->DrawAlpha(flags);
|
||||
}
|
||||
|
||||
void CModel::DrawUnsortedParts(const CModelFlags& flags) const
|
||||
{
|
||||
VerifyCurrentShader(flags.m_matSetIdx);
|
||||
x28_modelInst->DrawNormal(flags);
|
||||
}
|
||||
|
||||
void CModel::Draw(const CModelFlags& flags) const
|
||||
{
|
||||
VerifyCurrentShader(flags.m_matSetIdx);
|
||||
x28_modelInst->Draw(flags);
|
||||
}
|
||||
|
||||
void CModel::Touch(int shaderIdx) const
|
||||
{
|
||||
VerifyCurrentShader(shaderIdx);
|
||||
x28_modelInst->TryLockTextures();
|
||||
}
|
||||
|
||||
bool CModel::IsLoaded(int shaderIdx) const
|
||||
{
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user