Read the material name and save it,

Shorten transparency evaluation,
Need to:
- read in the data values,
- save the texture name somewhere else,
- use the data :D
This commit is contained in:
C-Fu 2017-01-20 11:18:48 +01:00
parent eb0592373f
commit abd9070e90
1 changed files with 31 additions and 41 deletions

View File

@ -217,7 +217,24 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
for (auto& it : chunkList)
{
// TODO: don't load default texture, make it NULL
// name
if (!strcmp("NAME", it->name))
{
m_file.seekg(it->position);
char* buffer = new char[it->size + 1];
*buffer = { 0 };
m_file.read(buffer, it->size);
m_materials->back().name = buffer;
delete[] buffer;
}
// TODO: read the data information
// data
else if(!strcmp("DATA", it->name))
{
}
// TODO: use diffuse color instead of default texture
//TODO: get information from flags
// attributes
if (!strcmp("ATRB", it->name))
@ -235,10 +252,9 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
std::cout << "specular" << std::endl;
}
// additive transparency
if ((flag << 1) >> 7)
// additive transparency || hard edged transparency || double-sided transparency || single-sided transparency
if ((flag << 1) >> 7 || (flag << 3) >> 7 || (flag << 4) >> 7 || (flag << 5) >> 7)
{
std::cout << "additive transparency" << std::endl;
m_materials->back().transparent = true;
}
// per-pixel lighting
@ -246,24 +262,6 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
std::cout << "per-pixel lighting" << std::endl;
}
// hard-edged transparency
if ((flag << 3) >> 7)
{
std::cout << "hard-edged transparency" << std::endl;
m_materials->back().transparent = true;
}
// double-sided transparency
if ((flag << 4) >> 7)
{
std::cout << "double-sided transparency" << std::endl;
m_materials->back().transparent = true;
}
// single-sided transparency
if ((flag << 5) >> 7)
{
std::cout << "single-sided transparency" << std::endl;
m_materials->back().transparent = true;
}
// glow
if ((flag << 6) >> 7)
{
@ -274,10 +272,9 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
std::cout << "emissive" << std::endl;
}
}
// texture name
// texture zero
else if (!strcmp("TX0D", it->name))
{
// get the texture name
@ -285,14 +282,13 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
char* buffer = new char[it->size + 1];
*buffer = { 0 };
m_file.read(buffer, it->size);
m_materials->back().name = buffer;
QString texName(buffer);
delete[] buffer;
// load the texture
if (m_materials->back().name.isEmpty())
loadTexture(m_materials->back().texture, "");
else
loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().name);
// load the texture if the name is not empty
// TODO: save filename for the output
if (!texName.isEmpty())
loadTexture(m_materials->back().texture, m_filepath + "/" + texName);
}
}
}
@ -686,19 +682,13 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath)
{
bool loadSuccess(false);
QImage img;
if (filepath.isEmpty())
{
loadSuccess = true;
img = QImage(1, 1, QImage::Format_RGB32);
img.fill(Qt::red);
}
else
img = loadTga(filepath, loadSuccess);
QImage img = loadTga(filepath, loadSuccess);
if (!loadSuccess)
{
emit sendMessage("WARNING: texture not found or corrupted: " + m_materials->back().name, 1);
return;
}
// Load image to OglTexture
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());