Add two new options for appending *objects*:

1) append in current active layer (off by default)
2) append at 3d cursor (off by default). When more than one object is selected this will first calculate the bounding box of the centers of the objects, and then use the distance of the bounding box center to the 3d cursor to transform all objects.
This commit is contained in:
Nathan Letwory 2004-09-13 06:57:24 +00:00
parent 025e6b8b4f
commit 538e11a45d
3 changed files with 49 additions and 2 deletions

View File

@ -101,6 +101,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_storage_types.h" // for relname flags
#include "BKE_bad_level_calls.h" // for reopen_text build_seqar (from WHILE_SEQ) open_plugin_seq set_rects_butspace check_imasel_copy
@ -117,6 +118,8 @@
#include "BKE_mesh.h" // for ME_ defines (patching)
#include "BKE_armature.h" // for precalc_bonelist_irestmats
#include "BKE_action.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BIF_butspace.h" // for do_versions, patching event codes
@ -5135,6 +5138,7 @@ static void append_named_part(FileData *fd, Main *mainvar, Scene *scene, char *n
if(id==0) ob= mainvar->object.last;
else ob= (Object *)id;
if((flag & FILE_ACTIVELAY)) ob->lay = G.scene->lay;
base->lay= ob->lay;
base->object= ob;
ob->id.us++;
@ -5213,7 +5217,12 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode)
FileData *fd= (FileData*) sfile->libfiledata;
ListBase mainlist;
Main *mainl;
int a, totsel=0;
int a, totsel=0,count=0;
float *curs,centerloc[3],vec[3],min[3],max[3];
Base *centerbase;
Object *ob;
INIT_MINMAX(min, max);
/* are there files selected? */
for(a=0; a<sfile->totfile; a++) {
@ -5277,6 +5286,7 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode)
/* give a base to loose objects */
/* give_base_to_objects(G.scene, &(G.main->object)); */
/* has been removed... erm, why? (ton) */
/* 20040907: looks like they are give base already in append_named_part(); -Nathan L */
/* patch to prevent switch_endian happens twice */
if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
@ -5285,6 +5295,37 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode)
}
if(sfile->flag & FILE_STRINGCODE) BLI_makestringcode(G.sce, mainl->curlib->name);
if(sfile->flag & FILE_ATCURSOR) {
centerbase= (G.scene->base.first);
while(centerbase) {
if(((centerbase)->flag & SELECT)) {
VECCOPY(vec, centerbase->object->loc);
DO_MINMAX(vec, min, max);
count++;
}
centerbase= centerbase->next;
}
if(count) {
centerloc[0]= (min[0]+max[0])/2;
centerloc[1]= (min[1]+max[1])/2;
centerloc[2]= (min[2]+max[2])/2;
curs = G.scene->cursor;
VECSUB(centerloc,curs,centerloc);
centerbase= (G.scene->base.first);
while(centerbase) {
if( ((centerbase)->flag & SELECT)) {
ob= centerbase->object;
ob->loc[0] += centerloc[0];
ob->loc[1] += centerloc[1];
ob->loc[2] += centerloc[2];
}
centerbase= centerbase->next;
}
}
}
}
/* ************* READ LIBRARY ************** */

View File

@ -396,6 +396,8 @@ typedef struct SpaceImaSel {
#define FILE_LINK 4
#define FILE_HIDE_DOT 8
#define FILE_AUTOSELECT 16
#define FILE_ACTIVELAY 32
#define FILE_ATCURSOR 64
/* sfile->sort */
#define FILE_SORTALPHA 0

View File

@ -148,7 +148,11 @@ void file_buttons(void)
uiDefButS(block, TOGN|BIT|2, B_REDR, "Append", xco+=XIC,0,100,YIC, &sfile->flag, 0, 0, 0, 0, "Copies selected data into current project");
uiDefButS(block, TOG|BIT|2, B_REDR, "Link", xco+=100,0,100,YIC, &sfile->flag, 0, 0, 0, 0, "Creates a link to selected data from current project");
uiBlockEndAlign(block);
uiDefButS(block, TOGN|BIT|4, B_REDR, "AutoSelect", xco+=110,0,100,YIC, &sfile->flag, 0, 0, 0, 0, "Autoselect imported objects");
uiBlockBeginAlign(block);
uiDefButS(block, TOGN|BIT|4, B_REDR, "Autosel", xco+=125,0,65,YIC, &sfile->flag, 0, 0, 0, 0, "Autoselect imported objects");
uiDefButS(block, TOG|BIT|5, B_REDR, "Active Layer", xco+=65,0,80,YIC, &sfile->flag, 0, 0, 0, 0, "Append object(s) in active layer");
uiDefButS(block, TOG|BIT|6, 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");
uiBlockEndAlign(block);
}
if(sfile->type==FILE_UNIX) {