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