Added Model and related classes
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#ifndef BaseTexture_h__
|
||||
#define BaseTexture_h__
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <cstdio>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Rendering/PNG.h"
|
||||
|
||||
class BaseTexture : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
public:
|
||||
unsigned int Width = 0;
|
||||
unsigned int Height = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef Model_h__
|
||||
#define Model_h__
|
||||
|
||||
#include "Rendering/RawModel.h"
|
||||
|
||||
class Model : public RawModel
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
private:
|
||||
Model(std::string fileName);
|
||||
|
||||
public:
|
||||
~Model();
|
||||
|
||||
GLuint VAO;
|
||||
GLuint ElementBuffer;
|
||||
|
||||
private:
|
||||
GLuint VertexBuffer;
|
||||
GLuint DiffuseVertexColorBuffer;
|
||||
GLuint SpecularVertexColorBuffer;
|
||||
GLuint NormalBuffer;
|
||||
GLuint TangentNormalsBuffer;
|
||||
GLuint BiTangentNormalsBuffer;
|
||||
GLuint TextureCoordBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef PNG_h_
|
||||
#define PNG_h_
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
class PNG : public Image
|
||||
{
|
||||
public:
|
||||
PNG(std::string path);
|
||||
~PNG();
|
||||
|
||||
private:
|
||||
static void pngErrorFunction(png_structp png_ptr, png_const_charp error_msg);
|
||||
static void pngWarningFunction(png_structp png_ptr, png_const_charp warning_msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef RawModel_h__
|
||||
#define RawModel_h__
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Rendering/Texture.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
|
||||
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 BiTangent;
|
||||
glm::vec2 TextureCoords;
|
||||
glm::vec4 DiffuseVertexColor;
|
||||
glm::vec4 SpecularVertexColor;
|
||||
glm::vec4 BoneIndices1;
|
||||
glm::vec4 BoneIndices2;
|
||||
glm::vec4 BoneWeights1;
|
||||
glm::vec4 BoneWeights2;
|
||||
};
|
||||
|
||||
struct MaterialGroup
|
||||
{
|
||||
float Shininess;
|
||||
std::shared_ptr<dd::Texture> Texture;
|
||||
std::shared_ptr<dd::Texture> NormalMap;
|
||||
std::shared_ptr<dd::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:
|
||||
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;
|
||||
|
||||
void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
#ifndef Skeleton_h__
|
||||
#define Skeleton_h__
|
||||
|
||||
#include <sstream>
|
||||
|
||||
//struct Bone
|
||||
//{
|
||||
// Bone(std::string name, glm::mat4 offsetMatrix)
|
||||
// : Name(name)
|
||||
// , OffsetMatrix(offsetMatrix)
|
||||
// { }
|
||||
//
|
||||
// ~Bone()
|
||||
// {
|
||||
// for (auto kv : Children) {
|
||||
// delete kv.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::string Name;
|
||||
// glm::mat4 OffsetMatrix;
|
||||
// glm::mat4 LocalMatrix;
|
||||
//
|
||||
// std::map<std::string, Bone*> Children;
|
||||
//};
|
||||
|
||||
class Skeleton
|
||||
{
|
||||
public:
|
||||
struct Bone
|
||||
{
|
||||
Bone(int id, Bone* parent, std::string name, glm::mat4 offsetMatrix)
|
||||
: ID(id)
|
||||
, Parent(parent)
|
||||
, Name(name)
|
||||
, OffsetMatrix(offsetMatrix)
|
||||
{ }
|
||||
|
||||
int ID;
|
||||
std::string Name;
|
||||
glm::mat4 OffsetMatrix;
|
||||
|
||||
Bone* Parent;
|
||||
std::vector<Bone*> Children;
|
||||
};
|
||||
|
||||
struct Animation
|
||||
{
|
||||
struct Keyframe
|
||||
{
|
||||
struct BoneProperty
|
||||
{
|
||||
int ID;
|
||||
glm::vec3 Position;
|
||||
glm::quat Rotation;
|
||||
glm::vec3 Scale = glm::vec3(1);
|
||||
};
|
||||
|
||||
int Index = 0;
|
||||
double Time = 0.0;
|
||||
std::map<int, Keyframe::BoneProperty> BoneProperties;
|
||||
};
|
||||
|
||||
std::string Name;
|
||||
double Duration;
|
||||
std::vector<Keyframe> Keyframes;
|
||||
};
|
||||
|
||||
Skeleton() { }
|
||||
~Skeleton();
|
||||
|
||||
Bone* RootBone;
|
||||
|
||||
std::map<int, Bone*> Bones;
|
||||
|
||||
// Attach a new bone to the skeleton
|
||||
// Returns: New bone index
|
||||
int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix);
|
||||
|
||||
int GetBoneID(std::string name);
|
||||
|
||||
const Animation* GetAnimation(std::string name);
|
||||
std::vector<glm::mat4> GetFrameBones(const Animation& animation, double time, bool noRootMotion = false);
|
||||
void AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe& currentFrame, const Animation::Keyframe& nextFrame, float progress, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||
void PrintSkeleton();
|
||||
void PrintSkeleton(const Bone* parent, int depthCount);
|
||||
std::map<std::string, Animation> Animations;
|
||||
|
||||
private:
|
||||
std::map<std::string, Bone*> m_BonesByName;
|
||||
|
||||
int GetKeyframe(const Animation& animation, double time);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef Texture_h__
|
||||
#define Texture_h__
|
||||
|
||||
#include "Rendering/BaseTexture.h"
|
||||
|
||||
class Texture : public BaseTexture
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
private:
|
||||
Texture(std::string path);
|
||||
|
||||
public:
|
||||
~Texture();
|
||||
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
GLuint m_Texture = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user