Commit for Pull
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "Core/Ray.h"
|
||||
#include "Core/AABB.h"
|
||||
#include "Engine/Rendering/RawModel.h"
|
||||
#include "Engine/Rendering/RawModelAssimp.h"
|
||||
#include "Core/Entity.h"
|
||||
|
||||
class World;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef Model_h__
|
||||
#define Model_h__
|
||||
|
||||
#include "RawModel.h"
|
||||
#include "RawModelAssimp.h"
|
||||
#include "../OpenGL.h"
|
||||
|
||||
class Model : public RawModel
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef RawModel_h__
|
||||
#define RawModel_h__
|
||||
#ifndef RawModelAssimp_h__
|
||||
#define RawModelAssimp_h__
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -23,7 +23,7 @@ class RawModel : public Resource
|
||||
friend class ResourceManager;
|
||||
|
||||
protected:
|
||||
RawModel(std::string fileName);
|
||||
RawModel(std::string fileName);
|
||||
|
||||
public:
|
||||
~RawModel();
|
||||
@@ -33,14 +33,10 @@ public:
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec3 Tangent;
|
||||
glm::vec3 BiTangent;
|
||||
glm::vec3 BiNormal;
|
||||
glm::vec2 TextureCoords;
|
||||
glm::vec4 DiffuseVertexColor;
|
||||
glm::vec4 SpecularVertexColor;
|
||||
glm::vec4 BoneIndices1;
|
||||
glm::vec4 BoneIndices2;
|
||||
glm::vec4 BoneWeights1;
|
||||
glm::vec4 BoneWeights2;
|
||||
glm::vec4 BoneIndices;
|
||||
glm::vec4 BoneWeights;
|
||||
};
|
||||
|
||||
struct MaterialGroup
|
||||
@@ -64,8 +60,6 @@ private:
|
||||
std::vector<glm::ivec2> BoneIndices;
|
||||
std::vector<glm::vec2> BoneWeights;
|
||||
std::vector<glm::vec3> Normals;
|
||||
std::vector<glm::vec4> DiffuseVertexColor;
|
||||
std::vector<glm::vec4> SpecularVertexColor;
|
||||
std::vector<glm::vec3> TangentNormals;
|
||||
std::vector<glm::vec3> BiTangentNormals;
|
||||
std::vector<glm::vec2> TextureCoords;
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef RawModelCustom_h__
|
||||
#define RawModelCustom_h__
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "../Common.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
#include "Texture.h"
|
||||
#include "Skeleton.h"
|
||||
|
||||
#include "boost\endian\buffers.hpp"
|
||||
|
||||
class RawModel : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
protected:
|
||||
RawModel(std::string fileName);
|
||||
|
||||
public:
|
||||
~RawModel();
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec3 Tangent;
|
||||
glm::vec3 BiNormal;
|
||||
glm::vec2 TextureCoords;
|
||||
glm::vec4 BoneIndices;
|
||||
glm::vec4 BoneWeights;
|
||||
};
|
||||
|
||||
struct MaterialGroup
|
||||
{
|
||||
float Shininess;
|
||||
std::shared_ptr<::Texture> Texture;
|
||||
std::shared_ptr<::Texture> NormalMap;
|
||||
std::shared_ptr<::Texture> SpecularMap;
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
};
|
||||
|
||||
std::vector<MaterialGroup> TextureGroups;
|
||||
|
||||
std::vector<Vertex> m_Vertices;
|
||||
std::vector<unsigned int> m_Indices;
|
||||
Skeleton* m_Skeleton = nullptr;
|
||||
glm::mat4 m_Matrix;
|
||||
|
||||
private:
|
||||
|
||||
bool ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||
bool ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||
bool ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||
bool ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||
|
||||
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -18,7 +18,7 @@ Model::Model(std::string fileName)
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4, 4, 4, 4, 4 };
|
||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||
int stride = 0;
|
||||
for (int size : structSizes) {
|
||||
stride += size;
|
||||
@@ -34,10 +34,6 @@ 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++;
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
@@ -48,10 +44,6 @@ Model::Model(std::string fileName)
|
||||
glEnableVertexAttribArray(4);
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
glEnableVertexAttribArray(7);
|
||||
glEnableVertexAttribArray(8);
|
||||
glEnableVertexAttribArray(9);
|
||||
glEnableVertexAttribArray(10);
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
//CreateBuffers();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Rendering/RawModel.h"
|
||||
#include "Rendering/RawModelAssimp.h"
|
||||
|
||||
RawModel::RawModel(std::string fileName)
|
||||
{
|
||||
@@ -38,7 +38,7 @@ RawModel::RawModel(std::string fileName)
|
||||
//LOG_DEBUG("Index count %i", numIndices);
|
||||
|
||||
//LOG_DEBUG("Model has %i embedded textures", scene->mNumTextures);
|
||||
|
||||
|
||||
std::vector<std::tuple<std::string, glm::mat4>> boneInfo;
|
||||
std::map<std::string, int> boneNameMapping;
|
||||
|
||||
@@ -75,17 +75,6 @@ RawModel::RawModel(std::string fileName)
|
||||
desc.TextureCoords = glm::vec2(uv.x, uv.y);
|
||||
}
|
||||
|
||||
// Material diffuse color
|
||||
aiColor3D diffuse;
|
||||
material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse);
|
||||
float opacity;
|
||||
material->Get(AI_MATKEY_OPACITY, opacity);
|
||||
desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, opacity);
|
||||
// Material specular color
|
||||
aiColor3D specular;
|
||||
material->Get(AI_MATKEY_COLOR_SPECULAR, specular);
|
||||
desc.SpecularVertexColor = glm::vec4(specular.r, specular.g, specular.b, 1.f);
|
||||
|
||||
m_Vertices.push_back(desc);
|
||||
}
|
||||
|
||||
@@ -125,7 +114,7 @@ RawModel::RawModel(std::string fileName)
|
||||
}
|
||||
for (auto& vertex : m_Vertices) {
|
||||
vertex.Tangent = glm::normalize(vertex.Tangent);
|
||||
vertex.BiTangent = glm::normalize(glm::cross(vertex.Tangent, glm::normalize(vertex.Normal)));
|
||||
vertex.BiNormal = glm::normalize(glm::cross(vertex.Tangent, glm::normalize(vertex.Normal)));
|
||||
}
|
||||
|
||||
// Material info
|
||||
@@ -203,10 +192,7 @@ RawModel::RawModel(std::string fileName)
|
||||
LOG_WARNING("Vertex weights (%i) greater than max weights per vertex (%i)", weights.size(), maxWeights);
|
||||
}
|
||||
for (int weightIndex = 0; weightIndex < weights.size() && weightIndex < maxWeights && weightIndex < 4; ++weightIndex) {
|
||||
std::tie(desc.BoneIndices1[weightIndex], desc.BoneWeights1[weightIndex]) = weights[weightIndex];
|
||||
}
|
||||
for (int weightIndex = 4; weightIndex < weights.size() && weightIndex < maxWeights && weightIndex < 8; ++weightIndex) {
|
||||
std::tie(desc.BoneIndices2[weightIndex - 4], desc.BoneWeights2[weightIndex - 4]) = weights[weightIndex];
|
||||
std::tie(desc.BoneIndices[weightIndex], desc.BoneWeights[weightIndex]) = weights[weightIndex];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "Rendering\RawModelCustom.h"
|
||||
|
||||
RawModel::RawModel(std::string fileName)
|
||||
{
|
||||
boost::endian::big_int16_buf_t* test;
|
||||
int16_t tal;
|
||||
test = &(boost::endian::big_int16_buf_t)tal;
|
||||
|
||||
char* fileData;
|
||||
std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate);
|
||||
|
||||
if (!in.is_open())
|
||||
LOG_ERROR("Failed to load custom binary model \"%s\"", fileName.c_str());
|
||||
|
||||
unsigned int fileByteSize = in.tellg();
|
||||
in.seekg(0, std::ios_base::beg);
|
||||
|
||||
fileData = new char[fileByteSize];
|
||||
in.read(fileData, fileByteSize);
|
||||
in.close();
|
||||
|
||||
unsigned int offset = 0;
|
||||
ReadMeshFileHeader(offset, fileData, fileByteSize);
|
||||
ReadMesh(offset, fileData, fileByteSize);
|
||||
|
||||
}
|
||||
|
||||
bool RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
m_Vertices.resize(*fileData);
|
||||
offset += sizeof(unsigned int);
|
||||
m_Indices.resize(*(fileData + offset));
|
||||
offset += sizeof(unsigned int);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
ReadVertices(offset, fileData, fileByteSize);
|
||||
ReadIndices(offset, fileData, fileByteSize);
|
||||
}
|
||||
|
||||
bool RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
memcpy(&m_Vertices[0], fileData, m_Vertices.size() * sizeof(Vertex));
|
||||
offset += m_Vertices.size() * sizeof(Vertex);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
memcpy(&m_Indices[0], fileData, m_Indices.size() * sizeof(unsigned int));
|
||||
offset += m_Indices.size() * sizeof(unsigned int);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
RawModel::~RawModel()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -92,12 +92,12 @@ Mesh MeshClass::GetMeshData(MObject object)
|
||||
double biTangent[3];
|
||||
double biNormal[3];
|
||||
VertexLayout thisVertex;
|
||||
MFloatVectorArray biTangents;
|
||||
MFloatVectorArray Tangents;
|
||||
MFloatVectorArray biNormals;
|
||||
|
||||
std::map<int, WeightInfo> vertexWeights = GetWeightData();
|
||||
|
||||
mesh.getTangents(biTangents, MSpace::kObject, NULL);
|
||||
mesh.getTangents(Tangents, MSpace::kObject, NULL);
|
||||
mesh.getBinormals(biNormals, MSpace::kObject, NULL);
|
||||
|
||||
MItMeshFaceVertex faceVert(object);
|
||||
@@ -123,12 +123,12 @@ Mesh MeshClass::GetMeshData(MObject object)
|
||||
thisVertex.Normal[1] = normal[1];
|
||||
thisVertex.Normal[2] = normal[2];
|
||||
|
||||
MFloatVector biTangent = biTangents[faceVert.tangentId()];
|
||||
MFloatVector Tangent = Tangents[faceVert.tangentId()];
|
||||
//MVector tmp = faceVert.getTangent(MSpace::kObject, NULL);
|
||||
//tmp.get(biTangent);
|
||||
thisVertex.BiTangent[0] = biTangent[0];
|
||||
thisVertex.BiTangent[1] = biTangent[1];
|
||||
thisVertex.BiTangent[2] = biTangent[2];
|
||||
thisVertex.Tangent[0] = Tangent[0];
|
||||
thisVertex.Tangent[1] = Tangent[1];
|
||||
thisVertex.Tangent[2] = Tangent[2];
|
||||
|
||||
MFloatVector biNormal = biNormals[faceVert.tangentId()];
|
||||
//faceVert.getBinormal().get(biNormal);
|
||||
|
||||
@@ -12,8 +12,8 @@ class VertexLayout : public OutputData
|
||||
public:
|
||||
float Pos[3];
|
||||
float Normal[3];
|
||||
float Tangent[3];
|
||||
float BiNormal[3];
|
||||
float BiTangent[3];
|
||||
float Uv[2];
|
||||
float BoneIndices[4];
|
||||
float BoneWeights[4];
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
{
|
||||
out.write((char*)&Pos, sizeof(float) * 3);
|
||||
out.write((char*)&Normal, sizeof(float) * 3);
|
||||
out.write((char*)&BiNormal, sizeof(float) * 3);
|
||||
out.write((char*)&Tangent, sizeof(float) * 3);
|
||||
out.write((char*)&BiTangent, sizeof(float) * 3);
|
||||
out.write((char*)&Uv, sizeof(float) * 2);
|
||||
out.write((char*)&BoneIndices, sizeof(float) * 4);
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
{
|
||||
out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl;
|
||||
out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl;
|
||||
out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl;
|
||||
out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl;
|
||||
out << BiTangent[0] << " " << BiTangent[1] << " " << BiTangent[2] << endl;
|
||||
out << Uv[0] << " " << Uv[1] << endl;
|
||||
out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl;
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
return
|
||||
this->Pos[0] == right.Pos[0] && this->Pos[1] == right.Pos[1] && this->Pos[2] == right.Pos[2] &&
|
||||
this->Normal[0] == right.Normal[0] && this->Normal[1] == right.Normal[1] && this->Normal[2] == right.Normal[2] &&
|
||||
this->BiNormal[0] == right.BiNormal[0] && this->BiNormal[1] == right.BiNormal[1] && this->BiNormal[2] == right.BiNormal[2] &&
|
||||
this->Tangent[0] == right.Tangent[0] && this->Tangent[1] == right.Tangent[1] && this->Tangent[2] == right.Tangent[2] &&
|
||||
this->BiTangent[0] == right.BiTangent[0] && this->BiTangent[1] == right.BiTangent[1] && this->BiTangent[2] == right.BiTangent[2] &&
|
||||
this->Uv[0] == right.Uv[0] && this->Uv[1] == right.Uv[1] &&
|
||||
this->BoneIndices[0] == right.BoneIndices[0] && this->BoneIndices[1] == right.BoneIndices[1] && this->BoneIndices[2] == right.BoneIndices[2] && this->BoneIndices[3] == right.BoneIndices[3] &&
|
||||
|
||||
Reference in New Issue
Block a user