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_force.h"
78 #include "DNA_scene_types.h"
79 #include "DNA_screen_types.h"
80 #include "DNA_texture_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"
93 #include "BKE_action.h"
95 #include "BKE_armature.h"
96 #include "BKE_constraint.h"
97 #include "BKE_blender.h"
98 #include "BKE_booleanops.h"
99 #include "BKE_curve.h"
100 #include "BKE_displist.h"
101 #include "BKE_depsgraph.h"
102 #include "BKE_DerivedMesh.h"
103 #include "BKE_effect.h"
104 #include "BKE_font.h"
105 #include "BKE_global.h"
106 #include "BKE_group.h"
109 #include "BKE_lattice.h"
110 #include "BKE_library.h"
111 #include "BKE_main.h"
112 #include "BKE_material.h"
113 #include "BKE_mball.h"
114 #include "BKE_mesh.h"
116 #include "BKE_object.h"
117 #include "BKE_property.h"
119 #include "BKE_scene.h"
120 #include "BKE_softbody.h"
121 #include "BKE_subsurf.h"
122 #include "BKE_texture.h"
123 #include "BKE_utildefines.h"
124 #include "BKE_modifier.h"
126 #include "BIF_butspace.h"
127 #include "BIF_editconstraint.h"
128 #include "BIF_editdeform.h"
129 #include "BIF_editfont.h"
130 #include "BIF_editlattice.h"
131 #include "BIF_editmesh.h"
132 #include "BIF_editoops.h"
133 #include "BIF_editview.h"
134 #include "BIF_editarmature.h"
136 #include "BIF_graphics.h"
137 #include "BIF_interface.h"
138 #include "BIF_meshtools.h"
139 #include "BIF_mywindow.h"
140 #include "BIF_resources.h"
141 #include "BIF_screen.h"
142 #include "BIF_space.h"
143 #include "BIF_toolbox.h"
144 #include "BIF_toets.h"
146 #include "BSE_edit.h"
147 #include "BSE_editipo.h"
148 #include "BSE_filesel.h" /* For activate_databrowse() */
149 #include "BSE_view.h"
150 #include "BSE_drawview.h"
151 #include "BSE_trans_types.h"
152 #include "BSE_editipo_types.h"
154 #include "BDR_vpaint.h"
155 #include "BDR_editmball.h"
156 #include "BDR_editobject.h"
157 #include "BDR_drawobject.h"
158 #include "BDR_editcurve.h"
159 #include "BDR_unwrapper.h"
162 #include "mydevice.h"
166 #include "butspace.h"
167 #include "BIF_transform.h"
169 #include "BIF_poseobject.h"
171 /* used in editipo, editcurve and here */
172 #define BEZSELECTED(bezt) (((bezt)->f1 & 1) || ((bezt)->f2 & 1) || ((bezt)->f3 & 1))
174 /* local prototypes -------------*/
176 /* --------------------------------- */
178 void add_object_draw(int type) /* for toolbox or menus, only non-editmode stuff */
182 G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT);
183 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
185 if ELEM3(curarea->spacetype, SPACE_VIEW3D, SPACE_BUTS, SPACE_INFO) {
186 if (G.obedit) exit_editmode(2); // freedata, and undo
187 ob= add_object(type);
188 set_active_base(BASACT);
189 base_init_from_view3d(BASACT, G.vd);
191 /* only undo pushes on objects without editmode... */
192 if(type==OB_EMPTY) BIF_undo_push("Add Empty");
193 else if(type==OB_LAMP) {
194 BIF_undo_push("Add Lamp");
195 if(G.vd->drawtype == OB_SHADED) reshadeall_displist();
197 else if(type==OB_LATTICE) BIF_undo_push("Add Lattice");
198 else if(type==OB_CAMERA) BIF_undo_push("Add Camera");
200 allqueue(REDRAWVIEW3D, 0);
203 redraw_test_buttons(OBACT);
205 allqueue(REDRAWALL, 0);
207 deselect_all_area_oops();
208 set_select_flag_oops();
210 DAG_scene_sort(G.scene);
211 allqueue(REDRAWINFO, 1); /* 1, because header->win==0! */
214 void add_objectLamp(short type)
218 /* this function also comes from an info window */
219 if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
222 add_object_draw(OB_LAMP);
223 base_init_from_view3d(BASACT, G.vd);
226 la = BASACT->object->data;
229 allqueue(REDRAWALL, 0);
232 /* note: now unlinks constraints as well */
233 void free_and_unlink_base(Base *base)
238 BLI_remlink(&G.scene->base, base);
239 free_libblock_us(&G.main->object, base->object);
243 void delete_obj(int ok)
249 if(G.scene->id.lib) return;
253 Base *nbase= base->next;
256 if(ok==0 && (ok=okee("Erase selected Object(s)"))==0) return;
257 if(base->object->type==OB_LAMP) islamp= 1;
259 free_and_unlink_base(base);
266 G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT);
267 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
269 if(islamp && G.vd->drawtype==OB_SHADED) reshadeall_displist();
271 redraw_test_buttons(OBACT);
272 allqueue(REDRAWVIEW3D, 0);
273 allqueue (REDRAWACTION, 0);
274 allqueue(REDRAWIPO, 0);
275 allqueue(REDRAWDATASELECT, 0);
276 allspace(OOPS_TEST, 0);
277 allqueue(REDRAWOOPS, 0);
278 allqueue(REDRAWACTION, 0);
279 allqueue(REDRAWNLA, 0);
281 DAG_scene_sort(G.scene);
283 BIF_undo_push("Delete object(s)");
286 static int return_editmesh_indexar(int *tot, int **indexar, float *cent)
288 EditMesh *em = G.editMesh;
290 int *index, nr, totvert=0;
292 for(eve= em->verts.first; eve; eve= eve->next) {
293 if(eve->f & SELECT) totvert++;
295 if(totvert==0) return 0;
297 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
300 cent[0]= cent[1]= cent[2]= 0.0;
302 for(eve= em->verts.first; eve; eve= eve->next) {
303 if(eve->f & SELECT) {
305 VecAddf(cent, cent, eve->co);
310 VecMulf(cent, 1.0f/(float)totvert);
315 static int return_editmesh_vgroup(char *name, float *cent)
317 EditMesh *em = G.editMesh;
321 cent[0]= cent[1]= cent[2]= 0.0;
323 if (G.obedit->actdef) {
325 /* find the vertices */
326 for(eve= em->verts.first; eve; eve= eve->next) {
327 for (i=0; i<eve->totweight; i++){
328 if(eve->dw[i].def_nr == (G.obedit->actdef-1)) {
330 VecAddf(cent, cent, eve->co);
335 bDeformGroup *defGroup = BLI_findlink(&G.obedit->defbase, G.obedit->actdef-1);
336 strcpy(name, defGroup->name);
337 VecMulf(cent, 1.0f/(float)totvert);
345 static void select_editmesh_hook(HookModifierData *hmd)
347 EditMesh *em = G.editMesh;
351 for(eve= em->verts.first; eve; eve= eve->next, nr++) {
352 if(nr==hmd->indexar[index]) {
354 if(index < hmd->totindex-1) index++;
360 static int return_editlattice_indexar(int *tot, int **indexar, float *cent)
363 int *index, nr, totvert=0, a;
366 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
369 if(bp->f1 & SELECT) {
370 if(bp->hide==0) totvert++;
375 if(totvert==0) return 0;
377 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
380 cent[0]= cent[1]= cent[2]= 0.0;
382 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
385 if(bp->f1 & SELECT) {
388 VecAddf(cent, cent, bp->vec);
395 VecMulf(cent, 1.0f/(float)totvert);
400 static void select_editlattice_hook(HookModifierData *hmd)
403 int index=0, nr=0, a;
406 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
409 if(hmd->indexar[index]==nr) {
411 if(index < hmd->totindex-1) index++;
418 static int return_editcurve_indexar(int *tot, int **indexar, float *cent)
420 extern ListBase editNurb;
424 int *index, a, nr, totvert=0;
426 for(nu= editNurb.first; nu; nu= nu->next) {
427 if((nu->type & 7)==CU_BEZIER) {
431 if(bezt->f1 & SELECT) totvert++;
432 if(bezt->f2 & SELECT) totvert++;
433 if(bezt->f3 & SELECT) totvert++;
439 a= nu->pntsu*nu->pntsv;
441 if(bp->f1 & SELECT) totvert++;
446 if(totvert==0) return 0;
448 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
451 cent[0]= cent[1]= cent[2]= 0.0;
453 for(nu= editNurb.first; nu; nu= nu->next) {
454 if((nu->type & 7)==CU_BEZIER) {
458 if(bezt->f1 & SELECT) {
460 VecAddf(cent, cent, bezt->vec[0]);
463 if(bezt->f2 & SELECT) {
465 VecAddf(cent, cent, bezt->vec[1]);
468 if(bezt->f3 & SELECT) {
470 VecAddf(cent, cent, bezt->vec[2]);
478 a= nu->pntsu*nu->pntsv;
480 if(bp->f1 & SELECT) {
482 VecAddf(cent, cent, bp->vec);
490 VecMulf(cent, 1.0f/(float)totvert);
495 static void select_editcurve_hook(HookModifierData *hmd)
497 extern ListBase editNurb;
501 int index=0, a, nr=0;
503 for(nu= editNurb.first; nu; nu= nu->next) {
504 if((nu->type & 7)==CU_BEZIER) {
508 if(nr == hmd->indexar[index]) {
510 if(index<hmd->totindex-1) index++;
513 if(nr == hmd->indexar[index]) {
515 if(index<hmd->totindex-1) index++;
518 if(nr == hmd->indexar[index]) {
520 if(index<hmd->totindex-1) index++;
529 a= nu->pntsu*nu->pntsv;
531 if(nr == hmd->indexar[index]) {
533 if(index<hmd->totindex-1) index++;
542 void hook_select(HookModifierData *hmd)
544 if(G.obedit->type==OB_MESH) select_editmesh_hook(hmd);
545 else if(G.obedit->type==OB_LATTICE) select_editlattice_hook(hmd);
546 else if(G.obedit->type==OB_CURVE) select_editcurve_hook(hmd);
547 else if(G.obedit->type==OB_SURF) select_editcurve_hook(hmd);
550 int hook_getIndexArray(int *tot, int **indexar, char *name, float *cent_r)
556 switch(G.obedit->type) {
558 /* check selected vertices first */
559 if( return_editmesh_indexar(tot, indexar, cent_r)) return 1;
560 else return return_editmesh_vgroup(name, cent_r);
563 return return_editcurve_indexar(tot, indexar, cent_r);
565 return return_editlattice_indexar(tot, indexar, cent_r);
573 ModifierData *md = NULL;
574 HookModifierData *hmd = NULL;
578 if(G.obedit==NULL) return;
580 if(modifiers_findByType(G.obedit, eModifierType_Hook))
581 mode= pupmenu("Hooks %t|Add, To New Empty %x1|Add, To Selected Object %x2|Remove... %x3|Reassign... %x4|Select... %x5|Clear Offset...%x6");
583 mode= pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
589 if(mode==2) { // selected object
590 Base *base= FIRSTBASE;
592 if TESTBASELIB(base) {
601 error("Requires selected Object");
609 // make pupmenu with hooks
610 for(md=G.obedit->modifiers.first; md; md= md->next) {
611 if (md->type==eModifierType_Hook)
616 error("Object has no hooks yet");
620 cp= MEM_callocN(maxlen+32, "temp string");
621 if(mode==3) strcpy(cp, "Remove %t|");
622 else if(mode==4) strcpy(cp, "Reassign %t|");
623 else if(mode==5) strcpy(cp, "Select %t|");
624 else if(mode==6) strcpy(cp, "Clear Offset %t|");
626 for(md=G.obedit->modifiers.first; md; md= md->next) {
627 if (md->type==eModifierType_Hook) {
628 strcat(cp, md->name);
639 for(md=G.obedit->modifiers.first; md; md=md->next) {
640 if (md->type==eModifierType_Hook) {
646 hmd = (HookModifierData*) md;
650 /* do it, new hooks or reassign */
651 if(mode==1 || mode==2 || mode==4) {
653 int tot, ok, *indexar;
656 ok = hook_getIndexArray(&tot, &indexar, name, cent);
659 error("Requires selected vertices or active Vertex Group");
664 Base *base= BASACT, *newbase;
666 ob= add_object(OB_EMPTY);
669 newbase->lay= base->lay;
670 ob->lay= newbase->lay;
672 /* transform cent to global coords for loc */
673 VecMat4MulVecfl(ob->loc, G.obedit->obmat, cent);
675 /* restore, add_object sets active */
678 /* if mode is 2 or 4, ob has been set */
681 if(mode==1 || mode==2) {
682 ModifierData *md = G.obedit->modifiers.first;
684 while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) {
688 hmd = (HookModifierData*) modifier_new(eModifierType_Hook);
689 BLI_insertlinkbefore(&G.obedit->modifiers, md, hmd);
690 sprintf(hmd->modifier.name, "Hook-%s", ob->id.name+2);
692 else if (hmd->indexar) MEM_freeN(hmd->indexar); // reassign, hook was set
695 hmd->indexar= indexar;
696 VECCOPY(hmd->cent, cent);
698 BLI_strncpy(hmd->name, name, 32);
700 if(mode==1 || mode==2) {
701 /* matrix calculus */
702 /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
707 Mat4Invert(ob->imat, ob->obmat);
708 /* apparently this call goes from right to left... */
709 Mat4MulSerie(hmd->parentinv, ob->imat, G.obedit->obmat, NULL,
710 NULL, NULL, NULL, NULL, NULL);
714 else if(mode==3) { // remove
715 BLI_remlink(&G.obedit->modifiers, md);
718 else if(mode==5) { // select
721 else if(mode==6) { // clear offset
722 where_is_object(ob); // ob is hook->parent
724 Mat4Invert(ob->imat, ob->obmat);
725 /* this call goes from right to left... */
726 Mat4MulSerie(hmd->parentinv, ob->imat, G.obedit->obmat, NULL,
727 NULL, NULL, NULL, NULL, NULL);
730 allqueue(REDRAWVIEW3D, 0);
731 allqueue(REDRAWBUTSOBJECT, 0);
732 DAG_scene_sort(G.scene);
734 BIF_undo_push("Add hook");
737 void make_track(void)
742 if(G.scene->id.lib) return;
746 if(BASACT==0) return;
748 mode= pupmenu("Make Track %t|TrackTo Constraint %x1|LockTrack Constraint %x2|Old Track %x3");
754 bTrackToConstraint *data;
758 if TESTBASELIB(base) {
760 con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
761 strcpy (con->name, "AutoTrack");
764 data->tar = BASACT->object;
765 base->object->recalc |= OB_RECALC;
767 /* Lamp and Camera track differently by default */
768 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
769 data->reserved1 = TRACK_nZ;
770 data->reserved2 = UP_Y;
773 add_constraint_to_object(con, base->object);
782 bLockTrackConstraint *data;
786 if TESTBASELIB(base) {
788 con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
789 strcpy (con->name, "AutoTrack");
792 data->tar = BASACT->object;
793 base->object->recalc |= OB_RECALC;
795 /* Lamp and Camera track differently by default */
796 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
797 data->trackflag = TRACK_nZ;
798 data->lockflag = LOCK_Y;
801 add_constraint_to_object(con, base->object);
811 if TESTBASELIB(base) {
813 base->object->track= BASACT->object;
814 base->object->recalc |= OB_RECALC;
821 allqueue(REDRAWOOPS, 0);
822 allqueue(REDRAWVIEW3D, 0);
823 DAG_scene_sort(G.scene);
825 BIF_undo_push("Make Track");
828 void apply_obmat(Object *ob)
830 float mat[3][3], imat[3][3], tmat[3][3];
832 /* from obmat to loc rot size */
835 Mat3CpyMat4(mat, ob->obmat);
837 VECCOPY(ob->loc, ob->obmat[3]);
839 if(ob->transflag & OB_QUAT) {
840 Mat3ToQuat(mat, ob->quat);
841 QuatToMat3(ob->quat, tmat);
844 Mat3ToEul(mat, ob->rot);
845 EulToMat3(ob->rot, tmat);
849 Mat3MulMat3(tmat, imat, mat);
851 ob->size[0]= tmat[0][0];
852 ob->size[1]= tmat[1][1];
853 ob->size[2]= tmat[2][2];
857 void clear_parent(void)
864 if(G.scene->id.lib) return;
866 mode= pupmenu("OK? %t|Clear Parent %x1|Clear and Keep Transformation (Clear Track) %x2|Clear Parent Inverse %x3");
872 if TESTBASELIB(base) {
874 if(mode==1 || mode==2) {
875 par= base->object->parent;
876 base->object->parent= NULL;
877 base->object->recalc |= OB_RECALC;
880 base->object->track= NULL;
881 apply_obmat(base->object);
885 Mat4One(base->object->parentinv);
886 base->object->recalc |= OB_RECALC;
892 DAG_scene_sort(G.scene);
893 DAG_scene_flush_update(G.scene, screen_view3d_layers());
894 allqueue(REDRAWVIEW3D, 0);
895 allqueue(REDRAWOOPS, 0);
897 BIF_undo_push("Clear Parent");
900 void clear_track(void)
906 if(G.scene->id.lib) return;
908 mode= pupmenu("OK? %t|Clear Track %x1| Clear Track and Keep Transform %x2");
914 if TESTBASELIB(base) {
915 base->object->track= NULL;
916 base->object->recalc |= OB_RECALC;
919 apply_obmat(base->object);
925 DAG_scene_sort(G.scene);
926 allqueue(REDRAWVIEW3D, 0);
927 allqueue(REDRAWOOPS, 0);
929 BIF_undo_push("Clear Track");
932 void clear_object(char mode)
936 float *v1, *v3, mat[3][3];
940 if(G.scene->id.lib) return;
942 if(mode=='r') str= "Clear rotation";
943 else if(mode=='g') str= "Clear location";
944 else if(mode=='s') str= "Clear scale";
945 else if(mode=='o') str= "Clear origin";
950 if TESTBASELIB(base) {
953 if(ob->flag & OB_POSEMODE) {
954 // no test if we got armature; could be in future...
955 clear_armature(ob, mode);
957 else if((G.f & G_WEIGHTPAINT)==0) {
960 memset(ob->rot, 0, 3*sizeof(float));
961 memset(ob->drot, 0, 3*sizeof(float));
966 memset(ob->loc, 0, 3*sizeof(float));
967 memset(ob->dloc, 0, 3*sizeof(float));
970 memset(ob->dsize, 0, 3*sizeof(float));
978 v3= ob->parentinv[3];
980 Mat3CpyMat4(mat, ob->parentinv);
985 Mat3MulVecfl(mat, v3);
989 ob->recalc |= OB_RECALC_OB;
995 allqueue(REDRAWVIEW3D, 0);
996 DAG_scene_flush_update(G.scene, screen_view3d_layers());
1000 void reset_slowparents(void)
1002 /* back to original locations */
1007 if(base->object->parent) {
1008 if(base->object->partype & PARSLOW) {
1009 base->object->partype -= PARSLOW;
1010 where_is_object(base->object);
1011 base->object->partype |= PARSLOW;
1018 void set_slowparent(void)
1022 if( okee("Set slow parent")==0 ) return;
1026 if TESTBASELIB(base) {
1027 if(base->object->parent) base->object->partype |= PARSLOW;
1031 BIF_undo_push("Slow parent");
1034 void make_vertex_parent(void)
1036 EditMesh *em = G.editMesh;
1043 int a, v1=0, v2=0, v3=0, nr=1;
1045 /* we need 1 to 3 selected vertices */
1047 if(G.obedit->type==OB_MESH) {
1048 eve= em->verts.first;
1052 else if(v2==0) v2= nr;
1053 else if(v3==0) v3= nr;
1060 else if ELEM(G.obedit->type, OB_SURF, OB_CURVE) {
1061 extern ListBase editNurb;
1064 if((nu->type & 7)==CU_BEZIER) {
1068 if(BEZSELECTED(bezt)) {
1070 else if(v2==0) v2= nr;
1071 else if(v3==0) v3= nr;
1080 a= nu->pntsu*nu->pntsv;
1082 if(bp->f1 & SELECT) {
1084 else if(v2==0) v2= nr;
1085 else if(v3==0) v3= nr;
1097 if( !(v1 && v2==0 && v3==0) && !(v1 && v2 && v3) ) {
1098 error("Select either 1 or 3 vertices to parent to");
1102 if(okee("Make vertex parent")==0) return;
1106 if TESTBASELIB(base) {
1110 ob->recalc |= OB_RECALC;
1111 par= BASACT->object->parent;
1118 error("Loop in parents");
1121 ob->parent= BASACT->object;
1123 ob->partype= PARVERT3;
1128 /* inverse parent matrix */
1129 what_does_parent(ob);
1130 Mat4Invert(ob->parentinv, workob.obmat);
1134 ob->partype= PARVERT1;
1137 /* inverse parent matrix */
1138 what_does_parent(ob);
1139 Mat4Invert(ob->parentinv, workob.obmat);
1147 allqueue(REDRAWVIEW3D, 0);
1149 DAG_scene_sort(G.scene);
1150 // BIF_undo_push(str); not, conflicts with editmode undo...
1153 int test_parent_loop(Object *par, Object *ob)
1155 /* test if 'ob' is a parent somewhere in par's parents */
1157 if(par==0) return 0;
1158 if(ob == par) return 1;
1160 return test_parent_loop(par->parent, ob);
1164 void make_parent(void)
1168 bPoseChannel *pchan= NULL;
1171 if(G.scene->id.lib) return;
1173 if ELEM3(G.obedit->type, OB_MESH, OB_CURVE, OB_SURF) make_vertex_parent();
1174 else if (G.obedit->type==OB_ARMATURE) make_bone_parent();
1177 if(BASACT==0) return;
1180 par= BASACT->object;
1182 if(par->type == OB_LATTICE){
1183 mode= pupmenu("Make Parent %t|Normal Parent %x1|Lattice Deform %x2");
1194 else if(par->type == OB_CURVE){
1196 bFollowPathConstraint *data;
1198 mode= pupmenu("Make Parent %t|Normal Parent %x1|Follow Path %x2|Curve Deform %x3|Path Constraint %x4");
1206 Curve *cu= par->data;
1209 if((cu->flag & CU_PATH)==0) {
1210 cu->flag |= CU_PATH|CU_FOLLOW;
1211 makeDispListCurveTypes(par, 0); // force creation of path data
1213 else cu->flag |= CU_FOLLOW;
1222 if TESTBASELIB(base) {
1224 float cmat[4][4], vec[3], size[3];
1226 con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1227 strcpy (con->name, "AutoPath");
1230 data->tar = BASACT->object;
1232 add_constraint_to_object(con, base->object);
1234 get_constraint_target_matrix(con, TARGET_OBJECT, NULL, cmat, size, G.scene->r.cfra - base->object->sf);
1235 VecSubf(vec, base->object->obmat[3], cmat[3]);
1237 base->object->loc[0] = vec[0];
1238 base->object->loc[1] = vec[1];
1239 base->object->loc[2] = vec[2];
1245 allqueue(REDRAWVIEW3D, 0);
1246 DAG_scene_sort(G.scene);
1247 BIF_undo_push("make Parent");
1251 else if(par->type == OB_ARMATURE){
1255 if TESTBASELIB(base) {
1257 if(base->object->type==OB_MESH) {
1258 if(par->flag & OB_POSEMODE)
1259 mode= pupmenu("Make Parent To%t|Bone %x1|Armature %x2|Object %x3");
1261 mode= pupmenu("Make Parent To%t|Armature %x2|Object %x3");
1265 if(par->flag & OB_POSEMODE)
1266 mode= pupmenu("Make Parent To %t|Bone %x1|Object %x3");
1268 mode= pupmenu("Make Parent To %t|Object %x3");
1279 pchan= get_active_posechannel(par);
1282 error("No active Bone");
1283 allqueue(REDRAWVIEW3D, 0);
1299 if(qual & LR_SHIFTKEY) {
1300 if(okee("Make parent without inverse")==0) return;
1303 if(qual & LR_ALTKEY) {
1304 if(okee("Make vertex parent")==0) return;
1306 else if(okee("Make parent")==0) return;
1308 /* now we'll clearparentandkeeptransform all objects */
1311 if TESTBASELIB(base) {
1312 if(base!=BASACT && base->object->parent) {
1313 base->object->parent= NULL;
1314 apply_obmat(base->object);
1322 par->recalc |= OB_RECALC_OB;
1326 if TESTBASELIB(base) {
1329 if( test_parent_loop(par, base->object) ) {
1330 error("Loop in parents");
1334 base->object->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
1336 /* the ifs below are horrible code (ton) */
1338 if (par->type==OB_ARMATURE) {
1339 base->object->partype= mode;
1341 strcpy (base->object->parsubstr, pchan->name);
1343 base->object->parsubstr[0]=0;
1346 if(qual & LR_ALTKEY) {
1347 base->object->partype= PARVERT1;
1349 else if(ELEM(par->type, OB_CURVE, OB_LATTICE)) {
1350 base->object->partype= mode;
1353 base->object->partype= PAROBJECT;
1357 base->object->parent= par;
1359 /* calculate inverse parent matrix? */
1360 if( (qual & LR_SHIFTKEY) ) {
1362 Mat4One(base->object->parentinv);
1363 memset(base->object->loc, 0, 3*sizeof(float));
1366 if(mode==PARSKEL && par->type == OB_ARMATURE) {
1367 /* Prompt the user as to whether he wants to
1368 * add some vertex groups based on the bones
1369 * in the parent armature.
1371 create_vgroups_from_armature(base->object,
1374 base->object->partype= PAROBJECT;
1375 what_does_parent(base->object);
1376 Mat4One (base->object->parentinv);
1377 base->object->partype= mode;
1380 what_does_parent(base->object);
1381 Mat4Invert(base->object->parentinv, workob.obmat);
1384 if(par->type==OB_ARMATURE && mode == PARSKEL){
1385 verify_defgroups(base->object);
1392 allqueue(REDRAWVIEW3D, 0);
1393 allqueue(REDRAWOOPS, 0);
1395 DAG_scene_sort(G.scene);
1396 DAG_scene_flush_update(G.scene, screen_view3d_layers());
1398 BIF_undo_push("make Parent");
1402 void enter_editmode(void)
1411 if(G.scene->id.lib) return;
1414 if((G.vd==NULL || (base->lay & G.vd->lay))==0) return;
1416 strcpy(G.editModeTitleExtra, "");
1419 if(ob->data==0) return;
1423 error("Can't edit library data");
1427 if(ob->type==OB_MESH) {
1431 error("Can't edit library data");
1437 allqueue(REDRAWBUTSLOGIC, 0);
1438 if(G.f & G_FACESELECT) allqueue(REDRAWIMAGE, 0);
1440 if (ob->type==OB_ARMATURE){
1441 arm=base->object->data;
1444 error("Can't edit library data");
1449 make_editArmature();
1450 allqueue (REDRAWVIEW3D,0);
1452 else if(ob->type==OB_FONT) {
1457 else if(ob->type==OB_MBALL) {
1462 else if(ob->type==OB_LATTICE) {
1467 else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
1472 allqueue(REDRAWBUTSEDIT, 0);
1473 allqueue(REDRAWOOPS, 0);
1477 setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
1479 allqueue(REDRAWVIEW3D, 1);
1480 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
1483 else G.obedit= NULL;
1485 scrarea_queue_headredraw(curarea);
1488 void exit_editmode(int freedata) /* freedata==0 at render, 1= freedata, 2= do undo buffer too */
1492 if(G.obedit==NULL) return;
1494 if(G.obedit->type==OB_MESH) {
1499 if(G.totvert>MESH_MAX_VERTS) {
1500 error("Too many vertices");
1505 if(freedata) free_editMesh(G.editMesh);
1507 if(G.f & G_FACESELECT)
1508 allqueue(REDRAWIMAGE, 0);
1509 if(G.f & G_WEIGHTPAINT)
1510 mesh_octree_table(G.obedit, NULL, 'e');
1512 else if (G.obedit->type==OB_ARMATURE){
1513 load_editArmature();
1514 if (freedata) free_editArmature();
1516 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1517 extern ListBase editNurb;
1519 if(freedata) freeNurblist(&editNurb);
1521 else if(G.obedit->type==OB_FONT && freedata) {
1524 else if(G.obedit->type==OB_LATTICE) {
1526 if(freedata) free_editLatt();
1528 else if(G.obedit->type==OB_MBALL) {
1529 extern ListBase editelems;
1531 if(freedata) BLI_freelistN(&editelems);
1536 /* for example; displist make is different in editmode */
1537 if(freedata) G.obedit= NULL;
1539 /* total remake of softbody data */
1540 if(modifiers_isSoftbodyEnabled(ob)) {
1541 if (ob->soft && ob->soft->keys) {
1542 notice("Erased Baked SoftBody");
1545 sbObjectToSoftbody(ob);
1547 /* also flush ob recalc, doesn't take much overhead, but used for particles */
1548 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
1551 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
1555 allqueue(REDRAWVIEW3D, 1);
1556 allqueue(REDRAWBUTSALL, 0);
1557 allqueue(REDRAWACTION, 0);
1558 allqueue(REDRAWNLA, 0);
1559 allqueue(REDRAWIPO, 0);
1560 allqueue(REDRAWOOPS, 0);
1562 scrarea_queue_headredraw(curarea);
1564 if(G.obedit==NULL && freedata==2)
1565 BIF_undo_push("Editmode");
1568 void check_editmode(int type)
1571 if (G.obedit==0 || G.obedit->type==type) return;
1573 exit_editmode(2); // freedata, and undo
1576 /* 0 == do centre, 1 == centre new, 2 == centre cursor */
1578 void docentre(int centremode)
1580 EditMesh *em = G.editMesh;
1589 float cent[3], centn[3], min[3], max[3], omat[3][3];
1593 if(G.scene->id.lib || G.vd==NULL) return;
1595 cent[0]= cent[1]= cent[2]= 0.0;
1599 INIT_MINMAX(min, max);
1601 if(G.obedit->type==OB_MESH) {
1602 for(eve= em->verts.first; eve; eve= eve->next) {
1603 if(G.vd->around==V3D_CENTROID) {
1605 VECADD(cent, cent, eve->co);
1608 DO_MINMAX(eve->co, min, max);
1612 if(G.vd->around==V3D_CENTROID) {
1613 VecMulf(cent, 1.0f/(float)total);
1616 cent[0]= (min[0]+max[0])/2.0f;
1617 cent[1]= (min[1]+max[1])/2.0f;
1618 cent[2]= (min[2]+max[2])/2.0f;
1621 for(eve= em->verts.first; eve; eve= eve->next) {
1622 VecSubf(eve->co, eve->co, cent);
1625 recalc_editnormals();
1632 if TESTBASELIB(base) {
1633 base->object->flag &= ~OB_DONE;
1637 me= G.main->mesh.first;
1639 me->flag &= ~ME_ISDONE;
1646 if TESTBASELIB(base) {
1647 if((base->object->flag & OB_DONE)==0) {
1649 base->object->flag |= OB_DONE;
1651 if(G.obedit==0 && (me=get_mesh(base->object)) ) {
1654 error("Can't change the center of a mesh with vertex keys");
1659 VECCOPY(cent, give_cursor());
1660 Mat4Invert(base->object->imat, base->object->obmat);
1661 Mat4MulVecfl(base->object->imat, cent);
1663 INIT_MINMAX(min, max);
1666 for(a=0; a<me->totvert; a++, mvert++) {
1667 DO_MINMAX(mvert->co, min, max);
1670 cent[0]= (min[0]+max[0])/2.0f;
1671 cent[1]= (min[1]+max[1])/2.0f;
1672 cent[2]= (min[2]+max[2])/2.0f;
1676 for(a=0; a<me->totvert; a++, mvert++) {
1677 VecSubf(mvert->co, mvert->co, cent);
1679 me->flag |= ME_ISDONE;
1682 Mat3CpyMat4(omat, base->object->obmat);
1684 VECCOPY(centn, cent);
1685 Mat3MulVecfl(omat, centn);
1686 base->object->loc[0]+= centn[0];
1687 base->object->loc[1]+= centn[1];
1688 base->object->loc[2]+= centn[2];
1691 ob= G.main->object.first;
1693 if((ob->flag & OB_DONE)==0) {
1698 ob->flag |= OB_DONE;
1699 ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
1701 Mat3CpyMat4(omat, ob->obmat);
1702 VECCOPY(centn, cent);
1703 Mat3MulVecfl(omat, centn);
1704 ob->loc[0]+= centn[0];
1705 ob->loc[1]+= centn[1];
1706 ob->loc[2]+= centn[2];
1708 if(tme && (tme->flag & ME_ISDONE)==0) {
1710 for(a=0; a<tme->totvert; a++, mvert++) {
1711 VecSubf(mvert->co, mvert->co, cent);
1713 tme->flag |= ME_ISDONE;
1722 else if ELEM(base->object->type, OB_CURVE, OB_SURF) {
1724 /* totally weak code here... (ton) */
1725 if(G.obedit==base->object) {
1726 extern ListBase editNurb;
1727 nu1= editNurb.first;
1731 cu= base->object->data;
1732 nu1= cu->nurb.first;
1736 VECCOPY(cent, give_cursor());
1737 Mat4Invert(base->object->imat, base->object->obmat);
1738 Mat4MulVecfl(base->object->imat, cent);
1740 /* don't allow Z change if curve is 2D */
1741 if( !( cu->flag & CU_3D ) )
1744 INIT_MINMAX(min, max);
1748 minmaxNurb(nu, min, max);
1752 cent[0]= (min[0]+max[0])/2.0f;
1753 cent[1]= (min[1]+max[1])/2.0f;
1754 cent[2]= (min[2]+max[2])/2.0f;
1759 if( (nu->type & 7)==1) {
1762 VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
1763 VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
1764 VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
1768 a= nu->pntsu*nu->pntsv;
1770 VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
1775 if(centremode && G.obedit==0) {
1776 Mat3CpyMat4(omat, base->object->obmat);
1778 Mat3MulVecfl(omat, cent);
1779 base->object->loc[0]+= cent[0];
1780 base->object->loc[1]+= cent[1];
1781 base->object->loc[2]+= cent[2];
1789 else if(base->object->type==OB_FONT) {
1792 cu= base->object->data;
1793 if(cu->bb==0) return;
1795 cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
1796 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 */
1798 /* not really ok, do this better once! */
1799 cu->xof /= cu->fsize;
1800 cu->yof /= cu->fsize;
1802 allqueue(REDRAWBUTSEDIT, 0);
1804 base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
1810 DAG_scene_flush_update(G.scene, screen_view3d_layers());
1811 allqueue(REDRAWVIEW3D, 0);
1812 BIF_undo_push("Do Centre");
1815 void docentre_new(void)
1817 if(G.scene->id.lib) return;
1820 error("Unable to center new in Edit Mode");
1827 void docentre_cursor(void)
1829 if(G.scene->id.lib) return;
1832 error("Unable to center cursor in Edit Mode");
1839 void movetolayer(void)
1842 unsigned int lay= 0, local;
1845 if(G.scene->id.lib) return;
1849 if TESTBASE(base) lay |= base->lay;
1857 if(G.vd->localview) {
1858 /* now we can move out of localview. */
1859 if (!okee("Move from localview")) return;
1863 lay= base->lay & ~G.vd->lay;
1865 base->object->lay= lay;
1866 base->object->flag &= ~SELECT;
1867 base->flag &= ~SELECT;
1868 if(base->object->type==OB_LAMP) islamp= 1;
1873 if( movetolayer_buts(&lay)==0 ) return;
1875 /* normal non localview operation */
1879 /* upper byte is used for local view */
1880 local= base->lay & 0xFF000000;
1881 base->lay= lay + local;
1882 base->object->lay= lay;
1883 if(base->object->type==OB_LAMP) islamp= 1;
1888 if(islamp && G.vd->drawtype == OB_SHADED) reshadeall_displist();
1890 /* warning, active object may be hidden now */
1893 DAG_scene_sort(G.scene);
1895 allqueue(REDRAWBUTSEDIT, 0);
1896 allqueue(REDRAWVIEW3D, 0);
1897 allqueue(REDRAWOOPS, 0);
1898 allqueue(REDRAWINFO, 0);
1900 BIF_undo_push("Move to layer");
1906 Base *oldbase = BASACT;
1907 Curve *cu= ob->data;
1909 int slen= strlen(p);
1912 for (i = 0; i<=slen; p++, i++) {
1913 adduplicate(1, U.dupflag);
1916 text_to_curve(OBACT, 0); // pass 1: only one letter, adapt position
1917 text_to_curve(OBACT, 0); // pass 2: remake
1918 freedisplist(&OBACT->disp);
1919 makeDispListCurveTypes(OBACT, 0);
1921 OBACT->flag &= ~SELECT;
1922 BASACT->flag &= ~SELECT;
1923 oldbase->flag |= SELECT;
1924 oldbase->object->flag |= SELECT;
1925 set_active_base(oldbase);
1929 void special_editmenu(void)
1931 static short numcuts= 2;
1937 if(ob==NULL) return;
1939 if(G.obedit==NULL) {
1941 if(ob->flag & OB_POSEMODE) {
1942 pose_special_editmenu();
1944 else if(G.f & G_FACESELECT) {
1945 Mesh *me= get_mesh(ob);
1949 if(me==0 || me->tface==0) return;
1951 nr= pupmenu("Specials%t|Set Tex%x1| Shared%x2| Light%x3| Invisible%x4| Collision%x5|Clr Tex%x6| Shared%x7| Light%x8| Invisible%x9| Collision%x10");
1953 for(a=me->totface, tface= me->tface; a>0; a--, tface++) {
1954 if(tface->flag & SELECT) {
1957 tface->mode |= TF_TEX; break;
1959 tface->mode |= TF_SHAREDCOL; break;
1961 tface->mode |= TF_LIGHT; break;
1963 tface->mode |= TF_INVISIBLE; break;
1965 tface->mode |= TF_DYNAMIC; break;
1967 tface->mode &= ~TF_TEX;
1971 tface->mode &= ~TF_SHAREDCOL; break;
1973 tface->mode &= ~TF_LIGHT; break;
1975 tface->mode &= ~TF_INVISIBLE; break;
1977 tface->mode &= ~TF_DYNAMIC; break;
1981 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1982 allqueue(REDRAWVIEW3D, 0);
1983 allqueue(REDRAWBUTSEDIT, 0);
1984 BIF_undo_push("Change texture face");
1986 else if(G.f & G_VERTEXPAINT) {
1987 Mesh *me= get_mesh(ob);
1989 if(me==0 || (me->mcol==NULL && me->tface==NULL) ) return;
1991 nr= pupmenu("Specials%t|Shared VertexCol%x1");
1994 if(me->tface) tface_to_mcol(me);
1996 copy_vpaint_undo( (unsigned int *)me->mcol, me->totface);
1997 do_shared_vertexcol(me);
1999 if(me->tface) mcol_to_tface(me, 1);
2000 BIF_undo_push("Shared VertexCol");
2002 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2005 else if(G.f & G_WEIGHTPAINT) {
2006 Object *par= modifiers_isDeformedByArmature(ob);
2007 if(par && (par->flag & OB_POSEMODE)) {
2008 nr= pupmenu("Specials%t|Apply Bone Envelopes to VertexGroups %x1");
2011 if(me->dvert) copy_wpaint_undo(me->dvert, me->totvert);
2012 pose_adds_vgroups(ob);
2017 Base *base, *base_select= NULL;
2019 // Get the active object mesh.
2020 Mesh *me= get_mesh(ob);
2022 // Booleans, if the active object is a mesh...
2023 if (me && ob->id.lib==NULL) {
2025 // Bring up a little menu with the boolean operation choices on.
2026 nr= pupmenu("Boolean Tools%t|Intersect%x1|Union%x2|Difference%x3|Add Intersect Modifier%x4|Add Union Modifier%x5|Add Difference Modifier%x6");
2029 // user has made a choice of a menu element.
2030 // All of the boolean functions require 2 mesh objects
2031 // we search through the object list to find the other
2032 // selected item and make sure it is distinct and a mesh.
2034 for(base= FIRSTBASE; base; base= base->next) {
2035 if TESTBASELIB(base) {
2036 if(base->object != ob) base_select= base;
2041 if (get_mesh(base_select->object)) {
2044 ret = NewBooleanMesh(BASACT,base_select,nr);
2046 error("An internal error occurred");
2047 } else if(ret==-1) {
2048 error("Selected meshes must have faces to perform boolean operations");
2049 } else if (ret==-2) {
2050 error("Both meshes must be a closed mesh");
2052 else BIF_undo_push("Boolean");
2055 BooleanModifierData *bmd = NULL;
2056 bmd = (BooleanModifierData *)modifier_new(eModifierType_Boolean);
2057 BLI_addtail(&ob->modifiers, bmd);
2058 bmd->object = base_select->object;
2059 bmd->modifier.mode |= eModifierMode_Realtime;
2061 case 4: bmd->operation = eBooleanModifierOp_Intersect; break;
2062 case 5: bmd->operation = eBooleanModifierOp_Union; break;
2063 case 6: bmd->operation = eBooleanModifierOp_Difference; break;
2065 do_common_editbuts(B_CHANGEDEP);
2066 BIF_undo_push("Add Boolean modifier");
2069 error("Please select 2 meshes");
2072 error("Please select 2 meshes");
2076 allqueue(REDRAWVIEW3D, 0);
2078 else if (ob->type == OB_FONT) {
2079 nr= pupmenu("Split %t|Characters%x1");
2082 case 1: split_font();
2088 else if(G.obedit->type==OB_MESH) {
2090 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");
2095 esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, 1, 0);
2097 BIF_undo_push("ESubdivide Single");
2100 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2102 esubdivideflag(1, 0.0, G.scene->toolsettings->editbutflag, numcuts, 0);
2103 BIF_undo_push("ESubdivide");
2106 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2108 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2110 fac= -( (float)randfac )/100;
2111 esubdivideflag(1, fac, G.scene->toolsettings->editbutflag, numcuts, 0);
2112 BIF_undo_push("Subdivide Fractal");
2115 case 12: /* smooth */
2116 //if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
2118 if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
2122 esubdivideflag(1, fac, G.scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
2123 BIF_undo_push("Subdivide Smooth");
2130 notice("Removed %d Vertices", removedoublesflag(1, G.scene->toolsettings->doublimit));
2131 BIF_undo_push("Remove Doubles");
2144 BIF_undo_push("Flip Normals");
2153 mesh_set_smooth_faces(1);
2156 mesh_set_smooth_faces(0);
2159 shape_copy_select_from();
2166 BIF_undo_push("Select Vertex Path");
2170 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2172 if(nr>0) waitcursor(0);
2175 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
2177 nr= pupmenu("Specials%t|Subdivide%x1|Switch Direction%x2|Set Goal Weight %x3");
2184 switchdirectionNurb2();
2188 static float weight= 1.0f;
2189 extern ListBase editNurb;
2195 if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) {
2196 for(nu= editNurb.first; nu; nu= nu->next) {
2198 for(bezt=nu->bezt, a=0; a<nu->pntsu; a++, bezt++) {
2199 if(bezt->f2 & SELECT)
2200 bezt->weight= weight;
2204 for(bp=nu->bp, a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
2215 DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
2217 else if(G.obedit->type==OB_ARMATURE) {
2218 nr= pupmenu("Specials%t|Subdivide %x1|Flip Left-Right Names%x2");
2220 subdivide_armature();
2222 armature_flip_names();
2224 else if(G.obedit->type==OB_LATTICE) {
2225 static float weight= 1.0f;
2226 if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) {
2227 int a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
2228 BPoint *bp= editLatt->def;
2239 allqueue(REDRAWVIEW3D, 0);
2243 void convertmenu(void)
2245 Base *base, *basen, *basact, *basedel=NULL;
2246 Object *obact, *ob, *ob1;
2252 int ok=0, nr = 0, a;
2254 if(G.scene->id.lib) return;
2257 if(obact==0) return;
2258 if(!obact->flag & SELECT) return;
2259 if(G.obedit) return;
2261 basact= BASACT; /* will be restored */
2263 if(obact->type==OB_FONT) {
2264 nr= pupmenu("Convert Font to%t|Curve%x1|Curve (Single filling group)%x2");
2267 else if(obact->type==OB_MBALL) {
2268 nr= pupmenu("Convert Metaball to%t|Mesh (keep original)%x1|Mesh (Delete Original)%x2");
2271 else if(obact->type==OB_CURVE) {
2272 nr= pupmenu("Convert Curve to%t|Mesh");
2275 else if(obact->type==OB_SURF) {
2276 nr= pupmenu("Convert Nurbs Surface to%t|Mesh");
2279 else if(obact->type==OB_MESH) {
2280 nr= pupmenu("Convert Modifiers to%t|Mesh (Keep Original)%x1|Mesh (Delete Original)%x2");
2285 /* don't forget multiple users! */
2290 if TESTBASELIB(base) {
2291 base->object->flag &= ~OB_DONE;
2298 if TESTBASELIB(base) {
2302 if(ob->flag & OB_DONE);
2303 else if(ob->type==OB_MESH && ob->modifiers.first) { /* converting a mesh with no modifiers causes a segfault */
2310 ob->flag |= OB_DONE;
2312 ob1= copy_object(ob);
2313 ob1->recalc |= OB_RECALC;
2315 basen= MEM_mallocN(sizeof(Base), "duplibase");
2317 BLI_addhead(&G.scene->base, basen); /* addhead: otherwise eternal loop */
2319 basen->flag |= SELECT;
2320 base->flag &= ~SELECT;
2321 ob->flag &= ~SELECT;
2323 /* decrement original mesh's usage count */
2327 /* make a new copy of the mesh */
2328 ob1->data= copy_mesh(me);
2331 /* make new mesh data from the original copy */
2332 dm= mesh_get_derived_final(ob1, &needsfree);
2333 //dm= mesh_create_derived_no_deform(ob1, NULL); this was called original (instead of get_derived). man o man why! (ton)
2335 dlm= dm->convertToDispListMesh(dm, 0);
2336 displistmesh_to_mesh(dlm, ob1->data);
2337 if(needsfree) dm->release(dm);
2338 object_free_modifiers(ob1); /* after derivedmesh calls! */
2340 /* If the original object is active then make this object active */
2342 set_active_base( basen );
2346 else if(ob->type==OB_FONT) {
2347 ob->flag |= OB_DONE;
2357 cu->vfontb->id.us--;
2361 cu->vfonti->id.us--;
2365 cu->vfontbi->id.us--;
2370 ob1= G.main->object.first;
2373 ob1->type= OB_CURVE;
2374 ob1->recalc |= OB_RECALC;
2387 else if ELEM(ob->type, OB_CURVE, OB_SURF) {
2390 ob->flag |= OB_DONE;
2394 if(dl==0) makeDispListCurveTypes(ob, 0); // force creation
2396 nurbs_to_mesh(ob); /* also does users */
2398 /* texspace and normals */
2401 exit_editmode(1); // freedata, but no undo
2405 else if(ob->type==OB_MBALL) {
2407 if(nr==1 || nr == 2) {
2408 ob= find_basis_mball(ob);
2410 if(ob->disp.first && !(ob->flag&OB_DONE)) {
2413 ob->flag |= OB_DONE;
2415 ob1= copy_object(ob);
2416 ob1->recalc |= OB_RECALC;
2418 basen= MEM_mallocN(sizeof(Base), "duplibase");
2420 BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2422 basen->flag |= SELECT;
2423 basedel->flag &= ~SELECT;
2424 ob->flag &= ~SELECT;
2429 ob1->data= add_mesh();
2434 me->totcol= mb->totcol;
2436 me->mat= MEM_dupallocN(mb->mat);
2437 for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
2440 mball_to_mesh(&ob->disp, ob1->data);
2442 /* So we can see the wireframe */
2445 exit_editmode(1); // freedata, but no undo
2448 /* If the original object is active then make this object active */
2450 set_active_base( basen );
2459 if(basedel != NULL && nr == 2)
2460 free_and_unlink_base(basedel);
2465 allqueue(REDRAWVIEW3D, 0);
2466 allqueue(REDRAWOOPS, 0);
2467 allspace(OOPS_TEST, 0);
2468 allqueue(REDRAWBUTSEDIT, 0);
2469 BIF_undo_push("Convert Object");
2471 DAG_scene_sort(G.scene);
2474 /* Change subdivision properties of mesh object ob, if
2475 * level==-1 then toggle subsurf, else set to level.
2477 void flip_subdivison(Object *ob, int level)
2479 ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);
2482 SubsurfModifierData *smd = (SubsurfModifierData*) md;
2485 if (smd->modifier.mode&(eModifierMode_Render|eModifierMode_Realtime)) {
2486 smd->modifier.mode &= ~(eModifierMode_Render|eModifierMode_Realtime);
2488 smd->modifier.mode |= (eModifierMode_Render|eModifierMode_Realtime);
2491 smd->levels = level;
2494 SubsurfModifierData *smd = (SubsurfModifierData*) modifier_new(eModifierType_Subsurf);
2496 BLI_addtail(&ob->modifiers, smd);
2499 smd->levels = level;
2504 allqueue(REDRAWVIEW3D, 0);
2505 allqueue(REDRAWOOPS, 0);
2506 allqueue(REDRAWBUTSEDIT, 0);
2507 allqueue(REDRAWBUTSOBJECT, 0);
2508 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2510 BIF_undo_push("Switch subsurf on/off");
2513 static void copymenu_properties(Object *ob)
2515 bProperty *prop, *propn, *propc;
2520 prop= ob->prop.first;
2527 error("No properties in the active object to copy");
2531 str= MEM_callocN(24+32*tot, "copymenu prop");
2533 strcpy(str, "Copy Property %t");
2536 prop= ob->prop.first;
2540 strcat(str, prop->name);
2547 prop= ob->prop.first;
2558 if(base != BASACT) {
2559 if(TESTBASELIB(base)) {
2560 prop= get_property(base->object, propc->name);
2562 free_property(prop);
2563 BLI_remlink(&base->object->prop, prop);
2565 propn= copy_property(propc);
2566 BLI_addtail(&base->object->prop, propn);
2574 allqueue(REDRAWVIEW3D, 0);
2576 BIF_undo_push("Copy properties");
2579 static void copymenu_logicbricks(Object *ob)
2585 if(base->object != ob) {
2586 if(TESTBASELIB(base)) {
2588 /* first: free all logic */
2589 free_sensors(&base->object->sensors);
2590 unlink_controllers(&base->object->controllers);
2591 free_controllers(&base->object->controllers);
2592 unlink_actuators(&base->object->actuators);
2593 free_actuators(&base->object->actuators);
2595 /* now copy it, this also works without logicbricks! */
2596 clear_sca_new_poins_ob(ob);
2597 copy_sensors(&base->object->sensors, &ob->sensors);
2598 copy_controllers(&base->object->controllers, &ob->controllers);
2599 copy_actuators(&base->object->actuators, &ob->actuators);
2600 set_sca_new_poins_ob(base->object);
2602 /* some menu settings */
2603 base->object->scavisflag= ob->scavisflag;
2604 base->object->scaflag= ob->scaflag;
2610 BIF_undo_push("Copy logic");
2613 static void copymenu_modifiers(Object *ob)
2619 strcpy(str, "Copy Modifiers %t");
2621 sprintf(str+strlen(str), "|All%%x%d|%%l", NUM_MODIFIER_TYPES);
2623 for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
2624 ModifierTypeInfo *mti = modifierType_getInfo(i);
2626 if (ELEM(i, eModifierType_Hook, eModifierType_Softbody)) continue;
2628 if ( (mti->flags&eModifierTypeFlag_AcceptsCVs) ||
2629 (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
2630 sprintf(str+strlen(str), "|%s%%x%d", mti->name, i);
2634 event = pupmenu(str);
2635 if(event<=0) return;
2637 for (base= FIRSTBASE; base; base= base->next) {
2638 if(base->object != ob) {
2639 if(TESTBASELIB(base)) {
2642 base->object->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
2644 if (base->object->type==ob->type) {
2646 if (event==NUM_MODIFIER_TYPES) {
2647 object_free_modifiers(base->object);
2649 for (md=ob->modifiers.first; md; md=md->next) {
2650 if (md->type!=eModifierType_Hook) {
2651 ModifierData *nmd = modifier_new(md->type);
2652 modifier_copyData(md, nmd);
2653 BLI_addtail(&base->object->modifiers, nmd);
2657 /* copy specific types */
2658 ModifierData *md, *mdn;
2660 /* remove all with type 'event' */
2661 for (md=base->object->modifiers.first; md; md=mdn) {
2663 if(md->type==event) {
2664 BLI_remlink(&base->object->modifiers, md);
2669 /* copy all with type 'event' */
2670 for (md=ob->modifiers.first; md; md=md->next) {
2671 if (md->type==event) {
2673 mdn = modifier_new(event);
2674 BLI_addtail(&base->object->modifiers, mdn);
2676 modifier_copyData(md, mdn);
2685 allqueue(REDRAWVIEW3D, 0);
2686 allqueue(REDRAWBUTSOBJECT, 0);
2687 DAG_scene_sort(G.scene);
2689 BIF_undo_push("Copy modifiers");
2692 void copy_attr_menu()
2698 /* If you change this menu, don't forget to update the menu in header_view3d.c
2699 * view3d_edit_object_copyattrmenu() and in toolbox.c
2701 strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Drawtype%x4|Time Offset%x5|Dupli%x6|%l|Mass%x7|Damping%x8|Properties%x9|Logic Bricks%x10|%l");
2703 if(!(ob=OBACT)) return;
2705 strcat (str, "|Object Constraints%x22");
2706 strcat (str, "|NLA Strips%x26");
2708 if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
2709 strcat(str, "|Texture Space%x17");
2712 if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
2713 if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19|UV Orco%x28");
2715 if((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
2716 strcat(str, "|Curve Resolution%x25");
2719 if(ob->type==OB_MESH){
2720 strcat(str, "|Subdiv%x21|AutoSmooth%x27");
2723 if( give_parteff(ob) ) strcat(str, "|Particle Settings%x20");
2725 if(ob->soft) strcat(str, "|Soft Body Settings%x23");
2727 if(ob->type==OB_MESH || ob->type==OB_CURVE){
2728 strcat(str, "|Modifiers ...%x24");
2731 event= pupmenu(str);
2732 if(event<= 0) return;
2737 void copy_attr(short event)
2743 void *poin1, *poin2=0;
2744 int do_scene_sort= 0;
2746 if(G.scene->id.lib) return;
2748 if(!(ob=OBACT)) return;
2751 /* obedit_copymenu(); */
2755 if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
2756 if(ob->type==OB_MESH) poin2= &(((Mesh *)ob->data)->texflag);
2757 else if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) poin2= &(((Curve *)ob->data)->texflag);
2758 else if(ob->type==OB_MBALL) poin2= &(((MetaBall *)ob->data)->texflag);
2762 copymenu_properties(ob);
2765 else if(event==10) {
2766 copymenu_logicbricks(ob);
2769 else if(event==24) {
2770 copymenu_modifiers(ob);
2776 if(base != BASACT) {
2777 if(TESTBASELIB(base)) {
2778 base->object->recalc |= OB_RECALC_OB;
2780 if(event==1) { /* loc */
2781 VECCOPY(base->object->loc, ob->loc);
2782 VECCOPY(base->object->dloc, ob->dloc);
2784 else if(event==2) { /* rot */
2785 VECCOPY(base->object->rot, ob->rot);
2786 VECCOPY(base->object->drot, ob->drot);
2787 VECCOPY(base->object->quat, ob->quat);
2788 VECCOPY(base->object->dquat, ob->dquat);
2790 else if(event==3) { /* size */
2791 VECCOPY(base->object->size, ob->size);
2792 VECCOPY(base->object->dsize, ob->dsize);
2794 else if(event==4) { /* drawtype */
2795 base->object->dt= ob->dt;
2796 base->object->dtx= ob->dtx;
2797 base->object->empty_drawtype= ob->empty_drawtype;
2798 base->object->empty_drawsize= ob->empty_drawsize;
2800 else if(event==5) { /* time offs */
2801 base->object->sf= ob->sf;
2803 else if(event==6) { /* dupli */
2804 base->object->dupon= ob->dupon;
2805 base->object->dupoff= ob->dupoff;
2806 base->object->dupsta= ob->dupsta;
2807 base->object->dupend= ob->dupend;
2809 base->object->transflag &= ~OB_DUPLI;
2810 base->object->transflag |= (ob->transflag & OB_DUPLI);
2812 base->object->dup_group= ob->dup_group;
2814 id_us_plus((ID *)ob->dup_group);
2816 else if(event==7) { /* mass */
2817 base->object->mass= ob->mass;
2819 else if(event==8) { /* damping */
2820 base->object->damping= ob->damping;
2821 base->object->rdamping= ob->rdamping;
2823 else if(event==17) { /* tex space */
2826 if(obt->type==OB_MESH) poin1= &(((Mesh *)obt->data)->texflag);
2827 else if ELEM3(obt->type, OB_CURVE, OB_SURF, OB_FONT) poin1= &(((Curve *)obt->data)->texflag);
2828 else if(obt->type==OB_MBALL) poin1= &(((MetaBall *)obt->data)->texflag);
2831 memcpy(poin1, poin2, 4+12+12+12);
2833 if(obt->type==OB_MESH) ;
2834 else if(obt->type==OB_MBALL) tex_space_mball(obt);
2835 else tex_space_curve(obt->data);
2838 else if(event==18) { /* font settings */
2840 if(base->object->type==ob->type) {
2842 cu1= base->object->data;
2844 cu1->spacemode= cu->spacemode;
2845 cu1->spacing= cu->spacing;
2846 cu1->linedist= cu->linedist;
2847 cu1->shear= cu->shear;
2848 cu1->fsize= cu->fsize;
2851 cu1->textoncurve= cu->textoncurve;
2852 cu1->wordspace= cu->wordspace;
2853 cu1->ulpos= cu->ulpos;
2854 cu1->ulheight= cu->ulheight;
2855 if(cu1->vfont) cu1->vfont->id.us--;
2856 cu1->vfont= cu->vfont;
2857 id_us_plus((ID *)cu1->vfont);
2858 if(cu1->vfontb) cu1->vfontb->id.us--;
2859 cu1->vfontb= cu->vfontb;
2860 id_us_plus((ID *)cu1->vfontb);
2861 if(cu1->vfonti) cu1->vfonti->id.us--;
2862 cu1->vfonti= cu->vfonti;
2863 id_us_plus((ID *)cu1->vfonti);
2864 if(cu1->vfontbi) cu1->vfontbi->id.us--;
2865 cu1->vfontbi= cu->vfontbi;
2866 id_us_plus((ID *)cu1->vfontbi);
2868 text_to_curve(base->object, 0); // needed?
2871 strcpy(cu1->family, cu->family);
2873 base->object->recalc |= OB_RECALC_DATA;
2876 else if(event==19) { /* bevel settings */
2878 if ELEM(base->object->type, OB_CURVE, OB_FONT) {
2880 cu1= base->object->data;