add normal to VertexData
This commit is contained in:
parent
5c2f5503fc
commit
948578f506
|
@ -21,6 +21,7 @@ struct VertexData
|
|||
{
|
||||
QVector3D position;
|
||||
QVector2D texCoord;
|
||||
QVector3D normal;
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
|
|
|
@ -10,6 +10,7 @@ uniform mat4 m_matrix;
|
|||
|
||||
attribute vec4 a_position;
|
||||
attribute vec2 a_texcoord;
|
||||
attribute vec3 a_normal;
|
||||
|
||||
varying vec2 v_texcoord;
|
||||
|
||||
|
|
|
@ -196,6 +196,14 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
|||
program->enableAttributeArray(texcoordLocation);
|
||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||
|
||||
//Offset for normal
|
||||
offset += sizeof(QVector2D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex normal data
|
||||
int normLocation = program->attributeLocation("a_normal");
|
||||
program->enableAttributeArray(normLocation);
|
||||
program->setAttributeBuffer(normLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Paint
|
||||
|
||||
for (auto& it : m_drawList)
|
||||
|
|
|
@ -384,15 +384,31 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
|
|||
}
|
||||
|
||||
// normals
|
||||
/*else if (!strcmp("NRML", it->name))
|
||||
else if (!strcmp("NRML", it->name))
|
||||
{
|
||||
fsMesh.seekg(it->position);
|
||||
std::uint32_t tempSize;
|
||||
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
||||
// List of normals
|
||||
// long int - 4 - number of normal vectores stored in this list
|
||||
// float[3][] - 12 each - UVW vector for each vertex
|
||||
}*/
|
||||
std::uint32_t tmp_size;
|
||||
m_file.seekg(it->position);
|
||||
m_file.read(F2V(tmp_size), sizeof(tmp_size));
|
||||
|
||||
if (tmp_size < new_segment->vertices.size())
|
||||
{
|
||||
emit sendMessage("WARNING: too less normals " + QString::number(tmp_size) + " < " + QString::number(new_segment->vertices.size()), 1);
|
||||
|
||||
for (unsigned int i = new_segment->vertices.size(); i != tmp_size; i--)
|
||||
for (unsigned int j = 0; j < 3; j++)
|
||||
new_segment->vertices[i - 1].normal[j] = 0;
|
||||
}
|
||||
else if (tmp_size > new_segment->vertices.size())
|
||||
{
|
||||
emit sendMessage("WARNING: too many normals " + QString::number(tmp_size) + " > " + QString::number(new_segment->vertices.size()), 1);
|
||||
tmp_size = new_segment->vertices.size();
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < tmp_size; i++)
|
||||
for (unsigned int j = 0; j < 3; j++)
|
||||
m_file.read(F2V(new_segment->vertices[i].normal[j]), sizeof(float));
|
||||
|
||||
}
|
||||
|
||||
// uv
|
||||
else if (!strcmp("UV0L", it->name))
|
||||
|
@ -584,12 +600,9 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
|
|||
}
|
||||
|
||||
for (unsigned int i = 0; i < tmp_size; i++)
|
||||
{
|
||||
float tmp[2];
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue