This commit is contained in:
2026-03-05 15:20:18 +03:00
parent 70c3459703
commit f8f69d3b88
25 changed files with 261 additions and 31 deletions

View File

@@ -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)