fixed crash
This commit is contained in:
parent
ee8705f9e4
commit
9a5d09b80c
|
@ -31,4 +31,6 @@ private:
|
|||
|
||||
void readVertex(Segment* dataDestination, std::streampos position);
|
||||
void readUV(Segment* dataDestination, std::streampos position);
|
||||
|
||||
QMatrix4x4 getParentMatrix(std::string parent) const;
|
||||
};
|
|
@ -26,7 +26,7 @@ GeometryEngine::~GeometryEngine()
|
|||
for (auto it : m_textures)
|
||||
delete it;
|
||||
m_textures.clear();
|
||||
m_textures.squeeze();
|
||||
m_drawList.clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,11 +41,49 @@ void GeometryEngine::initCubeGeometry()
|
|||
|
||||
try
|
||||
{
|
||||
MshFile file("..\\Release\\Msh\\sphere.msh");
|
||||
MshFile file("..\\Release\\Msh\\triClothMan.msh");
|
||||
models = file.getModels();
|
||||
//TODO use models local, apply MVP directly to the vertex, save size and tex index info
|
||||
|
||||
//TODO normalize
|
||||
//TODO: handle the textures
|
||||
|
||||
// collect data
|
||||
unsigned int offsetCount(0);
|
||||
for (auto& modelIterator : *models)
|
||||
{
|
||||
for (auto& segmentIterator : modelIterator->segmList)
|
||||
{
|
||||
// get draw information
|
||||
DrawInformation new_info;
|
||||
new_info.offset = offsetCount;
|
||||
new_info.size = segmentIterator->indices.size();
|
||||
new_info.textureIndex = segmentIterator->textureIndex;
|
||||
new_info.modelMatrix = modelIterator->m4x4Translation;
|
||||
|
||||
// add offset to indices
|
||||
for (auto& it : segmentIterator->indices)
|
||||
it += new_info.offset;
|
||||
|
||||
// save data
|
||||
vertexData += segmentIterator->vertices;
|
||||
indexData += segmentIterator->indices;
|
||||
m_drawList.push_back(new_info);
|
||||
|
||||
// update offset
|
||||
offsetCount += new_info.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer vertex data to VBO 0
|
||||
m_arrayBuf.bind();
|
||||
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
|
||||
|
||||
// Transfer index data to VBO 1
|
||||
m_indexBuf.bind();
|
||||
m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint));
|
||||
|
||||
// load the texture
|
||||
initTexture();
|
||||
|
||||
}
|
||||
catch (std::invalid_argument e)
|
||||
{
|
||||
|
@ -53,43 +91,7 @@ void GeometryEngine::initCubeGeometry()
|
|||
auto msg = e.what();
|
||||
}
|
||||
|
||||
// collect data
|
||||
unsigned int offsetCount(0);
|
||||
for (auto& modelIterator : *models)
|
||||
{
|
||||
for (auto& segmentIterator : modelIterator->segmList)
|
||||
{
|
||||
// get draw information
|
||||
DrawInformation new_info;
|
||||
new_info.offset = offsetCount;
|
||||
new_info.size = segmentIterator->indices.size();
|
||||
new_info.textureIndex = segmentIterator->textureIndex;
|
||||
new_info.modelMatrix = modelIterator->m4x4Translation;
|
||||
|
||||
// add offset to indices
|
||||
for (auto& it : segmentIterator->indices)
|
||||
it += new_info.offset;
|
||||
|
||||
// save data
|
||||
vertexData += segmentIterator->vertices;
|
||||
indexData += segmentIterator->indices;
|
||||
m_drawList.push_back(new_info);
|
||||
|
||||
// update offset
|
||||
offsetCount += new_info.size;
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer vertex data to VBO 0
|
||||
m_arrayBuf.bind();
|
||||
m_arrayBuf.allocate(vertexData.data(),vertexData.size() * sizeof(VertexData));
|
||||
|
||||
// Transfer index data to VBO 1
|
||||
m_indexBuf.bind();
|
||||
m_indexBuf.allocate(indexData.data(), indexData.size() * sizeof(GLuint));
|
||||
|
||||
// load the texture
|
||||
initTexture();
|
||||
|
||||
}
|
||||
|
||||
void GeometryEngine::initTexture()
|
||||
|
@ -146,9 +148,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
|||
{
|
||||
// bind the correct texture
|
||||
if (it.textureIndex < m_textures.size())
|
||||
m_textures.last()->bind();
|
||||
else
|
||||
m_textures.at(it.textureIndex)->bind();
|
||||
else
|
||||
m_textures.last()->bind();
|
||||
|
||||
// Set model matrix
|
||||
program->setUniformValue("m_matrix", it.modelMatrix);
|
||||
|
|
|
@ -17,6 +17,7 @@ MshFile::MshFile(const char * path)
|
|||
|
||||
MshFile::~MshFile()
|
||||
{
|
||||
//TODO: clean up
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,6 +295,8 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>
|
|||
dataDestination->m4x4Translation.rotate(QQuaternion(tmp_rotation[3], tmp_rotation[0], tmp_rotation[1], tmp_rotation[2]));
|
||||
dataDestination->m4x4Translation.translate(tmp_trans[0], tmp_trans[1], tmp_trans[2]);
|
||||
|
||||
dataDestination->m4x4Translation = getParentMatrix(dataDestination->parent) * dataDestination->m4x4Translation;
|
||||
|
||||
}
|
||||
|
||||
// geometry data
|
||||
|
@ -604,4 +607,21 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
|
|||
for (unsigned int j = 0; j < 2; j++)
|
||||
m_file.read(F2V(dataDestination->vertices[i].texCoord[j]), sizeof(float));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QMatrix4x4 MshFile::getParentMatrix(std::string parent) const
|
||||
{
|
||||
QMatrix4x4 matrix;
|
||||
|
||||
for (auto& it : *m_models)
|
||||
{
|
||||
if (!strcmp(parent.c_str(), it->name.c_str()))
|
||||
{
|
||||
//TODO: the other way around??
|
||||
matrix = getParentMatrix(it->parent) * it->m4x4Translation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue