simplified animatable objects interface

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 53bf4f41bd
commit c91a7f39f6
6 changed files with 11 additions and 18 deletions
+1 -7
View File
@@ -2,12 +2,6 @@
#include "animationController.h"
namespace vb01{
Animatable::Animatable(AnimationController *controller){
this->animationController = controller;
}
void Animatable::update(){
if(animationController)
animationController->update();
Animatable::Animatable(){
}
}
+1 -4
View File
@@ -10,13 +10,10 @@ namespace vb01{
public:
enum Type{NODE, BONE};
Animatable(AnimationController*);
void update();
Animatable();
virtual void animate(float, KeyframeChannel){}
inline AnimationController *getAnimationController(){return animationController;}
inline Type getType(){return type;}
private:
AnimationController *animationController = nullptr;
protected:
Type type;
};
+4 -2
View File
@@ -15,11 +15,12 @@ using namespace std;
using namespace glm;
namespace vb01{
Node::Node(Vector3 pos, Quaternion orientation, Vector3 scale, string name, AnimationController *controller) : Animatable(controller){
Node::Node(Vector3 pos, Quaternion orientation, Vector3 scale, string name, AnimationController *controller) : Animatable(){
this->pos = pos;
this->scale = scale;
this->orientation = orientation;
this->name = name;
this->controller = controller;
Animatable::type = Animatable::NODE;
globalAxis[0] = Vector3::VEC_I;
@@ -54,7 +55,8 @@ namespace vb01{
c->update();
for(ParticleEmitter *p : emitters)
p->update();
Animatable::update();
if(controller)
controller->update();
}
}
+1
View File
@@ -72,6 +72,7 @@ namespace vb01{
void updateShaders();
Quaternion adjustRot(std::vector<Node*>, Quaternion, bool);
AnimationController *controller = nullptr;
protected:
virtual void animate(float, KeyframeChannel);
+3 -4
View File
@@ -170,7 +170,7 @@ namespace vb01{
}
}
void VbModelReader::readAnimations(Animatable *animatable, vector<string> &animationData, int numAnimations){
void VbModelReader::readAnimations(Animatable *animatable, AnimationController *controller, vector<string> &animationData, int numAnimations){
int animStartLine = 0;
for(int i = 0; i < numAnimations; i++){
@@ -179,7 +179,6 @@ namespace vb01{
string groupsLine = animationData[animStartLine + 1];
Animation *animation = new Animation(currentAnim);
AnimationController *controller = (animatable ? animatable->getAnimationController() : currentSkeleton->getAnimationController());
controller->addAnimation(animation);
int numKeyframeGroups = atoi(groupsLine.substr(groupsLine.find_first_of(':') + 2).c_str());
@@ -257,7 +256,7 @@ namespace vb01{
skeletonSubData.clear();
skeletonSubData = vector<string>(skeletonData.begin() + (boneStartLine + numBones + 1), skeletonData.end());
readAnimations(nullptr, skeletonSubData, numAnimations);
readAnimations(nullptr, controller, skeletonSubData, numAnimations);
skeletonSubData.clear();
currentSkeleton = nullptr;
@@ -436,7 +435,7 @@ namespace vb01{
int numAnimLineId = shapeKeyStartLine + numShapes * (1 + numVertices);
int numAnimations = atoi(meshData[numAnimLineId].substr(meshData[numAnimLineId].find_first_of(':') + 1).c_str());
meshSubData = vector<string>(meshData.begin() + (numAnimLineId + 1), meshData.end());
readAnimations(node, meshSubData, numAnimations);
readAnimations(node, controller, meshSubData, numAnimations);
meshSubData.clear();
string skeletonLine = meshData[5];
+1 -1
View File
@@ -25,7 +25,7 @@ namespace vb01{
void connectNodes();
void createBones(Skeleton*, std::vector<std::string>&);
void readAnimations(Animatable*, std::vector<std::string>&, int);
void readAnimations(Animatable*, AnimationController*, std::vector<std::string>&, int);
Skeleton* readSkeleton(std::vector<std::string>&);
void readVertices(std::vector<Vector3>&, std::vector<Vector3>&, std::vector<float>&, std::vector<std::string>&, int);
void readFaces(std::vector<Vector3>&, std::vector<Vector3>&, std::vector<u32>&, std::vector<float>&, std::vector<std::string>&, int, Mesh::Vertex*, u32*);