Armature related fixes and cleanups:
authorChris Want <cwant@ualberta.ca>
Tue, 27 Jan 2004 06:08:37 +0000 (06:08 +0000)
committerChris Want <cwant@ualberta.ca>
Tue, 27 Jan 2004 06:08:37 +0000 (06:08 +0000)
* Armatures that had constraint targets inside other armatures
  weren't transform()-ing correctly

* Issues with lattice deformed objects that are parents of bones
  when rendering an animation. Seems to be mostly OK now with the
  exception of the first rendered frame -- weird bugs like this have
  plagued blender for ages, which leads me to believe that
  RE_rotateBlenderScene() is a piece of garbage that nobody understands
  (especially me).

* made a few helper functions to clean up some repeated code related
  to clearing constraint status and rebuilding displists.

source/blender/blenkernel/BKE_constraint.h
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/scene.c
source/blender/renderconverter/intern/convertBlenderScene.c
source/blender/src/drawview.c
source/blender/src/editobject.c
source/blender/src/headerbuttons.c

index 6570f547e487973b6a9afed025317250d6cd2057..273b9d2a0a5f2c3b1db23c5469afb5e60fa3cfa3 100644 (file)
@@ -51,6 +51,8 @@ struct bConstraintChannel *clone_constraint_channels (struct ListBase *dst, stru
 void relink_constraints (struct ListBase *list);
 void free_constraint_data (struct bConstraint *con);
 void clear_object_constraint_status (struct Object *ob);
+void clear_all_constraints(void);
+void rebuild_all_armature_displists(void);
 void do_constraint_channels (struct ListBase *conbase, struct ListBase *chanbase, float ctime);
 short get_constraint_target (struct bConstraint *con, short ownertype, void *ownerdata, float mat[][4], float size[3], float time);
 struct bConstraintChannel *find_constraint_channel (ListBase *list, const char *name);
index a37980b041dc251354a16657758c08fb3c6f6719..053034d96206027507b1290c60848f5e7e28a459 100644 (file)
@@ -45,6 +45,7 @@
 #include "DNA_object_types.h"
 #include "DNA_action_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_scene_types.h"
 
 #include "BKE_utildefines.h"
 #include "BKE_action.h"
@@ -407,6 +408,27 @@ void clear_object_constraint_status (Object *ob)
        }
 }
 
+void clear_all_constraints(void)
+{
+       Base *base;
+
+       /* Clear the constraint "done" flags -- this must be done
+        * before displists are calculated for objects that are
+        * deformed by armatures */
+       for (base = G.scene->base.first; base; base=base->next){
+               clear_object_constraint_status(base->object);
+       }
+}
+
+void rebuild_all_armature_displists(void) {
+       Base *base;
+
+       for (base = G.scene->base.first; base; base=base->next){
+               clear_object_constraint_status(base->object);
+               make_displists_by_armature(base->object);
+       }
+}
+
 short get_constraint_target (bConstraint *con, short ownertype, void* ownerdata, float mat[][4], float size[3], float ctime)
 {
        short valid=0;
index 7f47042be765d17d8305c6477ab57797e9f2d05e..3dd9ad2180c40703a09c895bb608d1ddbaff1a02 100644 (file)
@@ -75,6 +75,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_anim.h"
+#include "BKE_constraint.h"
 
 #include "BKE_library.h"
 
@@ -407,6 +408,7 @@ void set_scene_bg(Scene *sce)
        do_all_keys();
 #ifdef __NLA
        do_all_actions();
+       rebuild_all_armature_displists();
 #endif
        do_all_ikas();
 
index d752a9589257a0795cbc094ba039fbb5314f9e7f..c1eb91cce76f25859c385a1ac3f250df0930f37c 100644 (file)
@@ -2813,6 +2813,7 @@ void RE_rotateBlenderScene(void)
        do_all_keys();
 #ifdef __NLA
        do_all_actions();
+       rebuild_all_armature_displists();
 #endif
        do_all_ikas();
        test_all_displists();
@@ -2831,7 +2832,6 @@ void RE_rotateBlenderScene(void)
                clear_object_constraint_status(base->object);
                if (base->object->type==OB_ARMATURE) {
                        where_is_armature (base->object);
-                       make_displists_by_armature(base->object);
                }
                else
 
index ef2145edfcd1887f4736f9b8e488b304ffcc8d03..285ad44769f11b9003dc689ad8019347d92f6c0e 100644 (file)
@@ -1390,7 +1390,6 @@ void do_viewbuts(unsigned short event)
                        bPoseChannel *chan;
                        bArmature *arm;
                        Bone *bone;
-                       Base *base;
 
                        arm = get_armature(OBACT);
                        if (!arm) return;
@@ -1411,10 +1410,7 @@ void do_viewbuts(unsigned short event)
                        
                        set_pose_channel (G.obpose->pose, chan);
 
-                       for (base = G.scene->base.first; base; base=base->next){
-                               clear_object_constraint_status(base->object);
-                               make_displists_by_armature(base->object);
-                       }
+                       rebuild_all_armature_displists();
 
                        allqueue(REDRAWVIEW3D, 1);
                }
@@ -1688,10 +1684,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
         * or else armatures/poses/displists get recalculated all of the
         * time
         */
-       /* Clear the constraint "done" flags */
-       for (base = G.scene->base.first; base; base=base->next){
-               clear_object_constraint_status(base->object);
-       }
+       clear_all_constraints();
 #endif
 
        /* draw set first */
@@ -1897,12 +1890,7 @@ void drawview3d_render(struct View3D *v3d)
        /* abuse! to make sure it doesnt draw the helpstuff */
        G.f |= G_SIMULATION;
 
-       /* Clear the constraint "done" flags -- this must be done
-        * before displists are calculated for objects that are
-        * deformed by armatures */
-       for (base = G.scene->base.first; base; base=base->next){
-               clear_object_constraint_status(base->object);
-       }
+       clear_all_constraints();
        do_all_ipos();
        BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
        do_all_keys();
@@ -1955,9 +1943,9 @@ void drawview3d_render(struct View3D *v3d)
                
                G.f &= ~G_PICKSEL;
        }
-       for (base = G.scene->base.first; base; base=base->next){
-               clear_object_constraint_status(base->object);
-       }
+
+       clear_all_constraints();
+
        /* first not selected and duplis */
        base= G.scene->base.first;
        while(base) {
@@ -2383,12 +2371,7 @@ void inner_play_anim_loop(int init, int mode)
 
        set_timecursor(CFRA);
 
-       /* Clear the constraint "done" flags -- this must be done
-        * before displists are calculated for objects that are
-        * deformed by armatures */
-       for (base = G.scene->base.first; base; base=base->next){
-               clear_object_constraint_status(base->object);
-       }
+       clear_all_constraints();
        do_all_ipos();
        BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
        do_all_keys();
@@ -2489,13 +2472,7 @@ int play_anim(int mode)
        if(event==SPACEKEY);
        else CFRA= cfraont;
 
-       /* Clear the constraint "done" flags -- this must be done
-        * before displists are calculated for objects that are
-        * deformed by armatures */
-       for (base = G.scene->base.first; base; base=base->next){
-               clear_object_constraint_status(base->object);
-       }
-
+       clear_all_constraints();
        do_all_ipos();
        do_all_keys();
        do_all_actions();
index 7335fd07ea94cbd945bb276d97b8d5ee81d98937..217e629009aaeff59f166c466ce5b274f96b04bb 100644 (file)
@@ -2629,21 +2629,23 @@ static void clear_pose_update_flag(Object *ob) {
        }
 }
 
-static void pose_flags_reset_done(Object *ob) {
+static int pose_flags_reset_done(Object *ob) {
        /* Clear the constraint done status for every pose channe;
         * that has been flagged as needing constant updating
         */
        bPoseChannel *chan;
+       int numreset = 0;
 
        if (ob->pose) {
                for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
                        if (chan->flag & PCHAN_TRANS_UPDATE) {
                                chan->flag &= ~PCHAN_DONE;
+                               numreset++;
                        }
 
                }
        }
-
+       return numreset;
 }
 
 static int is_ob_constraint_target(Object *ob, ListBase *conlist) {
@@ -2998,6 +3000,22 @@ static int pose_do_update_flag(Object *ob) {
        return do_update;
 }
 
+void figure_pose_updating(void)
+{
+       Base *base;
+
+       flag_moving_objects();
+
+       for (base= FIRSTBASE; base; base= base->next) {
+               /* Recalculate the pose if necessary, regardless of
+                * whether the layer is visible or not.
+                */
+               if (pose_do_update_flag(base->object))
+                       base->flag |= BA_WHERE_UPDATE;
+       }
+
+}
+
 /*** POSE FIGURIN' -- END ***/
 
 
@@ -3014,18 +3032,10 @@ static void setbaseflags_for_editing(int mode)  /* 0,'g','r','s' */
        Base *base;
        
        copy_baseflags();
-       flag_moving_objects();
-
 
        for (base= FIRSTBASE; base; base= base->next) {
                base->flag &= ~(BA_PARSEL+BA_WASSEL);
 
-               /* Recalculate the pose if necessary, regardless of
-                * whether the layer is visible or not.
-                */
-               if (pose_do_update_flag(base->object))
-                       base->flag |= BA_WHERE_UPDATE;
-
                if( (base->lay & G.vd->lay) && base->object->id.lib==0) {
                        Object *ob= base->object;
                        Object *parsel= is_a_parent_selected(ob);
@@ -3700,10 +3710,6 @@ void special_trans_update(int keyflags)
                                base->object->partype |= PARSLOW;
                        }
                        else if(base->flag & BA_WHERE_UPDATE) {
-                               /* deal with the armature case */
-                               pose_flags_reset_done(base->object);
-                               make_displists_by_armature(base->object);
-
                                where_is_object(base->object);
                                if(base->object->type==OB_IKA) {
                                        itterate_ika(base->object);
@@ -3724,6 +3730,16 @@ void special_trans_update(int keyflags)
                
        }
 
+       base= FIRSTBASE;
+       while(base) {
+               if (pose_flags_reset_done(base->object)) {
+                       if (!is_delay_deform())
+                               make_displists_by_armature(base->object);
+               }
+
+               base= base->next;
+       }
+
 #if 1
        if (G.obpose && G.obpose->type == OB_ARMATURE)
                clear_pose_constraint_status(G.obpose);
@@ -4486,6 +4502,7 @@ void transform(int mode)
                case OB_ARMATURE:
                        /* figure out which bones need calculating */
                        figure_bone_nocalc(G.obpose);
+                       figure_pose_updating();
                        make_trans_bones(mode);
                        break;
                }
@@ -4497,7 +4514,7 @@ void transform(int mode)
                else if (mode=='s' || mode=='S') opt= 's';
                
                setbaseflags_for_editing(opt);
-               
+               figure_pose_updating();
                make_trans_objects();
        }
        
index 7f023f37916d5f45ebe28896b273feefc8282517..2bd1ea98d3da19bfd318825f764169cfb3653076 100644 (file)
@@ -509,13 +509,7 @@ void do_update_for_newframe(int mute)
        allqueue(REDRAWBUTSSHADING, 0);
        allqueue(REDRAWBUTSOBJECT, 0);
 
-       /* Clear the constraint "done" flags -- this must be done
-        * before displists are calculated for objects that are
-        * deformed by armatures */
-       for (base = G.scene->base.first; base; base=base->next){
-               clear_object_constraint_status(base->object);
-       }
-
+       clear_all_constraints();
        /* layers/materials, object ipos are calculted in where_is_object (too) */
        do_all_ipos();
        BPY_do_all_scripts(SCRIPT_FRAMECHANGED);