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);