Animation stuff
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <Collage/types/bone.h>
|
||||
|
||||
struct KeyFrame {
|
||||
@@ -7,4 +8,21 @@ struct KeyFrame {
|
||||
Bone bone;
|
||||
};
|
||||
|
||||
typedef std::vector<KeyFrame> Animation;
|
||||
class Animation {
|
||||
public:
|
||||
std::string name;
|
||||
float deltaBetweenKeyFrames;
|
||||
std::vector<KeyFrame> keyFrames;
|
||||
};
|
||||
|
||||
class AnimationState { //Information which would be stored on each animated entity.
|
||||
protected:
|
||||
Animation* animation = nullptr;
|
||||
public:
|
||||
std::vector<Animation*>* animations; //Will point to the list of animations on the model.
|
||||
std::chrono::high_resolution_clock::time_point start; //When the current animation was started.
|
||||
[[nodiscard]] float animationTime() const; //The amount of time in ms that the animation has been running for.
|
||||
Animation* getAnimation();
|
||||
void setAnimation(Animation* anim);
|
||||
void reset();
|
||||
};
|
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include<J3ML/Geometry.h>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include<J3ML/Geometry.h>
|
||||
#include <Collage/types/textureInfo.h>
|
||||
#include <Collage/types/bone.h>
|
||||
|
||||
typedef Vector3 Vertex;
|
||||
|
||||
@@ -16,35 +15,26 @@ enum struct ModelType : uint8_t {
|
||||
COLLADA = 3, //*Very* complicated.
|
||||
};
|
||||
|
||||
struct FaceIndices {
|
||||
unsigned int vertexIndex[3];
|
||||
unsigned int texCoordIndex[3];
|
||||
};
|
||||
|
||||
class SkeletalVertex : public Vertex {
|
||||
int8_t joints[3]; //The index of 4 bones that can effect the vertex. 0 represents an empty slot. -1 represents the root bone.
|
||||
Vector4 weights; //The 4 weights must total to 1.0
|
||||
std::vector<int> bones; //The index of bones that can effect the vertex. 0 represents an empty slot. -1 represents the root bone.
|
||||
std::vector<float> weights; //The 4 weights must total to 1.0
|
||||
};
|
||||
|
||||
class Model {
|
||||
protected:
|
||||
void load(const std::string& file);
|
||||
void loadOBJ(const std::string& filename);
|
||||
public:
|
||||
ModelType type;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint> indices;
|
||||
std::vector<TextureInformation> textureInfo;
|
||||
public:
|
||||
ModelType type;
|
||||
const std::vector<Vertex>& getVertices();
|
||||
const std::vector<uint>& getIndices();
|
||||
const std::vector<TextureInformation>& getTextureInformation();
|
||||
Model() = default;
|
||||
explicit Model(const std::string& file);
|
||||
};
|
||||
|
||||
class SkeletalModel : public Model {
|
||||
protected:
|
||||
std::vector<SkeletalVertex> vertices;
|
||||
public:
|
||||
std::vector<SkeletalVertex>& getSkeletalVertices();
|
||||
std::vector<SkeletalVertex> vertices;
|
||||
Bone boneMap;
|
||||
};
|
@@ -1,6 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <Collage/types/model.h>
|
||||
|
||||
//The OBJ *must* be exported as a triangle mesh and without normals.
|
||||
//TODO support more options.
|
||||
void Model::loadOBJ(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
std::vector<Vector3> positions;
|
||||
@@ -28,7 +31,6 @@ void Model::loadOBJ(const std::string& filename) {
|
||||
vertexIndex[i]--;
|
||||
texCoordIndex[i]--;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
Vertex vertex;
|
||||
Vector2 textureCoordinate;
|
||||
@@ -42,4 +44,5 @@ void Model::loadOBJ(const std::string& filename) {
|
||||
}
|
||||
textureInfo.push_back(tInfo);
|
||||
file.close();
|
||||
type = ModelType::WAVEFRONT_OBJ;
|
||||
};
|
@@ -1,2 +1,21 @@
|
||||
#include <Collage/types/animation.h>
|
||||
#include <Collage/types/keyFrame.h>
|
||||
|
||||
Animation* AnimationState::getAnimation() {
|
||||
if (animation == nullptr)
|
||||
throw std::runtime_error("There is no current animation.");
|
||||
return animation;
|
||||
}
|
||||
|
||||
void AnimationState::setAnimation(Animation* anim) {
|
||||
animation = anim;
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void AnimationState::reset() {
|
||||
animation = animations[0]; //The "idle" or "default" animation should *always* be in slot 0.
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
float AnimationState::animationTime() const {
|
||||
return std::chrono::duration<float, std::milli>(std::chrono::high_resolution_clock::now() - start).count();
|
||||
}
|
||||
|
@@ -5,22 +5,6 @@ void Model::load(const std::string& file) {
|
||||
loadOBJ(file);
|
||||
}
|
||||
|
||||
const std::vector<Vector3>& Model::getVertices() {
|
||||
return vertices;
|
||||
}
|
||||
|
||||
const std::vector<uint>& Model::getIndices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
const std::vector<TextureInformation>& Model::getTextureInformation() {
|
||||
return textureInfo;
|
||||
}
|
||||
|
||||
Model::Model(const std::string &file) {
|
||||
load(file);
|
||||
}
|
||||
|
||||
std::vector<SkeletalVertex>& SkeletalModel::getSkeletalVertices() {
|
||||
return vertices;
|
||||
}
|
||||
|
Reference in New Issue
Block a user