]> git.tdb.fi Git - libs/gl.git/commitdiff
Check for armature mismatches in Animation
authorMikko Rasa <tdb@tdb.fi>
Tue, 4 Jun 2019 22:42:49 +0000 (01:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 4 Jun 2019 22:42:49 +0000 (01:42 +0300)
Also set the armature if a keyframe with a pose is added and there is no
armature yet.

source/animation.cpp
source/pose.h

index ab9d6e6085c35a36d1f430b652586411e7849047..6c9e179dc749dc16642b5b755f6afd7e36fecf2b 100644 (file)
@@ -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 RefPtr<const KeyFra
                throw invalid_argument("Animation::add_keyframe");
        if(!keyframes.empty() && t<keyframes.back().time)
                throw invalid_argument("Animation::add_keyframe");
+       if(kf->get_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;
index 41fc3de596986940f7f60528d4af510615894557..cbd8137bc4b861f5ccdb7d3e9b0411e754c57faa 100644 (file)
@@ -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;
 };