4 * ***** BEGIN GPL/BL DUAL 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. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
34 * Theorie: (matrices) A x B x C == A x ( B x C x Binv) x B
35 * ofwel: OB x PAR x EDIT = OB x (PAR x EDIT x PARinv) x PAR
51 #include "MEM_guardedalloc.h"
57 #include "IMB_imbuf_types.h"
59 #include "DNA_action_types.h"
60 #include "DNA_armature_types.h"
61 #include "DNA_camera_types.h"
62 #include "DNA_constraint_types.h"
63 #include "DNA_curve_types.h"
64 #include "DNA_effect_types.h"
65 #include "DNA_group_types.h"
66 #include "DNA_image_types.h"
67 #include "DNA_ipo_types.h"
68 #include "DNA_key_types.h"
69 #include "DNA_lamp_types.h"
70 #include "DNA_lattice_types.h"
71 #include "DNA_material_types.h"
72 #include "DNA_mesh_types.h"
73 #include "DNA_meshdata_types.h"
74 #include "DNA_meta_types.h"
75 #include "DNA_nla_types.h"
76 #include "DNA_object_types.h"
77 #include "DNA_object_fluidsim.h"
78 #include "DNA_object_force.h"
79 #include "DNA_scene_types.h"
80 #include "DNA_space_types.h"
81 #include "DNA_screen_types.h"
82 #include "DNA_texture_types.h"
83 #include "DNA_particle_types.h"
84 #include "DNA_property_types.h"
85 #include "DNA_userdef_types.h"
86 #include "DNA_view3d_types.h"
87 #include "DNA_vfont_types.h"
88 #include "DNA_world_types.h"
89 #include "DNA_modifier_types.h"
91 #include "BLI_blenlib.h"
92 #include "BLI_arithb.h"
93 #include "BLI_editVert.h"
94 #include "BLI_ghash.h"
96 #include "BKE_action.h"
98 #include "BKE_armature.h"
99 #include "BKE_constraint.h"
100 #include "BKE_customdata.h"
101 #include "BKE_blender.h"
102 #include "BKE_booleanops.h"
103 #include "BKE_cloth.h"
104 #include "BKE_curve.h"
105 #include "BKE_displist.h"
106 #include "BKE_depsgraph.h"
107 #include "BKE_DerivedMesh.h"
108 #include "BKE_effect.h"
109 #include "BKE_font.h"
110 #include "BKE_global.h"
111 #include "BKE_group.h"
113 #include "BKE_image.h"
115 #include "BKE_lattice.h"
116 #include "BKE_library.h"
117 #include "BKE_main.h"
118 #include "BKE_material.h"
119 #include "BKE_mball.h"
120 #include "BKE_mesh.h"
122 #include "BKE_object.h"
123 #include "BKE_particle.h"
124 #include "BKE_property.h"
126 #include "BKE_scene.h"
127 #include "BKE_softbody.h"
128 #include "BKE_subsurf.h"
129 #include "BKE_texture.h"
130 #include "BKE_utildefines.h"
131 #include "BKE_modifier.h"
133 #include "BIF_butspace.h"
134 #include "BIF_editconstraint.h"
135 #include "BIF_editdeform.h"
136 #include "BIF_editfont.h"
137 #include "BIF_editlattice.h"
138 #include "BIF_editmesh.h"
139 #include "BIF_editoops.h"
140 #include "BIF_editparticle.h"
141 #include "BIF_editview.h"
142 #include "BIF_editarmature.h"
144 #include "BIF_graphics.h"
145 #include "BIF_interface.h"
146 #include "BIF_meshtools.h"
147 #include "BIF_mywindow.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"
177 #include "mydevice.h"
181 #include "butspace.h"
182 #include "multires.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);
341 BIF_undo_push("Delete object(s)");
344 static int return_editmesh_indexar(int *tot, int **indexar, float *cent)
346 EditMesh *em = G.editMesh;
348 int *index, nr, totvert=0;
350 for(eve= em->verts.first; eve; eve= eve->next) {
351 if(eve->f & SELECT) totvert++;
353 if(totvert==0) return 0;
355 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
358 cent[0]= cent[1]= cent[2]= 0.0;
360 for(eve= em->verts.first; eve; eve= eve->next) {
361 if(eve->f & SELECT) {
363 VecAddf(cent, cent, eve->co);
368 VecMulf(cent, 1.0f/(float)totvert);
373 static int return_editmesh_vgroup(char *name, float *cent)
375 EditMesh *em = G.editMesh;
380 cent[0]= cent[1]= cent[2]= 0.0;
382 if(G.obedit->actdef) {
384 /* find the vertices */
385 for(eve= em->verts.first; eve; eve= eve->next) {
386 dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
389 for(i=0; i<dvert->totweight; i++){
390 if(dvert->dw[i].def_nr == (G.obedit->actdef-1)) {
392 VecAddf(cent, cent, eve->co);
398 bDeformGroup *defGroup = BLI_findlink(&G.obedit->defbase, G.obedit->actdef-1);
399 strcpy(name, defGroup->name);
400 VecMulf(cent, 1.0f/(float)totvert);
408 static void select_editmesh_hook(HookModifierData *hmd)
410 EditMesh *em = G.editMesh;
414 for(eve= em->verts.first; eve; eve= eve->next, nr++) {
415 if(nr==hmd->indexar[index]) {
417 if(index < hmd->totindex-1) index++;
423 static int return_editlattice_indexar(int *tot, int **indexar, float *cent)
426 int *index, nr, totvert=0, a;
429 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
432 if(bp->f1 & SELECT) {
433 if(bp->hide==0) totvert++;
438 if(totvert==0) return 0;
440 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
443 cent[0]= cent[1]= cent[2]= 0.0;
445 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
448 if(bp->f1 & SELECT) {
451 VecAddf(cent, cent, bp->vec);
458 VecMulf(cent, 1.0f/(float)totvert);
463 static void select_editlattice_hook(HookModifierData *hmd)
466 int index=0, nr=0, a;
469 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
472 if(hmd->indexar[index]==nr) {
474 if(index < hmd->totindex-1) index++;
481 static int return_editcurve_indexar(int *tot, int **indexar, float *cent)
483 extern ListBase editNurb;
487 int *index, a, nr, totvert=0;
489 for(nu= editNurb.first; nu; nu= nu->next) {
490 if((nu->type & 7)==CU_BEZIER) {
494 if(bezt->f1 & SELECT) totvert++;
495 if(bezt->f2 & SELECT) totvert++;
496 if(bezt->f3 & SELECT) totvert++;
502 a= nu->pntsu*nu->pntsv;
504 if(bp->f1 & SELECT) totvert++;
509 if(totvert==0) return 0;
511 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
514 cent[0]= cent[1]= cent[2]= 0.0;
516 for(nu= editNurb.first; nu; nu= nu->next) {
517 if((nu->type & 7)==CU_BEZIER) {
521 if(bezt->f1 & SELECT) {
523 VecAddf(cent, cent, bezt->vec[0]);
526 if(bezt->f2 & SELECT) {
528 VecAddf(cent, cent, bezt->vec[1]);
531 if(bezt->f3 & SELECT) {
533 VecAddf(cent, cent, bezt->vec[2]);
541 a= nu->pntsu*nu->pntsv;
543 if(bp->f1 & SELECT) {
545 VecAddf(cent, cent, bp->vec);
553 VecMulf(cent, 1.0f/(float)totvert);
558 static void select_editcurve_hook(HookModifierData *hmd)
560 extern ListBase editNurb;
564 int index=0, a, nr=0;
566 for(nu= editNurb.first; nu; nu= nu->next) {
567 if((nu->type & 7)==CU_BEZIER) {
571 if(nr == hmd->indexar[index]) {
573 if(index<hmd->totindex-1) index++;
576 if(nr == hmd->indexar[index]) {
578 if(index<hmd->totindex-1) index++;
581 if(nr == hmd->indexar[index]) {
583 if(index<hmd->totindex-1) index++;
592 a= nu->pntsu*nu->pntsv;
594 if(nr == hmd->indexar[index]) {
596 if(index<hmd->totindex-1) index++;
605 void hook_select(HookModifierData *hmd)
607 if(G.obedit->type==OB_MESH) select_editmesh_hook(hmd);
608 else if(G.obedit->type==OB_LATTICE) select_editlattice_hook(hmd);
609 else if(G.obedit->type==OB_CURVE) select_editcurve_hook(hmd);
610 else if(G.obedit->type==OB_SURF) select_editcurve_hook(hmd);
613 int hook_getIndexArray(int *tot, int **indexar, char *name, float *cent_r)
619 switch(G.obedit->type) {
621 /* check selected vertices first */
622 if( return_editmesh_indexar(tot, indexar, cent_r)) return 1;
623 else return return_editmesh_vgroup(name, cent_r);
626 return return_editcurve_indexar(tot, indexar, cent_r);
628 return return_editlattice_indexar(tot, indexar, cent_r);
636 ModifierData *md = NULL;
637 HookModifierData *hmd = NULL;
641 if(G.obedit==NULL) return;
643 if(modifiers_findByType(G.obedit, eModifierType_Hook))
644 mode= pupmenu("Hooks %t|Add, To New Empty %x1|Add, To Selected Object %x2|Remove... %x3|Reassign... %x4|Select... %x5|Clear Offset...%x6");
646 mode= pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
652 if(mode==2) { /* selected object */
653 Base *base= FIRSTBASE;
655 if TESTBASELIB(base) {
664 error("Requires selected Object");
672 /* make pupmenu with hooks */
673 for(md=G.obedit->modifiers.first; md; md= md->next) {
674 if (md->type==eModifierType_Hook)
679 error("Object has no hooks yet");
683 cp= MEM_callocN(maxlen+32, "temp string");
684 if(mode==3) strcpy(cp, "Remove %t|");
685 else if(mode==4) strcpy(cp, "Reassign %t|");
686 else if(mode==5) strcpy(cp, "Select %t|");
687 else if(mode==6) strcpy(cp, "Clear Offset %t|");
689 for(md=G.obedit->modifiers.first; md; md= md->next) {
690 if (md->type==eModifierType_Hook) {
691 strcat(cp, md->name);
702 for(md=G.obedit->modifiers.first; md; md=md->next) {
703 if (md->type==eModifierType_Hook) {
709 hmd = (HookModifierData*) md;
713 /* do it, new hooks or reassign */
714 if(mode==1 || mode==2 || mode==4) {
716 int tot, ok, *indexar;
719 ok = hook_getIndexArray(&tot, &indexar, name, cent);
722 error("Requires selected vertices or active Vertex Group");
727 Base *base= BASACT, *newbase;
729 ob= add_object(OB_EMPTY);
732 newbase->lay= base->lay;
733 ob->lay= newbase->lay;
735 /* transform cent to global coords for loc */
736 VecMat4MulVecfl(ob->loc, G.obedit->obmat, cent);
738 /* restore, add_object sets active */
741 /* if mode is 2 or 4, ob has been set */
744 if(mode==1 || mode==2) {
745 ModifierData *md = G.obedit->modifiers.first;
747 while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) {
751 hmd = (HookModifierData*) modifier_new(eModifierType_Hook);
752 BLI_insertlinkbefore(&G.obedit->modifiers, md, hmd);
753 sprintf(hmd->modifier.name, "Hook-%s", ob->id.name+2);
755 else if (hmd->indexar) MEM_freeN(hmd->indexar); /* reassign, hook was set */
758 hmd->indexar= indexar;
759 VECCOPY(hmd->cent, cent);
761 BLI_strncpy(hmd->name, name, 32);
763 if(mode==1 || mode==2) {
764 /* matrix calculus */
765 /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
770 Mat4Invert(ob->imat, ob->obmat);
771 /* apparently this call goes from right to left... */
772 Mat4MulSerie(hmd->parentinv, ob->imat, G.obedit->obmat, NULL,
773 NULL, NULL, NULL, NULL, NULL);
777 else if(mode==3) { /* remove */
778 BLI_remlink(&G.obedit->modifiers, md);
781 else if(mode==5) { /* select */
784 else if(mode==6) { /* clear offset */
785 where_is_object(ob); /* ob is hook->parent */
787 Mat4Invert(ob->imat, ob->obmat);
788 /* this call goes from right to left... */
789 Mat4MulSerie(hmd->parentinv, ob->imat, G.obedit->obmat, NULL,
790 NULL, NULL, NULL, NULL, NULL);
793 allqueue(REDRAWVIEW3D, 0);
794 allqueue(REDRAWBUTSOBJECT, 0);
795 DAG_scene_sort(G.scene);
797 BIF_undo_push("Add hook");
800 void make_track(void)
805 if(G.scene->id.lib) return;
809 if(BASACT==0) return;
811 mode= pupmenu("Make Track %t|TrackTo Constraint %x1|LockTrack Constraint %x2|Old Track %x3");
817 bTrackToConstraint *data;
821 if TESTBASELIB(base) {
823 con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
824 strcpy (con->name, "AutoTrack");
827 data->tar = BASACT->object;
828 base->object->recalc |= OB_RECALC;
830 /* Lamp and Camera track differently by default */
831 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
832 data->reserved1 = TRACK_nZ;
833 data->reserved2 = UP_Y;
836 add_constraint_to_object(con, base->object);
845 bLockTrackConstraint *data;
849 if TESTBASELIB(base) {
851 con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
852 strcpy (con->name, "AutoTrack");
855 data->tar = BASACT->object;
856 base->object->recalc |= OB_RECALC;
858 /* Lamp and Camera track differently by default */
859 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
860 data->trackflag = TRACK_nZ;
861 data->lockflag = LOCK_Y;
864 add_constraint_to_object(con, base->object);
874 if TESTBASELIB(base) {
876 base->object->track= BASACT->object;
877 base->object->recalc |= OB_RECALC;
884 allqueue(REDRAWOOPS, 0);
885 allqueue(REDRAWVIEW3D, 0);
886 DAG_scene_sort(G.scene);
888 BIF_undo_push("Make Track");
891 void apply_obmat(Object *ob)
893 float mat[3][3], imat[3][3], tmat[3][3];
895 /* from obmat to loc rot size */
898 Mat3CpyMat4(mat, ob->obmat);
900 VECCOPY(ob->loc, ob->obmat[3]);
902 if(ob->transflag & OB_QUAT) {
903 Mat3ToQuat(mat, ob->quat);
904 QuatToMat3(ob->quat, tmat);
907 Mat3ToEul(mat, ob->rot);
908 EulToMat3(ob->rot, tmat);
912 Mat3MulMat3(tmat, imat, mat);
914 ob->size[0]= tmat[0][0];
915 ob->size[1]= tmat[1][1];
916 ob->size[2]= tmat[2][2];
920 void clear_parent(void)
927 if(G.scene->id.lib) return;
929 mode= pupmenu("OK? %t|Clear Parent %x1|Clear and Keep Transformation (Clear Track) %x2|Clear Parent Inverse %x3");
935 if TESTBASELIB(base) {
937 if(mode==1 || mode==2) {
938 par= base->object->parent;
939 base->object->parent= NULL;
940 base->object->recalc |= OB_RECALC;
943 base->object->track= NULL;
944 apply_obmat(base->object);
948 Mat4One(base->object->parentinv);
949 base->object->recalc |= OB_RECALC;
955 DAG_scene_sort(G.scene);
956 DAG_scene_flush_update(G.scene, screen_view3d_layers());
957 allqueue(REDRAWVIEW3D, 0);
958 allqueue(REDRAWOOPS, 0);
960 BIF_undo_push("Clear Parent");
963 void clear_track(void)
969 if(G.scene->id.lib) return;
971 mode= pupmenu("OK? %t|Clear Track %x1| Clear Track and Keep Transform %x2");
977 if TESTBASELIB(base) {
978 base->object->track= NULL;
979 base->object->recalc |= OB_RECALC;
982 apply_obmat(base->object);
988 DAG_scene_sort(G.scene);
989 allqueue(REDRAWVIEW3D, 0);
990 allqueue(REDRAWOOPS, 0);
992 BIF_undo_push("Clear Track");
995 void clear_object(char mode)
999 float *v1, *v3, mat[3][3];
1000 int armature_clear= 0;
1003 if(G.obedit) return;
1004 if(G.scene->id.lib) return;
1006 if(mode=='r') str= "Clear rotation";
1007 else if(mode=='g') str= "Clear location";
1008 else if(mode=='s') str= "Clear scale";
1009 else if(mode=='o') str= "Clear origin";
1014 if TESTBASELIB(base) {
1017 if ((ob->flag & OB_POSEMODE)) {
1018 /* only clear pose transforms if:
1019 * - with a mesh in weightpaint mode, it's related armature needs to be cleared
1020 * - with clearing transform of object being edited at the time
1022 if ((G.f & G_WEIGHTPAINT) || ob==OBACT) {
1023 clear_armature(ob, mode);
1024 armature_clear= 1; /* silly system to prevent another dag update, so no action applied */
1027 else if((G.f & G_WEIGHTPAINT)==0) {
1030 memset(ob->rot, 0, 3*sizeof(float));
1031 memset(ob->drot, 0, 3*sizeof(float));
1036 struct VNode *vnode = (VNode*)ob->vnode;
1037 ((VObjectData*)vnode->data)->flag |= ROT_SEND_READY;
1038 b_verse_send_transformation(ob);
1043 else if(mode=='g') {
1044 memset(ob->loc, 0, 3*sizeof(float));
1045 memset(ob->dloc, 0, 3*sizeof(float));
1048 struct VNode *vnode = (VNode*)ob->vnode;
1049 ((VObjectData*)vnode->data)->flag |= POS_SEND_READY;
1050 b_verse_send_transformation(ob);
1055 else if(mode=='s') {
1056 memset(ob->dsize, 0, 3*sizeof(float));
1062 struct VNode *vnode = (VNode*)ob->vnode;
1063 ((VObjectData*)vnode->data)->flag |= SCALE_SEND_READY;
1064 b_verse_send_transformation(ob);
1069 else if(mode=='o') {
1072 v3= ob->parentinv[3];
1074 Mat3CpyMat4(mat, ob->parentinv);
1079 Mat3MulVecfl(mat, v3);
1083 ob->recalc |= OB_RECALC_OB;
1089 allqueue(REDRAWVIEW3D, 0);
1090 if(armature_clear==0) /* in this case flush was done */
1091 DAG_scene_flush_update(G.scene, screen_view3d_layers());
1095 void reset_slowparents(void)
1097 /* back to original locations */
1102 if(base->object->parent) {
1103 if(base->object->partype & PARSLOW) {
1104 base->object->partype -= PARSLOW;
1105 where_is_object(base->object);
1106 base->object->partype |= PARSLOW;
1113 void set_slowparent(void)
1117 if( okee("Set slow parent")==0 ) return;
1121 if TESTBASELIB(base) {
1122 if(base->object->parent) base->object->partype |= PARSLOW;
1126 BIF_undo_push("Slow parent");
1129 void make_vertex_parent(void)
1131 EditMesh *em = G.editMesh;
1138 int a, v1=0, v2=0, v3=0, v4=0, nr=1;
1140 /* we need 1 to 3 selected vertices */
1142 if(G.obedit->type==OB_MESH) {
1143 eve= em->verts.first;
1147 else if(v2==0) v2= nr;
1148 else if(v3==0) v3= nr;
1149 else if(v4==0) v4= nr;
1156 else if ELEM(G.obedit->type, OB_SURF, OB_CURVE) {
1157 extern ListBase editNurb;
1160 if((nu->type & 7)==CU_BEZIER) {
1164 if(BEZSELECTED(bezt)) {
1166 else if(v2==0) v2= nr;
1167 else if(v3==0) v3= nr;
1168 else if(v4==0) v4= nr;
1177 a= nu->pntsu*nu->pntsv;
1179 if(bp->f1 & SELECT) {
1181 else if(v2==0) v2= nr;
1182 else if(v3==0) v3= nr;
1183 else if(v4==0) v4= nr;
1193 else if(G.obedit->type==OB_LATTICE) {
1195 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
1198 if(bp->f1 & SELECT) {
1200 else if(v2==0) v2= nr;
1201 else if(v3==0) v3= nr;
1202 else if(v4==0) v4= nr;
1210 if(v4 || !((v1 && v2==0 && v3==0) || (v1 && v2 && v3)) ) {
1211 error("Select either 1 or 3 vertices to parent to");
1215 if(okee("Make vertex parent")==0) return;
1219 if TESTBASELIB(base) {
1223 ob->recalc |= OB_RECALC;
1224 par= BASACT->object->parent;
1231 error("Loop in parents");
1234 ob->parent= BASACT->object;
1236 ob->partype= PARVERT3;
1241 /* inverse parent matrix */
1242 what_does_parent(ob);
1243 Mat4Invert(ob->parentinv, workob.obmat);
1247 ob->partype= PARVERT1;
1250 /* inverse parent matrix */
1251 what_does_parent(ob);
1252 Mat4Invert(ob->parentinv, workob.obmat);
1260 allqueue(REDRAWVIEW3D, 0);
1262 DAG_scene_sort(G.scene);
1263 /* BIF_undo_push(str); not, conflicts with editmode undo... */
1266 static Object *group_objects_menu(Group *group)
1273 for(go= group->gobject.first; go; go= go->next) {
1277 if(len==0) return NULL;
1279 str= MEM_callocN(40+32*len, "menu");
1281 strcpy(str, "Make Proxy for: %t");
1283 for(nr=1, go= group->gobject.first; go; go= go->next, nr++) {
1284 a+= sprintf(str+a, "|%s %%x%d", go->ob->id.name+2, nr);
1287 a= pupmenu_col(str, 20);
1290 go= BLI_findlink(&group->gobject, a-1);
1297 /* adds empty object to become local replacement data of a library-linked object */
1298 void make_proxy(void)
1303 if(G.scene->id.lib) return;
1304 if(ob==NULL) return;
1307 if(ob->dup_group && ob->dup_group->id.lib) {
1309 /* gives menu with list of objects in group */
1310 ob= group_objects_menu(ob->dup_group);
1312 else if(ob->id.lib) {
1313 if(okee("Make Proxy Object")==0)
1317 error("Can only make proxy for a referenced object or group");
1323 Base *newbase, *oldbase= BASACT;
1326 newob= add_object(OB_EMPTY);
1328 strcpy(name, gob->id.name+2);
1330 strcpy(name, ob->id.name+2);
1331 strcat(name, "_proxy");
1332 rename_id(&newob->id, name);
1335 newbase= BASACT; /* add_object sets active... */
1336 newbase->lay= oldbase->lay;
1337 newob->lay= newbase->lay;
1339 /* remove base, leave user count of object, it gets linked in object_make_proxy */
1341 BLI_remlink(&G.scene->base, oldbase);
1344 object_make_proxy(newob, ob, gob);
1346 DAG_scene_sort(G.scene);
1347 DAG_object_flush_update(G.scene, newob, OB_RECALC);
1348 allqueue(REDRAWALL, 0);
1349 BIF_undo_push("Make Proxy Object");
1353 int test_parent_loop(Object *par, Object *ob)
1355 /* test if 'ob' is a parent somewhere in par's parents */
1357 if(par==0) return 0;
1358 if(ob == par) return 1;
1360 return test_parent_loop(par->parent, ob);
1364 void make_parent(void)
1368 bPoseChannel *pchan= NULL;
1371 if(G.scene->id.lib) return;
1373 if ELEM4(G.obedit->type, OB_MESH, OB_CURVE, OB_SURF, OB_LATTICE) make_vertex_parent();
1374 else if (G.obedit->type==OB_ARMATURE) make_bone_parent();
1377 if(BASACT==0) return;
1380 par= BASACT->object;
1382 if(par->type == OB_LATTICE){
1383 mode= pupmenu("Make Parent %t|Normal Parent %x1|Lattice Deform %x2");
1394 else if(par->type == OB_CURVE){
1395 mode= pupmenu("Make Parent %t|Normal Parent %x1|Follow Path %x2|Curve Deform %x3|Path Constraint %x4");
1403 Curve *cu= par->data;
1406 if((cu->flag & CU_PATH)==0) {
1407 cu->flag |= CU_PATH|CU_FOLLOW;
1408 makeDispListCurveTypes(par, 0); /* force creation of path data */
1410 else cu->flag |= CU_FOLLOW;
1417 bFollowPathConstraint *data;
1421 if TESTBASELIB(base) {
1423 float cmat[4][4], vec[3];
1425 con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1426 strcpy (con->name, "AutoPath");
1429 data->tar = BASACT->object;
1431 add_constraint_to_object(con, base->object);
1433 get_constraint_target_matrix(con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, G.scene->r.cfra - base->object->sf);
1434 VecSubf(vec, base->object->obmat[3], cmat[3]);
1436 base->object->loc[0] = vec[0];
1437 base->object->loc[1] = vec[1];
1438 base->object->loc[2] = vec[2];
1444 allqueue(REDRAWVIEW3D, 0);
1445 DAG_scene_sort(G.scene);
1446 BIF_undo_push("Make Parent");
1450 else if(par->type == OB_ARMATURE){
1454 if TESTBASELIB(base) {
1456 if(ELEM(base->object->type, OB_MESH, OB_LATTICE)) {
1457 if(par->flag & OB_POSEMODE)
1458 mode= pupmenu("Make Parent To%t|Bone %x1|Armature %x2|Object %x3");
1460 mode= pupmenu("Make Parent To%t|Armature %x2|Object %x3");
1464 if(par->flag & OB_POSEMODE)
1465 mode= pupmenu("Make Parent To %t|Bone %x1|Object %x3");
1467 mode= pupmenu("Make Parent To %t|Object %x3");
1478 pchan= get_active_posechannel(par);
1481 error("No active Bone");
1482 allqueue(REDRAWVIEW3D, 0);
1498 if(qual & LR_SHIFTKEY) {
1499 if(okee("Make parent without inverse")==0) return;
1502 if(qual & LR_ALTKEY) {
1503 if(okee("Make vertex parent")==0) return;
1505 else if(okee("Make parent")==0) return;
1507 /* now we'll clearparentandkeeptransform all objects */
1510 if TESTBASELIB(base) {
1511 if(base!=BASACT && base->object->parent) {
1512 base->object->parent= NULL;
1513 apply_obmat(base->object);
1521 par->recalc |= OB_RECALC_OB;
1525 if TESTBASELIB(base) {
1528 if( test_parent_loop(par, base->object) ) {
1529 error("Loop in parents");
1533 base->object->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
1535 /* the ifs below are horrible code (ton) */
1537 if (par->type==OB_ARMATURE) {
1538 base->object->partype= mode;
1540 strcpy (base->object->parsubstr, pchan->name);
1542 base->object->parsubstr[0]=0;
1545 if(qual & LR_ALTKEY) {
1546 base->object->partype= PARVERT1;
1548 else if(ELEM(par->type, OB_CURVE, OB_LATTICE)) {
1549 base->object->partype= mode;
1552 base->object->partype= PAROBJECT;
1556 base->object->parent= par;
1558 /* calculate inverse parent matrix? */
1559 if( (qual & LR_SHIFTKEY) ) {
1561 Mat4One(base->object->parentinv);
1562 memset(base->object->loc, 0, 3*sizeof(float));
1565 if(mode==PARSKEL && base->object->type==OB_MESH && par->type == OB_ARMATURE) {
1566 /* Prompt the user as to whether he wants to
1567 * add some vertex groups based on the bones
1568 * in the parent armature.
1570 create_vgroups_from_armature(base->object,
1573 base->object->partype= PAROBJECT;
1574 what_does_parent(base->object);
1575 Mat4One (base->object->parentinv);
1576 base->object->partype= mode;
1579 what_does_parent(base->object);
1580 Mat4Invert(base->object->parentinv, workob.obmat);
1587 allqueue(REDRAWVIEW3D, 0);
1588 allqueue(REDRAWOOPS, 0);
1590 DAG_scene_sort(G.scene);
1591 DAG_scene_flush_update(G.scene, screen_view3d_layers());
1593 BIF_undo_push("make Parent");
1597 void enter_editmode(int wc)
1605 if(G.scene->id.lib) return;
1608 if((G.vd==NULL || (base->lay & G.vd->lay))==0) return;
1610 strcpy(G.editModeTitleExtra, "");
1613 if(ob->data==0) return;
1615 if (object_data_is_libdata(ob)) {
1620 if(wc) waitcursor(1);
1622 if(ob->type==OB_MESH) {
1625 if(me->pv) sculptmode_pmv_off(me);
1629 allqueue(REDRAWBUTSLOGIC, 0);
1630 /*if(G.f & G_FACESELECT) allqueue(REDRAWIMAGE, 0);*/
1631 if (EM_texFaceCheck())
1632 allqueue(REDRAWIMAGE, 0);
1635 if (ob->type==OB_ARMATURE){
1636 arm= base->object->data;
1639 * The function object_data_is_libdata make a problem here, the
1640 * check for ob->proxy return 0 and let blender enter to edit mode
1641 * this causa a crash when you try leave the edit mode.
1642 * The problem is that i can't remove the ob->proxy check from
1643 * object_data_is_libdata that prevent the bugfix #6614, so
1644 * i add this little hack here.
1652 make_editArmature();
1653 /* to ensure all goes in restposition and without striding */
1654 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC);
1656 allqueue (REDRAWVIEW3D,0);
1658 else if(ob->type==OB_FONT) {
1663 else if(ob->type==OB_MBALL) {
1668 else if(ob->type==OB_LATTICE) {
1673 else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
1678 allqueue(REDRAWBUTSEDIT, 0);
1679 allqueue(REDRAWOOPS, 0);
1683 setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
1685 allqueue(REDRAWVIEW3D, 1);
1686 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
1689 else G.obedit= NULL;
1691 if(wc) waitcursor(0);
1693 scrarea_queue_headredraw(curarea);
1696 void exit_editmode(int flag) /* freedata==0 at render, 1= freedata, 2= do undo buffer too */
1699 int freedata = flag & EM_FREEDATA;
1701 if(G.obedit==NULL) return;
1703 if(flag & EM_WAITCURSOR) waitcursor(1);
1704 if(G.obedit->type==OB_MESH) {
1709 if(EM_texFaceCheck())
1710 allqueue(REDRAWIMAGE, 0);
1712 if(retopo_mesh_paint_check())
1715 if(G.totvert>MESH_MAX_VERTS) {
1716 error("Too many vertices");
1721 if(freedata) free_editMesh(G.editMesh);
1723 if(G.f & G_WEIGHTPAINT)
1724 mesh_octree_table(G.obedit, NULL, 'e');
1726 else if (G.obedit->type==OB_ARMATURE){
1727 load_editArmature();
1728 if (freedata) free_editArmature();
1730 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1731 extern ListBase editNurb;
1733 if(freedata) freeNurblist(&editNurb);
1735 else if(G.obedit->type==OB_FONT && freedata) {
1738 else if(G.obedit->type==OB_LATTICE) {
1740 if(freedata) free_editLatt();
1742 else if(G.obedit->type==OB_MBALL) {
1743 extern ListBase editelems;
1745 if(freedata) BLI_freelistN(&editelems);
1750 /* for example; displist make is different in editmode */
1751 if(freedata) G.obedit= NULL;
1753 /* total remake of softbody data */
1754 if(modifiers_isSoftbodyEnabled(ob)) {
1755 if (ob->soft && ob->soft->keys) {
1756 notice("Erase Baked SoftBody");
1759 sbObjectToSoftbody(ob);
1762 if(modifiers_isClothEnabled(ob)) {
1763 cloth_free_modifier(modifiers_isClothEnabled(ob));
1766 if(ob->type==OB_MESH && get_mesh(ob)->mr)
1767 multires_edge_level_update(ob, get_mesh(ob));
1769 /* also flush ob recalc, doesn't take much overhead, but used for particles */
1770 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
1773 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
1777 allqueue(REDRAWVIEW3D, 1);
1778 allqueue(REDRAWBUTSALL, 0);
1779 allqueue(REDRAWACTION, 0);
1780 allqueue(REDRAWNLA, 0);
1781 allqueue(REDRAWIPO, 0);
1782 allqueue(REDRAWOOPS, 0);
1784 scrarea_queue_headredraw(curarea);
1786 if(G.obedit==NULL && (flag & EM_FREEUNDO))
1787 BIF_undo_push("Editmode");
1789 if(flag & EM_WAITCURSOR) waitcursor(0);
1792 void check_editmode(int type)
1795 if (G.obedit==0 || G.obedit->type==type) return;
1797 exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
1800 /* 0 == do center, 1 == center new, 2 == center cursor */
1802 void docenter(int centermode)
1804 EditMesh *em = G.editMesh;
1813 float cent[3], centn[3], min[3], max[3], omat[3][3];
1816 /* keep track of what is changed */
1817 int tot_change=0, tot_lib_error=0, tot_key_error=0, tot_multiuser_arm_error=0;
1820 if(G.scene->id.lib || G.vd==NULL) return;
1822 cent[0]= cent[1]= cent[2]= 0.0;
1826 INIT_MINMAX(min, max);
1828 if(G.obedit->type==OB_MESH) {
1829 for(eve= em->verts.first; eve; eve= eve->next) {
1830 if(G.vd->around==V3D_CENTROID) {
1832 VECADD(cent, cent, eve->co);
1835 DO_MINMAX(eve->co, min, max);
1839 if(G.vd->around==V3D_CENTROID) {
1840 VecMulf(cent, 1.0f/(float)total);
1843 cent[0]= (min[0]+max[0])/2.0f;
1844 cent[1]= (min[1]+max[1])/2.0f;
1845 cent[2]= (min[2]+max[2])/2.0f;
1848 for(eve= em->verts.first; eve; eve= eve->next) {
1849 VecSubf(eve->co, eve->co, cent);
1852 recalc_editnormals();
1858 for (base=FIRSTBASE; base; base= base->next) {
1859 if TESTBASELIB(base)
1860 base->object->flag &= ~OB_DONE;
1863 for (me= G.main->mesh.first; me; me= me->id.next) {
1864 me->flag &= ~ME_ISDONE;
1870 if TESTBASELIB(base) {
1871 if((base->object->flag & OB_DONE)==0) {
1872 base->object->flag |= OB_DONE;
1874 if(base->object->id.lib) {
1877 else if(G.obedit==0 && (me=get_mesh(base->object)) ) {
1880 /*error("Can't change the center of a mesh with vertex keys");
1883 } else if (me->id.lib) {
1887 VECCOPY(cent, give_cursor());
1888 Mat4Invert(base->object->imat, base->object->obmat);
1889 Mat4MulVecfl(base->object->imat, cent);
1891 INIT_MINMAX(min, max);
1893 for(a=0; a<me->totvert; a++, mvert++) {
1894 DO_MINMAX(mvert->co, min, max);
1897 cent[0]= (min[0]+max[0])/2.0f;
1898 cent[1]= (min[1]+max[1])/2.0f;
1899 cent[2]= (min[2]+max[2])/2.0f;
1903 for(a=0; a<me->totvert; a++, mvert++) {
1904 VecSubf(mvert->co, mvert->co, cent);
1906 me->flag |= ME_ISDONE;
1909 Mat3CpyMat4(omat, base->object->obmat);
1911 VECCOPY(centn, cent);
1912 Mat3MulVecfl(omat, centn);
1913 base->object->loc[0]+= centn[0];
1914 base->object->loc[1]+= centn[1];
1915 base->object->loc[2]+= centn[2];
1918 ob= G.main->object.first;
1920 if((ob->flag & OB_DONE)==0) {
1925 ob->flag |= OB_DONE;
1926 ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
1928 Mat3CpyMat4(omat, ob->obmat);
1929 VECCOPY(centn, cent);
1930 Mat3MulVecfl(omat, centn);
1931 ob->loc[0]+= centn[0];
1932 ob->loc[1]+= centn[1];
1933 ob->loc[2]+= centn[2];
1935 if(tme && (tme->flag & ME_ISDONE)==0) {
1937 for(a=0; a<tme->totvert; a++, mvert++) {
1938 VecSubf(mvert->co, mvert->co, cent);
1940 tme->flag |= ME_ISDONE;
1951 else if ELEM(base->object->type, OB_CURVE, OB_SURF) {
1953 /* totally weak code here... (ton) */
1954 if(G.obedit==base->object) {
1955 extern ListBase editNurb;
1956 nu1= editNurb.first;
1960 cu= base->object->data;
1961 nu1= cu->nurb.first;
1968 VECCOPY(cent, give_cursor());
1969 Mat4Invert(base->object->imat, base->object->obmat);
1970 Mat4MulVecfl(base->object->imat, cent);
1972 /* don't allow Z change if curve is 2D */
1973 if( !( cu->flag & CU_3D ) )
1976 INIT_MINMAX(min, max);
1980 minmaxNurb(nu, min, max);
1984 cent[0]= (min[0]+max[0])/2.0f;
1985 cent[1]= (min[1]+max[1])/2.0f;
1986 cent[2]= (min[2]+max[2])/2.0f;
1991 if( (nu->type & 7)==1) {
1994 VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
1995 VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
1996 VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
2000 a= nu->pntsu*nu->pntsv;
2002 VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
2007 if(centermode && G.obedit==0) {
2008 Mat3CpyMat4(omat, base->object->obmat);
2010 Mat3MulVecfl(omat, cent);
2011 base->object->loc[0]+= cent[0];
2012 base->object->loc[1]+= cent[1];
2013 base->object->loc[2]+= cent[2];
2018 if (centermode==0) {
2019 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2025 else if(base->object->type==OB_FONT) {
2028 cu= base->object->data;
2032 } else if (cu->id.lib) {
2035 cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
2036 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 */
2038 /* not really ok, do this better once! */
2039 cu->xof /= cu->fsize;
2040 cu->yof /= cu->fsize;
2042 allqueue(REDRAWBUTSEDIT, 0);
2046 else if(base->object->type==OB_ARMATURE) {
2047 bArmature *arm = base->object->data;
2051 } else if(arm->id.us>1) {
2052 /*error("Can't apply to a multi user armature");
2054 tot_multiuser_arm_error++;
2056 /* Function to recenter armatures in editarmature.c
2057 * Bone + object locations are handled there.
2059 docenter_armature(base->object, centermode);
2065 base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
2071 DAG_scene_flush_update(G.scene, screen_view3d_layers());
2072 allqueue(REDRAWVIEW3D, 0);
2073 BIF_undo_push("Do Center");
2076 /* Warn if any errors occured */
2077 if (tot_lib_error+tot_key_error+tot_multiuser_arm_error) {
2079 sprintf(err, "Warning %i Object(s) Not Centered, %i Changed:", tot_lib_error+tot_key_error+tot_multiuser_arm_error, tot_change);
2082 sprintf(err+strlen(err), "|%i linked library objects", tot_lib_error);
2084 sprintf(err+strlen(err), "|%i mesh key object(s)", tot_key_error);
2085 if (tot_multiuser_arm_error)
2086 sprintf(err+strlen(err), "|%i multiuser armature object(s)", tot_multiuser_arm_error);
2092 void docenter_new(void)
2094 if(G.scene->id.lib) return;
2097 error("Unable to center new in Edit Mode");
2104 void docenter_cursor(void)
2106 if(G.scene->id.lib) return;
2109 error("Unable to center cursor in Edit Mode");
2116 void movetolayer(void)
2119 unsigned int lay= 0, local;
2122 if(G.scene->id.lib) return;
2126 if TESTBASE(base) lay |= base->lay;
2134 if(G.vd->localview) {
2135 /* now we can move out of localview. */
2136 if (!okee("Move from localview")) return;
2140 lay= base->lay & ~G.vd->lay;
2142 base->object->lay= lay;
2143 base->object->flag &= ~SELECT;
2144 base->flag &= ~SELECT;
2145 if(base->object->type==OB_LAMP) islamp= 1;
2150 if( movetolayer_buts(&lay, NULL)==0 ) return;
2152 /* normal non localview operation */
2156 /* upper byte is used for local view */
2157 local= base->lay & 0xFF000000;
2158 base->lay= lay + local;
2159 base->object->lay= lay;
2160 if(base->object->type==OB_LAMP) islamp= 1;
2165 if(islamp) reshadeall_displist(); /* only frees */
2167 /* warning, active object may be hidden now */
2170 DAG_scene_sort(G.scene);
2172 allqueue(REDRAWBUTSEDIT, 0);
2173 allqueue(REDRAWVIEW3D, 0);
2174 allqueue(REDRAWOOPS, 0);
2175 allqueue(REDRAWINFO, 0);
2177 BIF_undo_push("Move to layer");
2180 /* THIS IS BAD CODE! do not bring back before it has a real implementation (ton) */
2184 Base *oldbase = BASACT;
2185 Curve *cu= ob->data;
2187 int slen= strlen(p);
2190 for (i = 0; i<=slen; p++, i++) {
2191 adduplicate(1, U.dupflag);
2194 text_to_curve(OBACT, 0); /* pass 1: only one letter, adapt position */
2195 text_to_curve(OBACT, 0); /* pass 2: remake */
2196 freedisplist(&OBACT->disp);
2197 makeDispListCurveTypes(OBACT, 0);
2199 OBACT->flag &= ~SELECT;
2200 BASACT->flag &= ~SELECT;
2201 oldbase->flag |= SELECT;
2202 oldbase->object->flag |= SELECT;
2203 set_active_base(oldbase);
2207 void special_editmenu(void)
2209 static short numcuts= 2;
2215 if(ob==NULL) return;
2217 if(G.obedit==NULL) {
2219 if(ob->flag & OB_POSEMODE) {
2220 pose_special_editmenu();
2222 else if(FACESEL_PAINT_TEST) {
2223 Mesh *me= get_mesh(ob);
2228 if(me==0 || me->mtface==0) return;
2230 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");
2234 for(a=me->totface; a>0; a--, tface++, mface++) {
2235 if(mface->flag & ME_FACE_SEL) {
2238 tface->mode |= TF_TEX; break;
2240 tface->mode |= TF_SHAREDCOL; break;
2242 tface->mode |= TF_LIGHT; break;
2244 tface->mode |= TF_INVISIBLE; break;
2246 tface->mode |= TF_DYNAMIC; break;
2248 tface->mode |= TF_TWOSIDE; break;
2250 tface->mode &= ~TF_TEX;
2254 tface->mode &= ~TF_SHAREDCOL; break;
2256 tface->mode &= ~TF_LIGHT; break;
2258 tface->mode &= ~TF_INVISIBLE; break;
2260 tface->mode &= ~TF_DYNAMIC; break;
2262 tface->mode &= ~TF_TWOSIDE; break;
2266 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2267 allqueue(REDRAWVIEW3D, 0);
2268 allqueue(REDRAWBUTSEDIT, 0);
2269 BIF_undo_push("Change texture face");
2271 else if(G.f & G_VERTEXPAINT) {
2272 Mesh *me= get_mesh(ob);
2274 if(me==0 || (me->mcol==NULL && me->mtface==NULL) ) return;
2276 nr= pupmenu("Specials%t|Shared VertexCol%x1");
2279 do_shared_vertexcol(me);
2281 BIF_undo_push("Shared VertexCol");
2283 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2286 else if(G.f & G_WEIGHTPAINT) {
2287 Object *par= modifiers_isDeformedByArmature(ob);
2289 if(par && (par->flag & OB_POSEMODE)) {
2290 nr= pupmenu("Specials%t|Apply Bone Envelopes to Vertex Groups %x1|Apply Bone Heat Weights to Vertex Groups %x2");
2293 pose_adds_vgroups(ob, (nr == 2));
2296 else if(G.f & G_PARTICLEEDIT) {
2297 ParticleSystem *psys = PE_get_current(ob);
2298 ParticleEditSettings *pset = PE_settings();
2303 if(G.scene->selectmode & SCE_SELECT_POINT)
2304 nr= pupmenu("Specials%t|Rekey%x1|Subdivide%x2|Select First%x3|Select Last%x4");
2306 nr= pupmenu("Specials%t|Rekey%x1");
2310 if(button(&pset->totrekey, 2, 100, "Number of Keys:")==0) return;
2325 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2327 if(nr>0) waitcursor(0);
2330 Base *base, *base_select= NULL;
2332 /* Get the active object mesh. */
2333 Mesh *me= get_mesh(ob);
2335 /* Booleans, if the active object is a mesh... */
2336 if (me && ob->id.lib==NULL) {
2338 /* Bring up a little menu with the boolean operation choices on. */
2339 nr= pupmenu("Boolean Tools%t|Intersect%x1|Union%x2|Difference%x3|Add Intersect Modifier%x4|Add Union Modifier%x5|Add Difference Modifier%x6");
2342 /* user has made a choice of a menu element.
2343 All of the boolean functions require 2 mesh objects
2344 we search through the object list to find the other
2345 selected item and make sure it is distinct and a mesh. */
2347 for(base= FIRSTBASE; base; base= base->next) {
2348 if TESTBASELIB(base) {
2349 if(base->object != ob) base_select= base;
2354 if (get_mesh(base_select->object)) {
2357 ret = NewBooleanMesh(BASACT,base_select,nr);
2359 error("An internal error occurred");
2360 } else if(ret==-1) {
2361 error("Selected meshes must have faces to perform boolean operations");
2362 } else if (ret==-2) {
2363 error("Both meshes must be a closed mesh");
2365 else BIF_undo_push("Boolean");
2368 BooleanModifierData *bmd = NULL;
2369 bmd = (BooleanModifierData *)modifier_new(eModifierType_Boolean);
2370 BLI_addtail(&ob->modifiers, bmd);
2371 bmd->object = base_select->object;
2372 bmd->modifier.mode |= eModifierMode_Realtime;
2374 case 4: bmd->operation = eBooleanModifierOp_Intersect; break;
2375 case 5: bmd->operation = eBooleanModifierOp_Union; break;
2376 case 6: bmd->operation = eBooleanModifierOp_Difference; break;
2378 do_common_editbuts(B_CHANGEDEP);
2379 BIF_undo_push("Add Boolean modifier");
2382 error("Please select 2 meshes");
2385 error("Please select 2 meshes");
2389 allqueue(REDRAWVIEW3D, 0);
2391 else if (ob->type == OB_FONT) {
2392 /* removed until this gets a decent implementation (ton) */
2393 /* nr= pupmenu("Split %t|Characters%x1");
2396 case 1: split_font();
2403 else if(G.obedit->type==OB_MESH) {
2404 /* 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 */
2406 nr= pupmenu("Subdivide Mesh%t|Subdivide%x1|Subdivide Multi%x2|Subdivide Multi Fractal%x3|Subdivide Smooth%x4");
2410 esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, 1, 0);
2412 BIF_undo_push("ESubdivide Single");
2415 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2417 esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, numcuts, 0);
2418 BIF_undo_push("ESubdivide");
2421 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2423 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2425 fac= -( (float)randfac )/100;
2426 esubdivideflag(1, fac, G.scene->toolsettings->editbutflag, numcuts, 0);
2427 BIF_undo_push("Subdivide Fractal");
2432 if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
2436 esubdivideflag(1, fac, G.scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
2437 BIF_undo_push("Subdivide Smooth");
2442 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");
2447 esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, 1, 0);
2449 BIF_undo_push("ESubdivide Single");
2452 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2454 esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, numcuts, 0);
2455 BIF_undo_push("ESubdivide");
2458 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2460 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2462 fac= -( (float)randfac )/100;
2463 esubdivideflag(1, fac, G.scene->toolsettings->editbutflag, numcuts, 0);
2464 BIF_undo_push("Subdivide Fractal");
2467 case 12: /* smooth */
2468 /* if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return; */
2470 if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
2474 esubdivideflag(1, fac, G.scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
2475 BIF_undo_push("Subdivide Smooth");
2482 notice("Removed %d Vertices", removedoublesflag(1, 0, G.scene->toolsettings->doublimit));
2483 BIF_undo_push("Remove Doubles");
2496 BIF_undo_push("Flip Normals");
2505 mesh_set_smooth_faces(1);
2508 mesh_set_smooth_faces(0);
2511 shape_copy_select_from();
2518 BIF_undo_push("Select Vertex Path");
2523 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2525 if(nr>0) waitcursor(0);
2528 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
2530 nr= pupmenu("Specials%t|Subdivide%x1|Switch Direction%x2|Set Goal Weight %x3|Set Radius %x4|Smooth Radius %x5");
2537 switchdirectionNurb2();
2549 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2551 else if(G.obedit->type==OB_ARMATURE) {
2552 nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Flip Left-Right Names%x3");
2554 subdivide_armature(1);
2556 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2558 subdivide_armature(numcuts);
2561 armature_flip_names();
2563 else if(G.obedit->type==OB_LATTICE) {
2564 static float weight= 1.0f;
2565 if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) {
2566 int a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
2567 BPoint *bp= editLatt->def;
2578 allqueue(REDRAWVIEW3D, 0);
2582 static void curvetomesh(Object *ob)
2587 ob->flag |= OB_DONE;
2591 if(dl==0) makeDispListCurveTypes(ob, 0); /* force creation */
2593 nurbs_to_mesh(ob); /* also does users */
2594 if (ob->type != OB_MESH) {
2595 error("can't convert curve to mesh");
2597 object_free_modifiers(ob);
2601 void convertmenu(void)
2603 Base *base, *basen=NULL, *basact, *basedel=NULL;
2604 Object *obact, *ob, *ob1;
2609 int ok=0, nr = 0, a;
2611 if(G.scene->id.lib) return;
2614 if(obact==0) return;
2615 if(!obact->flag & SELECT) return;
2616 if(G.obedit) return;
2618 basact= BASACT; /* will be restored */
2620 if(obact->type==OB_FONT) {
2621 nr= pupmenu("Convert Font to%t|Curve%x1|Curve (Single filling group)%x2|Mesh%x3");
2624 else if(obact->type==OB_MBALL) {
2625 nr= pupmenu("Convert Metaball to%t|Mesh (keep original)%x1|Mesh (Delete Original)%x2");
2628 else if(obact->type==OB_CURVE) {
2629 nr= pupmenu("Convert Curve to%t|Mesh");
2632 else if(obact->type==OB_SURF) {
2633 nr= pupmenu("Convert Nurbs Surface to%t|Mesh");
2636 else if(obact->type==OB_MESH) {
2637 nr= pupmenu("Convert Modifiers to%t|Mesh (Keep Original)%x1|Mesh (Delete Original)%x2");
2642 /* don't forget multiple users! */
2647 if TESTBASELIB(base) {
2648 base->object->flag &= ~OB_DONE;
2655 if TESTBASELIB(base) {
2659 if(ob->flag & OB_DONE);
2660 else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
2665 ob->flag |= OB_DONE;
2667 ob1= copy_object(ob);
2668 ob1->recalc |= OB_RECALC;
2670 basen= MEM_mallocN(sizeof(Base), "duplibase");
2672 BLI_addhead(&G.scene->base, basen); /* addhead: otherwise eternal loop */
2674 basen->flag |= SELECT;
2675 base->flag &= ~SELECT;
2676 ob->flag &= ~SELECT;
2678 /* decrement original mesh's usage count */
2682 /* make a new copy of the mesh */
2683 ob1->data= copy_mesh(me);
2686 /* make new mesh data from the original copy */
2687 dm= mesh_get_derived_final(ob1, CD_MASK_MESH);
2688 /* dm= mesh_create_derived_no_deform(ob1, NULL); this was called original (instead of get_derived). man o man why! (ton) */
2690 DM_to_mesh(dm, ob1->data);
2693 object_free_modifiers(ob1); /* after derivedmesh calls! */
2695 /* If the original object is active then make this object active */
2697 set_active_base( basen );
2701 else if(ob->type==OB_FONT) {
2702 ob->flag |= OB_DONE;
2712 cu->vfontb->id.us--;
2716 cu->vfonti->id.us--;
2720 cu->vfontbi->id.us--;
2725 ob1= G.main->object.first;
2728 ob1->type= OB_CURVE;
2729 ob1->recalc |= OB_RECALC;
2734 if (nr==2 || nr==3) {
2745 else if ELEM(ob->type, OB_CURVE, OB_SURF) {
2750 else if(ob->type==OB_MBALL) {
2752 if(nr==1 || nr == 2) {
2753 ob= find_basis_mball(ob);
2755 if(ob->disp.first && !(ob->flag&OB_DONE)) {
2758 ob->flag |= OB_DONE;
2760 ob1= copy_object(ob);
2761 ob1->recalc |= OB_RECALC;
2763 basen= MEM_mallocN(sizeof(Base), "duplibase");
2765 BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2767 basen->flag |= SELECT;
2768 basedel->flag &= ~SELECT;
2769 ob->flag &= ~SELECT;
2774 ob1->data= add_mesh("Mesh");
2779 me->totcol= mb->totcol;
2781 me->mat= MEM_dupallocN(mb->mat);
2782 for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
2785 mball_to_mesh(&ob->disp, ob1->data);
2787 /* So we can see the wireframe */
2790 /* If the original object is active then make this object active */
2792 set_active_base( basen );
2801 if(basedel != NULL && nr == 2) {
2804 free_and_unlink_base(basedel);
2809 /* texspace and normals */
2810 if(!basen) BASACT= base;
2812 enter_editmode(EM_WAITCURSOR);
2813 exit_editmode(EM_FREEDATA|EM_WAITCURSOR); /* freedata, but no undo */
2817 allqueue(REDRAWVIEW3D, 0);
2818 allqueue(REDRAWOOPS, 0);
2819 allspace(OOPS_TEST, 0);
2820 allqueue(REDRAWBUTSEDIT, 0);
2821 BIF_undo_push("Convert Object");
2823 DAG_scene_sort(G.scene);
2826 /* Change subdivision properties of mesh object ob, if
2827 * level==-1 then toggle subsurf, else set to level.
2828 * *set allows to toggle multiple selections
2830 static void object_flip_subdivison(Object *ob, int *set, int level, int mode)
2834 if(ob->type!=OB_MESH)