From a9c375e17065bcc429b430bd8211a9ee845159a5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 5 Jun 2019 01:42:49 +0300 Subject: [PATCH] Check for armature mismatches in Animation Also set the armature if a keyframe with a pose is added and there is no armature yet. --- source/animation.cpp | 7 +++++++ source/pose.h | 1 + 2 files changed, 8 insertions(+) diff --git a/source/animation.cpp b/source/animation.cpp index ab9d6e60..6c9e179d 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -23,6 +23,8 @@ Animation::~Animation() void Animation::set_armature(const Armature &a) { + if(!keyframes.empty() && &a!=armature) + throw invalid_operation("Animation::set_armature"); armature = &a; } @@ -64,9 +66,14 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const RefPtrget_pose() && armature && kf->get_pose()->get_armature()!=armature) + throw invalid_argument("Animation::add_keyframe"); bool realloc = (keyframes.size()>=keyframes.capacity()); + if(kf->get_pose() && !armature) + armature = kf->get_pose()->get_armature(); + keyframes.push_back(TimedKeyFrame()); TimedKeyFrame &tkf = keyframes.back(); tkf.time = t; diff --git a/source/pose.h b/source/pose.h index 41fc3de5..cbd8137b 100644 --- a/source/pose.h +++ b/source/pose.h @@ -48,6 +48,7 @@ public: Pose(const Armature &); void set_armature(const Armature &); + const Armature *get_armature() const { return armature; } void rotate_link(unsigned, float, const Vector3 &); const Matrix &get_link_matrix(unsigned) const; }; -- 2.45.2