mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-05-28 18:21:20 +00:00
Model/material changes - addition of CMaterial clone functions, better encapsulation for CMaterialSet, removal of SModelData from model loading methods
This commit is contained in:
parent
4450606fbf
commit
086819b939
@ -180,7 +180,6 @@ HEADERS += \
|
|||||||
Resource/model/CModel.h \
|
Resource/model/CModel.h \
|
||||||
Resource/model/CStaticModel.h \
|
Resource/model/CStaticModel.h \
|
||||||
Resource/model/CVertex.h \
|
Resource/model/CVertex.h \
|
||||||
Resource/model/SModelData.h \
|
|
||||||
Resource/script/CProperty.h \
|
Resource/script/CProperty.h \
|
||||||
Resource/script/CScriptLayer.h \
|
Resource/script/CScriptLayer.h \
|
||||||
Resource/script/CScriptObject.h \
|
Resource/script/CScriptObject.h \
|
||||||
|
@ -44,40 +44,40 @@ void CGameArea::MergeTerrain()
|
|||||||
if (mTerrainMerged) return;
|
if (mTerrainMerged) return;
|
||||||
|
|
||||||
// Nothing really complicated here - iterate through every terrain submesh, add each to a static model
|
// Nothing really complicated here - iterate through every terrain submesh, add each to a static model
|
||||||
for (u32 tm = 0; tm < mTerrainModels.size(); tm++)
|
for (u32 iMdl = 0; iMdl < mTerrainModels.size(); iMdl++)
|
||||||
{
|
{
|
||||||
CModel *mdl = mTerrainModels[tm];
|
CModel *pMdl = mTerrainModels[iMdl];
|
||||||
u32 SubmeshCount = mdl->GetSurfaceCount();
|
u32 SubmeshCount = pMdl->GetSurfaceCount();
|
||||||
|
|
||||||
for (u32 sub = 0; sub < SubmeshCount; sub++)
|
for (u32 iSurf = 0; iSurf < SubmeshCount; iSurf++)
|
||||||
{
|
{
|
||||||
SSurface *s = mdl->GetSurface(sub);
|
SSurface *pSurf = pMdl->GetSurface(iSurf);
|
||||||
CMaterial *mat = mMaterialSet->materials[s->MaterialID];
|
CMaterial *pMat = mMaterialSet->MaterialByIndex(pSurf->MaterialID);
|
||||||
|
|
||||||
bool NewMat = true;
|
bool newMat = true;
|
||||||
for (std::vector<CStaticModel*>::iterator it = mStaticTerrainModels.begin(); it != mStaticTerrainModels.end(); it++)
|
for (std::vector<CStaticModel*>::iterator it = mStaticTerrainModels.begin(); it != mStaticTerrainModels.end(); it++)
|
||||||
{
|
{
|
||||||
if ((*it)->GetMaterial() == mat)
|
if ((*it)->GetMaterial() == pMat)
|
||||||
{
|
{
|
||||||
// When we append a new submesh to an existing static model, we bump it to the back of the vector.
|
// When we append a new submesh to an existing static model, we bump it to the back of the vector.
|
||||||
// This is because mesh ordering actually matters sometimes
|
// This is because mesh ordering actually matters sometimes
|
||||||
// (particularly with multi-layered transparent meshes)
|
// (particularly with multi-layered transparent meshes)
|
||||||
// so we need to at least try to maintain it.
|
// so we need to at least try to maintain it.
|
||||||
// This is maybe not the most efficient way to do this, but it works.
|
// This is maybe not the most efficient way to do this, but it works.
|
||||||
CStaticModel *mdl = *it;
|
CStaticModel *pStatic = *it;
|
||||||
mdl->AddSurface(s);
|
pStatic->AddSurface(pSurf);
|
||||||
mStaticTerrainModels.erase(it);
|
mStaticTerrainModels.erase(it);
|
||||||
mStaticTerrainModels.push_back(mdl);
|
mStaticTerrainModels.push_back(pStatic);
|
||||||
NewMat = false;
|
newMat = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NewMat)
|
if (newMat)
|
||||||
{
|
{
|
||||||
CStaticModel *smdl = new CStaticModel(mat);
|
CStaticModel *pStatic = new CStaticModel(pMat);
|
||||||
smdl->AddSurface(s);
|
pStatic->AddSurface(pSurf);
|
||||||
mStaticTerrainModels.push_back(smdl);
|
mStaticTerrainModels.push_back(pStatic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,23 @@ CMaterial::CMaterial()
|
|||||||
mpIndirectTexture = nullptr;
|
mpIndirectTexture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMaterial::CMaterial(EGame version, EVertexDescription vtxDesc)
|
||||||
|
{
|
||||||
|
mpShader = nullptr;
|
||||||
|
mShaderStatus = eNoShader;
|
||||||
|
mRecalcHash = true;
|
||||||
|
mEnableBloom = (version == eCorruption);
|
||||||
|
mVersion = version;
|
||||||
|
mOptions = eDepthWrite;
|
||||||
|
mVtxDesc = vtxDesc;
|
||||||
|
mBlendSrcFac = GL_ONE;
|
||||||
|
mBlendDstFac = GL_ZERO;
|
||||||
|
mLightingEnabled = true;
|
||||||
|
mEchoesUnknownA = 0;
|
||||||
|
mEchoesUnknownB = 0;
|
||||||
|
mpIndirectTexture = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
CMaterial::~CMaterial()
|
CMaterial::~CMaterial()
|
||||||
{
|
{
|
||||||
for (u32 iPass = 0; iPass < mPasses.size(); iPass++)
|
for (u32 iPass = 0; iPass < mPasses.size(); iPass++)
|
||||||
@ -37,6 +54,31 @@ CMaterial::~CMaterial()
|
|||||||
delete mpShader;
|
delete mpShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMaterial* CMaterial::Clone()
|
||||||
|
{
|
||||||
|
CMaterial *pOut = new CMaterial();
|
||||||
|
pOut->mName = mName;
|
||||||
|
pOut->mEnableBloom = mEnableBloom;
|
||||||
|
pOut->mVersion = mVersion;
|
||||||
|
pOut->mOptions = mOptions;
|
||||||
|
pOut->mVtxDesc = mVtxDesc;
|
||||||
|
for (u32 iKonst = 0; iKonst < 4; iKonst++)
|
||||||
|
pOut->mKonstColors[iKonst] = mKonstColors[iKonst];
|
||||||
|
pOut->mBlendSrcFac = mBlendSrcFac;
|
||||||
|
pOut->mBlendDstFac = mBlendDstFac;
|
||||||
|
pOut->mLightingEnabled = mLightingEnabled;
|
||||||
|
pOut->mEchoesUnknownA = mEchoesUnknownA;
|
||||||
|
pOut->mEchoesUnknownB = mEchoesUnknownB;
|
||||||
|
pOut->mpIndirectTexture = mpIndirectTexture;
|
||||||
|
pOut->mIndTextureToken = CToken(pOut->mpIndirectTexture);
|
||||||
|
|
||||||
|
pOut->mPasses.resize(mPasses.size());
|
||||||
|
for (u32 iPass = 0; iPass < mPasses.size(); iPass++)
|
||||||
|
pOut->mPasses[iPass] = mPasses[iPass]->Clone(pOut);
|
||||||
|
|
||||||
|
return pOut;
|
||||||
|
}
|
||||||
|
|
||||||
void CMaterial::GenerateShader()
|
void CMaterial::GenerateShader()
|
||||||
{
|
{
|
||||||
delete mpShader;
|
delete mpShader;
|
||||||
@ -159,6 +201,11 @@ void CMaterial::Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ************ GETTERS ************
|
// ************ GETTERS ************
|
||||||
|
std::string CMaterial::Name() const
|
||||||
|
{
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
EGame CMaterial::Version() const
|
EGame CMaterial::Version() const
|
||||||
{
|
{
|
||||||
return mVersion;
|
return mVersion;
|
||||||
@ -220,6 +267,11 @@ CMaterialPass* CMaterial::Pass(u32 PassIndex) const
|
|||||||
|
|
||||||
|
|
||||||
// ************ SETTERS ************
|
// ************ SETTERS ************
|
||||||
|
void CMaterial::SetName(const std::string& name)
|
||||||
|
{
|
||||||
|
mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
void CMaterial::SetOptions(EMaterialOptions Options)
|
void CMaterial::SetOptions(EMaterialOptions Options)
|
||||||
{
|
{
|
||||||
mOptions = Options;
|
mOptions = Options;
|
||||||
|
@ -50,6 +50,7 @@ private:
|
|||||||
static CColor sCurrentTint; // The tint for the currently bound material
|
static CColor sCurrentTint; // The tint for the currently bound material
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
|
std::string mName; // Name of the material
|
||||||
CShader *mpShader; // This material's generated shader. Created with GenerateShader().
|
CShader *mpShader; // This material's generated shader. Created with GenerateShader().
|
||||||
EShaderStatus mShaderStatus; // A status variable so that PWE won't crash if a shader fails to compile.
|
EShaderStatus mShaderStatus; // A status variable so that PWE won't crash if a shader fails to compile.
|
||||||
u64 mParametersHash; // A hash of all the parameters that can identify this TEV setup.
|
u64 mParametersHash; // A hash of all the parameters that can identify this TEV setup.
|
||||||
@ -72,13 +73,16 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CMaterial();
|
CMaterial();
|
||||||
|
CMaterial(EGame version, EVertexDescription vtxDesc);
|
||||||
~CMaterial();
|
~CMaterial();
|
||||||
|
CMaterial* Clone();
|
||||||
void GenerateShader();
|
void GenerateShader();
|
||||||
bool SetCurrent(ERenderOptions Options);
|
bool SetCurrent(ERenderOptions Options);
|
||||||
u64 HashParameters();
|
u64 HashParameters();
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
std::string Name() const;
|
||||||
EGame Version() const;
|
EGame Version() const;
|
||||||
EMaterialOptions Options() const;
|
EMaterialOptions Options() const;
|
||||||
EVertexDescription VtxDesc() const;
|
EVertexDescription VtxDesc() const;
|
||||||
@ -93,6 +97,7 @@ public:
|
|||||||
CMaterialPass* Pass(u32 PassIndex) const;
|
CMaterialPass* Pass(u32 PassIndex) const;
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
void SetName(const std::string& name);
|
||||||
void SetOptions(EMaterialOptions Options);
|
void SetOptions(EMaterialOptions Options);
|
||||||
void SetBlendMode(GLenum SrcFac, GLenum DstFac);
|
void SetBlendMode(GLenum SrcFac, GLenum DstFac);
|
||||||
void SetKonst(CColor& Konst, u32 KIndex);
|
void SetKonst(CColor& Konst, u32 KIndex);
|
||||||
|
@ -30,6 +30,31 @@ CMaterialPass::~CMaterialPass()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMaterialPass* CMaterialPass::Clone(CMaterial *pParent)
|
||||||
|
{
|
||||||
|
CMaterialPass *pOut = new CMaterialPass(pParent);
|
||||||
|
pOut->mPassType = mPassType;
|
||||||
|
pOut->mSettings = mSettings;
|
||||||
|
for (u32 iIn = 0; iIn < 4; iIn++) {
|
||||||
|
pOut->mColorInputs[iIn] = mColorInputs[iIn];
|
||||||
|
pOut->mAlphaInputs[iIn] = mAlphaInputs[iIn];
|
||||||
|
}
|
||||||
|
pOut->mColorOutput = mColorOutput;
|
||||||
|
pOut->mAlphaOutput = mAlphaOutput;
|
||||||
|
pOut->mKColorSel = mKColorSel;
|
||||||
|
pOut->mKAlphaSel = mKAlphaSel;
|
||||||
|
pOut->mRasSel = mRasSel;
|
||||||
|
pOut->mTexCoordSource = mTexCoordSource;
|
||||||
|
pOut->mpTexture = mpTexture;
|
||||||
|
pOut->mTexToken = CToken(pOut->mpTexture);
|
||||||
|
pOut->mAnimMode = mAnimMode;
|
||||||
|
for (u32 iParam = 0; iParam < 4; iParam++)
|
||||||
|
pOut->mAnimParams[iParam] = mAnimParams[iParam];
|
||||||
|
pOut->mEnabled = mEnabled;
|
||||||
|
|
||||||
|
return pOut;
|
||||||
|
}
|
||||||
|
|
||||||
void CMaterialPass::HashParameters(CHashFNV1A &Hash)
|
void CMaterialPass::HashParameters(CHashFNV1A &Hash)
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
|
@ -44,6 +44,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
CMaterialPass(CMaterial *pParent);
|
CMaterialPass(CMaterial *pParent);
|
||||||
~CMaterialPass();
|
~CMaterialPass();
|
||||||
|
CMaterialPass* Clone(CMaterial *pParent);
|
||||||
void HashParameters(CHashFNV1A& Hash);
|
void HashParameters(CHashFNV1A& Hash);
|
||||||
void LoadTexture(u32 PassIndex);
|
void LoadTexture(u32 PassIndex);
|
||||||
void SetAnimCurrent(ERenderOptions Options, u32 PassIndex);
|
void SetAnimCurrent(ERenderOptions Options, u32 PassIndex);
|
||||||
|
@ -2,10 +2,41 @@
|
|||||||
#include <Core/CResCache.h>
|
#include <Core/CResCache.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
CMaterialSet::CMaterialSet() {}
|
CMaterialSet::CMaterialSet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
CMaterialSet::~CMaterialSet()
|
CMaterialSet::~CMaterialSet()
|
||||||
{
|
{
|
||||||
for (u32 m = 0; m < materials.size(); m++)
|
for (u32 iMat = 0; iMat < mMaterials.size(); iMat++)
|
||||||
delete materials[m];
|
delete mMaterials[iMat];
|
||||||
|
}
|
||||||
|
|
||||||
|
CMaterialSet* CMaterialSet::Clone()
|
||||||
|
{
|
||||||
|
CMaterialSet *pOut = new CMaterialSet();
|
||||||
|
|
||||||
|
pOut->mMaterials.resize(mMaterials.size());
|
||||||
|
for (u32 iMat = 0; iMat < mMaterials.size(); iMat++)
|
||||||
|
pOut->mMaterials[iMat] = mMaterials[iMat]->Clone();
|
||||||
|
|
||||||
|
return pOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 CMaterialSet::NumMaterials()
|
||||||
|
{
|
||||||
|
return mMaterials.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
CMaterial* CMaterialSet::MaterialByIndex(u32 index)
|
||||||
|
{
|
||||||
|
if (index >= NumMaterials()) return nullptr;
|
||||||
|
return mMaterials[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
CMaterial* CMaterialSet::MaterialByName(const std::string &name)
|
||||||
|
{
|
||||||
|
for (auto it = mMaterials.begin(); it != mMaterials.end(); it++)
|
||||||
|
if ((*it)->Name() == name) return *it;
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,18 @@
|
|||||||
|
|
||||||
class CMaterialSet
|
class CMaterialSet
|
||||||
{
|
{
|
||||||
public:
|
friend class CMaterialLoader;
|
||||||
std::vector<CTexture*> textures;
|
friend class CMaterialCooker;
|
||||||
std::vector<CMaterial*> materials;
|
|
||||||
|
|
||||||
|
std::vector<CMaterial*> mMaterials;
|
||||||
|
|
||||||
|
public:
|
||||||
CMaterialSet();
|
CMaterialSet();
|
||||||
~CMaterialSet();
|
~CMaterialSet();
|
||||||
|
CMaterialSet* Clone();
|
||||||
|
u32 NumMaterials();
|
||||||
|
CMaterial* MaterialByIndex(u32 index);
|
||||||
|
CMaterial* MaterialByName(const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CMATERIALSET_H
|
#endif // CMATERIALSET_H
|
||||||
|
@ -11,11 +11,11 @@ void CMaterialCooker::WriteMatSetPrime(COutputStream& Out)
|
|||||||
{
|
{
|
||||||
// Gather texture list from the materials before starting
|
// Gather texture list from the materials before starting
|
||||||
mTextureIDs.clear();
|
mTextureIDs.clear();
|
||||||
u32 NumMats = mpSet->materials.size();
|
u32 NumMats = mpSet->mMaterials.size();
|
||||||
|
|
||||||
for (u32 iMat = 0; iMat < NumMats; iMat++)
|
for (u32 iMat = 0; iMat < NumMats; iMat++)
|
||||||
{
|
{
|
||||||
CMaterial *pMat = mpSet->materials[iMat];
|
CMaterial *pMat = mpSet->mMaterials[iMat];
|
||||||
|
|
||||||
u32 NumPasses = pMat->PassCount();
|
u32 NumPasses = pMat->PassCount();
|
||||||
for (u32 iPass = 0; iPass < NumPasses; iPass++)
|
for (u32 iPass = 0; iPass < NumPasses; iPass++)
|
||||||
@ -49,7 +49,7 @@ void CMaterialCooker::WriteMatSetPrime(COutputStream& Out)
|
|||||||
|
|
||||||
for (u32 iMat = 0; iMat < NumMats; iMat++)
|
for (u32 iMat = 0; iMat < NumMats; iMat++)
|
||||||
{
|
{
|
||||||
mpMat = mpSet->materials[iMat];
|
mpMat = mpSet->mMaterials[iMat];
|
||||||
WriteMaterialPrime(Out);
|
WriteMaterialPrime(Out);
|
||||||
MatEndOffsets[iMat] = Out.Tell() - MatsStart;
|
MatEndOffsets[iMat] = Out.Tell() - MatsStart;
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,7 @@ void CAreaLoader::ReadGeometryPrime()
|
|||||||
for (u32 m = 0; m < mNumMeshes; m++) {
|
for (u32 m = 0; m < mNumMeshes; m++) {
|
||||||
std::cout << "\rLoading mesh " << std::dec << m + 1 << "/" << mNumMeshes;
|
std::cout << "\rLoading mesh " << std::dec << m + 1 << "/" << mNumMeshes;
|
||||||
|
|
||||||
SModelData *data = CModelLoader::LoadWorldModel(*mpMREA, *mBlockMgr, *mpArea->mMaterialSet, mVersion);
|
CModel *pTerrainModel = CModelLoader::LoadWorldModel(*mpMREA, *mBlockMgr, *mpArea->mMaterialSet, mVersion);
|
||||||
CModel *pTerrainModel = new CModel(data, mpArea->mMaterialSet);
|
|
||||||
mpArea->AddWorldModel(pTerrainModel);
|
mpArea->AddWorldModel(pTerrainModel);
|
||||||
|
|
||||||
if (mVersion >= eEchoes) {
|
if (mVersion >= eEchoes) {
|
||||||
@ -326,8 +325,7 @@ void CAreaLoader::ReadGeometryCorruption()
|
|||||||
{
|
{
|
||||||
std::cout << "\rLoading mesh " << std::dec << iMesh + 1 << "/" << mNumMeshes;
|
std::cout << "\rLoading mesh " << std::dec << iMesh + 1 << "/" << mNumMeshes;
|
||||||
|
|
||||||
SModelData *pData = CModelLoader::LoadCorruptionWorldModel(*mpMREA, *mBlockMgr, *mpArea->mMaterialSet, CurWOBJSection, CurGPUSection, mVersion);
|
CModel *pWorldModel = CModelLoader::LoadCorruptionWorldModel(*mpMREA, *mBlockMgr, *mpArea->mMaterialSet, CurWOBJSection, CurGPUSection, mVersion);
|
||||||
CModel *pWorldModel = new CModel(pData, mpArea->mMaterialSet);
|
|
||||||
mpArea->AddWorldModel(pWorldModel);
|
mpArea->AddWorldModel(pWorldModel);
|
||||||
|
|
||||||
CurWOBJSection += 4;
|
CurWOBJSection += 4;
|
||||||
|
@ -33,28 +33,29 @@ CMaterialSet* CMaterialLoader::LoadMaterialSet(CInputStream& Mat, EGame Version)
|
|||||||
void CMaterialLoader::ReadPrimeMatSet()
|
void CMaterialLoader::ReadPrimeMatSet()
|
||||||
{
|
{
|
||||||
// Textures
|
// Textures
|
||||||
u32 TexCount = mpFile->ReadLong();
|
u32 numTextures = mpFile->ReadLong();
|
||||||
mpSet->textures.resize(TexCount);
|
mTextures.resize(numTextures);
|
||||||
|
|
||||||
for (u32 t = 0; t < TexCount; t++)
|
for (u32 iTex = 0; iTex < numTextures; iTex++)
|
||||||
{
|
{
|
||||||
u32 TextureID = mpFile->ReadLong();
|
u32 TextureID = mpFile->ReadLong();
|
||||||
mpSet->textures[t] = (CTexture*) gResCache.GetResource(TextureID, "TXTR");
|
mTextures[iTex] = (CTexture*) gResCache.GetResource(TextureID, "TXTR");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Materials
|
// Materials
|
||||||
u32 MatCount = mpFile->ReadLong();
|
u32 numMats = mpFile->ReadLong();
|
||||||
std::vector<u32> offsets(MatCount);
|
std::vector<u32> offsets(numMats);
|
||||||
for (u32 m = 0; m < MatCount; m++)
|
for (u32 iMat = 0; iMat < numMats; iMat++)
|
||||||
offsets[m] = mpFile->ReadLong();
|
offsets[iMat] = mpFile->ReadLong();
|
||||||
|
|
||||||
u32 mats_start = mpFile->Tell();
|
u32 matsStart = mpFile->Tell();
|
||||||
mpSet->materials.resize(MatCount);
|
mpSet->mMaterials.resize(numMats);
|
||||||
for (u32 m = 0; m < MatCount; m++)
|
for (u32 iMat = 0; iMat < numMats; iMat++)
|
||||||
{
|
{
|
||||||
mpSet->materials[m] = ReadPrimeMaterial();
|
mpSet->mMaterials[iMat] = ReadPrimeMaterial();
|
||||||
mpSet->materials[m]->mVersion = mVersion;
|
mpSet->mMaterials[iMat]->mVersion = mVersion;
|
||||||
mpFile->Seek(mats_start + offsets[m], SEEK_SET);
|
mpSet->mMaterials[iMat]->mName = std::string("Material #") + std::to_string(iMat);
|
||||||
|
mpFile->Seek(matsStart + offsets[iMat], SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
|
|||||||
if (pMat->mOptions & CMaterial::eIndStage)
|
if (pMat->mOptions & CMaterial::eIndStage)
|
||||||
{
|
{
|
||||||
u32 IndTexIndex = mpFile->ReadLong();
|
u32 IndTexIndex = mpFile->ReadLong();
|
||||||
pMat->mpIndirectTexture = mpSet->textures[IndTexIndex];
|
pMat->mpIndirectTexture = mTextures[IndTexIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color channels
|
// Color channels
|
||||||
@ -149,13 +150,14 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
|
|||||||
CMaterialPass *pPass = pMat->Pass(iTev);
|
CMaterialPass *pPass = pMat->Pass(iTev);
|
||||||
|
|
||||||
u8 TexSel = mpFile->ReadByte();
|
u8 TexSel = mpFile->ReadByte();
|
||||||
if ((TexSel == 0xFF) || (TexSel >= mpSet->textures.size()))
|
|
||||||
|
if ((TexSel == 0xFF) || (TexSel >= mTextures.size()))
|
||||||
{
|
{
|
||||||
pPass->mpTexture = nullptr;
|
pPass->mpTexture = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pPass->mpTexture = mpSet->textures[ TextureIndices[TexSel] ];
|
pPass->mpTexture = mTextures[TextureIndices[TexSel]];
|
||||||
pPass->mTexToken = CToken(pPass->mpTexture);
|
pPass->mTexToken = CToken(pPass->mpTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,14 +247,15 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
|
|||||||
void CMaterialLoader::ReadCorruptionMatSet()
|
void CMaterialLoader::ReadCorruptionMatSet()
|
||||||
{
|
{
|
||||||
u32 NumMats = mpFile->ReadLong();
|
u32 NumMats = mpFile->ReadLong();
|
||||||
mpSet->materials.resize(NumMats);
|
mpSet->mMaterials.resize(NumMats);
|
||||||
|
|
||||||
for (u32 iMat = 0; iMat < NumMats; iMat++)
|
for (u32 iMat = 0; iMat < NumMats; iMat++)
|
||||||
{
|
{
|
||||||
u32 Size = mpFile->ReadLong();
|
u32 Size = mpFile->ReadLong();
|
||||||
u32 Next = mpFile->Tell() + Size;
|
u32 Next = mpFile->Tell() + Size;
|
||||||
mpSet->materials[iMat] = ReadCorruptionMaterial();
|
mpSet->mMaterials[iMat] = ReadCorruptionMaterial();
|
||||||
mpSet->materials[iMat]->mVersion = mVersion;
|
mpSet->mMaterials[iMat]->mVersion = mVersion;
|
||||||
|
mpSet->mMaterials[iMat]->mName = std::string("Material #") + std::to_string(iMat);
|
||||||
mpFile->Seek(Next, SEEK_SET);
|
mpFile->Seek(Next, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,7 +360,6 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
|
|||||||
}
|
}
|
||||||
|
|
||||||
CTexture *pTex = (CTexture*) gResCache.GetResource(TextureID, "TXTR");
|
CTexture *pTex = (CTexture*) gResCache.GetResource(TextureID, "TXTR");
|
||||||
mpSet->textures.push_back(pTex);
|
|
||||||
pPass->mpTexture = pTex;
|
pPass->mpTexture = pTex;
|
||||||
pPass->mTexToken = CToken(pTex);
|
pPass->mTexToken = CToken(pTex);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ class CMaterialLoader
|
|||||||
CMaterialSet *mpSet;
|
CMaterialSet *mpSet;
|
||||||
CInputStream *mpFile;
|
CInputStream *mpFile;
|
||||||
EGame mVersion;
|
EGame mVersion;
|
||||||
|
std::vector<CTexture*> mTextures;
|
||||||
bool mHasOPAC;
|
bool mHasOPAC;
|
||||||
bool mHas0x400;
|
bool mHas0x400;
|
||||||
|
|
||||||
|
@ -115,128 +115,116 @@ void CModelLoader::LoadSurfaceOffsets(CInputStream& Model)
|
|||||||
mpBlockMgr->ToNextBlock();
|
mpBlockMgr->ToNextBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
SModelData* CModelLoader::LoadSurfaces(CInputStream& Model)
|
SSurface* CModelLoader::LoadSurface(CInputStream& Model)
|
||||||
{
|
{
|
||||||
// This function is meant to be called at the start of the first surface
|
SSurface *pSurf = new SSurface;
|
||||||
SModelData *pData = new SModelData;
|
|
||||||
u32 Offset = Model.Tell();
|
|
||||||
|
|
||||||
// Surfaces
|
// Surface header
|
||||||
pData->mSurfaces.resize(mSurfaceCount);
|
if (mVersion < eReturns)
|
||||||
|
LoadSurfaceHeaderPrime(Model, pSurf);
|
||||||
|
else
|
||||||
|
LoadSurfaceHeaderDKCR(Model, pSurf);
|
||||||
|
|
||||||
for (u32 iSurf = 0; iSurf < mSurfaceCount; iSurf++)
|
bool HasAABB = (pSurf->AABox != CAABox::skInfinite);
|
||||||
|
CMaterial *pMat = mMaterials[0]->MaterialByIndex(pSurf->MaterialID);
|
||||||
|
|
||||||
|
// Primitive table
|
||||||
|
u8 Flag = Model.ReadByte();
|
||||||
|
u32 NextSurface = mpBlockMgr->NextOffset();
|
||||||
|
|
||||||
|
while ((Flag != 0) && ((u32) Model.Tell() < NextSurface))
|
||||||
{
|
{
|
||||||
SSurface *pSurf = new SSurface;
|
SSurface::SPrimitive Prim;
|
||||||
pData->mSurfaces[iSurf] = pSurf;
|
Prim.Type = EGXPrimitiveType(Flag & 0xF8);
|
||||||
u32 NextSurface = mpBlockMgr->NextOffset();
|
u16 VertexCount = Model.ReadShort();
|
||||||
|
|
||||||
// Surface header
|
for (u16 iVtx = 0; iVtx < VertexCount; iVtx++)
|
||||||
if (mVersion < eReturns)
|
|
||||||
LoadSurfaceHeaderPrime(Model, pSurf);
|
|
||||||
else
|
|
||||||
LoadSurfaceHeaderDKCR(Model, pSurf);
|
|
||||||
|
|
||||||
bool HasAABB = (pSurf->AABox != CAABox::skInfinite);
|
|
||||||
CMaterial *pMat = mMaterials[0]->materials[pSurf->MaterialID];
|
|
||||||
|
|
||||||
// Primitive table
|
|
||||||
u8 Flag = Model.ReadByte();
|
|
||||||
|
|
||||||
while ((Flag != 0) && ((u32) Model.Tell() < NextSurface))
|
|
||||||
{
|
{
|
||||||
SSurface::SPrimitive Prim;
|
CVertex Vtx;
|
||||||
Prim.Type = EGXPrimitiveType(Flag & 0xF8);
|
EVertexDescription VtxDesc = pMat->VtxDesc();
|
||||||
u16 VertexCount = Model.ReadShort();
|
|
||||||
|
|
||||||
for (u16 iVtx = 0; iVtx < VertexCount; iVtx++)
|
for (u32 iMtxAttr = 0; iMtxAttr < 8; iMtxAttr++)
|
||||||
|
if (VtxDesc & (ePosMtx << iMtxAttr)) Model.Seek(0x1, SEEK_CUR);
|
||||||
|
|
||||||
|
// Only thing to do here is check whether each attribute is present, and if so, read it.
|
||||||
|
// A couple attributes have special considerations; normals can be floats or shorts, as can tex0, depending on vtxfmt.
|
||||||
|
// tex0 can also be read from either UV buffer; depends what the material says.
|
||||||
|
|
||||||
|
// Position
|
||||||
|
if (VtxDesc & ePosition)
|
||||||
{
|
{
|
||||||
CVertex Vtx;
|
u16 PosIndex = Model.ReadShort() & 0xFFFF;
|
||||||
EVertexDescription VtxDesc = pMat->VtxDesc();
|
Vtx.Position = mPositions[PosIndex];
|
||||||
|
Vtx.ArrayPosition = PosIndex;
|
||||||
|
|
||||||
for (u32 iMtxAttr = 0; iMtxAttr < 8; iMtxAttr++)
|
if (!HasAABB) pSurf->AABox.ExpandBounds(Vtx.Position);
|
||||||
if (VtxDesc & (ePosMtx << iMtxAttr)) Model.Seek(0x1, SEEK_CUR);
|
|
||||||
|
|
||||||
// Only thing to do here is check whether each attribute is present, and if so, read it.
|
|
||||||
// A couple attributes have special considerations; normals can be floats or shorts, as can tex0, depending on vtxfmt.
|
|
||||||
// tex0 can also be read from either UV buffer; depends what the material says.
|
|
||||||
|
|
||||||
// Position
|
|
||||||
if (VtxDesc & ePosition)
|
|
||||||
{
|
|
||||||
u16 PosIndex = Model.ReadShort() & 0xFFFF;
|
|
||||||
Vtx.Position = mPositions[PosIndex];
|
|
||||||
Vtx.ArrayPosition = PosIndex;
|
|
||||||
|
|
||||||
if (!HasAABB) pSurf->AABox.ExpandBounds(Vtx.Position);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normal
|
|
||||||
if (VtxDesc & eNormal)
|
|
||||||
Vtx.Normal = mNormals[Model.ReadShort() & 0xFFFF];
|
|
||||||
|
|
||||||
// Color
|
|
||||||
for (u32 c = 0; c < 2; c++)
|
|
||||||
if (VtxDesc & (eColor0 << (c * 2)))
|
|
||||||
Vtx.Color[c] = mColors[Model.ReadShort() & 0xFFFF];
|
|
||||||
|
|
||||||
// Tex Coords - these are done a bit differently in DKCR than in the Prime series
|
|
||||||
if (mVersion < eReturns)
|
|
||||||
{
|
|
||||||
// Tex0
|
|
||||||
if (VtxDesc & eTex0)
|
|
||||||
{
|
|
||||||
if ((mFlags & eHasTex1) && (pMat->Options() & CMaterial::eShortTexCoord))
|
|
||||||
Vtx.Tex[0] = mTex1[Model.ReadShort() & 0xFFFF];
|
|
||||||
else
|
|
||||||
Vtx.Tex[0] = mTex0[Model.ReadShort() & 0xFFFF];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tex1-7
|
|
||||||
for (u32 iTex = 1; iTex < 7; iTex++)
|
|
||||||
if (VtxDesc & (eTex0 << (iTex * 2)))
|
|
||||||
Vtx.Tex[iTex] = mTex0[Model.ReadShort() & 0xFFFF];
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Tex0-7
|
|
||||||
for (u32 iTex = 0; iTex < 7; iTex++)
|
|
||||||
{
|
|
||||||
if (VtxDesc & (eTex0 << iTex * 2))
|
|
||||||
{
|
|
||||||
if (!mSurfaceUsingTex1)
|
|
||||||
Vtx.Tex[iTex] = mTex0[Model.ReadShort() & 0xFFFF];
|
|
||||||
else
|
|
||||||
Vtx.Tex[iTex] = mTex1[Model.ReadShort() & 0xFFFF];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Prim.Vertices.push_back(Vtx);
|
|
||||||
} // Vertex array end
|
|
||||||
|
|
||||||
// Update vertex/triangle count
|
|
||||||
pSurf->VertexCount += VertexCount;
|
|
||||||
|
|
||||||
switch (Prim.Type)
|
|
||||||
{
|
|
||||||
case eGX_Triangles:
|
|
||||||
pSurf->TriangleCount += VertexCount / 3;
|
|
||||||
break;
|
|
||||||
case eGX_TriangleFan:
|
|
||||||
case eGX_TriangleStrip:
|
|
||||||
pSurf->TriangleCount += VertexCount - 2;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pSurf->Primitives.push_back(Prim);
|
// Normal
|
||||||
Flag = Model.ReadByte();
|
if (VtxDesc & eNormal)
|
||||||
} // Primitive table end
|
Vtx.Normal = mNormals[Model.ReadShort() & 0xFFFF];
|
||||||
|
|
||||||
mpBlockMgr->ToNextBlock();
|
// Color
|
||||||
} // Submesh table end
|
for (u32 c = 0; c < 2; c++)
|
||||||
|
if (VtxDesc & (eColor0 << (c * 2)))
|
||||||
|
Vtx.Color[c] = mColors[Model.ReadShort() & 0xFFFF];
|
||||||
|
|
||||||
return pData;
|
// Tex Coords - these are done a bit differently in DKCR than in the Prime series
|
||||||
|
if (mVersion < eReturns)
|
||||||
|
{
|
||||||
|
// Tex0
|
||||||
|
if (VtxDesc & eTex0)
|
||||||
|
{
|
||||||
|
if ((mFlags & eHasTex1) && (pMat->Options() & CMaterial::eShortTexCoord))
|
||||||
|
Vtx.Tex[0] = mTex1[Model.ReadShort() & 0xFFFF];
|
||||||
|
else
|
||||||
|
Vtx.Tex[0] = mTex0[Model.ReadShort() & 0xFFFF];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tex1-7
|
||||||
|
for (u32 iTex = 1; iTex < 7; iTex++)
|
||||||
|
if (VtxDesc & (eTex0 << (iTex * 2)))
|
||||||
|
Vtx.Tex[iTex] = mTex0[Model.ReadShort() & 0xFFFF];
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Tex0-7
|
||||||
|
for (u32 iTex = 0; iTex < 7; iTex++)
|
||||||
|
{
|
||||||
|
if (VtxDesc & (eTex0 << iTex * 2))
|
||||||
|
{
|
||||||
|
if (!mSurfaceUsingTex1)
|
||||||
|
Vtx.Tex[iTex] = mTex0[Model.ReadShort() & 0xFFFF];
|
||||||
|
else
|
||||||
|
Vtx.Tex[iTex] = mTex1[Model.ReadShort() & 0xFFFF];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Prim.Vertices.push_back(Vtx);
|
||||||
|
} // Vertex array end
|
||||||
|
|
||||||
|
// Update vertex/triangle count
|
||||||
|
pSurf->VertexCount += VertexCount;
|
||||||
|
|
||||||
|
switch (Prim.Type)
|
||||||
|
{
|
||||||
|
case eGX_Triangles:
|
||||||
|
pSurf->TriangleCount += VertexCount / 3;
|
||||||
|
break;
|
||||||
|
case eGX_TriangleFan:
|
||||||
|
case eGX_TriangleStrip:
|
||||||
|
pSurf->TriangleCount += VertexCount - 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSurf->Primitives.push_back(Prim);
|
||||||
|
Flag = Model.ReadByte();
|
||||||
|
} // Primitive table end
|
||||||
|
|
||||||
|
mpBlockMgr->ToNextBlock();
|
||||||
|
return pSurf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModelLoader::LoadSurfaceHeaderPrime(CInputStream& Model, SSurface *pSurf)
|
void CModelLoader::LoadSurfaceHeaderPrime(CInputStream& Model, SSurface *pSurf)
|
||||||
@ -378,19 +366,23 @@ CModel* CModelLoader::LoadCMDL(CInputStream& CMDL)
|
|||||||
// Mesh
|
// Mesh
|
||||||
Loader.LoadAttribArrays(CMDL);
|
Loader.LoadAttribArrays(CMDL);
|
||||||
Loader.LoadSurfaceOffsets(CMDL);
|
Loader.LoadSurfaceOffsets(CMDL);
|
||||||
SModelData *pData = Loader.LoadSurfaces(CMDL);
|
pModel->mSurfaces.reserve(Loader.mSurfaceCount);
|
||||||
|
|
||||||
|
for (u32 iSurf = 0; iSurf < Loader.mSurfaceCount; iSurf++)
|
||||||
|
{
|
||||||
|
SSurface *pSurf = Loader.LoadSurface(CMDL);
|
||||||
|
pModel->mSurfaces.push_back(pSurf);
|
||||||
|
}
|
||||||
|
|
||||||
pModel->SetData(pData);
|
|
||||||
pModel->mAABox = AABox;
|
pModel->mAABox = AABox;
|
||||||
pModel->mHasOwnSurfaces = true;
|
pModel->mHasOwnSurfaces = true;
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
delete pData;
|
|
||||||
delete Loader.mpBlockMgr;
|
delete Loader.mpBlockMgr;
|
||||||
return pModel;
|
return pModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
SModelData* CModelLoader::LoadWorldModel(CInputStream& MREA, CBlockMgrIn& BlockMgr, CMaterialSet& MatSet, EGame Version)
|
CModel* CModelLoader::LoadWorldModel(CInputStream& MREA, CBlockMgrIn& BlockMgr, CMaterialSet& MatSet, EGame Version)
|
||||||
{
|
{
|
||||||
CModelLoader Loader;
|
CModelLoader Loader;
|
||||||
Loader.mpBlockMgr = &BlockMgr;
|
Loader.mpBlockMgr = &BlockMgr;
|
||||||
@ -403,13 +395,27 @@ SModelData* CModelLoader::LoadWorldModel(CInputStream& MREA, CBlockMgrIn& BlockM
|
|||||||
Loader.LoadWorldMeshHeader(MREA);
|
Loader.LoadWorldMeshHeader(MREA);
|
||||||
Loader.LoadAttribArrays(MREA);
|
Loader.LoadAttribArrays(MREA);
|
||||||
Loader.LoadSurfaceOffsets(MREA);
|
Loader.LoadSurfaceOffsets(MREA);
|
||||||
SModelData *pData = Loader.LoadSurfaces(MREA);
|
|
||||||
pData->mAABox = Loader.mAABox;
|
|
||||||
|
|
||||||
return pData;
|
CModel *pModel = new CModel();
|
||||||
|
pModel->mMaterialSets.resize(1);
|
||||||
|
pModel->mMaterialSets[0] = &MatSet;
|
||||||
|
pModel->mHasOwnMaterials = false;
|
||||||
|
pModel->mSurfaces.reserve(Loader.mSurfaceCount);
|
||||||
|
pModel->mHasOwnSurfaces = true;
|
||||||
|
|
||||||
|
for (u32 iSurf = 0; iSurf < Loader.mSurfaceCount; iSurf++)
|
||||||
|
{
|
||||||
|
SSurface *pSurf = Loader.LoadSurface(MREA);
|
||||||
|
pModel->mSurfaces.push_back(pSurf);
|
||||||
|
pModel->mVertexCount += pSurf->VertexCount;
|
||||||
|
pModel->mTriangleCount += pSurf->TriangleCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
pModel->mAABox = Loader.mAABox;
|
||||||
|
return pModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
SModelData* CModelLoader::LoadCorruptionWorldModel(CInputStream &MREA, CBlockMgrIn &BlockMgr, CMaterialSet &MatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version)
|
CModel* CModelLoader::LoadCorruptionWorldModel(CInputStream &MREA, CBlockMgrIn &BlockMgr, CMaterialSet &MatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version)
|
||||||
{
|
{
|
||||||
CModelLoader Loader;
|
CModelLoader Loader;
|
||||||
Loader.mpBlockMgr = &BlockMgr;
|
Loader.mpBlockMgr = &BlockMgr;
|
||||||
@ -423,12 +429,26 @@ SModelData* CModelLoader::LoadCorruptionWorldModel(CInputStream &MREA, CBlockMgr
|
|||||||
BlockMgr.ToBlock(HeaderSecNum);
|
BlockMgr.ToBlock(HeaderSecNum);
|
||||||
Loader.LoadWorldMeshHeader(MREA);
|
Loader.LoadWorldMeshHeader(MREA);
|
||||||
Loader.LoadSurfaceOffsets(MREA);
|
Loader.LoadSurfaceOffsets(MREA);
|
||||||
|
|
||||||
BlockMgr.ToBlock(GPUSecNum);
|
BlockMgr.ToBlock(GPUSecNum);
|
||||||
Loader.LoadAttribArrays(MREA);
|
Loader.LoadAttribArrays(MREA);
|
||||||
SModelData *pData = Loader.LoadSurfaces(MREA);
|
|
||||||
pData->mAABox = Loader.mAABox;
|
CModel *pModel = new CModel();
|
||||||
return pData;
|
pModel->mMaterialSets.resize(1);
|
||||||
|
pModel->mMaterialSets[0] = &MatSet;
|
||||||
|
pModel->mHasOwnMaterials = false;
|
||||||
|
pModel->mSurfaces.reserve(Loader.mSurfaceCount);
|
||||||
|
pModel->mHasOwnSurfaces = true;
|
||||||
|
|
||||||
|
for (u32 iSurf = 0; iSurf < Loader.mSurfaceCount; iSurf++)
|
||||||
|
{
|
||||||
|
SSurface *pSurf = Loader.LoadSurface(MREA);
|
||||||
|
pModel->mSurfaces.push_back(pSurf);
|
||||||
|
pModel->mVertexCount += pSurf->VertexCount;
|
||||||
|
pModel->mTriangleCount += pSurf->TriangleCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
pModel->mAABox = Loader.mAABox;
|
||||||
|
return pModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
EGame CModelLoader::GetFormatVersion(u32 Version)
|
EGame CModelLoader::GetFormatVersion(u32 Version)
|
||||||
|
@ -47,14 +47,14 @@ private:
|
|||||||
void LoadAttribArrays(CInputStream& Model);
|
void LoadAttribArrays(CInputStream& Model);
|
||||||
void LoadAttribArraysDKCR(CInputStream& Model);
|
void LoadAttribArraysDKCR(CInputStream& Model);
|
||||||
void LoadSurfaceOffsets(CInputStream& Model);
|
void LoadSurfaceOffsets(CInputStream& Model);
|
||||||
SModelData* LoadSurfaces(CInputStream& Model);
|
SSurface* LoadSurface(CInputStream& Model);
|
||||||
void LoadSurfaceHeaderPrime(CInputStream& Model, SSurface *pSurf);
|
void LoadSurfaceHeaderPrime(CInputStream& Model, SSurface *pSurf);
|
||||||
void LoadSurfaceHeaderDKCR(CInputStream& Model, SSurface *pSurf);
|
void LoadSurfaceHeaderDKCR(CInputStream& Model, SSurface *pSurf);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CModel* LoadCMDL(CInputStream& CMDL);
|
static CModel* LoadCMDL(CInputStream& CMDL);
|
||||||
static SModelData* LoadWorldModel(CInputStream& MREA, CBlockMgrIn& BlockMgr, CMaterialSet& MatSet, EGame Version);
|
static CModel* LoadWorldModel(CInputStream& MREA, CBlockMgrIn& BlockMgr, CMaterialSet& MatSet, EGame Version);
|
||||||
static SModelData* LoadCorruptionWorldModel(CInputStream& MREA, CBlockMgrIn& BlockMgr, CMaterialSet& MatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version);
|
static CModel* LoadCorruptionWorldModel(CInputStream& MREA, CBlockMgrIn& BlockMgr, CMaterialSet& MatSet, u32 HeaderSecNum, u32 GPUSecNum, EGame Version);
|
||||||
static EGame GetFormatVersion(u32 Version);
|
static EGame GetFormatVersion(u32 Version);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,22 +6,8 @@ CModel::CModel() : CBasicModel()
|
|||||||
{
|
{
|
||||||
mHasOwnMaterials = true;
|
mHasOwnMaterials = true;
|
||||||
mHasOwnSurfaces = true;
|
mHasOwnSurfaces = true;
|
||||||
}
|
mVertexCount = 0;
|
||||||
|
mTriangleCount = 0;
|
||||||
CModel::CModel(SModelData *pModelData) : CBasicModel()
|
|
||||||
{
|
|
||||||
SetData(pModelData);
|
|
||||||
mHasOwnMaterials = false;
|
|
||||||
mHasOwnSurfaces = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CModel::CModel(SModelData *data, CMaterialSet *pMatSet) : CBasicModel()
|
|
||||||
{
|
|
||||||
SetData(data);
|
|
||||||
mMaterialSets.resize(1);
|
|
||||||
mMaterialSets[0] = pMatSet;
|
|
||||||
mHasOwnMaterials = false;
|
|
||||||
mHasOwnSurfaces = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CModel::~CModel()
|
CModel::~CModel()
|
||||||
@ -31,22 +17,6 @@ CModel::~CModel()
|
|||||||
delete mMaterialSets[m];
|
delete mMaterialSets[m];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModel::SetData(SModelData *pModelData)
|
|
||||||
{
|
|
||||||
mAABox = pModelData->mAABox;
|
|
||||||
mSurfaces = pModelData->mSurfaces;
|
|
||||||
|
|
||||||
mVertexCount = 0;
|
|
||||||
mTriangleCount = 0;
|
|
||||||
|
|
||||||
for (u32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
|
|
||||||
{
|
|
||||||
SSurface *pSurf = mSurfaces[iSurf];
|
|
||||||
mVertexCount += pSurf->VertexCount;
|
|
||||||
mTriangleCount += pSurf->TriangleCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CModel::BufferGL()
|
void CModel::BufferGL()
|
||||||
{
|
{
|
||||||
mVBO.Clear();
|
mVBO.Clear();
|
||||||
@ -117,7 +87,7 @@ void CModel::DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet)
|
|||||||
|
|
||||||
// Bind material
|
// Bind material
|
||||||
SSurface *pSurf = mSurfaces[Surface];
|
SSurface *pSurf = mSurfaces[Surface];
|
||||||
CMaterial *pMat = mMaterialSets[MatSet]->materials[pSurf->MaterialID];
|
CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID);
|
||||||
|
|
||||||
if ((Options & eNoMaterialSetup) == 0)
|
if ((Options & eNoMaterialSetup) == 0)
|
||||||
{
|
{
|
||||||
@ -147,7 +117,7 @@ u32 CModel::GetMatSetCount()
|
|||||||
u32 CModel::GetMatCount()
|
u32 CModel::GetMatCount()
|
||||||
{
|
{
|
||||||
if (mMaterialSets.empty()) return 0;
|
if (mMaterialSets.empty()) return 0;
|
||||||
else return mMaterialSets[0]->materials.size();
|
else return mMaterialSets[0]->NumMaterials();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMaterialSet* CModel::GetMatSet(u32 MatSet)
|
CMaterialSet* CModel::GetMatSet(u32 MatSet)
|
||||||
@ -163,7 +133,7 @@ CMaterial* CModel::GetMaterialByIndex(u32 MatSet, u32 Index)
|
|||||||
if (GetMatCount() == 0)
|
if (GetMatCount() == 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return mMaterialSets[MatSet]->materials[Index];
|
return mMaterialSets[MatSet]->MaterialByIndex(Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMaterial* CModel::GetMaterialBySurface(u32 MatSet, u32 Surface)
|
CMaterial* CModel::GetMaterialBySurface(u32 MatSet, u32 Surface)
|
||||||
@ -176,8 +146,8 @@ bool CModel::HasTransparency(u32 MatSet)
|
|||||||
if (MatSet >= mMaterialSets.size())
|
if (MatSet >= mMaterialSets.size())
|
||||||
MatSet = mMaterialSets.size() - 1;
|
MatSet = mMaterialSets.size() - 1;
|
||||||
|
|
||||||
for (u32 iMat = 0; iMat < mMaterialSets[MatSet]->materials.size(); iMat++)
|
for (u32 iMat = 0; iMat < mMaterialSets[MatSet]->NumMaterials(); iMat++)
|
||||||
if (mMaterialSets[MatSet]->materials[iMat]->Options() & CMaterial::eTransparent ) return true;
|
if (mMaterialSets[MatSet]->MaterialByIndex(iMat)->Options() & CMaterial::eTransparent ) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -188,7 +158,7 @@ bool CModel::IsSurfaceTransparent(u32 Surface, u32 MatSet)
|
|||||||
MatSet = mMaterialSets.size() - 1;
|
MatSet = mMaterialSets.size() - 1;
|
||||||
|
|
||||||
u32 matID = mSurfaces[Surface]->MaterialID;
|
u32 matID = mSurfaces[Surface]->MaterialID;
|
||||||
return (mMaterialSets[MatSet]->materials[matID]->Options() & CMaterial::eTransparent) != 0;
|
return (mMaterialSets[MatSet]->MaterialByIndex(matID)->Options() & CMaterial::eTransparent) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CIndexBuffer* CModel::InternalGetIBO(u32 Surface, EGXPrimitiveType Primitive)
|
CIndexBuffer* CModel::InternalGetIBO(u32 Surface, EGXPrimitiveType Primitive)
|
||||||
|
@ -21,10 +21,8 @@ class CModel : public CBasicModel
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CModel();
|
CModel();
|
||||||
CModel(SModelData *pModelData);
|
CModel(CMaterialSet *pSet);
|
||||||
CModel(SModelData *pModelData, CMaterialSet *pMatSet);
|
|
||||||
~CModel();
|
~CModel();
|
||||||
void SetData(SModelData *pModelData);
|
|
||||||
|
|
||||||
void BufferGL();
|
void BufferGL();
|
||||||
void ClearGLBuffer();
|
void ClearGLBuffer();
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#ifndef SMODELDATA_H
|
|
||||||
#define SMODELDATA_H
|
|
||||||
|
|
||||||
#include "SSurface.h"
|
|
||||||
#include <Common/CAABox.h>
|
|
||||||
|
|
||||||
struct SModelData
|
|
||||||
{
|
|
||||||
CAABox mAABox;
|
|
||||||
std::vector<SSurface*> mSurfaces;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SMODELDATA_H
|
|
Loading…
x
Reference in New Issue
Block a user