2
* $Id: editobject.c 16921 2008-10-04 19:58:08Z blendix $
4
* ***** BEGIN GPL LICENSE BLOCK *****
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software Foundation,
18
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
* All rights reserved.
23
* The Original Code is: all of this file.
25
* Contributor(s): none yet.
27
* ***** END GPL LICENSE BLOCK *****
31
* Theorie: (matrices) A x B x C == A x ( B x C x Binv) x B
32
* ofwel: OB x PAR x EDIT = OB x (PAR x EDIT x PARinv) x PAR
48
#include "MEM_guardedalloc.h"
54
#include "IMB_imbuf_types.h"
56
#include "DNA_action_types.h"
57
#include "DNA_armature_types.h"
58
#include "DNA_camera_types.h"
59
#include "DNA_constraint_types.h"
60
#include "DNA_curve_types.h"
61
#include "DNA_effect_types.h"
62
#include "DNA_group_types.h"
63
#include "DNA_image_types.h"
64
#include "DNA_ipo_types.h"
65
#include "DNA_key_types.h"
66
#include "DNA_lamp_types.h"
67
#include "DNA_lattice_types.h"
68
#include "DNA_material_types.h"
69
#include "DNA_mesh_types.h"
70
#include "DNA_meshdata_types.h"
71
#include "DNA_meta_types.h"
72
#include "DNA_nla_types.h"
73
#include "DNA_object_types.h"
74
#include "DNA_object_fluidsim.h"
75
#include "DNA_object_force.h"
76
#include "DNA_scene_types.h"
77
#include "DNA_space_types.h"
78
#include "DNA_screen_types.h"
79
#include "DNA_texture_types.h"
80
#include "DNA_particle_types.h"
81
#include "DNA_property_types.h"
82
#include "DNA_userdef_types.h"
83
#include "DNA_view3d_types.h"
84
#include "DNA_vfont_types.h"
85
#include "DNA_world_types.h"
86
#include "DNA_modifier_types.h"
88
#include "BLI_blenlib.h"
89
#include "BLI_arithb.h"
90
#include "BLI_editVert.h"
91
#include "BLI_ghash.h"
94
#include "BKE_action.h"
96
#include "BKE_armature.h"
97
#include "BKE_constraint.h"
98
#include "BKE_customdata.h"
99
#include "BKE_blender.h"
100
#include "BKE_booleanops.h"
101
#include "BKE_cloth.h"
102
#include "BKE_curve.h"
103
#include "BKE_displist.h"
104
#include "BKE_depsgraph.h"
105
#include "BKE_DerivedMesh.h"
106
#include "BKE_effect.h"
107
#include "BKE_font.h"
108
#include "BKE_global.h"
109
#include "BKE_group.h"
111
#include "BKE_image.h"
113
#include "BKE_lattice.h"
114
#include "BKE_library.h"
115
#include "BKE_main.h"
116
#include "BKE_material.h"
117
#include "BKE_mball.h"
118
#include "BKE_mesh.h"
119
#include "BKE_multires.h"
121
#include "BKE_object.h"
122
#include "BKE_particle.h"
123
#include "BKE_property.h"
125
#include "BKE_scene.h"
126
#include "BKE_softbody.h"
127
#include "BKE_subsurf.h"
128
#include "BKE_texture.h"
129
#include "BKE_utildefines.h"
130
#include "BKE_modifier.h"
132
#include "BIF_butspace.h"
133
#include "BIF_editconstraint.h"
134
#include "BIF_editdeform.h"
135
#include "BIF_editfont.h"
136
#include "BIF_editlattice.h"
137
#include "BIF_editmesh.h"
138
#include "BIF_editoops.h"
139
#include "BIF_editparticle.h"
140
#include "BIF_editview.h"
141
#include "BIF_editarmature.h"
143
#include "BIF_graphics.h"
144
#include "BIF_interface.h"
145
#include "BIF_meshtools.h"
146
#include "BIF_mywindow.h"
147
#include "BIF_previewrender.h"
148
#include "BIF_resources.h"
149
#include "BIF_retopo.h"
150
#include "BIF_screen.h"
151
#include "BIF_space.h"
152
#include "BIF_toolbox.h"
153
#include "BIF_toets.h"
156
#include "BIF_verse.h"
159
#include "BSE_edit.h"
160
#include "BSE_editipo.h"
161
#include "BSE_filesel.h" /* For activate_databrowse() */
162
#include "BSE_view.h"
163
#include "BSE_drawview.h"
164
#include "BSE_trans_types.h"
165
#include "BSE_editipo_types.h"
167
#include "BDR_vpaint.h"
168
#include "BDR_sculptmode.h"
169
#include "BDR_editface.h"
170
#include "BDR_editmball.h"
171
#include "BDR_editobject.h"
172
#include "BDR_drawobject.h"
173
#include "BDR_editcurve.h"
174
#include "BDR_unwrapper.h"
175
#include "BDR_gpencil.h"
178
#include "mydevice.h"
182
#include "butspace.h"
183
#include "BIF_transform.h"
185
#include "BIF_poseobject.h"
188
/* --------------------------------- */
190
void exit_paint_modes(void)
192
if(G.f & G_VERTEXPAINT) set_vpaint();
193
if(G.f & G_TEXTUREPAINT) set_texturepaint();
194
if(G.f & G_WEIGHTPAINT) set_wpaint();
195
if(G.f & G_SCULPTMODE) set_sculptmode();
196
if(G.f & G_PARTICLEEDIT) PE_set_particle_edit();
198
G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE+G_PARTICLEEDIT);
201
void add_object_draw(int type) /* for toolbox or menus, only non-editmode stuff */
206
setcursor_space(SPACE_VIEW3D, CURSOR_STD);
208
if ELEM3(curarea->spacetype, SPACE_VIEW3D, SPACE_BUTS, SPACE_INFO) {
209
if (G.obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
210
ob= add_object(type);
211
set_active_base(BASACT);
212
base_init_from_view3d(BASACT, G.vd);
214
/* only undo pushes on objects without editmode... */
215
if(type==OB_EMPTY) BIF_undo_push("Add Empty");
216
else if(type==OB_LAMP) {
217
BIF_undo_push("Add Lamp");
218
reshadeall_displist(); /* only frees */
220
else if(type==OB_LATTICE) BIF_undo_push("Add Lattice");
221
else if(type==OB_CAMERA) BIF_undo_push("Add Camera");
223
allqueue(REDRAWVIEW3D, 0);
226
redraw_test_buttons(OBACT);
228
allqueue(REDRAWALL, 0);
230
deselect_all_area_oops();
231
set_select_flag_oops();
233
DAG_scene_sort(G.scene);
234
allqueue(REDRAWINFO, 1); /* 1, because header->win==0! */
237
void add_objectLamp(short type)
241
/* this function also comes from an info window */
242
if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
245
add_object_draw(OB_LAMP);
246
base_init_from_view3d(BASACT, G.vd);
249
la = BASACT->object->data;
252
allqueue(REDRAWALL, 0);
255
/* remove base from a specific scene */
256
/* note: now unlinks constraints as well */
257
void free_and_unlink_base_from_scene(Scene *scene, Base *base)
259
BLI_remlink(&scene->base, base);
260
free_libblock_us(&G.main->object, base->object);
264
/* remove base from the current scene */
265
void free_and_unlink_base(Base *base)
269
free_and_unlink_base_from_scene(G.scene, base);
272
void delete_obj(int ok)
278
if(G.scene->id.lib) return;
282
Base *nbase= base->next;
286
/* Shift Del is global delete */
287
if (G.qual & LR_SHIFTKEY) {
288
if(!okee("Erase selected Object(s) Globally")) return;
291
if(!okee("Erase selected Object(s)")) return;
298
if(base->object->type==OB_LAMP) islamp= 1;
300
if(base->object->vnode) b_verse_delete_object(base->object);
306
for (scene= G.main->scene.first; scene; scene= scene->id.next) {
307
if (scene != G.scene && !(scene->id.lib)) {
308
base_other= object_in_scene( base->object, scene );
310
if (base_other == scene->basact) scene->basact= NULL; /* in case the object was active */
311
free_and_unlink_base_from_scene( scene, base_other );
317
/* remove from current scene only */
318
free_and_unlink_base(base);
325
setcursor_space(SPACE_VIEW3D, CURSOR_STD);
327
if(islamp) reshadeall_displist(); /* only frees displist */
329
redraw_test_buttons(OBACT);
330
allqueue(REDRAWVIEW3D, 0);
331
allqueue (REDRAWACTION, 0);
332
allqueue(REDRAWIPO, 0);
333
allqueue(REDRAWDATASELECT, 0);
334
allspace(OOPS_TEST, 0);
335
allqueue(REDRAWOOPS, 0);
336
allqueue(REDRAWACTION, 0);
337
allqueue(REDRAWNLA, 0);
339
DAG_scene_sort(G.scene);
340
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
342
BIF_undo_push("Delete object(s)");
345
static int return_editmesh_indexar(int *tot, int **indexar, float *cent)
347
EditMesh *em = G.editMesh;
349
int *index, nr, totvert=0;
351
for(eve= em->verts.first; eve; eve= eve->next) {
352
if(eve->f & SELECT) totvert++;
354
if(totvert==0) return 0;
356
*indexar= index= MEM_mallocN(4*totvert, "hook indexar");
359
cent[0]= cent[1]= cent[2]= 0.0;
361
for(eve= em->verts.first; eve; eve= eve->next) {
362
if(eve->f & SELECT) {
364
VecAddf(cent, cent, eve->co);
369
VecMulf(cent, 1.0f/(float)totvert);
374
static int return_editmesh_vgroup(char *name, float *cent)
376
EditMesh *em = G.editMesh;
381
cent[0]= cent[1]= cent[2]= 0.0;
383
if(G.obedit->actdef) {
385
/* find the vertices */
386
for(eve= em->verts.first; eve; eve= eve->next) {
387
dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
390
for(i=0; i<dvert->totweight; i++){
391
if(dvert->dw[i].def_nr == (G.obedit->actdef-1)) {
393
VecAddf(cent, cent, eve->co);
399
bDeformGroup *defGroup = BLI_findlink(&G.obedit->defbase, G.obedit->actdef-1);
400
strcpy(name, defGroup->name);
401
VecMulf(cent, 1.0f/(float)totvert);
409
static void select_editmesh_hook(HookModifierData *hmd)
411
EditMesh *em = G.editMesh;
415
for(eve= em->verts.first; eve; eve= eve->next, nr++) {
416
if(nr==hmd->indexar[index]) {
418
if(index < hmd->totindex-1) index++;
424
static int return_editlattice_indexar(int *tot, int **indexar, float *cent)
427
int *index, nr, totvert=0, a;
430
a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
433
if(bp->f1 & SELECT) {
434
if(bp->hide==0) totvert++;
439
if(totvert==0) return 0;
441
*indexar= index= MEM_mallocN(4*totvert, "hook indexar");
444
cent[0]= cent[1]= cent[2]= 0.0;
446
a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
449
if(bp->f1 & SELECT) {
452
VecAddf(cent, cent, bp->vec);
459
VecMulf(cent, 1.0f/(float)totvert);
464
static void select_editlattice_hook(HookModifierData *hmd)
467
int index=0, nr=0, a;
470
a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
473
if(hmd->indexar[index]==nr) {
475
if(index < hmd->totindex-1) index++;
482
static int return_editcurve_indexar(int *tot, int **indexar, float *cent)
484
extern ListBase editNurb;
488
int *index, a, nr, totvert=0;
490
for(nu= editNurb.first; nu; nu= nu->next) {
491
if((nu->type & 7)==CU_BEZIER) {
495
if(bezt->f1 & SELECT) totvert++;
496
if(bezt->f2 & SELECT) totvert++;
497
if(bezt->f3 & SELECT) totvert++;
503
a= nu->pntsu*nu->pntsv;
505
if(bp->f1 & SELECT) totvert++;
510
if(totvert==0) return 0;
512
*indexar= index= MEM_mallocN(4*totvert, "hook indexar");
515
cent[0]= cent[1]= cent[2]= 0.0;
517
for(nu= editNurb.first; nu; nu= nu->next) {
518
if((nu->type & 7)==CU_BEZIER) {
522
if(bezt->f1 & SELECT) {
524
VecAddf(cent, cent, bezt->vec[0]);
527
if(bezt->f2 & SELECT) {
529
VecAddf(cent, cent, bezt->vec[1]);
532
if(bezt->f3 & SELECT) {
534
VecAddf(cent, cent, bezt->vec[2]);
542
a= nu->pntsu*nu->pntsv;
544
if(bp->f1 & SELECT) {
546
VecAddf(cent, cent, bp->vec);
554
VecMulf(cent, 1.0f/(float)totvert);
559
/* use this when the loc/size/rot of the parent has changed but the children should stay in the same place
560
* apply-size-rot or object center for eg */
561
static void ignore_parent_tx( Object *ob ) {
563
/* a change was made, adjust the children to compensate */
564
for (ob_child=G.main->object.first; ob_child; ob_child=ob_child->id.next) {
565
if (ob_child->parent == ob) {
566
apply_obmat(ob_child);
567
what_does_parent(ob_child);
568
Mat4Invert(ob_child->parentinv, workob.obmat);
573
static void select_editcurve_hook(HookModifierData *hmd)
575
extern ListBase editNurb;
579
int index=0, a, nr=0;
581
for(nu= editNurb.first; nu; nu= nu->next) {
582
if((nu->type & 7)==CU_BEZIER) {
586
if(nr == hmd->indexar[index]) {
588
if(index<hmd->totindex-1) index++;
591
if(nr == hmd->indexar[index]) {
593
if(index<hmd->totindex-1) index++;
596
if(nr == hmd->indexar[index]) {
598
if(index<hmd->totindex-1) index++;
607
a= nu->pntsu*nu->pntsv;
609
if(nr == hmd->indexar[index]) {
611
if(index<hmd->totindex-1) index++;
620
void hook_select(HookModifierData *hmd)
622
if(G.obedit->type==OB_MESH) select_editmesh_hook(hmd);
623
else if(G.obedit->type==OB_LATTICE) select_editlattice_hook(hmd);
624
else if(G.obedit->type==OB_CURVE) select_editcurve_hook(hmd);
625
else if(G.obedit->type==OB_SURF) select_editcurve_hook(hmd);
628
int hook_getIndexArray(int *tot, int **indexar, char *name, float *cent_r)
634
switch(G.obedit->type) {
636
/* check selected vertices first */
637
if( return_editmesh_indexar(tot, indexar, cent_r)) return 1;
638
else return return_editmesh_vgroup(name, cent_r);
641
return return_editcurve_indexar(tot, indexar, cent_r);
643
return return_editlattice_indexar(tot, indexar, cent_r);
649
void add_hook_menu(void)
653
if(G.obedit==NULL) return;
655
if(modifiers_findByType(G.obedit, eModifierType_Hook))
656
mode= pupmenu("Hooks %t|Add, To New Empty %x1|Add, To Selected Object %x2|Remove... %x3|Reassign... %x4|Select... %x5|Clear Offset...%x6");
658
mode= pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
665
allqueue(REDRAWVIEW3D, 0);
666
allqueue(REDRAWBUTSOBJECT, 0);
668
BIF_undo_push("Add hook");
671
void add_hook(int mode)
673
ModifierData *md = NULL;
674
HookModifierData *hmd = NULL;
677
if(G.obedit==NULL) return;
680
if(mode==2) { /* selected object */
681
Base *base= FIRSTBASE;
683
if TESTBASELIB(base) {
692
error("Requires selected Object");
700
/* make pupmenu with hooks */
701
for(md=G.obedit->modifiers.first; md; md= md->next) {
702
if (md->type==eModifierType_Hook)
707
error("Object has no hooks yet");
711
cp= MEM_callocN(maxlen+32, "temp string");
712
if(mode==3) strcpy(cp, "Remove %t|");
713
else if(mode==4) strcpy(cp, "Reassign %t|");
714
else if(mode==5) strcpy(cp, "Select %t|");
715
else if(mode==6) strcpy(cp, "Clear Offset %t|");
717
for(md=G.obedit->modifiers.first; md; md= md->next) {
718
if (md->type==eModifierType_Hook) {
719
strcat(cp, md->name);
730
for(md=G.obedit->modifiers.first; md; md=md->next) {
731
if (md->type==eModifierType_Hook) {
737
hmd = (HookModifierData*) md;
741
/* do it, new hooks or reassign */
742
if(mode==1 || mode==2 || mode==4) {
744
int tot, ok, *indexar;
747
ok = hook_getIndexArray(&tot, &indexar, name, cent);
750
error("Requires selected vertices or active Vertex Group");
755
Base *base= BASACT, *newbase;
757
ob= add_object(OB_EMPTY);
760
newbase->lay= base->lay;
761
ob->lay= newbase->lay;
763
/* transform cent to global coords for loc */
764
VecMat4MulVecfl(ob->loc, G.obedit->obmat, cent);
766
/* restore, add_object sets active */
769
/* if mode is 2 or 4, ob has been set */
772
if(mode==1 || mode==2) {
773
ModifierData *md = G.obedit->modifiers.first;
775
while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) {
779
hmd = (HookModifierData*) modifier_new(eModifierType_Hook);
780
BLI_insertlinkbefore(&G.obedit->modifiers, md, hmd);
781
sprintf(hmd->modifier.name, "Hook-%s", ob->id.name+2);
783
else if (hmd->indexar) MEM_freeN(hmd->indexar); /* reassign, hook was set */
786
hmd->indexar= indexar;
787
VECCOPY(hmd->cent, cent);
789
BLI_strncpy(hmd->name, name, 32);
791
if(mode==1 || mode==2) {
792
/* matrix calculus */
793
/* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
798
Mat4Invert(ob->imat, ob->obmat);
799
/* apparently this call goes from right to left... */
800
Mat4MulSerie(hmd->parentinv, ob->imat, G.obedit->obmat, NULL,
801
NULL, NULL, NULL, NULL, NULL);
805
else if(mode==3) { /* remove */
806
BLI_remlink(&G.obedit->modifiers, md);
809
else if(mode==5) { /* select */
812
else if(mode==6) { /* clear offset */
813
where_is_object(ob); /* ob is hook->parent */
815
Mat4Invert(ob->imat, ob->obmat);
816
/* this call goes from right to left... */
817
Mat4MulSerie(hmd->parentinv, ob->imat, G.obedit->obmat, NULL,
818
NULL, NULL, NULL, NULL, NULL);
821
DAG_scene_sort(G.scene);
824
void make_track(void)
829
if(G.scene->id.lib) return;
833
if(BASACT==0) return;
835
mode= pupmenu("Make Track %t|TrackTo Constraint %x1|LockTrack Constraint %x2|Old Track %x3");
841
bTrackToConstraint *data;
845
if TESTBASELIB(base) {
847
con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
848
strcpy (con->name, "AutoTrack");
851
data->tar = BASACT->object;
852
base->object->recalc |= OB_RECALC;
854
/* Lamp and Camera track differently by default */
855
if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
856
data->reserved1 = TRACK_nZ;
857
data->reserved2 = UP_Y;
860
add_constraint_to_object(con, base->object);
869
bLockTrackConstraint *data;
873
if TESTBASELIB(base) {
875
con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
876
strcpy (con->name, "AutoTrack");
879
data->tar = BASACT->object;
880
base->object->recalc |= OB_RECALC;
882
/* Lamp and Camera track differently by default */
883
if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
884
data->trackflag = TRACK_nZ;
885
data->lockflag = LOCK_Y;
888
add_constraint_to_object(con, base->object);
898
if TESTBASELIB(base) {
900
base->object->track= BASACT->object;
901
base->object->recalc |= OB_RECALC;
908
allqueue(REDRAWOOPS, 0);
909
allqueue(REDRAWVIEW3D, 0);
910
DAG_scene_sort(G.scene);
912
BIF_undo_push("Make Track");
915
void apply_obmat(Object *ob)
917
float mat[3][3], imat[3][3], tmat[3][3];
919
/* from obmat to loc rot size */
922
Mat3CpyMat4(mat, ob->obmat);
924
VECCOPY(ob->loc, ob->obmat[3]);
925
/* Quats arnt used yet */
926
/*if(ob->transflag & OB_QUAT) {
927
Mat3ToQuat(mat, ob->quat);
928
QuatToMat3(ob->quat, tmat);
931
Mat3ToEul(mat, ob->rot);
932
EulToMat3(ob->rot, tmat);
936
Mat3MulMat3(tmat, imat, mat);
938
ob->size[0]= tmat[0][0];
939
ob->size[1]= tmat[1][1];
940
ob->size[2]= tmat[2][2];
944
void clear_parent(void)
951
if(G.scene->id.lib) return;
953
mode= pupmenu("OK? %t|Clear Parent %x1|Clear and Keep Transformation (Clear Track) %x2|Clear Parent Inverse %x3");
959
if TESTBASELIB(base) {
961
if(mode==1 || mode==2) {
962
par= base->object->parent;
963
base->object->parent= NULL;
964
base->object->recalc |= OB_RECALC;
967
base->object->track= NULL;
968
apply_obmat(base->object);
972
Mat4One(base->object->parentinv);
973
base->object->recalc |= OB_RECALC;
979
DAG_scene_sort(G.scene);
980
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
981
allqueue(REDRAWVIEW3D, 0);
982
allqueue(REDRAWOOPS, 0);
984
BIF_undo_push("Clear Parent");
987
void clear_track(void)
993
if(G.scene->id.lib) return;
995
mode= pupmenu("OK? %t|Clear Track %x1| Clear Track and Keep Transform %x2");
1001
if TESTBASELIB(base) {
1002
base->object->track= NULL;
1003
base->object->recalc |= OB_RECALC;
1006
apply_obmat(base->object);
1012
DAG_scene_sort(G.scene);
1013
allqueue(REDRAWVIEW3D, 0);
1014
allqueue(REDRAWOOPS, 0);
1016
BIF_undo_push("Clear Track");
1019
void clear_object(char mode)
1023
float *v1, *v3, mat[3][3];
1024
int armature_clear= 0;
1027
if(G.obedit) return;
1028
if(G.scene->id.lib) return;
1030
if(mode=='r') str= "Clear rotation";
1031
else if(mode=='g') str= "Clear location";
1032
else if(mode=='s') str= "Clear scale";
1033
else if(mode=='o') str= "Clear origin";
1038
if TESTBASELIB(base) {
1041
if ((ob->flag & OB_POSEMODE)) {
1042
/* only clear pose transforms if:
1043
* - with a mesh in weightpaint mode, it's related armature needs to be cleared
1044
* - with clearing transform of object being edited at the time
1046
if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
1047
clear_armature(ob, mode);
1048
armature_clear= 1; /* silly system to prevent another dag update, so no action applied */
1051
else if((G.f & G_WEIGHTPAINT)==0) {
1052
/* only clear transforms of 'normal' (not armature) object if:
1053
* - not in weightpaint mode or editmode
1054
* - if that object's transform locks are not enabled (this is done on a per-channel basis)
1057
/* eulers can only get cleared if they are not protected */
1058
if ((ob->protectflag & OB_LOCK_ROTX)==0)
1059
ob->rot[0]= ob->drot[0]= 0.0f;
1060
if ((ob->protectflag & OB_LOCK_ROTY)==0)
1061
ob->rot[1]= ob->drot[1]= 0.0f;
1062
if ((ob->protectflag & OB_LOCK_ROTZ)==0)
1063
ob->rot[2]= ob->drot[2]= 0.0f;
1065
/* quats here are not really used anymore anywhere, so it probably doesn't
1066
* matter to not clear them whether the euler-based rotation is used
1068
/*QuatOne(ob->quat);
1069
QuatOne(ob->dquat);*/
1073
struct VNode *vnode = (VNode*)ob->vnode;
1074
((VObjectData*)vnode->data)->flag |= ROT_SEND_READY;
1075
b_verse_send_transformation(ob);
1080
else if (mode=='g') {
1081
if ((ob->protectflag & OB_LOCK_LOCX)==0)
1082
ob->loc[0]= ob->dloc[0]= 0.0f;
1083
if ((ob->protectflag & OB_LOCK_LOCY)==0)
1084
ob->loc[1]= ob->dloc[1]= 0.0f;
1085
if ((ob->protectflag & OB_LOCK_LOCZ)==0)
1086
ob->loc[2]= ob->dloc[2]= 0.0f;
1090
struct VNode *vnode = (VNode*)ob->vnode;
1091
((VObjectData*)vnode->data)->flag |= POS_SEND_READY;
1092
b_verse_send_transformation(ob);
1097
else if (mode=='s') {
1098
if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
1102
if ((ob->protectflag & OB_LOCK_SCALEY)==0) {
1106
if ((ob->protectflag & OB_LOCK_SCALEZ)==0) {
1112
struct VNode *vnode = (VNode*)ob->vnode;
1113
((VObjectData*)vnode->data)->flag |= SCALE_SEND_READY;
1114
b_verse_send_transformation(ob);
1119
else if(mode=='o') {
1122
v3= ob->parentinv[3];
1124
Mat3CpyMat4(mat, ob->parentinv);
1129
Mat3MulVecfl(mat, v3);
1133
ob->recalc |= OB_RECALC_OB;
1139
allqueue(REDRAWVIEW3D, 0);
1140
if(armature_clear==0) /* in this case flush was done */
1141
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
1145
void reset_slowparents(void)
1147
/* back to original locations */
1152
if(base->object->parent) {
1153
if(base->object->partype & PARSLOW) {
1154
base->object->partype -= PARSLOW;
1155
where_is_object(base->object);
1156
base->object->partype |= PARSLOW;
1163
void set_slowparent(void)
1167
if( okee("Set slow parent")==0 ) return;
1171
if TESTBASELIB(base) {
1172
if(base->object->parent) base->object->partype |= PARSLOW;
1176
BIF_undo_push("Slow parent");
1179
void make_vertex_parent(void)
1181
EditMesh *em = G.editMesh;
1188
int a, v1=0, v2=0, v3=0, v4=0, nr=1;
1190
/* we need 1 to 3 selected vertices */
1192
if(G.obedit->type==OB_MESH) {
1193
eve= em->verts.first;
1197
else if(v2==0) v2= nr;
1198
else if(v3==0) v3= nr;
1199
else if(v4==0) v4= nr;
1206
else if ELEM(G.obedit->type, OB_SURF, OB_CURVE) {
1207
extern ListBase editNurb;
1210
if((nu->type & 7)==CU_BEZIER) {
1214
if(BEZSELECTED_HIDDENHANDLES(bezt)) {
1216
else if(v2==0) v2= nr;
1217
else if(v3==0) v3= nr;
1218
else if(v4==0) v4= nr;
1227
a= nu->pntsu*nu->pntsv;
1229
if(bp->f1 & SELECT) {
1231
else if(v2==0) v2= nr;
1232
else if(v3==0) v3= nr;
1233
else if(v4==0) v4= nr;
1243
else if(G.obedit->type==OB_LATTICE) {
1245
a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
1248
if(bp->f1 & SELECT) {
1250
else if(v2==0) v2= nr;
1251
else if(v3==0) v3= nr;
1252
else if(v4==0) v4= nr;
1260
if(v4 || !((v1 && v2==0 && v3==0) || (v1 && v2 && v3)) ) {
1261
error("Select either 1 or 3 vertices to parent to");
1265
if(okee("Make vertex parent")==0) return;
1269
if TESTBASELIB(base) {
1273
ob->recalc |= OB_RECALC;
1274
par= BASACT->object->parent;
1281
error("Loop in parents");
1284
ob->parent= BASACT->object;
1286
ob->partype= PARVERT3;
1291
/* inverse parent matrix */
1292
what_does_parent(ob);
1293
Mat4Invert(ob->parentinv, workob.obmat);
1297
ob->partype= PARVERT1;
1300
/* inverse parent matrix */
1301
what_does_parent(ob);
1302
Mat4Invert(ob->parentinv, workob.obmat);
1310
allqueue(REDRAWVIEW3D, 0);
1312
DAG_scene_sort(G.scene);
1313
/* BIF_undo_push(str); not, conflicts with editmode undo... */
1316
static Object *group_objects_menu(Group *group)
1323
for(go= group->gobject.first; go; go= go->next) {
1327
if(len==0) return NULL;
1329
str= MEM_callocN(40+32*len, "menu");
1331
strcpy(str, "Make Proxy for: %t");
1333
for(nr=1, go= group->gobject.first; go; go= go->next, nr++) {
1334
a+= sprintf(str+a, "|%s %%x%d", go->ob->id.name+2, nr);
1337
a= pupmenu_col(str, 20);
1340
go= BLI_findlink(&group->gobject, a-1);
1347
/* adds empty object to become local replacement data of a library-linked object */
1348
void make_proxy(void)
1353
if(G.scene->id.lib) return;
1354
if(ob==NULL) return;
1357
if(ob->dup_group && ob->dup_group->id.lib) {
1359
/* gives menu with list of objects in group */
1360
ob= group_objects_menu(ob->dup_group);
1362
else if(ob->id.lib) {
1363
if(okee("Make Proxy Object")==0)
1367
error("Can only make proxy for a referenced object or group");
1373
Base *newbase, *oldbase= BASACT;
1376
newob= add_object(OB_EMPTY);
1378
strcpy(name, gob->id.name+2);
1380
strcpy(name, ob->id.name+2);
1381
strcat(name, "_proxy");
1382
rename_id(&newob->id, name);
1385
newbase= BASACT; /* add_object sets active... */
1386
newbase->lay= oldbase->lay;
1387
newob->lay= newbase->lay;
1389
/* remove base, leave user count of object, it gets linked in object_make_proxy */
1391
BLI_remlink(&G.scene->base, oldbase);
1394
object_make_proxy(newob, ob, gob);
1396
DAG_scene_sort(G.scene);
1397
DAG_object_flush_update(G.scene, newob, OB_RECALC);
1398
allqueue(REDRAWALL, 0);
1399
BIF_undo_push("Make Proxy Object");
1403
int test_parent_loop(Object *par, Object *ob)
1405
/* test if 'ob' is a parent somewhere in par's parents */
1407
if(par==0) return 0;
1408
if(ob == par) return 1;
1410
return test_parent_loop(par->parent, ob);
1414
void make_parent(void)
1418
bPoseChannel *pchan= NULL;
1421
if(G.scene->id.lib) return;
1423
if ELEM4(G.obedit->type, OB_MESH, OB_CURVE, OB_SURF, OB_LATTICE) make_vertex_parent();
1424
else if (G.obedit->type==OB_ARMATURE) make_bone_parent();
1427
if(BASACT==0) return;
1430
par= BASACT->object;
1432
if(par->type == OB_LATTICE){
1433
mode= pupmenu("Make Parent %t|Normal Parent %x1|Lattice Deform %x2");
1444
else if(par->type == OB_CURVE){
1445
mode= pupmenu("Make Parent %t|Normal Parent %x1|Follow Path %x2|Curve Deform %x3|Path Constraint %x4");
1453
Curve *cu= par->data;
1456
if((cu->flag & CU_PATH)==0) {
1457
cu->flag |= CU_PATH|CU_FOLLOW;
1458
makeDispListCurveTypes(par, 0); /* force creation of path data */
1460
else cu->flag |= CU_FOLLOW;
1467
bFollowPathConstraint *data;
1471
if TESTBASELIB(base) {
1473
float cmat[4][4], vec[3];
1475
con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1476
strcpy (con->name, "AutoPath");
1479
data->tar = BASACT->object;
1481
add_constraint_to_object(con, base->object);
1483
get_constraint_target_matrix(con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, G.scene->r.cfra - give_timeoffset(base->object));
1484
VecSubf(vec, base->object->obmat[3], cmat[3]);
1486
base->object->loc[0] = vec[0];
1487
base->object->loc[1] = vec[1];
1488
base->object->loc[2] = vec[2];
1494
allqueue(REDRAWVIEW3D, 0);
1495
DAG_scene_sort(G.scene);
1496
BIF_undo_push("Make Parent");
1500
else if(par->type == OB_ARMATURE){
1504
if TESTBASELIB(base) {
1506
if(ELEM(base->object->type, OB_MESH, OB_LATTICE)) {
1507
if(par->flag & OB_POSEMODE)
1508
mode= pupmenu("Make Parent To%t|Bone %x1|Armature %x2|Object %x3");
1510
mode= pupmenu("Make Parent To%t|Armature %x2|Object %x3");
1514
if(par->flag & OB_POSEMODE)
1515
mode= pupmenu("Make Parent To %t|Bone %x1|Object %x3");
1517
mode= pupmenu("Make Parent To %t|Object %x3");
1528
pchan= get_active_posechannel(par);
1531
error("No active Bone");
1532
allqueue(REDRAWVIEW3D, 0);
1548
if(qual & LR_SHIFTKEY) {
1549
if(okee("Make parent without inverse")==0) return;
1552
if(qual & LR_ALTKEY) {
1553
if(okee("Make vertex parent")==0) return;
1555
else if(okee("Make parent")==0) return;
1557
/* now we'll clearparentandkeeptransform all objects */
1560
if TESTBASELIB(base) {
1561
if(base!=BASACT && base->object->parent) {
1562
base->object->parent= NULL;
1563
apply_obmat(base->object);
1571
par->recalc |= OB_RECALC_OB;
1575
if TESTBASELIB(base) {
1578
if( test_parent_loop(par, base->object) ) {
1579
error("Loop in parents");
1583
base->object->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
1585
/* the ifs below are horrible code (ton) */
1587
if (par->type==OB_ARMATURE) {
1588
base->object->partype= mode;
1590
strcpy (base->object->parsubstr, pchan->name);
1592
base->object->parsubstr[0]=0;
1595
if(qual & LR_ALTKEY) {
1596
base->object->partype= PARVERT1;
1598
else if(ELEM(par->type, OB_CURVE, OB_LATTICE)) {
1599
base->object->partype= mode;
1602
base->object->partype= PAROBJECT;
1606
base->object->parent= par;
1608
/* calculate inverse parent matrix? */
1609
if( (qual & LR_SHIFTKEY) ) {
1611
Mat4One(base->object->parentinv);
1612
memset(base->object->loc, 0, 3*sizeof(float));
1615
if(mode==PARSKEL && base->object->type==OB_MESH && par->type == OB_ARMATURE) {
1616
/* Prompt the user as to whether he wants to
1617
* add some vertex groups based on the bones
1618
* in the parent armature.
1620
create_vgroups_from_armature(base->object,
1623
base->object->partype= PAROBJECT;
1624
what_does_parent(base->object);
1625
Mat4One (base->object->parentinv);
1626
base->object->partype= mode;
1629
what_does_parent(base->object);
1630
Mat4Invert(base->object->parentinv, workob.obmat);
1637
allqueue(REDRAWVIEW3D, 0);
1638
allqueue(REDRAWOOPS, 0);
1640
DAG_scene_sort(G.scene);
1641
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
1643
BIF_undo_push("make Parent");
1647
void enter_editmode(int wc)
1655
if(G.scene->id.lib) return;
1658
if((G.vd==NULL || (base->lay & G.vd->lay))==0) return;
1660
strcpy(G.editModeTitleExtra, "");
1663
if(ob->data==0) return;
1665
if (object_data_is_libdata(ob)) {
1670
if(wc) waitcursor(1);
1672
if(ob->type==OB_MESH) {
1675
if(me->pv) mesh_pmv_off(ob, me);
1679
allqueue(REDRAWBUTSLOGIC, 0);
1680
/*if(G.f & G_FACESELECT) allqueue(REDRAWIMAGE, 0);*/
1681
if (EM_texFaceCheck())
1682
allqueue(REDRAWIMAGE, 0);
1685
if (ob->type==OB_ARMATURE){
1686
arm= base->object->data;
1689
* The function object_data_is_libdata make a problem here, the
1690
* check for ob->proxy return 0 and let blender enter to edit mode
1691
* this causa a crash when you try leave the edit mode.
1692
* The problem is that i can't remove the ob->proxy check from
1693
* object_data_is_libdata that prevent the bugfix #6614, so
1694
* i add this little hack here.
1702
make_editArmature();
1703
/* to ensure all goes in restposition and without striding */
1704
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC);
1706
allqueue (REDRAWVIEW3D,0);
1708
else if(ob->type==OB_FONT) {
1713
else if(ob->type==OB_MBALL) {
1718
else if(ob->type==OB_LATTICE) {
1723
else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
1728
allqueue(REDRAWBUTSEDIT, 0);
1729
allqueue(REDRAWOOPS, 0);
1733
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
1735
allqueue(REDRAWVIEW3D, 1);
1736
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
1739
else G.obedit= NULL;
1741
if(wc) waitcursor(0);
1743
scrarea_queue_headredraw(curarea);
1746
void exit_editmode(int flag) /* freedata==0 at render, 1= freedata, 2= do undo buffer too */
1749
int freedata = flag & EM_FREEDATA;
1751
if(G.obedit==NULL) return;
1753
if(flag & EM_WAITCURSOR) waitcursor(1);
1754
if(G.obedit->type==OB_MESH) {
1759
if(EM_texFaceCheck())
1760
allqueue(REDRAWIMAGE, 0);
1762
if(retopo_mesh_paint_check())
1765
if(G.totvert>MESH_MAX_VERTS) {
1766
error("Too many vertices");
1771
if(freedata) free_editMesh(G.editMesh);
1773
if(G.f & G_WEIGHTPAINT)
1774
mesh_octree_table(G.obedit, NULL, 'e');
1776
else if (G.obedit->type==OB_ARMATURE){
1777
load_editArmature();
1778
if (freedata) free_editArmature();
1780
else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1781
extern ListBase editNurb;
1783
if(freedata) freeNurblist(&editNurb);
1785
else if(G.obedit->type==OB_FONT && freedata) {
1788
else if(G.obedit->type==OB_LATTICE) {
1790
if(freedata) free_editLatt();
1792
else if(G.obedit->type==OB_MBALL) {
1793
extern ListBase editelems;
1795
if(freedata) BLI_freelistN(&editelems);
1800
/* for example; displist make is different in editmode */
1801
if(freedata) G.obedit= NULL;
1803
if(ob->type==OB_MESH && get_mesh(ob)->mr)
1804
multires_edge_level_update(ob, get_mesh(ob));
1806
/* also flush ob recalc, doesn't take much overhead, but used for particles */
1807
DAG_object_flush_update(G.scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
1810
setcursor_space(SPACE_VIEW3D, CURSOR_STD);
1814
allqueue(REDRAWVIEW3D, 1);
1815
allqueue(REDRAWBUTSALL, 0);
1816
allqueue(REDRAWACTION, 0);
1817
allqueue(REDRAWNLA, 0);
1818
allqueue(REDRAWIPO, 0);
1819
allqueue(REDRAWOOPS, 0);
1821
scrarea_queue_headredraw(curarea);
1823
if(G.obedit==NULL && (flag & EM_FREEUNDO))
1824
BIF_undo_push("Editmode");
1826
if(flag & EM_WAITCURSOR) waitcursor(0);
1829
void check_editmode(int type)
1832
if (G.obedit==0 || G.obedit->type==type) return;
1834
exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
1837
/* 0 == do center, 1 == center new, 2 == center cursor */
1839
void docenter(int centermode)
1841
EditMesh *em = G.editMesh;
1850
float cent[3], centn[3], min[3], max[3], omat[3][3];
1853
/* keep track of what is changed */
1854
int tot_change=0, tot_lib_error=0, tot_key_error=0, tot_multiuser_arm_error=0;
1857
if(G.scene->id.lib || G.vd==NULL) return;
1859
cent[0]= cent[1]= cent[2]= 0.0;
1863
INIT_MINMAX(min, max);
1865
if(G.obedit->type==OB_MESH) {
1866
for(eve= em->verts.first; eve; eve= eve->next) {
1867
if(G.vd->around==V3D_CENTROID) {
1869
VECADD(cent, cent, eve->co);
1872
DO_MINMAX(eve->co, min, max);
1876
if(G.vd->around==V3D_CENTROID) {
1877
VecMulf(cent, 1.0f/(float)total);
1880
cent[0]= (min[0]+max[0])/2.0f;
1881
cent[1]= (min[1]+max[1])/2.0f;
1882
cent[2]= (min[2]+max[2])/2.0f;
1885
for(eve= em->verts.first; eve; eve= eve->next) {
1886
VecSubf(eve->co, eve->co, cent);
1889
recalc_editnormals();
1891
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
1896
for (base=FIRSTBASE; base; base= base->next) {
1897
if TESTBASELIB(base)
1898
base->object->flag &= ~OB_DONE;
1901
for (me= G.main->mesh.first; me; me= me->id.next) {
1902
me->flag &= ~ME_ISDONE;
1908
if TESTBASELIB(base) {
1909
if((base->object->flag & OB_DONE)==0) {
1910
base->object->flag |= OB_DONE;
1912
if(base->object->id.lib) {
1915
else if(G.obedit==0 && (me=get_mesh(base->object)) ) {
1918
/*error("Can't change the center of a mesh with vertex keys");
1921
} else if (me->id.lib) {
1925
VECCOPY(cent, give_cursor());
1926
Mat4Invert(base->object->imat, base->object->obmat);
1927
Mat4MulVecfl(base->object->imat, cent);
1929
INIT_MINMAX(min, max);
1931
for(a=0; a<me->totvert; a++, mvert++) {
1932
DO_MINMAX(mvert->co, min, max);
1935
cent[0]= (min[0]+max[0])/2.0f;
1936
cent[1]= (min[1]+max[1])/2.0f;
1937
cent[2]= (min[2]+max[2])/2.0f;
1941
for(a=0; a<me->totvert; a++, mvert++) {
1942
VecSubf(mvert->co, mvert->co, cent);
1944
me->flag |= ME_ISDONE;
1947
Mat3CpyMat4(omat, base->object->obmat);
1949
VECCOPY(centn, cent);
1950
Mat3MulVecfl(omat, centn);
1951
base->object->loc[0]+= centn[0];
1952
base->object->loc[1]+= centn[1];
1953
base->object->loc[2]+= centn[2];
1955
where_is_object(base->object);
1956
ignore_parent_tx(base->object);
1959
ob= G.main->object.first;
1961
if((ob->flag & OB_DONE)==0) {
1966
ob->flag |= OB_DONE;
1967
ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
1969
Mat3CpyMat4(omat, ob->obmat);
1970
VECCOPY(centn, cent);
1971
Mat3MulVecfl(omat, centn);
1972
ob->loc[0]+= centn[0];
1973
ob->loc[1]+= centn[1];
1974
ob->loc[2]+= centn[2];
1976
where_is_object(ob);
1977
ignore_parent_tx(ob);
1979
if(tme && (tme->flag & ME_ISDONE)==0) {
1981
for(a=0; a<tme->totvert; a++, mvert++) {
1982
VecSubf(mvert->co, mvert->co, cent);
1984
tme->flag |= ME_ISDONE;
1995
else if ELEM(base->object->type, OB_CURVE, OB_SURF) {
1997
/* totally weak code here... (ton) */
1998
if(G.obedit==base->object) {
1999
extern ListBase editNurb;
2000
nu1= editNurb.first;
2004
cu= base->object->data;
2005
nu1= cu->nurb.first;
2012
VECCOPY(cent, give_cursor());
2013
Mat4Invert(base->object->imat, base->object->obmat);
2014
Mat4MulVecfl(base->object->imat, cent);
2016
/* don't allow Z change if curve is 2D */
2017
if( !( cu->flag & CU_3D ) )
2020
INIT_MINMAX(min, max);
2024
minmaxNurb(nu, min, max);
2028
cent[0]= (min[0]+max[0])/2.0f;
2029
cent[1]= (min[1]+max[1])/2.0f;
2030
cent[2]= (min[2]+max[2])/2.0f;
2035
if( (nu->type & 7)==1) {
2038
VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
2039
VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
2040
VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
2044
a= nu->pntsu*nu->pntsv;
2046
VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
2051
if(centermode && G.obedit==0) {
2052
Mat3CpyMat4(omat, base->object->obmat);
2054
Mat3MulVecfl(omat, cent);
2055
base->object->loc[0]+= cent[0];
2056
base->object->loc[1]+= cent[1];
2057
base->object->loc[2]+= cent[2];
2059
where_is_object(base->object);
2060
ignore_parent_tx(base->object);
2065
if (centermode==0) {
2066
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2072
else if(base->object->type==OB_FONT) {
2075
cu= base->object->data;
2079
} else if (cu->id.lib) {
2082
cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
2083
cu->yof= -0.5f -0.5f*( cu->bb->vec[0][1] - cu->bb->vec[2][1]); /* extra 0.5 is the height of above line */
2085
/* not really ok, do this better once! */
2086
cu->xof /= cu->fsize;
2087
cu->yof /= cu->fsize;
2089
allqueue(REDRAWBUTSEDIT, 0);
2093
else if(base->object->type==OB_ARMATURE) {
2094
bArmature *arm = base->object->data;
2098
} else if(arm->id.us>1) {
2099
/*error("Can't apply to a multi user armature");
2101
tot_multiuser_arm_error++;
2103
/* Function to recenter armatures in editarmature.c
2104
* Bone + object locations are handled there.
2106
docenter_armature(base->object, centermode);
2109
where_is_object(base->object);
2110
ignore_parent_tx(base->object);
2116
base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
2122
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
2123
allqueue(REDRAWVIEW3D, 0);
2124
BIF_undo_push("Do Center");
2127
/* Warn if any errors occured */
2128
if (tot_lib_error+tot_key_error+tot_multiuser_arm_error) {
2130
sprintf(err, "Warning %i Object(s) Not Centered, %i Changed:", tot_lib_error+tot_key_error+tot_multiuser_arm_error, tot_change);
2133
sprintf(err+strlen(err), "|%i linked library objects", tot_lib_error);
2135
sprintf(err+strlen(err), "|%i mesh key object(s)", tot_key_error);
2136
if (tot_multiuser_arm_error)
2137
sprintf(err+strlen(err), "|%i multiuser armature object(s)", tot_multiuser_arm_error);
2143
void docenter_new(void)
2145
if(G.scene->id.lib) return;
2148
error("Unable to center new in Edit Mode");
2155
void docenter_cursor(void)
2157
if(G.scene->id.lib) return;
2160
error("Unable to center cursor in Edit Mode");
2167
void movetolayer(void)
2170
unsigned int lay= 0, local;
2173
if(G.scene->id.lib) return;
2177
if TESTBASE(base) lay |= base->lay;
2185
if(G.vd->localview) {
2186
/* now we can move out of localview. */
2187
if (!okee("Move from localview")) return;
2191
lay= base->lay & ~G.vd->lay;
2193
base->object->lay= lay;
2194
base->object->flag &= ~SELECT;
2195
base->flag &= ~SELECT;
2196
if(base->object->type==OB_LAMP) islamp= 1;
2201
if( movetolayer_buts(&lay, NULL)==0 ) return;
2203
/* normal non localview operation */
2207
/* upper byte is used for local view */
2208
local= base->lay & 0xFF000000;
2209
base->lay= lay + local;
2210
base->object->lay= lay;
2211
if(base->object->type==OB_LAMP) islamp= 1;
2216
if(islamp) reshadeall_displist(); /* only frees */
2218
/* warning, active object may be hidden now */
2221
DAG_scene_sort(G.scene);
2223
allqueue(REDRAWBUTSEDIT, 0);
2224
allqueue(REDRAWVIEW3D, 0);
2225
allqueue(REDRAWOOPS, 0);
2226
allqueue(REDRAWINFO, 0);
2228
BIF_undo_push("Move to layer");
2231
/* THIS IS BAD CODE! do not bring back before it has a real implementation (ton) */
2235
Base *oldbase = BASACT;
2236
Curve *cu= ob->data;
2238
int slen= strlen(p);
2241
for (i = 0; i<=slen; p++, i++) {
2242
adduplicate(1, U.dupflag);
2245
text_to_curve(OBACT, 0); /* pass 1: only one letter, adapt position */
2246
text_to_curve(OBACT, 0); /* pass 2: remake */
2247
freedisplist(&OBACT->disp);
2248
makeDispListCurveTypes(OBACT, 0);
2250
OBACT->flag &= ~SELECT;
2251
BASACT->flag &= ~SELECT;
2252
oldbase->flag |= SELECT;
2253
oldbase->object->flag |= SELECT;
2254
set_active_base(oldbase);
2258
static void helpline(short *mval, int *center2d)
2261
/* helpline, copied from transform.c actually */
2263
glDrawBuffer(GL_FRONT);
2265
BIF_ThemeColor(TH_WIRE);
2268
glBegin(GL_LINE_STRIP);
2270
glVertex2iv((GLint *)center2d);
2275
bglFlush(); // flush display for frontbuffer
2276
glDrawBuffer(GL_BACK);
2281
/* context: ob = lamp */
2282
/* code should be replaced with proper (custom) transform handles for lamp properties */
2283
static void spot_interactive(Object *ob, int mode)
2286
float transfac, dx, dy, ratio, origval;
2287
int keep_running= 1, center2d[2];
2288
short mval[2], mvalo[2];
2290
getmouseco_areawin(mval);
2291
getmouseco_areawin(mvalo);
2293
project_int(ob->obmat[3], center2d);
2294
if( center2d[0] > 100000 ) { /* behind camera */
2295
center2d[0]= curarea->winx/2;
2296
center2d[1]= curarea->winy/2;
2299
helpline(mval, center2d);
2301
/* ratio is like scaling */
2302
dx = (float)(center2d[0] - mval[0]);
2303
dy = (float)(center2d[1] - mval[1]);
2304
transfac = (float)sqrt( dx*dx + dy*dy);
2305
if(transfac==0.0f) transfac= 1.0f;
2308
origval= la->spotsize;
2312
origval= la->clipsta;
2314
origval= la->clipend;
2316
while (keep_running>0) {
2318
getmouseco_areawin(mval);
2320
/* essential for idling subloop */
2321
if(mval[0]==mvalo[0] && mval[1]==mvalo[1]) {
2327
dx = (float)(center2d[0] - mval[0]);
2328
dy = (float)(center2d[1] - mval[1]);
2329
ratio = (float)(sqrt( dx*dx + dy*dy))/transfac;
2333
if(mode==1) { /* spot */
2334
la->spotsize = ratio*origval;
2335
CLAMP(la->spotsize, 1.0f, 180.0f);
2336
sprintf(str, "Spot size %.2f\n", la->spotsize);
2338
else if(mode==2) { /* dist */
2339
la->dist = ratio*origval;
2340
CLAMP(la->dist, 0.01f, 5000.0f);
2341
sprintf(str, "Distance %.2f\n", la->dist);
2343
else if(mode==3) { /* sta */
2344
la->clipsta = ratio*origval;
2345
CLAMP(la->clipsta, 0.001f, 5000.0f);
2346
sprintf(str, "Distance %.2f\n", la->clipsta);
2348
else if(mode==4) { /* end */
2349
la->clipend = ratio*origval;
2350
CLAMP(la->clipend, 0.1f, 5000.0f);
2351
sprintf(str, "Clip End %.2f\n", la->clipend);
2358
/* handle shaded mode */
2359
shade_buttons_change_3d();
2363
force_draw_plus(SPACE_BUTS, 0);
2365
helpline(mval, center2d);
2370
unsigned short event= extern_qread(&val);
2388
if(keep_running==0) {
2390
la->spotsize= origval;
2394
la->clipsta= origval;
2396
la->clipend= origval;
2399
allqueue(REDRAWVIEW3D, 0);
2400
allqueue(REDRAWBUTSSHADING, 0);
2401
BIF_preview_changed(ID_LA);
2405
void special_editmenu(void)
2407
static short numcuts= 2;
2413
if(ob==NULL) return;
2415
if(G.obedit==NULL) {
2417
if(ob->flag & OB_POSEMODE) {
2418
pose_special_editmenu();
2420
else if(FACESEL_PAINT_TEST) {
2421
Mesh *me= get_mesh(ob);
2426
if(me==0 || me->mtface==0) return;
2428
nr= pupmenu("Specials%t|Set Tex%x1| Shared%x2| Light%x3| Invisible%x4| Collision%x5| TwoSide%x6|Clr Tex%x7| Shared%x8| Light%x9| Invisible%x10| Collision%x11| TwoSide%x12");
2432
for(a=me->totface; a>0; a--, tface++, mface++) {
2433
if(mface->flag & ME_FACE_SEL) {
2436
tface->mode |= TF_TEX; break;
2438
tface->mode |= TF_SHAREDCOL; break;
2440
tface->mode |= TF_LIGHT; break;
2442
tface->mode |= TF_INVISIBLE; break;
2444
tface->mode |= TF_DYNAMIC; break;
2446
tface->mode |= TF_TWOSIDE; break;
2448
tface->mode &= ~TF_TEX;
2452
tface->mode &= ~TF_SHAREDCOL; break;
2454
tface->mode &= ~TF_LIGHT; break;
2456
tface->mode &= ~TF_INVISIBLE; break;
2458
tface->mode &= ~TF_DYNAMIC; break;
2460
tface->mode &= ~TF_TWOSIDE; break;
2464
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2465
allqueue(REDRAWVIEW3D, 0);
2466
allqueue(REDRAWBUTSEDIT, 0);
2467
BIF_undo_push("Change texture face");
2469
else if(G.f & G_VERTEXPAINT) {
2470
Mesh *me= get_mesh(ob);
2472
if(me==0 || (me->mcol==NULL && me->mtface==NULL) ) return;
2474
nr= pupmenu("Specials%t|Shared VertexCol%x1");
2477
do_shared_vertexcol(me);
2479
BIF_undo_push("Shared VertexCol");
2481
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2484
else if(G.f & G_WEIGHTPAINT) {
2485
Object *par= modifiers_isDeformedByArmature(ob);
2487
if(par && (par->flag & OB_POSEMODE)) {
2488
nr= pupmenu("Specials%t|Apply Bone Envelopes to Vertex Groups %x1|Apply Bone Heat Weights to Vertex Groups %x2");
2491
pose_adds_vgroups(ob, (nr == 2));
2494
else if(G.f & G_PARTICLEEDIT) {
2495
ParticleSystem *psys = PE_get_current(ob);
2496
ParticleEditSettings *pset = PE_settings();
2501
if(G.scene->selectmode & SCE_SELECT_POINT)
2502
nr= pupmenu("Specials%t|Rekey%x1|Subdivide%x2|Select First%x3|Select Last%x4|Remove Doubles%x5");
2504
nr= pupmenu("Specials%t|Rekey%x1|Remove Doubles%x5");
2508
if(button(&pset->totrekey, 2, 100, "Number of Keys:")==0) return;
2522
PE_remove_doubles();
2526
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2528
if(nr>0) waitcursor(0);
2531
Base *base, *base_select= NULL;
2533
/* Get the active object mesh. */
2534
Mesh *me= get_mesh(ob);
2536
/* Booleans, if the active object is a mesh... */
2537
if (me && ob->id.lib==NULL) {
2539
/* Bring up a little menu with the boolean operation choices on. */
2540
nr= pupmenu("Boolean Tools%t|Intersect%x1|Union%x2|Difference%x3|Add Intersect Modifier%x4|Add Union Modifier%x5|Add Difference Modifier%x6");
2543
/* user has made a choice of a menu element.
2544
All of the boolean functions require 2 mesh objects
2545
we search through the object list to find the other
2546
selected item and make sure it is distinct and a mesh. */
2548
for(base= FIRSTBASE; base; base= base->next) {
2549
if TESTBASELIB(base) {
2550
if(base->object != ob) base_select= base;
2555
if (get_mesh(base_select->object)) {
2558
ret = NewBooleanMesh(BASACT,base_select,nr);
2560
error("An internal error occurred");
2561
} else if(ret==-1) {
2562
error("Selected meshes must have faces to perform boolean operations");
2563
} else if (ret==-2) {
2564
error("Both meshes must be a closed mesh");
2566
else BIF_undo_push("Boolean");
2569
BooleanModifierData *bmd = NULL;
2570
bmd = (BooleanModifierData *)modifier_new(eModifierType_Boolean);
2571
BLI_addtail(&ob->modifiers, bmd);
2572
bmd->object = base_select->object;
2573
bmd->modifier.mode |= eModifierMode_Realtime;
2575
case 4: bmd->operation = eBooleanModifierOp_Intersect; break;
2576
case 5: bmd->operation = eBooleanModifierOp_Union; break;
2577
case 6: bmd->operation = eBooleanModifierOp_Difference; break;
2579
do_common_editbuts(B_CHANGEDEP);
2580
BIF_undo_push("Add Boolean modifier");
2583
error("Please select 2 meshes");
2586
error("Please select 2 meshes");
2590
allqueue(REDRAWVIEW3D, 0);
2592
else if (ob->type == OB_LAMP) {
2594
if(la->type==LA_SPOT) {
2595
short nr= pupmenu("Lamp Tools%t|Spot Size%x1|Distance%x2|Clip Start%x3|Clip End%x4");
2597
spot_interactive(ob, nr);
2600
else if (ob->type == OB_FONT) {
2601
/* removed until this gets a decent implementation (ton) */
2602
/* nr= pupmenu("Split %t|Characters%x1");
2605
case 1: split_font();
2612
else if(G.obedit->type==OB_MESH) {
2613
/* This is all that is needed, since all other functionality is in Ctrl+ V/E/F but some users didnt like, so for now have the old/big menu */
2615
nr= pupmenu("Subdivide Mesh%t|Subdivide%x1|Subdivide Multi%x2|Subdivide Multi Fractal%x3|Subdivide Smooth%x4");
2619
esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, 1, 0);
2621
BIF_undo_push("ESubdivide Single");
2624
if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2626
esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, numcuts, 0);
2627
BIF_undo_push("ESubdivide");
2630
if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2632
if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2634
fac= -( (float)randfac )/100;
2635
esubdivideflag(1, fac, G.scene->toolsettings->editbutflag, numcuts, 0);
2636
BIF_undo_push("Subdivide Fractal");
2641
if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
2645
esubdivideflag(1, fac, G.scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
2646
BIF_undo_push("Subdivide Smooth");
2651
nr= pupmenu("Specials%t|Subdivide%x1|Subdivide Multi%x2|Subdivide Multi Fractal%x3|Subdivide Smooth%x12|Merge%x4|Remove Doubles%x5|Hide%x6|Reveal%x7|Select Swap%x8|Flip Normals %x9|Smooth %x10|Bevel %x11|Set Smooth %x14|Set Solid %x15|Blend From Shape%x16|Propagate To All Shapes%x17|Select Vertex Path%x18");
2656
esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, 1, 0);
2658
BIF_undo_push("ESubdivide Single");
2661
if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2663
esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, numcuts, 0);
2664
BIF_undo_push("ESubdivide");
2667
if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2669
if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2671
fac= -( (float)randfac )/100;
2672
esubdivideflag(1, fac, G.scene->toolsettings->editbutflag, numcuts, 0);
2673
BIF_undo_push("Subdivide Fractal");
2676
case 12: /* smooth */
2677
/* if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return; */
2679
if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
2683
esubdivideflag(1, fac, G.scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
2684
BIF_undo_push("Subdivide Smooth");
2691
notice("Removed %d Vertices", removedoublesflag(1, 0, G.scene->toolsettings->doublimit));
2692
BIF_undo_push("Remove Doubles");
2705
BIF_undo_push("Flip Normals");
2714
mesh_set_smooth_faces(1);
2717
mesh_set_smooth_faces(0);
2720
shape_copy_select_from();
2727
BIF_undo_push("Select Vertex Path");
2732
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2734
if(nr>0) waitcursor(0);
2737
else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
2739
nr= pupmenu("Specials%t|Subdivide%x1|Switch Direction%x2|Set Goal Weight%x3|Set Radius%x4|Smooth%x5|Smooth Radius%x6");
2746
switchdirectionNurb2();
2761
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2763
else if(G.obedit->type==OB_ARMATURE) {
2764
nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Switch Direction%x7|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6");
2766
subdivide_armature(1);
2768
if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2770
subdivide_armature(numcuts);
2773
armature_flip_names();
2774
else if(ELEM3(nr, 4, 5, 6)) {
2775
armature_autoside_names(nr-4);
2778
switch_direction_armature();
2780
else if(G.obedit->type==OB_LATTICE) {
2781
static float weight= 1.0f;
2782
if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) {
2783
int a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
2784
BPoint *bp= editLatt->def;
2795
allqueue(REDRAWVIEW3D, 0);
2799
static void curvetomesh(Object *ob)
2804
ob->flag |= OB_DONE;
2808
if(dl==0) makeDispListCurveTypes(ob, 0); /* force creation */
2810
nurbs_to_mesh(ob); /* also does users */
2811
if (ob->type != OB_MESH) {
2812
error("can't convert curve to mesh");
2814
object_free_modifiers(ob);
2818
void convertmenu(void)
2820
Base *base, *basen=NULL, *basact, *basedel=NULL;
2821
Object *obact, *ob, *ob1;
2826
int ok=0, nr = 0, a;
2828
if(G.scene->id.lib) return;
2831
if (obact == NULL) return;
2832
if(!obact->flag & SELECT) return;
2833
if(G.obedit) return;
2835
basact= BASACT; /* will be restored */
2837
if(obact->type==OB_FONT) {
2838
nr= pupmenu("Convert Font to%t|Curve%x1|Curve (Single filling group)%x2|Mesh%x3");
2841
else if(obact->type==OB_MBALL) {
2842
nr= pupmenu("Convert Metaball to%t|Mesh (keep original)%x1|Mesh (Delete Original)%x2");
2845
else if(obact->type==OB_CURVE) {
2846
nr= pupmenu("Convert Curve to%t|Mesh");
2849
else if(obact->type==OB_SURF) {
2850
nr= pupmenu("Convert Nurbs Surface to%t|Mesh");
2853
else if(obact->type==OB_MESH) {
2854
nr= pupmenu("Convert Modifiers to%t|Mesh (Keep Original)%x1|Mesh (Delete Original)%x2");
2859
/* don't forget multiple users! */
2864
if TESTBASELIB(base) {
2865
base->object->flag &= ~OB_DONE;
2872
if TESTBASELIB(base) {
2876
if(ob->flag & OB_DONE);
2877
else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
2882
ob->flag |= OB_DONE;
2884
ob1= copy_object(ob);
2885
ob1->recalc |= OB_RECALC;
2887
basen= MEM_mallocN(sizeof(Base), "duplibase");
2889
BLI_addhead(&G.scene->base, basen); /* addhead: otherwise eternal loop */
2891
basen->flag |= SELECT;
2892
base->flag &= ~SELECT;
2893
ob->flag &= ~SELECT;
2895
/* decrement original mesh's usage count */
2899
/* make a new copy of the mesh */
2900
ob1->data= copy_mesh(me);
2903
/* make new mesh data from the original copy */
2904
dm= mesh_get_derived_final(ob1, CD_MASK_MESH);
2905
/* dm= mesh_create_derived_no_deform(ob1, NULL); this was called original (instead of get_derived). man o man why! (ton) */
2907
DM_to_mesh(dm, ob1->data);
2910
object_free_modifiers(ob1); /* after derivedmesh calls! */
2912
/* If the original object is active then make this object active */
2914
set_active_base( basen );
2918
else if(ob->type==OB_FONT) {
2919
ob->flag |= OB_DONE;
2929
cu->vfontb->id.us--;
2933
cu->vfonti->id.us--;
2937
cu->vfontbi->id.us--;
2942
ob1= G.main->object.first;
2945
ob1->type= OB_CURVE;
2946
ob1->recalc |= OB_RECALC;
2951
if (nr==2 || nr==3) {
2962
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
2967
else if(ob->type==OB_MBALL) {
2969
if(nr==1 || nr == 2) {
2970
ob= find_basis_mball(ob);
2972
if(ob->disp.first && !(ob->flag&OB_DONE)) {
2975
ob->flag |= OB_DONE;
2977
ob1= copy_object(ob);
2978
ob1->recalc |= OB_RECALC;
2980
basen= MEM_mallocN(sizeof(Base), "duplibase");
2982
BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2984
basen->flag |= SELECT;
2985
basedel->flag &= ~SELECT;
2986
ob->flag &= ~SELECT;
2991
ob1->data= add_mesh("Mesh");
2996
me->totcol= mb->totcol;
2998
me->mat= MEM_dupallocN(mb->mat);
2999
for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
3002
mball_to_mesh(&ob->disp, ob1->data);
3004
/* So we can see the wireframe */
3007
/* If the original object is active then make this object active */
3009
set_active_base( basen );
3018
if(basedel != NULL && nr == 2) {
3021
free_and_unlink_base(basedel);
3026
/* delete object should renew depsgraph */
3028
DAG_scene_sort(G.scene);
3030
/* texspace and normals */
3031
if(!basen) BASACT= base;
3033
enter_editmode(EM_WAITCURSOR);
3034
exit_editmode(EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
3038
allqueue(REDRAWVIEW3D, 0);
3039
allqueue(REDRAWOOPS, 0);
3040
allspace(OOPS_TEST, 0);
3041
allqueue(REDRAWBUTSEDIT, 0);
3042
BIF_undo_push("Convert Object");
3044
DAG_scene_sort(G.scene);
3047
/* Change subdivision or particle properties of mesh object ob, if level==-1
3048
* then toggle subsurf, else set to level set allows to toggle multiple
3051
static void object_has_subdivision_particles(Object *ob, int *havesubdiv, int *havepart, int depth)
3053
if(ob->type==OB_MESH) {
3054
if(modifiers_findByType(ob, eModifierType_Subsurf))
3056
if(modifiers_findByType(ob, eModifierType_ParticleSystem))
3060
if(ob->dup_group && depth <= 4) {
3063
for(go= ob->dup_group->gobject.first; go; go= go->next)
3064
object_has_subdivision_particles(go->ob, havesubdiv, havepart, depth+1);
3068
static void object_flip_subdivison_particles(Object *ob, int *set, int level, int mode, int particles, int depth)
3072
if(ob->type==OB_MESH) {
3074
for(md=ob->modifiers.first; md; md=md->next) {
3075
if(md->type == eModifierType_ParticleSystem) {
3076
ParticleSystemModifierData *psmd = (ParticleSystemModifierData*)md;
3079
*set= psmd->modifier.mode&(mode);
3082
psmd->modifier.mode &= ~(mode);
3084
psmd->modifier.mode |= (mode);
3089
md = modifiers_findByType(ob, eModifierType_Subsurf);
3092
SubsurfModifierData *smd = (SubsurfModifierData*) md;
3096
*set= smd->modifier.mode&(mode);
3099
smd->modifier.mode &= ~(mode);
3101
smd->modifier.mode |= (mode);
3103
smd->levels = level;
3106
else if(depth == 0 && *set != 0) {
3107
SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
3109
BLI_addtail(&ob->modifiers, smd);
3112
smd->levels = level;
3120
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
3123
if(ob->dup_group && depth<=4) {
3126
for(go= ob->dup_group->gobject.first; go; go= go->next)
3127
object_flip_subdivison_particles(go->ob, set, level, mode, particles, depth+1);
3131
/* Change subdivision properties of mesh object ob, if
3132
* level==-1 then toggle subsurf, else set to level.
3135
void flip_subdivison(int level)
3139
int mode, pupmode, particles= 0, havesubdiv= 0, havepart= 0;
3141
if(G.qual & LR_ALTKEY)
3142
mode= eModifierMode_Realtime;
3144
mode= eModifierMode_Render|eModifierMode_Realtime;
3148
object_has_subdivision_particles(G.obedit, &havesubdiv, &havepart, 0);
3150
for(base= G.scene->base.first; base; base= base->next) {
3151
if(((level==-1) && (TESTBASE(base))) || (TESTBASELIB(base))) {
3152
object_has_subdivision_particles(base->object, &havesubdiv, &havepart, 0);
3160
if(havesubdiv && havepart) {
3161
pupmode= pupmenu("Switch%t|Subsurf %x1|Particle Systems %x2");
3164
else if(pupmode == 2)
3171
object_flip_subdivison_particles(G.obedit, &set, level, mode, particles, 0);
3173
for(base= G.scene->base.first; base; base= base->next) {
3174
if(((level==-1) && (TESTBASE(base))) || (TESTBASELIB(base))) {
3175
object_flip_subdivison_particles(base->object, &set, level, mode, particles, 0);
3181
allqueue(REDRAWVIEW3D, 0);
3182
allqueue(REDRAWOOPS, 0);
3183
allqueue(REDRAWBUTSEDIT, 0);
3184
allqueue(REDRAWBUTSOBJECT, 0);
3185
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
3188
BIF_undo_push("Switch particles on/off");
3190
BIF_undo_push("Switch subsurf on/off");
3193
static void copymenu_properties(Object *ob)
3200
prop= ob->prop.first;
3207
error("No properties in the active object to copy");
3211
str= MEM_callocN(50 + 33*tot, "copymenu prop");
3213
strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
3216
prop= ob->prop.first;
3220
strcat(str, prop->name);
3226
if ( nr==1 || nr==2 ) {
3229
if((base != BASACT) && TESTBASELIB(base)) {
3230
if (nr==1) { /* replace */
3231
copy_properties( &base->object->prop, &ob->prop );
3233
for(prop = ob->prop.first; prop; prop= prop->next ) {
3234
set_ob_property(base->object, prop);
3241
prop = BLI_findlink(&ob->prop, nr-4); /* account for first 3 menu items & menu index starting at 1*/
3244
for(base= FIRSTBASE; base; base= base->next) {
3245
if((base != BASACT) && TESTBASELIB(base)) {
3246
set_ob_property(base->object, prop);
3252
allqueue(REDRAWVIEW3D, 0);
3254
BIF_undo_push("Copy properties");
3257
static void copymenu_logicbricks(Object *ob)
3263
if(base->object != ob) {
3264
if(TESTBASELIB(base)) {
3266
/* first: free all logic */
3267
free_sensors(&base->object->sensors);
3268
unlink_controllers(&base->object->controllers);
3269
free_controllers(&base->object->controllers);
3270
unlink_actuators(&base->object->actuators);
3271
free_actuators(&base->object->actuators);
3273
/* now copy it, this also works without logicbricks! */
3274
clear_sca_new_poins_ob(ob);
3275
copy_sensors(&base->object->sensors, &ob->sensors);
3276
copy_controllers(&base->object->controllers, &ob->controllers);
3277
copy_actuators(&base->object->actuators, &ob->actuators);
3278
set_sca_new_poins_ob(base->object);
3280
/* some menu settings */
3281
base->object->scavisflag= ob->scavisflag;
3282
base->object->scaflag= ob->scaflag;
3284
/* set the initial state */
3285
base->object->state= ob->state;
3286
base->object->init_state= ob->init_state;
3291
BIF_undo_push("Copy logic");
3294
static void copymenu_modifiers(Object *ob)
3299
char *errorstr= NULL;
3301
strcpy(str, "Copy Modifiers %t");
3303
sprintf(str+strlen(str), "|All%%x%d|%%l", NUM_MODIFIER_TYPES);
3305
for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
3306
ModifierTypeInfo *mti = modifierType_getInfo(i);
3308
if(ELEM3(i, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance)) continue;
3310
if(i == eModifierType_Collision)
3313
if ( (mti->flags&eModifierTypeFlag_AcceptsCVs) ||
3314
(ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
3315
sprintf(str+strlen(str), "|%s%%x%d", mti->name, i);
3319
event = pupmenu(str);
3320
if(event<=0) return;
3322
for (base= FIRSTBASE; base; base= base->next) {
3323
if(base->object != ob) {
3324
if(TESTBASELIB(base)) {
3327
base->object->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
3329
if (base->object->type==ob->type) {
3331
if (event==NUM_MODIFIER_TYPES) {
3332
object_free_modifiers(base->object);
3334
for (md=ob->modifiers.first; md; md=md->next) {
3335
ModifierData *nmd = NULL;
3337
if(ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance)) continue;
3339
if(md->type == eModifierType_Collision)
3342
nmd = modifier_new(md->type);
3343
modifier_copyData(md, nmd);
3344
BLI_addtail(&base->object->modifiers, nmd);
3347
copy_object_particlesystems(base->object, ob);
3348
copy_object_softbody(base->object, ob);
3350
/* copy specific types */
3351
ModifierData *md, *mdn;
3353
/* remove all with type 'event' */
3354
for (md=base->object->modifiers.first; md; md=mdn) {
3356
if(md->type==event) {
3357
BLI_remlink(&base->object->modifiers, md);
3362
/* copy all with type 'event' */
3363
for (md=ob->modifiers.first; md; md=md->next) {
3364
if (md->type==event) {
3366
mdn = modifier_new(event);
3367
BLI_addtail(&base->object->modifiers, mdn);
3369
modifier_copyData(md, mdn);
3373
if(event == eModifierType_ParticleSystem) {
3374
object_free_particlesystems(base->object);
3375
copy_object_particlesystems(base->object, ob);
3377
else if(event == eModifierType_Softbody) {
3378
object_free_softbody(base->object);
3379
copy_object_softbody(base->object, ob);
3384
errorstr= "Did not copy modifiers to other Object types";
3389
if(errorstr) notice(errorstr);
3391
allqueue(REDRAWVIEW3D, 0);
3392
allqueue(REDRAWBUTSOBJECT, 0);
3393
DAG_scene_sort(G.scene);
3395
BIF_undo_push("Copy modifiers");
3398
/* both pointers should exist */
3399
static void copy_texture_space(Object *to, Object *ob)
3401
float *poin1= NULL, *poin2= NULL;
3404
if(ob->type==OB_MESH) {
3405
texflag= ((Mesh *)ob->data)->texflag;
3406
poin2= ((Mesh *)ob->data)->loc;
3408
else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
3409
texflag= ((Curve *)ob->data)->texflag;
3410
poin2= ((Curve *)ob->data)->loc;
3412
else if(ob->type==OB_MBALL) {
3413
texflag= ((MetaBall *)ob->data)->texflag;
3414
poin2= ((MetaBall *)ob->data)->loc;
3419
if(to->type==OB_MESH) {
3420
((Mesh *)to->data)->texflag= texflag;
3421
poin1= ((Mesh *)to->data)->loc;
3423
else if (ELEM3(to->type, OB_CURVE, OB_SURF, OB_FONT)) {
3424
((Curve *)to->data)->texflag= texflag;
3425
poin1= ((Curve *)to->data)->loc;
3427
else if(to->type==OB_MBALL) {
3428
((MetaBall *)to->data)->texflag= texflag;
3429
poin1= ((MetaBall *)to->data)->loc;
3434
memcpy(poin1, poin2, 9*sizeof(float)); /* this was noted in DNA_mesh, curve, mball */
3436
if(to->type==OB_MESH) ;
3437
else if(to->type==OB_MBALL) tex_space_mball(to);
3438
else tex_space_curve(to->data);
3442
void copy_attr(short event)
3448
int do_scene_sort= 0;
3450
if(G.scene->id.lib) return;
3452
if(!(ob=OBACT)) return;
3455
/* obedit_copymenu(); */
3459
copymenu_properties(ob);
3462
else if(event==10) {
3463
copymenu_logicbricks(ob);
3466
else if(event==24) {
3467
copymenu_modifiers(ob);
3473
if(base != BASACT) {
3474
if(TESTBASELIB(base)) {
3475
base->object->recalc |= OB_RECALC_OB;
3477
if(event==1) { /* loc */
3478
VECCOPY(base->object->loc, ob->loc);
3479
VECCOPY(base->object->dloc, ob->dloc);
3481
else if(event==2) { /* rot */
3482
VECCOPY(base->object->rot, ob->rot);
3483
VECCOPY(base->object->drot, ob->drot);
3484
/* Quats arnt used yet */
3485
/*VECCOPY(base->object->quat, ob->quat);
3486
VECCOPY(base->object->dquat, ob->dquat);*/
3488
else if(event==3) { /* size */
3489
VECCOPY(base->object->size, ob->size);
3490
VECCOPY(base->object->dsize, ob->dsize);
3492
else if(event==4) { /* drawtype */
3493
base->object->dt= ob->dt;
3494
base->object->dtx= ob->dtx;
3495
base->object->empty_drawtype= ob->empty_drawtype;
3496
base->object->empty_drawsize= ob->empty_drawsize;
3498
else if(event==5) { /* time offs */
3499
base->object->sf= ob->sf;
3501
else if(event==6) { /* dupli */
3502
base->object->dupon= ob->dupon;
3503
base->object->dupoff= ob->dupoff;
3504
base->object->dupsta= ob->dupsta;
3505
base->object->dupend= ob->dupend;
3507
base->object->transflag &= ~OB_DUPLI;
3508
base->object->transflag |= (ob->transflag & OB_DUPLI);
3510
base->object->dup_group= ob->dup_group;
3512
id_us_plus((ID *)ob->dup_group);
3514
else if(event==7) { /* mass */
3515
base->object->mass= ob->mass;
3517
else if(event==8) { /* damping */
3518
base->object->damping= ob->damping;
3519
base->object->rdamping= ob->rdamping;
3521
else if(event==11) { /* all physical attributes */
3522
base->object->gameflag = ob->gameflag;
3523
base->object->inertia = ob->inertia;
3524
base->object->formfactor = ob->formfactor;
3525
base->object->damping= ob->damping;
3526
base->object->rdamping= ob->rdamping;
3527
base->object->mass= ob->mass;
3528
if (ob->gameflag & OB_BOUNDS) {
3529
base->object->boundtype = ob->boundtype;
3531
base->object->margin= ob->margin;
3532
base->object->bsoft= copy_bulletsoftbody(ob->bsoft);
3535
else if(event==17) { /* tex space */
3536
copy_texture_space(base->object, ob);
3538
else if(event==18) { /* font settings */
3540
if(base->object->type==ob->type) {
3542
cu1= base->object->data;
3544
cu1->spacemode= cu->spacemode;
3545
cu1->spacing= cu->spacing;
3546
cu1->linedist= cu->linedist;
3547
cu1->shear= cu->shear;
3548
cu1->fsize= cu->fsize;
3551
cu1->textoncurve= cu->textoncurve;
3552
cu1->wordspace= cu->wordspace;
3553
cu1->ulpos= cu->ulpos;
3554
cu1->ulheight= cu->ulheight;
3555
if(cu1->vfont) cu1->vfont->id.us--;
3556
cu1->vfont= cu->vfont;
3557
id_us_plus((ID *)cu1->vfont);
3558
if(cu1->vfontb) cu1->vfontb->id.us--;
3559
cu1->vfontb= cu->vfontb;
3560
id_us_plus((ID *)cu1->vfontb);
3561
if(cu1->vfonti) cu1->vfonti->id.us--;
3562
cu1->vfonti= cu->vfonti;
3563
id_us_plus((ID *)cu1->vfonti);
3564
if(cu1->vfontbi) cu1->vfontbi->id.us--;
3565
cu1->vfontbi= cu->vfontbi;
3566
id_us_plus((ID *)cu1->vfontbi);
3568
text_to_curve(base->object, 0); /* needed? */
3571
strcpy(cu1->family, cu->family);
3573
base->object->recalc |= OB_RECALC_DATA;
3576
else if(event==19) { /* bevel settings */
3578
if ELEM(base->object->type, OB_CURVE, OB_FONT) {
3580
cu1= base->object->data;
3582
cu1->bevobj= cu->bevobj;
3583
cu1->taperobj= cu->taperobj;
3584
cu1->width= cu->width;
3585
cu1->bevresol= cu->bevresol;
3586
cu1->ext1= cu->ext1;
3587
cu1->ext2= cu->ext2;
3589
base->object->recalc |= OB_RECALC_DATA;
3592
else if(event==25) { /* curve resolution */
3594
if ELEM(base->object->type, OB_CURVE, OB_FONT) {
3596
cu1= base->object->data;
3598
cu1->resolu= cu->resolu;
3599
cu1->resolu_ren= cu->resolu_ren;
3601
nu= cu1->nurb.first;
3604
nu->resolu= cu1->resolu;
3608
base->object->recalc |= OB_RECALC_DATA;
3612
if (base->object->type==OB_MESH) {
3613
ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);
3616
ModifierData *tmd = modifiers_findByType(base->object, eModifierType_Subsurf);
3619
tmd = modifier_new(eModifierType_Subsurf);
3620
BLI_addtail(&base->object->modifiers, tmd);
3623
modifier_copyData(md, tmd);
3624
base->object->recalc |= OB_RECALC_DATA;
3628
else if(event==22) {
3629
/* Copy the constraint channels over */
3630
copy_constraints(&base->object->constraints, &ob->constraints);
3631
if (U.dupflag& USER_DUP_IPO)
3632
copy_constraint_channels(&base->object->constraintChannels, &ob->constraintChannels);
3634
clone_constraint_channels (&base->object->constraintChannels, &ob->constraintChannels);
3638
else if(event==23) {
3639
base->object->softflag= ob->softflag;
3640
if(base->object->soft) sbFree(base->object->soft);
3642
base->object->soft= copy_softbody(ob->soft);
3644
if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
3645
BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));
3648
else if(event==26) {
3649
copy_nlastrips(&base->object->nlastrips, &ob->nlastrips);
3651
else if(event==27) { /* autosmooth */
3652
if (base->object->type==OB_MESH) {
3654
Mesh *cme= base->object->data;
3655
cme->smoothresh= me->smoothresh;
3656
if(me->flag & ME_AUTOSMOOTH)
3657
cme->flag |= ME_AUTOSMOOTH;
3659
cme->flag &= ~ME_AUTOSMOOTH;
3662
else if(event==28) { /* UV orco */
3663
if ELEM(base->object->type, OB_CURVE, OB_SURF) {
3665
cu1= base->object->data;
3667
if(cu->flag & CU_UV_ORCO)
3668
cu1->flag |= CU_UV_ORCO;
3670
cu1->flag &= ~CU_UV_ORCO;
3673
else if(event==29) { /* protected bits */
3674
base->object->protectflag= ob->protectflag;
3676
else if(event==30) { /* index object */
3677
base->object->index= ob->index;
3679
else if(event==31) { /* object color */
3680
QUATCOPY(base->object->col, ob->col);
3687
allqueue(REDRAWVIEW3D, 0);
3689
DAG_scene_sort(G.scene);
3691
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
3694
allqueue(REDRAWBUTSOBJECT, 0);
3697
BIF_undo_push("Copy Attributes");
3700
void copy_attr_menu()
3706
if(!(ob=OBACT)) return;
3709
if (ob->type == OB_MESH)
3716
/* If you change this menu, don't forget to update the menu in header_view3d.c
3717
* view3d_edit_object_copyattrmenu() and in toolbox.c
3720
strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|Time Offset%x5|Dupli%x6|Object Color%x31|%l|Mass%x7|Damping%x8|All Physical Attributes%x11|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l");
3722
strcat (str, "|Object Constraints%x22");
3723
strcat (str, "|NLA Strips%x26");
3725
if (OB_SUPPORT_MATERIAL(ob)) {
3726
strcat(str, "|Texture Space%x17");
3729
if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
3730
if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19|UV Orco%x28");
3732
if((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
3733
strcat(str, "|Curve Resolution%x25");
3736
if(ob->type==OB_MESH){
3737
strcat(str, "|Subsurf Settings%x21|AutoSmooth%x27");
3740
if(ob->soft) strcat(str, "|Soft Body Settings%x23");
3742
strcat(str, "|Pass Index%x30");
3744
if(ob->type==OB_MESH || ob->type==OB_CURVE || ob->type==OB_LATTICE || ob->type==OB_SURF){
3745
strcat(str, "|Modifiers ...%x24");
3748
event= pupmenu(str);
3749
if(event<= 0) return;
3755
void link_to_scene(unsigned short nr)
3757
Scene *sce= (Scene*) BLI_findlink(&G.main->scene, G.curscreen->scenenr-1);
3761
if(sce->id.lib) return;
3765
if(TESTBASE(base)) {
3767
nbase= MEM_mallocN( sizeof(Base), "newbase");
3769
BLI_addhead( &(sce->base), nbase);
3770
id_us_plus((ID *)base->object);
3776
void make_links_menu()
3782
if(!(ob=OBACT)) return;
3784
strcpy(str, "Make Links %t|To Scene...%x1|%l|Object Ipo%x4");
3786
if(ob->type==OB_MESH)
3787
strcat(str, "|Mesh Data%x2|Materials%x3");
3788
else if(ob->type==OB_CURVE)
3789
strcat(str, "|Curve Data%x2|Materials%x3");
3790
else if(ob->type==OB_FONT)
3791
strcat(str, "|Text Data%x2|Materials%x3");
3792
else if(ob->type==OB_SURF)
3793
strcat(str, "|Surface Data%x2|Materials%x3");
3794
else if(ob->type==OB_MBALL)
3795
strcat(str, "|Materials%x3");
3796
else if(ob->type==OB_CAMERA)
3797
strcat(str, "|Camera Data%x2");
3798
else if(ob->type==OB_LAMP)
3799
strcat(str, "|Lamp Data%x2");
3800
else if(ob->type==OB_LATTICE)
3801
strcat(str, "|Lattice Data%x2");
3802
else if(ob->type==OB_ARMATURE)
3803
strcat(str, "|Armature Data%x2");
3805
event= pupmenu(str);
3807
if(event<= 0) return;
3812
void make_links(short event)
3815
Base *base, *nbase, *sbase;
3822
if(!(ob=OBACT)) return;
3825
IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), 0, &nr);
3830
activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE, &(G.curscreen->scenenr), link_to_scene );
3835
event= pupmenu_col(strp, 20);
3838
if(event<= 0) return;
3841
sce= G.main->scene.first;
3843
if(nr==event) break;
3848
error("This is the current scene");
3851
if(sce==0 || sce->id.lib) return;
3853
/* remember: is needed below */
3858
/* All non group linking */
3861
if(event==1 || base != BASACT) {
3865
if(TESTBASE(base)) {
3867
if(event==1) { /* to scene */
3869
/* test if already linked */
3870
sbase= sce->base.first;
3872
if(sbase->object==base->object) break;
3875
if(sbase) { /* remove */
3880
nbase= MEM_mallocN( sizeof(Base), "newbase");
3882
BLI_addhead( &(sce->base), nbase);
3883
id_us_plus((ID *)base->object);
3886
if(TESTBASELIB(base)) {
3887
if(event==2 || event==5) { /* obdata */
3888
if(ob->type==obt->type) {
3897
/* if amount of material indices changed: */
3898
test_object_materials(obt->data);
3900
obt->recalc |= OB_RECALC_DATA;
3903
else if(event==4) { /* ob ipo */
3904
if(obt->ipo) obt->ipo->id.us--;
3907
id_us_plus((ID *)obt->ipo);
3912
if(ob->dup_group) ob->dup_group->id.us--;
3913
obt->dup_group= ob->dup_group;
3914
if(obt->dup_group) {
3915
id_us_plus((ID *)obt->dup_group);
3916
obt->transflag |= OB_DUPLIGROUP;
3919
else if(event==3) { /* materials */
3921
/* new approach, using functions from kernel */
3922
for(a=0; a<ob->totcol; a++) {
3923
Material *ma= give_current_material(ob, a+1);
3924
assign_material(obt, ma, a+1); /* also works with ma==NULL */
3932
allqueue(REDRAWVIEW3D, 0);
3933
allqueue(REDRAWOOPS, 0);
3934
allqueue(REDRAWBUTSHEAD, 0);
3936
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
3938
BIF_undo_push("Create links");
3941
static void apply_objects_internal( int apply_scale, int apply_rot )
3943
Base *base, *basact;
3955
if (!apply_scale && !apply_rot) {
3957
error("Nothing to do!");
3960
/* first check if we can execute */
3961
for (base= FIRSTBASE; base; base= base->next) {
3962
if TESTBASELIB(base) {
3964
if(ob->type==OB_MESH) {
3968
error("Can't apply to a multi user mesh, doing nothing.");
3972
error("Can't apply to a mesh with vertex keys, doing nothing.");
3976
else if (ob->type==OB_ARMATURE) {
3980
error("Can't apply to a multi user armature, doing nothing.");
3984
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
3988
error("Can't apply to a multi user curve, doing nothing.");
3992
error("Can't apply to a curve with vertex keys, doing nothing.");
4002
for (base= FIRSTBASE; base; base= base->next) {
4003
if TESTBASELIB(base) {
4006
if(ob->type==OB_MESH) {
4007
if (apply_scale && apply_rot)
4008
object_to_mat3(ob, mat);
4009
else if (apply_scale)
4010
object_scale_to_mat3(ob, mat);
4012
object_rot_to_mat3(ob, mat);
4016
/* see checks above */
4019
for(a=0; a<me->totvert; a++, mvert++) {
4020
Mat3MulVecfl(mat, mvert->co);
4023
ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
4025
ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
4026
/*QuatOne(ob->quat);*/ /* Quats arnt used yet */
4028
where_is_object(ob);
4030
/* texspace and normals */
4032
enter_editmode(EM_WAITCURSOR);
4033
BIF_undo_push("Applied object"); /* editmode undo itself */
4034
exit_editmode(EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
4039
else if (ob->type==OB_ARMATURE) {
4040
if (apply_scale && apply_rot)
4041
object_to_mat3(ob, mat);
4042
else if (apply_scale)
4043
object_scale_to_mat3(ob, mat);
4045
object_rot_to_mat3(ob, mat);
4048
/* see checks above */
4049
apply_rot_armature(ob, mat);
4051
/* Reset the object's transforms */
4053
ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
4055
ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
4056
/*QuatOne(ob->quat); (not used anymore)*/
4058
where_is_object(ob);
4062
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
4064
if (apply_scale && apply_rot)
4065
object_to_mat3(ob, mat);
4066
else if (apply_scale)
4067
object_scale_to_mat3(ob, mat);
4069
object_rot_to_mat3(ob, mat);
4070
scale = Mat3ToScalef(mat);
4073
/* see checks above */
4077
if( (nu->type & 7)==1) {
4081
Mat3MulVecfl(mat, bezt->vec[0]);
4082
Mat3MulVecfl(mat, bezt->vec[1]);
4083
Mat3MulVecfl(mat, bezt->vec[2]);
4084
bezt->radius *= scale;
4089
a= nu->pntsu*nu->pntsv;
4092
Mat3MulVecfl(mat, bp->vec);
4099
ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
4101
ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
4102
/*QuatOne(ob->quat); (quats arnt used anymore)*/
4104
where_is_object(ob);
4106
/* texspace and normals */
4108
enter_editmode(EM_WAITCURSOR);
4109
BIF_undo_push("Applied object"); /* editmode undo itself */
4110
exit_editmode(EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
4118
ignore_parent_tx(ob);
4122
allqueue(REDRAWVIEW3D, 0);
4123
if (apply_scale && apply_rot)
4124
BIF_undo_push("Apply Objects Scale & Rotation");
4125
else if (apply_scale)
4126
BIF_undo_push("Apply Objects Scale");
4128
BIF_undo_push("Apply Objects Rotation");
4132
void apply_objects_locrot(void)
4134
apply_objects_internal(1, 1);
4137
void apply_objects_scale(void)
4139
apply_objects_internal(1, 0);
4142
void apply_objects_rot(void)
4144
apply_objects_internal(0, 1);
4147
void apply_objects_visual_tx( void )
4153
for (base= FIRSTBASE; base; base= base->next) {
4154
if TESTBASELIB(base) {
4156
where_is_object(ob);
4157
VECCOPY(ob->loc, ob->obmat[3]);
4158
Mat4ToSize(ob->obmat, ob->size);
4159
Mat4ToEul(ob->obmat, ob->rot);
4161
where_is_object(ob);
4167
allqueue(REDRAWVIEW3D, 0);
4168
BIF_undo_push("Apply Objects Visual Transform");
4172
void apply_object( void )
4176
if(G.scene->id.lib) return;
4177
if(G.obedit) return;
4179
if(G.qual & LR_SHIFTKEY) {
4183
if(ob->transflag & OB_DUPLI) {
4184
make_duplilist_real();
4187
if(okee("Apply deformation")) {
4188
object_apply_deform(ob);
4189
BIF_undo_push("Apply deformation");
4192
allqueue(REDRAWVIEW3D, 0);
4199
if ((ob->pose) && (ob->flag & OB_POSEMODE))
4200
evt = pupmenu("Apply Object%t|Current Pose as RestPose%x3");
4202
evt = pupmenu("Apply Object%t|Scale and Rotation to ObData%x1|Visual Transform to Objects Loc/Scale/Rot%x2|Scale to ObData%x4|Rotation to ObData%x5");
4203
if (evt==-1) return;
4207
apply_objects_locrot();
4210
apply_objects_visual_tx();
4213
apply_armature_pose2bones();
4216
apply_objects_scale();
4219
apply_objects_rot();
4227
/* ************ GENERAL *************** */
4230
/* now only used in 2d spaces, like ipo, nla, sima... */
4231
void apply_keyb_grid(float *val, float fac1, float fac2, float fac3, int invert)
4233
/* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */
4237
if(G.qual & LR_CTRLKEY) ctrl= 0;
4240
else ctrl= (G.qual & LR_CTRLKEY);
4242
if(ctrl && (G.qual & LR_SHIFTKEY)) {
4243
if(fac3!= 0.0) *val= fac3*floor(*val/fac3 +.5);
4246
if(fac2!= 0.0) *val= fac2*floor(*val/fac2 +.5);
4249
if(fac1!= 0.0) *val= fac1*floor(*val/fac1 +.5);
4253
int cylinder_intersect_test(void)
4255
EditMesh *em = G.editMesh;
4256
float *oldloc, speed[3], s, t, labda, labdacor, dist, len, len2, axis[3], *base, rc[3], n[3], o[3];
4259
v1= em->verts.first;
4263
VecSubf(axis, v1->co, base);
4268
VecSubf(speed, v1->co, oldloc);
4270
VecSubf(rc, oldloc, base);
4273
len2= Normalize(axis);
4275
Crossf(n, speed, axis);
4277
if(len==0.0) return 0;
4279
dist= fabs( rc[0]*n[0] + rc[1]*n[1] + rc[2]*n[2] );
4281
if( dist>=G.scene->editbutsize ) return 0;
4283
Crossf(o, rc, axis);
4284
t= -(o[0]*n[0] + o[1]*n[1] + o[2]*n[2])/len;
4287
s= fabs(sqrt(G.scene->editbutsize*G.scene->editbutsize-dist*dist) / (o[0]*speed[0] + o[1]*speed[1] + o[2]*speed[2]));
4292
/* two cases with no intersection point */
4293
if(labdacor>=1.0 && labda>=1.0) return 0;
4294
if(labdacor<=0.0 && labda<=0.0) return 0;
4299
rc[0]= oldloc[0] + labdacor*speed[0] - base[0];
4300
rc[1]= oldloc[1] + labdacor*speed[1] - base[1];
4301
rc[2]= oldloc[2] + labdacor*speed[2] - base[2];
4303
s= (rc[0]*axis[0] + rc[1]*axis[1] + rc[2]*axis[2]) ;
4305
if(s<0.0 || s>len2) return 0;
4307
n[0]= (rc[0] - s*axis[0]);
4308
n[1]= (rc[1] - s*axis[1]);
4309
n[2]= (rc[2] - s*axis[2]);
4311
printf("var1: %f, var2: %f, var3: %f\n", labdacor, len2, s);
4312
printf("var1: %f, var2: %f, var3: %f\n", rc[0], rc[1], rc[2]);
4313
printf("var1: %f, var2: %f, var3: %f\n", n[0], n[1], n[2]);
4318
int sphere_intersect_test(void)
4320
EditMesh *em = G.editMesh;
4321
float *oldloc, speed[3], labda, labdacor, len, bsq, u, disc, *base, rc[3];
4324
v1= em->verts.first;
4331
VecSubf(speed, v1->co, oldloc);
4332
len= Normalize(speed);
4333
if(len==0.0) return 0;
4335
VecSubf(rc, oldloc, base);
4336
bsq= rc[0]*speed[0] + rc[1]*speed[1] + rc[2]*speed[2];
4337
u= rc[0]*rc[0] + rc[1]*rc[1] + rc[2]*rc[2] - G.scene->editbutsize*G.scene->editbutsize;
4343
labdacor= (-bsq - disc)/len; /* entry point */
4344
labda= (-bsq + disc)/len;
4346
printf("var1: %f, var2: %f, var3: %f\n", labdacor, labda, G.scene->editbutsize);
4350
/* intersection and normal */
4351
rc[0]= oldloc[0] + labdacor*speed[0] - base[0];
4352
rc[1]= oldloc[1] + labdacor*speed[1] - base[1];
4353
rc[2]= oldloc[2] + labdacor*speed[2] - base[2];
4360
void std_rmouse_transform(void (*xf_func)(int, int))
4366
short context = (U.flag & USER_DRAGIMMEDIATE)?CTX_TWEAK:CTX_NONE;
4368
/* check for left mouse select/right mouse select */
4370
if(curarea->spacetype==SPACE_NODE)
4371
mousebut = L_MOUSE|R_MOUSE;
4372
else if (U.flag & USER_LMOUSESELECT)
4377
getmouseco_areawin(mval);
4381
while(get_mbut() & mousebut) {
4382
getmouseco_areawin(mval);
4383
if(abs(mval[0]-xo)+abs(mval[1]-yo) > 10) {
4384
if(curarea->spacetype==SPACE_VIEW3D) {
4385
initTransform(TFM_TRANSLATION, context);
4388
else if(curarea->spacetype==SPACE_IMAGE) {
4389
initTransform(TFM_TRANSLATION, context);
4395
while(get_mbut() & mousebut) BIF_wait_for_statechange();
4401
if(timer>=10*U.tb_rightmouse) {
4402
if(curarea->spacetype==SPACE_VIEW3D) {
4409
/* if gets here it's a select */
4410
BIF_undo_push("Select");
4413
void rightmouse_transform(void)
4415
std_rmouse_transform(NULL);
4419
/* ************************************** */
4422
static void single_object_users__forwardModifierLinks(void *userData, Object *ob, Object **obpoin)
4426
void single_object_users(int flag)
4431
clear_sca_new_poins(); /* sensor/contr/act */
4433
/* duplicate (must set newid) */
4438
if( (base->flag & flag)==flag ) {
4439
if(ob->id.lib==NULL && ob->id.us>1) {
4440
/* base gets copy of object */
4441
obn= copy_object(ob);
4449
ID_NEW(G.scene->camera);
4450
if(G.vd) ID_NEW(G.vd->camera);
4452
/* object pointers */
4456
if(ob->id.lib==NULL) {
4457
relink_constraints(&base->object->constraints);
4458
if (base->object->pose){
4460
for (chan = base->object->pose->chanbase.first; chan; chan=chan->next){
4461
relink_constraints(&chan->constraints);
4464
modifiers_foreachObjectLink(base->object, single_object_users__forwardModifierLinks, NULL);
4472
set_sca_new_poins();
4475
void new_id_matar(Material **matar, int totcol)
4480
for(a=0; a<totcol; a++) {
4482
if(id && id->lib==0) {
4484
matar[a]= (Material *)id->newid;
4485
id_us_plus(id->newid);
4489
matar[a]= copy_material(matar[a]);
4491
id->newid= (ID *)matar[a];
4497
void single_obdata_users(int flag)
4513
error("Can't make data single user, when data are shared at verse server");
4523
if(ob->id.lib==NULL && (base->flag & flag)==flag ) {
4526
if(id && id->us>1 && id->lib==0) {
4527
ob->recalc= OB_RECALC_DATA;
4531
if(id && id->us>1 && id->lib==NULL) {
4532
ob->data= la= copy_lamp(ob->data);
4533
for(a=0; a<MAX_MTEX; a++) {
4535
ID_NEW(la->mtex[a]->object);
4541
ob->data= copy_camera(ob->data);
4544
me= ob->data= copy_mesh(ob->data);
4546
ipo_idnew(me->key->ipo); /* drivers */
4549
ob->data= copy_mball(ob->data);
4554
ob->data= cu= copy_curve(ob->data);
4556
ID_NEW(cu->taperobj);
4559
ob->data= copy_lattice(ob->data);
4562
ob->recalc |= OB_RECALC_DATA;
4563
ob->data= copy_armature(ob->data);
4564
armature_rebuild_pose(ob, ob->data);
4567
printf("ERROR single_obdata_users: %s\n", id->name);
4568
error("Read console");
4573
id->newid= ob->data;
4577
id= (ID *)ob->action;
4578
if (id && id->us>1 && id->lib==NULL){
4580
ob->action= (bAction *)id->newid;
4581
id_us_plus(id->newid);
4584
ob->action= copy_action(ob->action);
4586
id->newid=(ID *)ob->action;
4590
if(id && id->us>1 && id->lib==NULL) {
4592
ob->ipo= (Ipo *)id->newid;
4593
id_us_plus(id->newid);
4596
ob->ipo= copy_ipo(ob->ipo);
4598
id->newid= (ID *)ob->ipo;
4600
ipo_idnew(ob->ipo); /* drivers */
4606
if(la->ipo && la->ipo->id.us>1) {
4608
la->ipo= copy_ipo(la->ipo);
4609
ipo_idnew(la->ipo); /* drivers */
4614
if(cam->ipo && cam->ipo->id.us>1) {
4616
cam->ipo= copy_ipo(cam->ipo);
4617
ipo_idnew(cam->ipo); /* drivers */
4626
me= G.main->mesh.first;
4628
ID_NEW(me->texcomesh);
4633
void single_ipo_users(int flag)
4642
if(ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
4643
ob->recalc= OB_RECALC_DATA;
4646
if(id && id->us>1 && id->lib==NULL) {
4647
ob->ipo= copy_ipo(ob->ipo);
4649
ipo_idnew(ob->ipo); /* drivers */
4656
void single_mat_users(int flag)
4668
if(ob->id.lib==NULL && (flag==0 || (base->flag & SELECT)) ) {
4670
for(a=1; a<=ob->totcol; a++) {
4671
ma= give_current_material(ob, a);
4673
/* do not test for LIB_NEW: this functions guaranteed delivers single_users! */
4676
man= copy_material(ma);
4679
assign_material(ob, man, a);
4682
man->ipo= copy_ipo(ma->ipo);
4684
ipo_idnew(ma->ipo); /* drivers */
4687
for(b=0; b<MAX_MTEX; b++) {
4688
if(ma->mtex[b] && ma->mtex[b]->tex) {
4689
tex= ma->mtex[b]->tex;
4691
ma->mtex[b]->tex= copy_texture(tex);
4705
void do_single_tex_user(Tex **from)
4713
*from= (Tex *)tex->id.newid;
4714
id_us_plus(tex->id.newid);
4717
else if(tex->id.us>1) {
4718
texn= copy_texture(tex);
4719
tex->id.newid= (ID *)texn;
4726
void single_tex_users_expand()
4728
/* only when 'parent' blocks are LIB_NEW */
4734
ma= G.main->mat.first;
4736
if(ma->id.flag & LIB_NEW) {
4737
for(b=0; b<MAX_MTEX; b++) {
4738
if(ma->mtex[b] && ma->mtex[b]->tex) {
4739
do_single_tex_user( &(ma->mtex[b]->tex) );
4746
la= G.main->lamp.first;
4748
if(la->id.flag & LIB_NEW) {
4749
for(b=0; b<MAX_MTEX; b++) {
4750
if(la->mtex[b] && la->mtex[b]->tex) {
4751
do_single_tex_user( &(la->mtex[b]->tex) );
4757
wo= G.main->world.first;
4759
if(wo->id.flag & LIB_NEW) {
4760
for(b=0; b<MAX_MTEX; b++) {
4761
if(wo->mtex[b] && wo->mtex[b]->tex) {
4762
do_single_tex_user( &(wo->mtex[b]->tex) );
4770
void single_mat_users_expand(void)
4772
/* only when 'parent' blocks are LIB_NEW */
4781
ob= G.main->object.first;
4783
if(ob->id.flag & LIB_NEW) {
4784
new_id_matar(ob->mat, ob->totcol);
4789
me= G.main->mesh.first;
4791
if(me->id.flag & LIB_NEW) {
4792
new_id_matar(me->mat, me->totcol);
4797
cu= G.main->curve.first;
4799
if(cu->id.flag & LIB_NEW) {
4800
new_id_matar(cu->mat, cu->totcol);
4805
mb= G.main->mball.first;
4807
if(mb->id.flag & LIB_NEW) {
4808
new_id_matar(mb->mat, mb->totcol);
4813
/* material imats */
4814
ma= G.main->mat.first;
4816
if(ma->id.flag & LIB_NEW) {
4817
for(a=0; a<MAX_MTEX; a++) {
4819
ID_NEW(ma->mtex[a]->object);
4827
void single_user(void)
4831
if(G.scene->id.lib) return;
4833
clear_id_newpoins();
4835
nr= pupmenu("Make Single User%t|Object|Object & ObData|Object & ObData & Materials+Tex|Materials+Tex|Ipos");
4838
if(nr==1) single_object_users(1);
4841
single_object_users(1);
4842
single_obdata_users(1);
4845
single_object_users(1);
4846
single_obdata_users(1);
4847
single_mat_users(1); /* also tex */
4851
single_mat_users(1);
4854
single_ipo_users(1);
4858
clear_id_newpoins();
4861
allqueue(REDRAWALL, 0);
4862
BIF_undo_push("Single user");
4866
/* ************************************************************* */
4868
/* helper for below, ma was checked to be not NULL */
4869
static void make_local_makelocalmaterial(Material *ma)
4874
make_local_material(ma);
4876
for(b=0; b<MAX_MTEX; b++) {
4877
if(ma->mtex[b] && ma->mtex[b]->tex) {
4878
make_local_texture(ma->mtex[b]->tex);
4883
if(id && id->lib) make_local_ipo(ma->ipo);
4888
void make_local_menu(void)
4892
/* If you modify this menu, please remember to update view3d_edit_object_makelocalmenu
4893
* in header_view3d.c and the menu in toolbox.c
4896
if(G.scene->id.lib) return;
4898
mode = pupmenu("Make Local%t|Selected Objects %x1|Selected Objects and Data %x2|All %x3");
4900
if (mode <= 0) return;
4905
void make_local(int mode)
4909
bActionStrip *strip;
4910
ParticleSystem *psys;
4911
Material *ma, ***matarar;
4917
/* WATCH: the function new_id(..) re-inserts the id block!!! */
4918
if(G.scene->id.lib) return;
4921
all_local(NULL, 0); /* NULL is all libs */
4922
allqueue(REDRAWALL, 0);
4925
else if(mode<1) return;
4927
clear_id_newpoins();
4931
if( TESTBASE(base) ) {
4934
make_local_object(ob);
4940
/* maybe object pointers */
4943
if( TESTBASE(base) ) {
4945
if(ob->id.lib==NULL) {
4955
if( TESTBASE(base) ) {
4963
make_local_lamp((Lamp *)id);
4967
if(id && id->lib) make_local_ipo(la->ipo);
4971
make_local_camera((Camera *)id);
4974
make_local_mesh((Mesh *)id);
4975
make_local_key( ((Mesh *)id)->key );
4978
make_local_mball((MetaBall *)id);
4984
make_local_curve(cu);
4986
if(id && id->lib) make_local_ipo(cu->ipo);
4987
make_local_key( cu->key );
4990
make_local_lattice((Lattice *)id);
4991
make_local_key( ((Lattice *)id)->key );
4994
make_local_armature ((bArmature *)id);
4998
for(psys=ob->particlesystem.first; psys; psys=psys->next)
4999
make_local_particlesettings(psys->part);
5002
if(id && id->lib) make_local_ipo(ob->ipo);
5004
id= (ID *)ob->action;
5005
if(id && id->lib) make_local_action(ob->action);
5007
for(strip=ob->nlastrips.first; strip; strip=strip->next) {
5008
if(strip->act && strip->act->id.lib)
5009
make_local_action(strip->act);
5018
if( TESTBASE(base) ) {
5020
if(ob->type==OB_LAMP) {
5022
for(b=0; b<MAX_MTEX; b++) {
5023
if(la->mtex[b] && la->mtex[b]->tex) {
5024
make_local_texture(la->mtex[b]->tex);
5030
for(a=0; a<ob->totcol; a++) {
5033
make_local_makelocalmaterial(ma);
5036
matarar= (Material ***)give_matarar(ob);
5038
for(a=0; a<ob->totcol; a++) {
5041
make_local_makelocalmaterial(ma);
5050
allqueue(REDRAWALL, 0);
5051
BIF_undo_push("Make local");
5054
static void copy_object__forwardModifierLinks(void *userData, Object *ob,
5057
/* this is copied from ID_NEW; it might be better to have a macro */
5058
if(*idpoin && (*idpoin)->newid) *idpoin = (*idpoin)->newid;
5062
/* after copying objects, copied data should get new pointers */
5063
static void copy_object_set_idnew(int dupflag)
5070
bActionStrip *strip;
5073
/* check object pointers */
5074
for(base= FIRSTBASE; base; base= base->next) {
5075
if TESTBASELIB(base) {
5077
relink_constraints(&ob->constraints);
5080
for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
5081
relink_constraints(&chan->constraints);
5084
modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
5088
ID_NEW(ob->proxy_group);
5090
for(strip= ob->nlastrips.first; strip; strip= strip->next) {
5091
bActionModifier *amod;
5092
for(amod= strip->modifiers.first; amod; amod= amod->next)
5099
if( dupflag & USER_DUP_MAT) {
5100
mao= G.main->mat.first;
5104
ma= (Material *)mao->id.newid;
5106
if(dupflag & USER_DUP_TEX) {
5107
for(a=0; a<MAX_MTEX; a++) {
5109
id= (ID *)ma->mtex[a]->tex;
5111
ID_NEW_US(ma->mtex[a]->tex)
5112
else ma->mtex[a]->tex= copy_texture(ma->mtex[a]->tex);
5121
else ma->ipo= copy_ipo(ma->ipo);
5130
if( dupflag & USER_DUP_IPO) {
5131
Lamp *la= G.main->lamp.first;
5134
Lamp *lan= (Lamp *)la->id.newid;
5138
else lan->ipo= copy_ipo(lan->ipo);
5147
ipo= G.main->ipo.first;
5149
if(ipo->id.lib==NULL && ipo->id.newid) {
5150
Ipo *ipon= (Ipo *)ipo->id.newid;
5152
for(icu= ipon->curve.first; icu; icu= icu->next) {
5154
ID_NEW(icu->driver->ob);
5161
set_sca_new_poins();
5163
clear_id_newpoins();
5167
/* This function duplicated the current visible selection, its used by Duplicate and Linked Duplicate
5168
Alt+D/Shift+D as well as Pythons Object.Duplicate(), it takes
5170
0: Duplicate with transform, Redraw.
5171
1: Duplicate, no transform, Redraw
5172
2: Duplicate, no transform, no redraw (Only used by python)
5173
if true the user will not be dropped into grab mode directly after and..
5174
dupflag: a flag made from constants declared in DNA_userdef_types.h
5175
The flag tells adduplicate() weather to copy data linked to the object, or to reference the existing data.
5176
U.dupflag for default operations or you can construct a flag as python does
5177
if the dupflag is 0 then no data will be copied (linked duplicate) */
5179
void adduplicate(int mode, int dupflag)
5182
Material ***matarar;
5187
if(G.scene->id.lib) return;
5188
clear_id_newpoins();
5189
clear_sca_new_poins(); /* sensor/contr/act */
5196
if(ob->flag & OB_POSEMODE) {
5200
obn= copy_object(ob);
5201
obn->recalc |= OB_RECALC;
5203
basen= MEM_mallocN(sizeof(Base), "duplibase");
5205
BLI_addhead(&G.scene->base, basen); /* addhead: prevent eternal loop */
5207
base->flag &= ~SELECT;
5209
if(basen->flag & OB_FROMGROUP) {
5211
for(group= G.main->group.first; group; group= group->id.next) {
5212
if(object_in_group(ob, group))
5213
add_to_group(group, obn);
5215
obn->flag |= OB_FROMGROUP; /* this flag is unset with copy_object() */
5218
if(BASACT==base) BASACT= basen;
5220
/* duplicates using userflags */
5222
if(dupflag & USER_DUP_IPO) {
5223
bConstraintChannel *chan;
5227
ID_NEW_US( obn->ipo)
5228
else obn->ipo= copy_ipo(obn->ipo);
5231
/* Handle constraint ipos */
5232
for (chan=obn->constraintChannels.first; chan; chan=chan->next){
5233
id= (ID *)chan->ipo;
5235
ID_NEW_US( chan->ipo)
5236
else chan->ipo= copy_ipo(chan->ipo);
5241
if(dupflag & USER_DUP_ACT){ /* Not buttons in the UI to modify this, add later? */
5242
id= (ID *)obn->action;
5244
ID_NEW_US(obn->action)
5246
obn->action= copy_action(obn->action);
5251
if(dupflag & USER_DUP_MAT) {
5252
for(a=0; a<obn->totcol; a++) {
5253
id= (ID *)obn->mat[a];
5255
ID_NEW_US(obn->mat[a])
5256
else obn->mat[a]= copy_material(obn->mat[a]);
5267
if(dupflag & USER_DUP_MESH) {
5268
ID_NEW_US2( obn->data )
5270
obn->data= copy_mesh(obn->data);
5272
if(obn->fluidsimSettings) {
5273
obn->fluidsimSettings->orgMesh = (Mesh *)obn->data;
5282
if(dupflag & USER_DUP_CURVE) {
5283
ID_NEW_US2(obn->data )
5285
obn->data= copy_curve(obn->data);
5292
if(dupflag & USER_DUP_SURF) {
5293
ID_NEW_US2( obn->data )
5295
obn->data= copy_curve(obn->data);
5302
if(dupflag & USER_DUP_FONT) {
5303
ID_NEW_US2( obn->data )
5305
obn->data= copy_curve(obn->data);
5312
if(dupflag & USER_DUP_MBALL) {
5313
ID_NEW_US2(obn->data )
5315
obn->data= copy_mball(obn->data);
5322
if(dupflag & USER_DUP_LAMP) {
5323
ID_NEW_US2(obn->data )
5324
else obn->data= copy_lamp(obn->data);
5330
obn->recalc |= OB_RECALC_DATA;
5331
if(obn->pose) obn->pose->flag |= POSE_RECALC;
5333
if(dupflag & USER_DUP_ARM) {
5334
ID_NEW_US2(obn->data )
5336
obn->data= copy_armature(obn->data);
5337
armature_rebuild_pose(obn, obn->data);
5347
ID_NEW_US2(obn->data )
5348
else obn->data= copy_lattice(obn->data);
5354
ID_NEW_US2(obn->data )
5355
else obn->data= copy_camera(obn->data);
5361
if(dupflag & USER_DUP_MAT) {
5362
matarar= give_matarar(obn);
5363
if(didit && matarar) {
5364
for(a=0; a<obn->totcol; a++) {
5365
id= (ID *)(*matarar)[a];
5367
ID_NEW_US( (*matarar)[a] )
5368
else (*matarar)[a]= copy_material((*matarar)[a]);
5376
/* send new created object to verse server,
5377
* when original object was linked with object node */
5379
b_verse_duplicate_object(((VNode*)ob->vnode)->session, ob, obn);
5388
copy_object_set_idnew(dupflag);
5390
DAG_scene_sort(G.scene);
5391
DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
5395
BIF_TransformSetUndo("Add Duplicate");
5396
initTransform(TFM_TRANSLATION, CTX_NONE);
5399
set_active_base(BASACT);
5400
if(mode!=2) { /* mode of 2 is used by python to avoid unrequested redraws */
5401
allqueue(REDRAWNLA, 0);
5402
allqueue(REDRAWACTION, 0); /* also oops */
5403
allqueue(REDRAWIPO, 0); /* also oops */
5407
void make_object_duplilist_real(Base *base)
5414
if(!base && !(base = BASACT))
5417
if(!(base->object->transflag & OB_DUPLI))
5420
lb= object_duplilist(G.scene, base->object);
5422
for(dob= lb->first; dob; dob= dob->next) {
5423
ob= copy_object(dob->ob);
5424
/* font duplis can have a totcol without material, we get them from parent
5425
* should be implemented better...
5427
if(ob->mat==NULL) ob->totcol= 0;
5429
basen= MEM_dupallocN(base);
5430
basen->flag &= ~OB_FROMDUPLI;
5431
BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
5433
ob->ipo= NULL; /* make sure apply works */
5434
ob->parent= ob->track= NULL;
5435
ob->disp.first= ob->disp.last= NULL;
5436
ob->transflag &= ~OB_DUPLI;
5438
Mat4CpyMat4(ob->obmat, dob->mat);
5442
copy_object_set_idnew(0);
5444
free_object_duplilist(lb);
5446
base->object->transflag &= ~OB_DUPLI;
5449
void make_duplilist_real()
5452
/* extern ListBase duplilist; */
5454
if(okee("Make dupli objects real")==0) return;
5456
clear_id_newpoins();
5461
make_object_duplilist_real(base);
5466
DAG_scene_sort(G.scene);
5468
allqueue(REDRAWVIEW3D, 0);
5469
allqueue(REDRAWOOPS, 0);
5471
BIF_undo_push("Make duplicates real");
5474
void selectlinks_menu(void)
5482
/* If you modify this menu, please remember to update view3d_select_linksmenu
5483
* in header_view3d.c and the menu in toolbox.c
5485
nr= pupmenu("Select Linked%t|Object Ipo%x1|ObData%x2|Material%x3|Texture%x4|DupliGroup%x5|ParticleSystem%x6");
5487
if (nr <= 0) return;
5492
void selectlinks(int nr)
5496
void *obdata = NULL;
5498
Material *mat = NULL, *mat1;
5505
* Current Material: 3
5506
* Current Texture: 4
5520
if(ob->data==0) return;
5523
else if(nr==3 || nr==4) {
5524
mat= give_current_material(ob, ob->actcol);
5527
if(mat->mtex[ (int)mat->texact ]) tex= mat->mtex[ (int)mat->texact ]->tex;
5532
if(ob->dup_group==NULL) return;
5535
if(ob->particlesystem.first==NULL) return;
5541
if (BASE_SELECTABLE(base) && !(base->flag & SELECT)) {
5543
if(base->object->ipo==ipo) base->flag |= SELECT;
5547
if(base->object->data==obdata) base->flag |= SELECT;
5550
else if(nr==3 || nr==4) {
5553
for(a=1; a<=ob->totcol; a++) {
5554
mat1= give_current_material(ob, a);
5556
if(mat1==mat) base->flag |= SELECT;
5559
else if(mat1 && nr==4) {
5560
for(b=0; b<MAX_MTEX; b++) {
5562
if(tex==mat1->mtex[b]->tex) {
5563
base->flag |= SELECT;
5573
if(base->object->dup_group==ob->dup_group) {
5574
base->flag |= SELECT;
5579
/* loop through other, then actives particles*/
5580
ParticleSystem *psys;
5581
ParticleSystem *psys_act;
5583
for(psys=base->object->particlesystem.first; psys; psys=psys->next) {
5584
for(psys_act=ob->particlesystem.first; psys_act; psys_act=psys_act->next) {
5585
if (psys->part == psys_act->part) {
5586
base->flag |= SELECT;
5592
if (base->flag & SELECT) {
5597
base->object->flag= base->flag;
5603
allqueue(REDRAWVIEW3D, 0);
5604
allqueue(REDRAWDATASELECT, 0);
5605
allqueue(REDRAWOOPS, 0);
5606
BIF_undo_push("Select linked");
5611
void image_aspect(void)
5613
/* all selected objects with an image map: scale in image aspect */
5621
if(G.obedit) return;
5622
if(G.scene->id.lib) return;
5626
if TESTBASELIB(base) {
5630
for(a=1; a<=ob->totcol; a++) {
5631
ma= give_current_material(ob, a);
5633
for(b=0; b<MAX_MTEX; b++) {
5634
if(ma->mtex[b] && ma->mtex[b]->tex) {
5635
tex= ma->mtex[b]->tex;
5636
if(tex->type==TEX_IMAGE && tex->ima) {
5637
ImBuf *ibuf= BKE_image_get_ibuf(tex->ima, NULL);
5641
if(ob->type==OB_MESH) {
5643
mesh_get_texspace(ob->data, NULL, NULL, size);
5644
space= size[0]/size[1];
5646
else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
5647
Curve *cu= ob->data;
5648
space= cu->size[0]/cu->size[1];
5654
if(x>y) ob->size[0]= ob->size[1]*x/y;
5655
else ob->size[1]= ob->size[0]*y/x;
5658
DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
5670
allqueue(REDRAWVIEW3D, 0);
5671
BIF_undo_push("Image aspect");
5674
void set_ob_ipoflags(void)
5680
error("Can't do this! Open a 3D window");
5686
if TESTBASELIB(base) {
5687
if(base->object->ipoflag & OB_DRAWKEY) {
5697
if TESTBASELIB(base) {
5699
base->object->ipoflag |= OB_DRAWKEY;
5700
if(base->object->ipo) base->object->ipo->showkey= 1;
5703
base->object->ipoflag &= ~OB_DRAWKEY;
5704
if(base->object->ipo) base->object->ipo->showkey= 0;
5709
allqueue(REDRAWVIEW3D, 0);
5710
allqueue(REDRAWBUTSOBJECT, 0);
5711
allqueue(REDRAWNLA, 0);
5712
allqueue (REDRAWACTION, 0);
5713
allspace(REMAKEIPO, 0);
5714
allqueue(REDRAWIPO, 0);
5717
void select_select_keys(void)
5725
error("Can't do this! Open a 3D window");
5729
if(G.scene->id.lib) return;
5731
if(okee("Show and select all keys")==0) return;
5735
if TESTBASELIB(base) {
5736
if(base->object->ipo) {
5737
base->object->ipoflag |= OB_DRAWKEY;
5738
base->object->ipo->showkey= 1;
5739
icu= base->object->ipo->curve.first;
5756
allqueue(REDRAWNLA, 0);
5757
allqueue(REDRAWACTION, 0);
5758
allqueue(REDRAWVIEW3D, 0);
5759
allspace(REMAKEIPO, 0);
5760
allqueue(REDRAWIPO, 0);
5762
BIF_undo_push("Select keys");
5767
int vergbaseco(const void *a1, const void *a2)
5774
if( (*x1)->sy > (*x2)->sy ) return 1;
5775
else if( (*x1)->sy < (*x2)->sy) return -1;
5776
else if( (*x1)->sx > (*x2)->sx ) return 1;
5777
else if( (*x1)->sx < (*x2)->sx ) return -1;
5783
void auto_timeoffs(void)
5785
Base *base, **basesort, **bs;
5790
if(BASACT==0 || G.vd==NULL) return;
5791
if(button(&offset, 0, 1000,"Total time")==0) return;
5793
/* make array of all bases, xco yco (screen) */
5796
if(TESTBASELIB(base)) {
5802
delta= (float)offset/(float)tot;
5805
bs= basesort= MEM_mallocN(sizeof(void *)*tot,"autotimeoffs");
5809
if(TESTBASELIB(base)) {
5815
qsort(basesort, tot, sizeof(void *), vergbaseco);
5818
for(a=0; a<tot; a++) {
5820
(*bs)->object->sf= start;
5825
MEM_freeN(basesort);
5827
allqueue(REDRAWVIEW3D, 0);
5828
allqueue(REDRAWBUTSOBJECT, 0);
5831
void ofs_timeoffs(void)
5836
if(BASACT==0 || G.vd==NULL) return;
5838
if(fbutton(&offset, -10000.0f, 10000.0f, 10, 10, "Offset")==0) return;
5840
/* make array of all bases, xco yco (screen) */
5843
if(TESTBASELIB(base)) {
5844
base->object->sf += offset;
5845
if (base->object->sf < -MAXFRAMEF) base->object->sf = -MAXFRAMEF;
5846
else if (base->object->sf > MAXFRAMEF) base->object->sf = MAXFRAMEF;
5851
allqueue(REDRAWVIEW3D, 0);
5852
allqueue(REDRAWBUTSOBJECT, 0);
5856
void rand_timeoffs(void)
5861
if(BASACT==0 || G.vd==NULL) return;
5863
if(fbutton(&rand, 0.0f, 10000.0f, 10, 10, "Randomize")==0) return;
5869
if(TESTBASELIB(base)) {
5870
base->object->sf += (BLI_drand()-0.5) * rand;
5871
if (base->object->sf < -MAXFRAMEF) base->object->sf = -MAXFRAMEF;
5872
else if (base->object->sf > MAXFRAMEF) base->object->sf = MAXFRAMEF;
5877
allqueue(REDRAWVIEW3D, 0);
5878
allqueue(REDRAWBUTSOBJECT, 0);
5882
void texspace_edit(void)
5887
/* first test if from visible and selected objects
5888
* texspacedraw is set:
5891
if(G.obedit) return;
5895
if TESTBASELIB(base) {
5905
nr= pupmenu("Texture Space %t|Grab/Move%x1|Size%x2");
5910
if TESTBASELIB(base) {
5911
base->object->dtx |= OB_TEXSPACE;
5918
initTransform(TFM_TRANSLATION, CTX_TEXTURE);
5922
initTransform(TFM_RESIZE, CTX_TEXTURE);
5926
initTransform(TFM_ROTATION, CTX_TEXTURE);
5931
/* ******************************************************************** */
5932
/* Mirror function in Edit Mode */
5934
void mirrormenu(void)
5936
if(G.f & G_PARTICLEEDIT) {
5940
initTransform(TFM_MIRROR, CTX_NO_PET);
5947
/* only called in object mode */
5948
short event, changed=0;
5952
HookModifierData *hmd;
5954
event= pupmenu("Modify Hooks for Selected...%t|Reset Offset%x1|Recenter at Cursor%x2");
5955
if (event==-1) return;
5956
if (event==2 && !(G.vd)) {
5957
error("Cannot perform this operation without a 3d view");
5961
for (base= FIRSTBASE; base; base= base->next) {
5962
if TESTBASELIB(base) {
5963
for (md = base->object->modifiers.first; md; md=md->next) {
5964
if (md->type==eModifierType_Hook) {
5966
hmd = (HookModifierData*) md;
5969
* Copied from modifiers_cursorHookCenter and
5970
* modifiers_clearHookOffset, should consolidate
5975
Mat4Invert(hmd->object->imat, hmd->object->obmat);
5976
Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL);
5979
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
5982
float *curs = give_cursor();
5983
float bmat[3][3], imat[3][3];
5985
where_is_object(ob);
5987
Mat3CpyMat4(bmat, ob->obmat);
5988
Mat3Inv(imat, bmat);
5990
curs= give_cursor();
5991
hmd->cent[0]= curs[0]-ob->obmat[3][0];
5992
hmd->cent[1]= curs[1]-ob->obmat[3][1];
5993
hmd->cent[2]= curs[2]-ob->obmat[3][2];
5994
Mat3MulVecfl(imat, hmd->cent);
5997
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
6006
BIF_undo_push("Clear hook offset for selected");
6008
BIF_undo_push("Hook cursor center for selected");
6010
allqueue(REDRAWVIEW3D, 0);
6011
allqueue(REDRAWBUTSEDIT, 0);
6016
* Returns true if the Object is a from an external blend file (libdata)
6018
int object_is_libdata(Object *ob)
6021
if (ob->proxy) return 0;
6022
if (ob->id.lib) return 1;
6028
* Returns true if the Object data is a from an external blend file (libdata)
6030
int object_data_is_libdata(Object *ob)
6033
if (ob->proxy) return 0;
6034
if (ob->id.lib) return 1;
6035
if (!ob->data) return 0;
6036
if (((ID *)ob->data)->lib) return 1;
6040
void hide_objects(int select)
6043
short changed = 0, changed_act = 0;
6044
for(base = FIRSTBASE; base; base=base->next){
6045
if ((base->lay & G.vd->lay) && (TESTBASELIB(base)==select)) {
6046
base->flag &= ~SELECT;
6047
base->object->flag = base->flag;
6048
base->object->restrictflag |= OB_RESTRICT_VIEW;
6057
if(select) BIF_undo_push("Hide Selected Objects");
6058
else if(select) BIF_undo_push("Hide Unselected Objects");
6059
DAG_scene_sort(G.scene);
6060
allqueue(REDRAWVIEW3D,0);
6061
allqueue(REDRAWOOPS,0);
6062
allqueue(REDRAWDATASELECT,0);
6063
if (changed_act) { /* these spaces depend on the active object */
6064
allqueue(REDRAWBUTSALL,0);
6065
allqueue(REDRAWIPO,0);
6066
allqueue(REDRAWACTION,0);
6072
void show_objects(void)
6076
for(base = FIRSTBASE; base; base=base->next){
6077
if((base->lay & G.vd->lay) && base->object->restrictflag & OB_RESTRICT_VIEW) {
6078
base->flag |= SELECT;
6079
base->object->flag = base->flag;
6080
base->object->restrictflag &= ~OB_RESTRICT_VIEW;
6085
BIF_undo_push("Unhide Objects");
6086
DAG_scene_sort(G.scene);
6087
allqueue(REDRAWVIEW3D,0);
6088
allqueue(REDRAWOOPS,0);