From c91a7f39f6f7d2765c2a26cc7270df08a51cd5fc Mon Sep 17 00:00:00 2001 From: devZoGok Date: Tue, 23 Feb 2021 11:18:23 +0200 Subject: [PATCH] simplified animatable objects interface --- animatable.cpp | 8 +------- animatable.h | 5 +---- node.cpp | 6 ++++-- node.h | 1 + vbModelReader.cpp | 7 +++---- vbModelReader.h | 2 +- 6 files changed, 11 insertions(+), 18 deletions(-) diff --git a/animatable.cpp b/animatable.cpp index 31dee57..280f0ab 100644 --- a/animatable.cpp +++ b/animatable.cpp @@ -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(){ } } diff --git a/animatable.h b/animatable.h index d2bc1d1..31d2702 100644 --- a/animatable.h +++ b/animatable.h @@ -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; }; diff --git a/node.cpp b/node.cpp index 4b6f021..18a1593 100755 --- a/node.cpp +++ b/node.cpp @@ -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(); } } diff --git a/node.h b/node.h index 6352da3..7258136 100755 --- a/node.h +++ b/node.h @@ -72,6 +72,7 @@ namespace vb01{ void updateShaders(); Quaternion adjustRot(std::vector, Quaternion, bool); + AnimationController *controller = nullptr; protected: virtual void animate(float, KeyframeChannel); diff --git a/vbModelReader.cpp b/vbModelReader.cpp index 3b71fc7..64337c2 100644 --- a/vbModelReader.cpp +++ b/vbModelReader.cpp @@ -170,7 +170,7 @@ namespace vb01{ } } - void VbModelReader::readAnimations(Animatable *animatable, vector &animationData, int numAnimations){ + void VbModelReader::readAnimations(Animatable *animatable, AnimationController *controller, vector &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(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(meshData.begin() + (numAnimLineId + 1), meshData.end()); - readAnimations(node, meshSubData, numAnimations); + readAnimations(node, controller, meshSubData, numAnimations); meshSubData.clear(); string skeletonLine = meshData[5]; diff --git a/vbModelReader.h b/vbModelReader.h index 66dfdc2..d9fd032 100644 --- a/vbModelReader.h +++ b/vbModelReader.h @@ -25,7 +25,7 @@ namespace vb01{ void connectNodes(); void createBones(Skeleton*, std::vector&); - void readAnimations(Animatable*, std::vector&, int); + void readAnimations(Animatable*, AnimationController*, std::vector&, int); Skeleton* readSkeleton(std::vector&); void readVertices(std::vector&, std::vector&, std::vector&, std::vector&, int); void readFaces(std::vector&, std::vector&, std::vector&, std::vector&, std::vector&, int, Mesh::Vertex*, u32*);