First commit, for test, for using Library files for synchronizing partial
authorTon Roosendaal <ton@blender.org>
Tue, 25 Oct 2005 15:58:51 +0000 (15:58 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 25 Oct 2005 15:58:51 +0000 (15:58 +0000)
data. This functionality is going to be in Outliner, for now only use
for testing while consulting me. :)

Usage: New option in SHIFT+F1 append window, "Sync Pose". When pressed, you
can append/load an *Object* of type Armature, this then replaces its
Armature and Pose with the selected Objects. After that it deletes the
appended object.

Note: it currently appends also Objects when used in Pose Constraints...

source/blender/makesdna/DNA_space_types.h
source/blender/src/filesel.c
source/blender/src/header_filesel.c

index f56f620cc0e533228a89d1649b90b92108f702b9..4483d23dea174bdd6e5f6f761ecc1f36de270653 100644 (file)
@@ -406,6 +406,7 @@ typedef struct SpaceImaSel {
 #define FILE_AUTOSELECT                16
 #define FILE_ACTIVELAY         32
 #define FILE_ATCURSOR          64
+#define FILE_SYNCPOSE          128
 
 /* sfile->sort */
 #define FILE_SORTALPHA         0
index 84f89da48b4d9af08103d4dfbbc7b91de19912ec..96178d2f20c9d0f3909fadd40adaa00264e7a1a4 100644 (file)
 
 #include "IMB_imbuf.h"
 
+#include "DNA_armature_types.h"
+#include "DNA_action_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_image_types.h"
 #include "DNA_ipo_types.h"
-#include "DNA_vfont_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_space_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_view3d_types.h"
 #include "DNA_userdef_types.h"
+#include "DNA_vfont_types.h"
+#include "DNA_view3d_types.h"
 
-#include "BKE_utildefines.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_library.h"
+#include "BKE_action.h"
+#include "BKE_constraint.h"
 #include "BKE_curve.h"
+#include "BKE_depsgraph.h"
 #include "BKE_font.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_material.h"
+#include "BKE_utildefines.h"
 
 #include "BIF_gl.h"
 #include "BIF_interface.h"
 #include "BLO_readfile.h"
 
 #include "BDR_editcurve.h"
+#include "BDR_editobject.h"
+
 #include "BPI_script.h"
 #include "BSE_filesel.h"
 #include "BSE_view.h"
@@ -2245,6 +2252,64 @@ static int is_a_library(SpaceFile *sfile, char *dir, char *group)
        return 1;
 }
 
+/* orange hack... :) */
+static void do_sync_pose(Library *lib)
+{
+       Object *ob, *obt;
+       Base *base;
+       bArmature *arm;
+       
+       /* find the armature and the pose from library */
+       for(ob= G.main->object.first; ob; ob= ob->id.next)
+               if(ob->type==OB_ARMATURE && ob->id.lib==lib)
+                       break;
+       
+       if(ob==NULL || ob->pose==NULL)
+               error("No pose appended");
+       
+       arm= ob->data;
+
+       /* for all visible objects in this scene */
+       for(base= G.scene->base.first; base; base= base->next) {
+               if((base->flag & SELECT) || (base->object->flag & OB_POSEMODE)) {
+                       obt= base->object;
+                       if(obt->type==OB_ARMATURE && obt->pose && ob!=obt) {
+                               bPoseChannel *chan;
+                               bArmature *oldarm= obt->data;
+                               
+                               /* link armature */
+                               oldarm->id.us--;
+                               obt->data= arm;
+                               arm->id.us++;
+                               
+                               /* link pose */
+                               free_pose_channels(obt->pose);
+                               MEM_freeN(obt->pose);
+                               copy_pose(&obt->pose, ob->pose, 1);
+                               
+                               /* relink */
+                               ob->id.newid= &obt->id;
+                               for (chan = obt->pose->chanbase.first; chan; chan=chan->next){
+                                       relink_constraints(&chan->constraints);
+                               }
+                               
+                               obt->pose->flag |= POSE_RECALC;
+                               obt->recalc |= OB_RECALC_DATA;
+                       }
+               }
+       }
+
+       /* prevent saving in file, unlink from scene */
+       for(base= G.scene->base.first; base; base= base->next) {
+               if(base->object==ob)
+                       break;
+       }
+       
+       if(base) {
+               free_and_unlink_base(base);
+       }
+}
+
 static void do_library_append(SpaceFile *sfile)
 {
        Library *lib;
@@ -2283,7 +2348,12 @@ static void do_library_append(SpaceFile *sfile)
                        lib= lib->id.next;
                }
                
-               if((sfile->flag & FILE_LINK)==0) all_local(lib);
+               if(sfile->flag & FILE_SYNCPOSE)
+                       do_sync_pose(lib);
+               if((sfile->flag & FILE_LINK)==0) 
+                       all_local(lib);
+               
+               DAG_scene_sort(G.scene);
        }
 }
 
index 4fefdc41a6e8e27d04fd27e4449e8b078a61e498..1d661a7940d8210539a08c442ab38bc393c89ffd 100644 (file)
@@ -144,13 +144,15 @@ void file_buttons(void)
                uiDefButBitS(block, TOG, FILE_AUTOSELECT, B_REDR, "Autosel", xco+=125,0,65,YIC, &sfile->flag, 0, 0, 0, 0, "Autoselect imported objects");
                uiDefButBitS(block, TOG, FILE_ACTIVELAY, B_REDR, "Active Layer", xco+=65,0,80,YIC, &sfile->flag, 0, 0, 0, 0, "Append object(s) in active layer");
                uiDefButBitS(block, TOG, FILE_ATCURSOR, B_REDR, "At Cursor", xco+=80,0,65,YIC, &sfile->flag, 0, 0, 0, 0, "Append object(s) at cursor, use centroid if more than one object is selected");
+               uiDefButBitS(block, TOG, FILE_SYNCPOSE, B_REDR, "Sync Pose", xco+=80,0,65,YIC, &sfile->flag, 0, 0, 0, 0, "If Object with Pose appended, link the Pose and Armature to all selected Objects");
                uiBlockEndAlign(block);
+               
+               xco+= 100;      // scroll
+               
        } else if(sfile->type==FILE_BLENDER) {
                uiDefButBitI(block, TOGN, G_FILE_NO_UI, B_REDR, "Load UI", xco+=XIC,0,80,YIC, &G.fileflags, 0, 0, 0, 0, "Load the UI setup as well as the scene data");
-               
        
-               xco+=100;
-
+               xco+= 100;      // scroll
        }
 
        if(sfile->type==FILE_UNIX) {