First commit.
This commit is contained in:
40
include/IO/Model/AnimBone.h
Normal file
40
include/IO/Model/AnimBone.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "KeyFrame.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class AnimBone
|
||||
{
|
||||
private:
|
||||
UInt_8 boneId;
|
||||
Array<KeyFrame> keyFrames;
|
||||
|
||||
public:
|
||||
AnimBone();
|
||||
|
||||
AnimBone(const UInt_8 boneId);
|
||||
|
||||
AnimBone(const UInt_8 boneId, const UInt_64 size);
|
||||
|
||||
AnimBone(const UInt_8 boneId, Array<KeyFrame> keyFrames);
|
||||
|
||||
AnimBone(AnimBone&& anim) noexcept;
|
||||
|
||||
AnimBone(const AnimBone& anim);
|
||||
|
||||
AnimBone& operator=(AnimBone&& anim) noexcept;
|
||||
|
||||
AnimBone& operator=(const AnimBone& anim);
|
||||
|
||||
UInt_8 GetBoneId() const;
|
||||
|
||||
Array<KeyFrame> GetKeyFrames() const;
|
||||
|
||||
Array<KeyFrame>& GetKeyFrames();
|
||||
|
||||
float GetPrevAndNext(KeyFrame& prev, KeyFrame& next, const float elapsed) const;
|
||||
};
|
||||
}
|
49
include/IO/Model/Animation.h
Normal file
49
include/IO/Model/Animation.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Str.h"
|
||||
#include "../../Array.h"
|
||||
#include "AnimBone.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Animation
|
||||
{
|
||||
private:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
float duration;
|
||||
Array<AnimBone> animated;
|
||||
|
||||
public:
|
||||
Animation();
|
||||
|
||||
Animation(Str_8 id, const float duration);
|
||||
|
||||
Animation(Str_8 id, const float duration, UInt_64 size);
|
||||
|
||||
Animation(Str_8 id, const float duration, Array<AnimBone> animated);
|
||||
|
||||
Animation(Animation&& anim) noexcept;
|
||||
|
||||
Animation(const Animation& anim);
|
||||
|
||||
Animation& operator=(Animation&& anim) noexcept;
|
||||
|
||||
Animation& operator=(const Animation& anim);
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
float GetDuration() const;
|
||||
|
||||
Array<AnimBone> GetAnimated() const;
|
||||
|
||||
Array<AnimBone>& GetAnimated();
|
||||
|
||||
Array<Mat4_f> Interpolate(const UInt_64 boneCount, const float elapsed) const;
|
||||
};
|
||||
}
|
73
include/IO/Model/Bone.h
Normal file
73
include/IO/Model/Bone.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Quat.h"
|
||||
#include "../../Mat4.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class Bone
|
||||
{
|
||||
private:
|
||||
UInt_64 hashName;
|
||||
Str_8 name;
|
||||
UInt_8 id;
|
||||
Mat4_f animTrans;
|
||||
Mat4_f localBindTrans;
|
||||
Mat4_f invBindTrans;
|
||||
Array<Bone> children;
|
||||
|
||||
public:
|
||||
Bone();
|
||||
|
||||
Bone(Str_8 name, const UInt_8 id, const Mat4_f& localBindTrans, const Mat4_f& invBindTrans);
|
||||
|
||||
Bone(Bone&& bone) noexcept;
|
||||
|
||||
Bone(const Bone& bone);
|
||||
|
||||
Bone& operator=(Bone&& bone) noexcept;
|
||||
|
||||
Bone& operator=(const Bone& bone);
|
||||
|
||||
UInt_64 GetHashName() const;
|
||||
|
||||
void SetName(Str_8 newId);
|
||||
|
||||
Str_8 GetName() const;
|
||||
|
||||
UInt_8 GetId() const;
|
||||
|
||||
void SetAnimTrans(const Mat4_f& newTrans);
|
||||
|
||||
Mat4_f GetAnimTrans() const;
|
||||
|
||||
void GetAnimTransRec(Array<Mat4_f>& output) const;
|
||||
|
||||
Mat4_f GetLocalBindTrans() const;
|
||||
|
||||
Mat4_f GetInvBindTrans() const;
|
||||
|
||||
UInt_8 GetBoneCount() const;
|
||||
|
||||
bool HasBone(const UInt_64 hashName, const UInt_8 id) const;
|
||||
|
||||
bool HasBone(const UInt_64 hashName) const;
|
||||
|
||||
bool HasBone(const UInt_8 id) const;
|
||||
|
||||
bool AddBone(Bone child);
|
||||
|
||||
const Bone* GetBone(const UInt_64 hashName) const;
|
||||
|
||||
Bone* GetBone(const UInt_64 hashName);
|
||||
|
||||
const Bone* GetBone(const UInt_8 id) const;
|
||||
|
||||
Bone* GetBone(const UInt_8 id);
|
||||
|
||||
const Array<Bone>& GetChildren() const;
|
||||
|
||||
Array<Bone>& GetChildren();
|
||||
};
|
||||
}
|
55
include/IO/Model/KeyFrame.h
Normal file
55
include/IO/Model/KeyFrame.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "../../Vec3.h"
|
||||
#include "../../Quat.h"
|
||||
#include "../../Mat4.h"
|
||||
#include "PropertyChange.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
class KeyFrame
|
||||
{
|
||||
private:
|
||||
float num;
|
||||
float timeStamp;
|
||||
Vec3_f pos;
|
||||
Quat_f rot;
|
||||
Vec3_f scale;
|
||||
Mat4_f trans;
|
||||
|
||||
public:
|
||||
KeyFrame();
|
||||
|
||||
KeyFrame(const float num, const float timeStamp, const Vec3_f& pos, const Quat_f& rot, const Vec3_f& scale);
|
||||
|
||||
KeyFrame(const float num, const float timeStamp);
|
||||
|
||||
KeyFrame(const KeyFrame& kf);
|
||||
|
||||
KeyFrame& operator=(const KeyFrame& kf);
|
||||
|
||||
float GetNum() const;
|
||||
|
||||
float GetTimeStamp() const;
|
||||
|
||||
void SetPos(const Vec3_f& newPos);
|
||||
|
||||
Vec3_f GetPos() const;
|
||||
|
||||
void SetRot(const Quat_f& newRot);
|
||||
|
||||
Quat_f GetRot() const;
|
||||
|
||||
void SetScale(const Vec3_f& newScale);
|
||||
|
||||
Vec3_f GetScale() const;
|
||||
|
||||
void CalculateTransform();
|
||||
|
||||
Mat4_f GetTrans() const;
|
||||
|
||||
static Mat4_f Interpolate(const KeyFrame& prev, const KeyFrame& next, const float percentage);
|
||||
};
|
||||
}
|
101
include/IO/Model/Mesh.h
Normal file
101
include/IO/Model/Mesh.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
const Array<Vertex_f> portraitGuiVerts({
|
||||
{{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
|
||||
{{0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
|
||||
{{1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
|
||||
{{1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
|
||||
});
|
||||
|
||||
const Array<UInt_32> portraitGuiIndices({
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
1
|
||||
});
|
||||
|
||||
const Array<Vertex_f> portraitVerts({
|
||||
{{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}},
|
||||
{{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}}
|
||||
});
|
||||
|
||||
const Array<UInt_32> portraitIndices({
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
2,
|
||||
1
|
||||
});
|
||||
|
||||
class Mesh : public Resource
|
||||
{
|
||||
protected:
|
||||
Array<Vertex_f> vertices;
|
||||
Array<UInt_32> indices;
|
||||
GpuBuffer srcVertBuffer;
|
||||
GpuBuffer dstVertBuffer;
|
||||
GpuBuffer srcIndBuffer;
|
||||
GpuBuffer dstIndBuffer;
|
||||
|
||||
public:
|
||||
Mesh();
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices, Array<UInt_32> indices);
|
||||
|
||||
Mesh(Str_8 id, Array<Vertex_f> vertices);
|
||||
|
||||
Mesh(Str_8 id);
|
||||
|
||||
Mesh(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh(const Mesh& mesh);
|
||||
|
||||
Mesh& operator=(Mesh&& mesh) noexcept;
|
||||
|
||||
Mesh& operator=(const Mesh& mesh);
|
||||
|
||||
bool UploadToGpu(GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
bool PostGpuUpload() override;
|
||||
|
||||
bool HasPostGpuUploaded() const override;
|
||||
|
||||
bool ReleaseFromGpu() override;
|
||||
|
||||
bool IsUploaded() const override;
|
||||
|
||||
void Bind(GpuCmdBuffer* cmdBuffer);
|
||||
|
||||
void Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances = 1);
|
||||
|
||||
void SetVertices(const Array<Vertex_f>& newVertices);
|
||||
|
||||
Array<Vertex_f> GetVertices() const;
|
||||
|
||||
Array<Vertex_f>& GetVertices();
|
||||
|
||||
void SetIndices(const Array<UInt_32>& newIndices);
|
||||
|
||||
bool HasIndices() const;
|
||||
|
||||
Array<UInt_32> GetIndices() const;
|
||||
|
||||
Array<UInt_32>& GetIndices();
|
||||
|
||||
void Calculate();
|
||||
|
||||
private:
|
||||
static void Calculate(Vertex_f& vert1, Vertex_f& vert2, Vertex_f& vert3);
|
||||
};
|
||||
}
|
80
include/IO/Model/Model.h
Normal file
80
include/IO/Model/Model.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Array.h"
|
||||
#include "../File.h"
|
||||
#include "Mesh.h"
|
||||
#include "Bone.h"
|
||||
#include "Animation.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class ModelEncoding : UInt_8
|
||||
{
|
||||
EHM
|
||||
};
|
||||
|
||||
class Model : public Resource
|
||||
{
|
||||
protected:
|
||||
Array<Mesh> meshes;
|
||||
Bone skeleton;
|
||||
Array<Animation> animations;
|
||||
|
||||
public:
|
||||
Model();
|
||||
|
||||
Model(const Str_8& filePath);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton, Array<Animation> animations);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes, Bone skeleton);
|
||||
|
||||
Model(Str_8 id, Array<Mesh> meshes);
|
||||
|
||||
Model(Model&& model) noexcept;
|
||||
|
||||
Model(const Model& model) = default;
|
||||
|
||||
Model& operator=(Model&& model) noexcept;
|
||||
|
||||
Model& operator=(const Model& model) = default;
|
||||
|
||||
bool UploadToGpu(GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
bool PostGpuUpload() override;
|
||||
|
||||
bool ReleaseFromGpu() override;
|
||||
|
||||
bool IsUploaded() const override;
|
||||
|
||||
void Draw(GpuCmdBuffer* cmdBuffer, const UInt_32 instances = 1);
|
||||
|
||||
Array<Mesh> GetMeshes() const;
|
||||
|
||||
Array<Mesh>& GetMeshes();
|
||||
|
||||
Mesh* GetMesh(const UInt_64 hashId);
|
||||
|
||||
Mesh* GetMesh(const Str_8& id);
|
||||
|
||||
Bone GetSkeleton() const;
|
||||
|
||||
Bone& GetSkeleton();
|
||||
|
||||
Animation* GetAnimation(const UInt_64 hashId);
|
||||
|
||||
Array<Animation> GetAnimations() const;
|
||||
|
||||
Array<Animation>& GetAnimations();
|
||||
|
||||
void Calculate();
|
||||
|
||||
void Export(const Str_8& filePath, const ModelEncoding encoding);
|
||||
|
||||
private:
|
||||
void ToEHM(File& file);
|
||||
|
||||
void FromEHM(File& file);
|
||||
};
|
||||
}
|
32
include/IO/Model/PropertyChange.h
Normal file
32
include/IO/Model/PropertyChange.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
enum class ChangeType : UInt_8
|
||||
{
|
||||
X_AXIS_POS,
|
||||
Y_AXIS_POS,
|
||||
Z_AXIS_POS,
|
||||
X_AXIS_SCALE,
|
||||
Y_AXIS_SCALE,
|
||||
Z_AXIS_SCALE,
|
||||
X_AXIS_ROT,
|
||||
Y_AXIS_ROT,
|
||||
Z_AXIS_ROT,
|
||||
W_AXIS_ROT,
|
||||
INVALID
|
||||
};
|
||||
|
||||
class PropertyChange
|
||||
{
|
||||
public:
|
||||
ChangeType type;
|
||||
float value;
|
||||
|
||||
PropertyChange();
|
||||
|
||||
PropertyChange(const ChangeType type, const float value);
|
||||
};
|
||||
}
|
49
include/IO/Model/Vertex.h
Normal file
49
include/IO/Model/Vertex.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../EHS.h"
|
||||
#include "../../Vec3.h"
|
||||
#include "../../Vec2.h"
|
||||
#include "../../Color4.h"
|
||||
|
||||
namespace lwe
|
||||
{
|
||||
template<typename T = float>
|
||||
class Vertex
|
||||
{
|
||||
public:
|
||||
Vec3<T> pos;
|
||||
Vec3<T> normal;
|
||||
Vec2<T> uv;
|
||||
Vec3<T> tan;
|
||||
Vec3<T> bTan;
|
||||
Vec4<UInt_8> bones;
|
||||
Vec4<float> weights;
|
||||
|
||||
Vertex() = default;
|
||||
|
||||
Vertex(const Vec3<T>& pos)
|
||||
: pos(pos), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vec3<T>& pos, const Vec3<T>& normal)
|
||||
: pos(pos), normal(normal), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vec3<T>& pos, const Vec3<T>& normal, const Vec2<T>& uv)
|
||||
: pos(pos), normal(normal), uv(uv), bones{0, 0, 0, 0}, weights{0.0f, 0.0f, 0.0f, 0.0f}
|
||||
{
|
||||
}
|
||||
|
||||
Vertex(const Vertex& vert)
|
||||
: pos(vert.pos), normal(vert.normal), uv(vert.uv), bones(vert.bones), weights(vert.weights)
|
||||
{
|
||||
}
|
||||
|
||||
Vertex& operator=(const Vertex& vert) = default;
|
||||
};
|
||||
|
||||
typedef Vertex<double> Vertex_d;
|
||||
typedef Vertex<float> Vertex_f;
|
||||
}
|
Reference in New Issue
Block a user