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