Non-skined mesh WIP
This commit is contained in:
@@ -16,8 +16,9 @@ public:
|
||||
~Model();
|
||||
const std::vector<RawModel::MaterialGroup>& MaterialGroups() const { return m_RawModel->MaterialGroups; }
|
||||
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; }
|
||||
const std::vector<RawModel::Vertex>& Vertices() const { return m_RawModel->m_Vertices; }
|
||||
|
||||
const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
|
||||
unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); }
|
||||
bool isSkined() const { return m_RawModel->isSkined; }
|
||||
GLuint VAO;
|
||||
GLuint ElementBuffer;
|
||||
RawModel* m_RawModel;
|
||||
|
||||
@@ -40,6 +40,9 @@ public:
|
||||
glm::vec3 Tangent;
|
||||
glm::vec3 BiNormal;
|
||||
glm::vec2 TextureCoords;
|
||||
};
|
||||
|
||||
struct SkinedVertex : public Vertex {
|
||||
glm::vec4 BoneIndices;
|
||||
glm::vec4 BoneWeights;
|
||||
};
|
||||
@@ -64,15 +67,33 @@ public:
|
||||
std::shared_ptr<::Texture> IncandescenceMap;
|
||||
};
|
||||
|
||||
std::vector<MaterialGroup> MaterialGroups;
|
||||
const Vertex* Vertices() const {
|
||||
if (isSkined) {
|
||||
return m_SkinedVertices.data();
|
||||
} else {
|
||||
return m_Vertices.data();
|
||||
}
|
||||
};
|
||||
|
||||
unsigned int NumVertices() const {
|
||||
if (isSkined) {
|
||||
return m_SkinedVertices.size();
|
||||
} else {
|
||||
return m_Vertices.size();
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<MaterialGroup> MaterialGroups;
|
||||
bool isSkined;
|
||||
|
||||
std::vector<Vertex> m_Vertices;
|
||||
std::vector<unsigned int> m_Indices;
|
||||
Skeleton* m_Skeleton = nullptr;
|
||||
glm::mat4 m_Matrix;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Vertex> m_Vertices;
|
||||
std::vector<SkinedVertex> m_SkinedVertices;
|
||||
|
||||
void ReadMeshFile(std::string filePath);
|
||||
void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||
|
||||
@@ -269,7 +269,8 @@ bool attachAABBComponentFromModel(World* world, EntityID id)
|
||||
|
||||
glm::vec3 mini = glm::vec3(INFINITY, INFINITY, INFINITY);
|
||||
glm::vec3 maxi = glm::vec3(-INFINITY, -INFINITY, -INFINITY);
|
||||
for (const auto& v : modelRes->Vertices()) {
|
||||
for (unsigned int i = 0; i < modelRes->NumberOfVertices(); i++) {
|
||||
const auto& v = modelRes->Vertices()[i];
|
||||
const auto& wPos = modelMatrix * glm::vec4(v.Position.x, v.Position.y, v.Position.z, 1);
|
||||
maxi.x = std::max(wPos.x, maxi.x);
|
||||
maxi.y = std::max(wPos.y, maxi.y);
|
||||
|
||||
@@ -24,7 +24,12 @@ Model::Model(std::string fileName)
|
||||
GLuint buffer;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->m_Vertices.size() * sizeof(RawModel::Vertex), &m_RawModel->m_Vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
if (m_RawModel->isSkined) {
|
||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * sizeof(RawModel::SkinedVertex), m_RawModel->Vertices(), GL_STATIC_DRAW);
|
||||
} else {
|
||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * sizeof(RawModel::Vertex), m_RawModel->Vertices(), GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
glGenBuffers(1, &ElementBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||
@@ -35,7 +40,13 @@ Model::Model(std::string fileName)
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||
std::vector<int> structSizes;
|
||||
if (m_RawModel->isSkined) {
|
||||
structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||
} else {
|
||||
structSizes = { 3, 3, 3, 3, 2 };
|
||||
}
|
||||
|
||||
int stride = 0;
|
||||
for (int size : structSizes) {
|
||||
stride += size;
|
||||
@@ -49,9 +60,11 @@ Model::Model(std::string fileName)
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
if (m_RawModel->isSkined) {
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
}
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
@@ -59,8 +72,10 @@ Model::Model(std::string fileName)
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
if (m_RawModel->isSkined) {
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
//CreateBuffers();
|
||||
|
||||
@@ -40,7 +40,14 @@ void RawModelCustom::ReadMeshFile(std::string filePath)
|
||||
void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
isSkined = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(bool);
|
||||
if (isSkined) {
|
||||
m_SkinedVertices.resize(*(unsigned int*)(fileData + offset));
|
||||
}
|
||||
else {
|
||||
m_Vertices.resize(*(unsigned int*)(fileData + offset));
|
||||
}
|
||||
offset += sizeof(unsigned int);
|
||||
m_Indices.resize(*(unsigned int*)(fileData + offset));
|
||||
offset += sizeof(unsigned int);
|
||||
@@ -57,12 +64,19 @@ void RawModelCustom::ReadMesh(unsigned int& offset, char* fileData, unsigned int
|
||||
void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
if (isSkined) {
|
||||
if (offset + m_SkinedVertices.size() * sizeof(SkinedVertex) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading skined vertices failed");
|
||||
}
|
||||
memcpy(&m_SkinedVertices[0], fileData + offset, m_Vertices.size() * sizeof(SkinedVertex));
|
||||
offset += m_SkinedVertices.size() * sizeof(SkinedVertex);
|
||||
} else {
|
||||
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading vertices failed");
|
||||
}
|
||||
|
||||
memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex));
|
||||
offset += m_Vertices.size() * sizeof(Vertex);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user