Fixes
This commit is contained in:
@@ -30,7 +30,6 @@ static std::string getFileNameWithoutExtension(const std::string& filename)
|
||||
|
||||
Model::Model()
|
||||
{
|
||||
m_AlbedoTexture = nullptr;
|
||||
m_numPoses = 0;
|
||||
|
||||
//m_boundingBox.min = glm::vec3(0.0f);
|
||||
@@ -39,7 +38,6 @@ Model::Model()
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
m_AlbedoTexture = nullptr;
|
||||
|
||||
for (int i = 0; i < m_meshes.size(); i++)
|
||||
ReleaseModelData(m_meshes[i]);
|
||||
@@ -268,6 +266,8 @@ void Model::LoadIqm(const char* filename)
|
||||
indices[j * 3 + 2] = a - pMesh->first_vertex;
|
||||
}
|
||||
|
||||
const char* pMaterialname = nullptr;
|
||||
|
||||
if (pHdr->ofs_text)
|
||||
{
|
||||
// #TODO: weird weird getting material name string is so wrong
|
||||
@@ -275,8 +275,9 @@ void Model::LoadIqm(const char* filename)
|
||||
const char* str = (char*)pHdr + pHdr->ofs_text;
|
||||
const char* materialname = &str[pMesh->material];
|
||||
|
||||
//if (materialname)
|
||||
// pMaterial = g_materialSystem.LoadMaterial(materialname);
|
||||
if (materialname)
|
||||
pMaterialname = materialname;
|
||||
//pMaterial = g_materialSystem.LoadMaterial(materialname);
|
||||
}
|
||||
|
||||
ModelData_t mesh = {};
|
||||
@@ -286,6 +287,14 @@ void Model::LoadIqm(const char* filename)
|
||||
mesh.vbcount = pMesh->num_vertexes;
|
||||
mesh.ib = g_renderDevice->CreateIndexBuffer(indices.data(), pMesh->num_triangles * sizeof(iqmtriangle), false);
|
||||
mesh.ibcount = pMesh->num_triangles * 3;
|
||||
|
||||
|
||||
std::string mtlfilename = getFileNameWithoutExtension(filename);
|
||||
mtlfilename += "_";
|
||||
mtlfilename += pMaterialname;
|
||||
mtlfilename += ".mtl";
|
||||
mesh.m_AlbedoTexture = LoadMtl(mtlfilename.c_str());
|
||||
|
||||
//mesh.m_material = pMaterial;
|
||||
//
|
||||
//if (!mesh.m_material)
|
||||
@@ -549,17 +558,19 @@ void Model::LoadObj(const char* filename)
|
||||
|
||||
std::string mtlfilename = getFileNameWithoutExtension(filename);
|
||||
mtlfilename += ".mtl";
|
||||
LoadMtl(mtlfilename.c_str());
|
||||
m_data.m_AlbedoTexture = LoadMtl(mtlfilename.c_str());
|
||||
}
|
||||
|
||||
void Model::LoadMtl(const char* filename)
|
||||
Texture2D* Model::LoadMtl(const char* filename)
|
||||
{
|
||||
Msg("Loading MTL file %s...", filename);
|
||||
|
||||
Texture2D* pAlbedo = nullptr;
|
||||
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
Msg("Model::LoadObj: Impossible to open the file !");
|
||||
return;
|
||||
Msg("Model::LoadMtl: Impossible to open the file !");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
@@ -575,7 +586,7 @@ void Model::LoadMtl(const char* filename)
|
||||
fgets(stupidBuffer, 1000, file);
|
||||
|
||||
const char* textureFilename = stupidBuffer + 1;
|
||||
m_AlbedoTexture = g_texturesManager->LoadTexture2D(textureFilename, true);
|
||||
pAlbedo = g_texturesManager->LoadTexture2D(textureFilename, true);
|
||||
}
|
||||
|
||||
//if (strcmp(lineHeader, "v") == 0) {
|
||||
@@ -592,6 +603,8 @@ void Model::LoadMtl(const char* filename)
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
return pAlbedo;
|
||||
}
|
||||
|
||||
void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*/)
|
||||
@@ -644,10 +657,10 @@ void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*
|
||||
g_shaderSystem->SetUniformMatrix(shader, UNIFORM_MVP_MATRIX, &mvp[0]);
|
||||
|
||||
|
||||
if (!m_AlbedoTexture)
|
||||
m_AlbedoTexture = g_texturesManager->LoadTexture2D("asdfasdf");
|
||||
if (!m_data.m_AlbedoTexture)
|
||||
m_data.m_AlbedoTexture = g_texturesManager->LoadTexture2D("MustBeEvilHackButDontCare");
|
||||
|
||||
g_texturesManager->SetTexture(0, m_AlbedoTexture);
|
||||
g_texturesManager->SetTexture(0, m_data.m_AlbedoTexture);
|
||||
g_shaderSystem->SetUniformSampler(shader, SAMPLER_ALBEDO, 0);
|
||||
|
||||
if (instance)
|
||||
|
||||
@@ -15,6 +15,7 @@ class Texture2D;
|
||||
|
||||
struct ModelData_t
|
||||
{
|
||||
Texture2D* m_AlbedoTexture;
|
||||
GPUBuffer* vb;
|
||||
GPUBuffer* ib;
|
||||
uint32_t vbcount;
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
|
||||
void LoadIqm(const char* filename);
|
||||
void LoadObj(const char* filename);
|
||||
void LoadMtl(const char* filename);
|
||||
Texture2D* LoadMtl(const char* filename);
|
||||
|
||||
void Draw(const glm::mat4& model, SkeletonInstance* instance = nullptr);
|
||||
|
||||
@@ -69,7 +70,6 @@ private:
|
||||
std::vector<ModelData_t> m_meshes;
|
||||
|
||||
BoundingBox m_boundingBox;
|
||||
Texture2D* m_AlbedoTexture;
|
||||
|
||||
int m_numPoses;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user