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
50 #include "BLI_winstuff.h"
52 #include "MEM_guardedalloc.h"
58 #include "IMB_imbuf_types.h"
60 #include "DNA_action_types.h"
61 #include "DNA_armature_types.h"
62 #include "DNA_camera_types.h"
63 #include "DNA_constraint_types.h"
64 #include "DNA_curve_types.h"
65 #include "DNA_effect_types.h"
66 #include "DNA_ika_types.h"
67 #include "DNA_image_types.h"
68 #include "DNA_ipo_types.h"
69 #include "DNA_key_types.h"
70 #include "DNA_lamp_types.h"
71 #include "DNA_lattice_types.h"
72 #include "DNA_material_types.h"
73 #include "DNA_mesh_types.h"
74 #include "DNA_meshdata_types.h"
75 #include "DNA_meta_types.h"
76 #include "DNA_object_types.h"
77 #include "DNA_scene_types.h"
78 #include "DNA_screen_types.h"
79 #include "DNA_texture_types.h"
80 #include "DNA_view3d_types.h"
81 #include "DNA_world_types.h"
82 #include "DNA_userdef_types.h"
83 #include "DNA_property_types.h"
84 #include "DNA_vfont_types.h"
86 #include "BLI_blenlib.h"
87 #include "BLI_arithb.h"
88 #include "BLI_editVert.h"
89 #include "BLI_ghash.h"
91 #include "BKE_constraint.h"
92 #include "BKE_action.h"
93 #include "BKE_armature.h"
94 #include "BKE_utildefines.h"
96 #include "BKE_blender.h"
97 #include "BKE_booleanops.h"
98 #include "BKE_curve.h"
99 #include "BKE_displist.h"
100 #include "BKE_effect.h"
101 #include "BKE_font.h"
102 #include "BKE_global.h"
106 #include "BKE_lattice.h"
107 #include "BKE_library.h"
108 #include "BKE_main.h"
109 #include "BKE_material.h"
110 #include "BKE_mball.h"
111 #include "BKE_mesh.h"
113 #include "BKE_object.h"
114 #include "BKE_property.h"
116 #include "BKE_scene.h"
117 #include "BKE_softbody.h"
118 #include "BKE_subsurf.h"
119 #include "BKE_texture.h"
120 #include "BKE_utildefines.h"
123 #include "BIF_graphics.h"
124 #include "BIF_interface.h"
125 #include "BIF_mywindow.h"
126 #include "BIF_toolbox.h"
127 #include "BIF_screen.h"
128 #include "BIF_space.h"
129 #include "BIF_toets.h"
130 #include "BIF_butspace.h"
131 #include "BIF_editconstraint.h"
132 #include "BIF_editdeform.h"
133 #include "BIF_editfont.h"
134 #include "BIF_editika.h"
135 #include "BIF_editlattice.h"
136 #include "BIF_editmesh.h"
137 #include "BIF_editoops.h"
138 #include "BIF_editview.h"
139 #include "BIF_editarmature.h"
140 #include "BIF_resources.h"
142 #include "BSE_edit.h"
143 #include "BSE_editaction.h"
144 #include "BSE_editipo.h"
145 #include "BSE_filesel.h" /* For activate_databrowse() */
146 #include "BSE_view.h"
147 #include "BSE_trans_types.h"
148 #include "BSE_editipo_types.h"
150 #include "BDR_vpaint.h"
151 #include "BDR_editmball.h"
152 #include "BDR_editobject.h"
153 #include "BDR_drawobject.h"
154 #include "BDR_editcurve.h"
155 #include "BDR_unwrapper.h"
158 #include "mydevice.h"
163 #include "BIF_transform.h"
165 #include "BIF_poseobject.h"
167 /* extern Lattice *copy_lattice(Lattice *lt); */
168 extern ListBase editNurb;
169 extern ListBase editelems;
171 TransOb *transmain= 0;
172 TransVert *transvmain= 0;
173 int tottrans=0, transmode=0; /* 1: texspace */
175 float prop_size= 1.0;
179 /* used in editipo, editcurve and here */
180 #define BEZSELECTED(bezt) (((bezt)->f1 & 1) || ((bezt)->f2 & 1) || ((bezt)->f3 & 1))
184 #define KEYFLAG_ROT 0x00000001
185 #define KEYFLAG_LOC 0x00000002
186 #define KEYFLAG_SIZE 0x00000004
188 float centre[3], centroid[3];
190 void mirrormenu(void);
192 void add_object_draw(int type) /* for toolbox or menus, only non-editmode stuff */
196 G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT);
197 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
199 if ELEM3(curarea->spacetype, SPACE_VIEW3D, SPACE_BUTS, SPACE_INFO) {
200 if (G.obedit) exit_editmode(2); // freedata, and undo
201 ob= add_object(type);
202 base_init_from_view3d(BASACT, G.vd);
204 /* only undo pushes on objects without editmode... */
205 if(type==OB_EMPTY) BIF_undo_push("Add Empty");
206 else if(type==OB_LAMP) {
207 BIF_undo_push("Add Lamp");
208 if(G.vd->drawtype == OB_SHADED) reshadeall_displist();
210 else if(type==OB_LATTICE) BIF_undo_push("Add Lattice");
211 else if(type==OB_CAMERA) BIF_undo_push("Add Camera");
213 allqueue(REDRAWVIEW3D, 0);
216 redraw_test_buttons(OBACT);
218 allqueue(REDRAWALL, 0);
220 deselect_all_area_oops();
221 set_select_flag_oops();
222 allqueue(REDRAWINFO, 1); /* 1, because header->win==0! */
225 void add_objectLamp(short type)
229 /* this function also comes from an info window */
230 if ELEM(curarea->spacetype, SPACE_VIEW3D, SPACE_INFO); else return;
233 add_object_draw(OB_LAMP);
234 base_init_from_view3d(BASACT, G.vd);
237 la = BASACT->object->data;
240 allqueue(REDRAWALL, 0);
243 void free_and_unlink_base(Base *base)
248 BLI_remlink(&G.scene->base, base);
249 free_libblock_us(&G.main->object, base->object);
253 void delete_obj(int ok)
260 if(G.scene->id.lib) return;
264 Base *nbase= base->next;
267 if(ok==0 && (ok=okee("Erase selected"))==0) return;
268 if(base->object->type==OB_LAMP) islamp= 1;
270 free_and_unlink_base(base);
277 G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT);
278 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
280 if(islamp && G.vd->drawtype==OB_SHADED) reshadeall_displist();
282 test_scene_constraints();
283 allqueue(REDRAWVIEW3D, 0);
284 redraw_test_buttons(OBACT);
285 allqueue (REDRAWACTION, 0);
286 allqueue(REDRAWIPO, 0);
287 allqueue(REDRAWDATASELECT, 0);
288 allqueue(REDRAWOOPS, 0);
289 allqueue(REDRAWACTION, 0);
290 allqueue(REDRAWNLA, 0);
292 BIF_undo_push("Delete object(s)");
295 int return_editmesh_indexar(int **indexar, float *cent)
297 EditMesh *em = G.editMesh;
299 int *index, nr, totvert=0;
301 for(eve= em->verts.first; eve; eve= eve->next) {
302 if(eve->f & SELECT) totvert++;
304 if(totvert==0) return 0;
306 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
308 cent[0]= cent[1]= cent[2]= 0.0;
310 for(eve= em->verts.first; eve; eve= eve->next) {
311 if(eve->f & SELECT) {
313 VecAddf(cent, cent, eve->co);
318 VecMulf(cent, 1.0/(float)totvert);
323 static void select_editmesh_hook(ObHook *hook)
325 EditMesh *em = G.editMesh;
329 for(eve= em->verts.first; eve; eve= eve->next, nr++) {
330 if(nr==hook->indexar[index]) {
332 if(index < hook->totindex-1) index++;
338 int return_editlattice_indexar(int **indexar, float *cent)
341 int *index, nr, totvert=0, a;
344 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
347 if(bp->f1 & SELECT) {
348 if(bp->hide==0) totvert++;
353 if(totvert==0) return 0;
355 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
357 cent[0]= cent[1]= cent[2]= 0.0;
359 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
362 if(bp->f1 & SELECT) {
365 VecAddf(cent, cent, bp->vec);
372 VecMulf(cent, 1.0/(float)totvert);
377 static void select_editlattice_hook(ObHook *hook)
380 int index=0, nr=0, a;
383 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
386 if(hook->indexar[index]==nr) {
388 if(index < hook->totindex-1) index++;
395 int return_editcurve_indexar(int **indexar, float *cent)
397 extern ListBase editNurb;
401 int *index, a, nr, totvert=0;
403 for(nu= editNurb.first; nu; nu= nu->next) {
404 if((nu->type & 7)==CU_BEZIER) {
408 if(bezt->f1 & SELECT) totvert++;
409 if(bezt->f2 & SELECT) totvert++;
410 if(bezt->f3 & SELECT) totvert++;
416 a= nu->pntsu*nu->pntsv;
418 if(bp->f1 & SELECT) totvert++;
423 if(totvert==0) return 0;
425 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
427 cent[0]= cent[1]= cent[2]= 0.0;
429 for(nu= editNurb.first; nu; nu= nu->next) {
430 if((nu->type & 7)==CU_BEZIER) {
434 if(bezt->f1 & SELECT) {
436 VecAddf(cent, cent, bezt->vec[0]);
439 if(bezt->f2 & SELECT) {
441 VecAddf(cent, cent, bezt->vec[1]);
444 if(bezt->f3 & SELECT) {
446 VecAddf(cent, cent, bezt->vec[2]);
454 a= nu->pntsu*nu->pntsv;
456 if(bp->f1 & SELECT) {
458 VecAddf(cent, cent, bp->vec);
466 VecMulf(cent, 1.0/(float)totvert);
471 static void select_editcurve_hook(ObHook *hook)
473 extern ListBase editNurb;
477 int index=0, a, nr=0;
479 for(nu= editNurb.first; nu; nu= nu->next) {
480 if((nu->type & 7)==CU_BEZIER) {
484 if(nr == hook->indexar[index]) {
486 if(index<hook->totindex-1) index++;
489 if(nr == hook->indexar[index]) {
491 if(index<hook->totindex-1) index++;
494 if(nr == hook->indexar[index]) {
496 if(index<hook->totindex-1) index++;
505 a= nu->pntsu*nu->pntsv;
507 if(nr == hook->indexar[index]) {
509 if(index<hook->totindex-1) index++;
523 int tot=0, *indexar, mode;
525 if(G.obedit==NULL) return;
527 if(G.obedit->hooks.first)
528 mode= pupmenu("Hooks %t|Add Hook, To New Empty %x1|Add Hook, To Selected Object %x2|Remove... %x3|Reassign... %x4|Select... %x5|Clear Offset...%x6");
530 mode= pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
536 if(mode==2) { // selected object
537 Base *base= FIRSTBASE;
539 if TESTBASELIB(base) {
548 error("Requires selected Object");
556 // make pupmenu with hooks
557 for(hook= G.obedit->hooks.first; hook; hook= hook->next) maxlen+=32;
560 error("Object has no hooks yet");
564 cp= MEM_callocN(maxlen+32, "temp string");
565 if(mode==3) strcpy(cp, "Remove %t|");
566 else if(mode==4) strcpy(cp, "Reassign %t|");
567 else if(mode==5) strcpy(cp, "Select %t|");
568 else if(mode==6) strcpy(cp, "Clear Offset %t|");
570 for(hook= G.obedit->hooks.first; hook; hook= hook->next) {
571 strcat(cp, hook->name);
581 for(hook= G.obedit->hooks.first; hook; hook= hook->next, a++) {
587 /* do it, new hooks or reassign */
588 if(mode==1 || mode==2 || mode==4) {
590 switch(G.obedit->type) {
592 tot= return_editmesh_indexar(&indexar, cent);
596 tot= return_editcurve_indexar(&indexar, cent);
599 tot= return_editlattice_indexar(&indexar, cent);
604 error("Requires selected vertices");
611 ob= add_object(OB_EMPTY);
612 /* transform cent to global coords for loc */
613 VecMat4MulVecfl(ob->loc, G.obedit->obmat, cent);
615 /* restore, add_object sets active */
618 /* if mode is 2 or 4, ob has been set */
621 if(mode==1 || mode==2) {
622 hook= MEM_callocN(sizeof(ObHook), "new hook");
623 BLI_addtail(&G.obedit->hooks, hook);
624 strncpy(hook->name, ob->id.name+2, 30);
627 else MEM_freeN(hook->indexar); // reassign, hook was set
630 hook->indexar= indexar;
631 VECCOPY(hook->cent, cent);
634 if(mode==1 || mode==2) {
635 /* matrix calculus */
636 /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
641 Mat4Invert(ob->imat, ob->obmat);
642 /* apparently this call goes from right to left... */
643 Mat4MulSerie(hook->parentinv, ob->imat, G.obedit->obmat, NULL,
644 NULL, NULL, NULL, NULL, NULL);
648 else if(mode==3) { // remove
649 BLI_remlink(&G.obedit->hooks, hook);
650 MEM_freeN(hook->indexar);
653 else if(mode==5) { // select
654 if(G.obedit->type==OB_MESH) select_editmesh_hook(hook);
655 else if(G.obedit->type==OB_LATTICE) select_editlattice_hook(hook);
656 else if(G.obedit->type==OB_CURVE) select_editcurve_hook(hook);
657 else if(G.obedit->type==OB_SURF) select_editcurve_hook(hook);
659 else if(mode==6) { // clear offset
660 where_is_object(ob); // ob is hook->parent
662 Mat4Invert(ob->imat, ob->obmat);
663 /* this call goes from right to left... */
664 Mat4MulSerie(hook->parentinv, ob->imat, G.obedit->obmat, NULL,
665 NULL, NULL, NULL, NULL, NULL);
668 allqueue(REDRAWVIEW3D, 0);
669 allqueue(REDRAWBUTSOBJECT, 0);
670 BIF_undo_push("Add hook");
673 void make_track(void)
678 if(G.scene->id.lib) return;
682 if(BASACT==0) return;
684 mode= pupmenu("Make Track %t|TrackTo Constraint %x1|LockTrack Constraint %x2|Old Track %x3");
690 bTrackToConstraint *data;
694 if TESTBASELIB(base) {
696 con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
697 strcpy (con->name, "AutoTrack");
700 data->tar = BASACT->object;
702 /* Lamp and Camera track differently by default */
703 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
704 data->reserved1 = TRACK_nZ;
705 data->reserved2 = UP_Y;
708 add_constraint_to_object(con, base->object);
714 test_scene_constraints();
715 allqueue(REDRAWVIEW3D, 0);
716 sort_baselist(G.scene);
720 bLockTrackConstraint *data;
724 if TESTBASELIB(base) {
726 con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
727 strcpy (con->name, "AutoTrack");
730 data->tar = BASACT->object;
732 /* Lamp and Camera track differently by default */
733 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
734 data->trackflag = TRACK_nZ;
735 data->lockflag = LOCK_Y;
738 add_constraint_to_object(con, base->object);
744 test_scene_constraints();
745 allqueue(REDRAWVIEW3D, 0);
746 sort_baselist(G.scene);
751 if TESTBASELIB(base) {
754 base->object->track= BASACT->object;
760 test_scene_constraints();
761 allqueue(REDRAWVIEW3D, 0);
762 allqueue(REDRAWOOPS, 0);
763 sort_baselist(G.scene);
765 BIF_undo_push("Make Track");
768 void apply_obmat(Object *ob)
770 float mat[3][3], imat[3][3], tmat[3][3];
772 /* from obmat to loc rot size */
775 Mat3CpyMat4(mat, ob->obmat);
777 VECCOPY(ob->loc, ob->obmat[3]);
779 if(ob->transflag & OB_QUAT) {
780 Mat3ToQuat(mat, ob->quat);
781 QuatToMat3(ob->quat, tmat);
784 Mat3ToEul(mat, ob->rot);
785 EulToMat3(ob->rot, tmat);
789 Mat3MulMat3(tmat, imat, mat);
791 ob->size[0]= tmat[0][0];
792 ob->size[1]= tmat[1][1];
793 ob->size[2]= tmat[2][2];
797 void clear_parent(void)
804 if(G.scene->id.lib) return;
806 mode= pupmenu("OK? %t|Clear Parent %x1|Clear and Keep Transformation (Clear Track) %x2|Clear Parent Inverse %x3");
812 if TESTBASELIB(base) {
814 if(mode==1 || mode==2) {
815 if(base->object->type==OB_IKA) {
816 Ika *ika= base->object->data;
819 par= base->object->parent;
820 base->object->parent= 0;
823 base->object->track= 0;
824 apply_obmat(base->object);
828 Mat4One(base->object->parentinv);
832 makeDispList(base->object); // just always..., checks are not available well (ton)
838 test_scene_constraints();
839 allqueue(REDRAWVIEW3D, 0);
840 allqueue(REDRAWOOPS, 0);
842 BIF_undo_push("Clear Parent");
845 void clear_track(void)
851 if(G.scene->id.lib) return;
853 mode= pupmenu("OK? %t|Clear Track %x1| Clear Track and Keep Transform %x2");
859 if TESTBASELIB(base) {
860 base->object->track= 0;
863 apply_obmat(base->object);
868 test_scene_constraints();
869 allqueue(REDRAWVIEW3D, 0);
870 allqueue(REDRAWOOPS, 0);
872 BIF_undo_push("Clear Track");
875 void clear_object(char mode)
879 float *v1, *v3, mat[3][3];
883 if(G.scene->id.lib) return;
885 if(mode=='r') str= "Clear rotation";
886 else if(mode=='g') str= "Clear location";
887 else if(mode=='s') str= "Clear size";
888 else if(mode=='o') str= "Clear origin";
893 switch (G.obpose->type){
895 clear_armature (G.obpose, mode);
897 clear_pose_constraint_status(G.obpose);
898 make_displists_by_armature (G.obpose);
903 allqueue(REDRAWVIEW3D, 0);
910 if TESTBASELIB(base) {
914 memset(ob->rot, 0, 3*sizeof(float));
915 memset(ob->drot, 0, 3*sizeof(float));
920 memset(ob->loc, 0, 3*sizeof(float));
921 memset(ob->dloc, 0, 3*sizeof(float));
924 memset(ob->dsize, 0, 3*sizeof(float));
932 v3= ob->parentinv[3];
934 Mat3CpyMat4(mat, ob->parentinv);
939 Mat3MulVecfl(mat, v3);
943 if(ob->parent && ob->partype==PARSKEL)
944 freedisplist(&ob->disp);
945 else if(ob->hooks.first)
946 freedisplist(&ob->disp);
951 allqueue(REDRAWVIEW3D, 0);
955 void reset_slowparents(void)
957 /* back to original locations */
962 if(base->object->parent) {
963 if(base->object->partype & PARSLOW) {
964 base->object->partype -= PARSLOW;
965 where_is_object(base->object);
966 base->object->partype |= PARSLOW;
973 void set_slowparent(void)
977 if( okee("Set slow parent")==0 ) return;
981 if TESTBASELIB(base) {
982 if(base->object->parent) base->object->partype |= PARSLOW;
986 BIF_undo_push("Slow parent");
989 void make_vertex_parent(void)
991 EditMesh *em = G.editMesh;
998 int a, v1=0, v2=0, v3=0, nr=1;
1000 /* we need 1 to 3 selected vertices */
1002 if(G.obedit->type==OB_MESH) {
1003 eve= em->verts.first;
1007 else if(v2==0) v2= nr;
1008 else if(v3==0) v3= nr;
1015 else if ELEM(G.obedit->type, OB_SURF, OB_CURVE) {
1018 if((nu->type & 7)==CU_BEZIER) {
1022 if(BEZSELECTED(bezt)) {
1024 else if(v2==0) v2= nr;
1025 else if(v3==0) v3= nr;
1034 a= nu->pntsu*nu->pntsv;
1036 if(bp->f1 & SELECT) {
1038 else if(v2==0) v2= nr;
1039 else if(v3==0) v3= nr;
1051 if( !(v1 && v2==0 && v3==0) && !(v1 && v2 && v3) ) {
1052 error("Select either 1 or 3 vertices to parent to");
1056 if(okee("Make vertex parent")==0) return;
1060 if TESTBASELIB(base) {
1063 par= BASACT->object->parent;
1070 error("Loop in parents");
1073 ob->parent= BASACT->object;
1075 ob->partype= PARVERT3;
1080 /* inverse parent matrix */
1081 what_does_parent(ob);
1082 Mat4Invert(ob->parentinv, workob.obmat);
1086 ob->partype= PARVERT1;
1089 /* inverse parent matrix */
1090 what_does_parent(ob);
1091 Mat4Invert(ob->parentinv, workob.obmat);
1099 allqueue(REDRAWVIEW3D, 0);
1101 // BIF_undo_push(str); not, conflicts with editmode undo...
1104 int test_parent_loop(Object *par, Object *ob)
1106 /* test if 'ob' is a parent somewhere in par's parents */
1108 if(par==0) return 0;
1109 if(ob == par) return 1;
1111 if(par->type==OB_IKA) {
1112 Ika *ika= par->data;
1114 if( ob == ika->parent ) return 1;
1115 if( test_parent_loop(ika->parent, ob) ) return 1;
1118 return test_parent_loop(par->parent, ob);
1122 void make_parent(void)
1126 short qual, mode=0, limbnr=0, effchild=0;
1131 if(G.scene->id.lib) return;
1133 if ELEM3(G.obedit->type, OB_MESH, OB_CURVE, OB_SURF) make_vertex_parent();
1134 else if (G.obedit->type==OB_ARMATURE) make_bone_parent();
1137 if(BASACT==0) return;
1140 par= BASACT->object;
1142 if(par->type == OB_CURVE){
1144 bFollowPathConstraint *data;
1146 mode= pupmenu("Make Parent %t|Normal Parent %x1|Follow Path %x2|Curve Deform %x3");
1160 if TESTBASELIB(base) {
1162 float cmat[4][4], vec[3], size[3];
1164 con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1165 strcpy (con->name, "AutoPath");
1168 data->tar = BASACT->object;
1170 add_constraint_to_object(con, base->object);
1172 get_constraint_target_matrix(con, TARGET_OBJECT, NULL, cmat, size, G.scene->r.cfra - base->object->sf);
1173 VecSubf(vec, base->object->obmat[3], cmat[3]);
1175 base->object->loc[0] = vec[0];
1176 base->object->loc[1] = vec[1];
1177 base->object->loc[2] = vec[2];
1183 test_scene_constraints();
1184 allqueue(REDRAWVIEW3D, 0);
1185 sort_baselist(G.scene);
1186 BIF_undo_push("make Parent");
1190 else if(par->type == OB_ARMATURE){
1194 if TESTBASELIB(base) {
1196 if(base->object->type==OB_MESH) {
1197 mode= pupmenu("Make Parent To%t|Bone %x1|Armature %x2|Object %x3");
1201 mode= pupmenu("Make Parent To %t|Bone %x1|Object %x3");
1212 /* Make bone popup menu */
1214 bonestr = make_bone_menu(get_armature(par));
1215 // if(mbutton(&bone, bonestr, 1, 24, "Bone: ")==0) {
1217 bonenr= pupmenu_col(bonestr, 20);
1219 MEM_freeN (bonestr);
1222 allqueue(REDRAWVIEW3D, 0);
1226 apply_pose_armature(get_armature(par), par->pose, 0);
1227 bone=get_indexed_bone(get_armature(par), bonenr);
1229 // error ("Invalid bone!");
1230 allqueue(REDRAWVIEW3D, 0);
1246 if(qual & LR_SHIFTKEY) {
1247 if(okee("Make parent without inverse")==0) return;
1250 if(qual & LR_ALTKEY) {
1251 if(okee("Make vertex parent")==0) return;
1253 else if(okee("Make parent")==0) return;
1258 if TESTBASELIB(base) {
1259 if(base->object->type==OB_IKA && base->object != par) {
1261 if(okee("Effector as Child")) effchild= 1;
1270 /* now we'll clearparentandkeeptransform all objects */
1273 if TESTBASELIB(base) {
1274 if(base!=BASACT && base->object->parent) {
1275 if(base->object->type==OB_IKA && effchild==1);
1277 base->object->parent= 0;
1278 apply_obmat(base->object);
1290 if TESTBASELIB(base) {
1293 if( test_parent_loop(par, base->object) ) {
1294 error("Loop in parents");
1298 /* the ifs below are horrible code (ton) */
1300 if(par->type==OB_IKA){
1301 base->object->partype= mode;
1302 base->object->par1= limbnr;
1304 else if (par->type==OB_ARMATURE){
1305 base->object->partype= mode;
1307 strcpy (base->object->parsubstr, bone->name);
1309 base->object->parsubstr[0]=0;
1312 if(qual & LR_ALTKEY) {
1313 base->object->partype= PARVERT1;
1315 else if(par->type==OB_CURVE) {
1316 base->object->partype= mode;
1319 base->object->partype= PAROBJECT;
1322 base->object->parent= par;
1324 /* calculate inverse parent matrix? */
1325 if( (qual & LR_SHIFTKEY) ) {
1327 Mat4One(base->object->parentinv);
1328 memset(base->object->loc, 0, 3*sizeof(float));
1331 if(mode==PARSKEL && par->type == OB_ARMATURE) {
1332 /* Prompt the user as to whether he wants to
1333 * add some vertex groups based on the bones
1334 * in the parent armature.
1336 create_vgroups_from_armature(base->object,
1339 base->object->partype= PAROBJECT;
1340 what_does_parent(base->object);
1341 Mat4One (base->object->parentinv);
1342 base->object->partype= mode;
1345 what_does_parent(base->object);
1346 Mat4Invert(base->object->parentinv, workob.obmat);
1349 if(par->type==OB_LATTICE) makeDispList(base->object);
1350 if(par->type==OB_CURVE && mode==PARSKEL) makeDispList(base->object);
1351 if(par->type==OB_ARMATURE && mode == PARSKEL){
1352 verify_defgroups(base->object);
1353 makeDispList(base->object);
1360 allqueue(REDRAWVIEW3D, 0);
1361 allqueue(REDRAWOOPS, 0);
1363 test_scene_constraints();
1364 sort_baselist(G.scene);
1366 BIF_undo_push("make Parent");
1370 void enter_editmode(void)
1380 if(G.scene->id.lib) return;
1383 if((base->lay & G.vd->lay)==0) return;
1386 if(ob->data==0) return;
1390 error("Can't edit library data");
1394 if(ob->type==OB_MESH) {
1398 error("Can't edit library data");
1404 allqueue(REDRAWBUTSLOGIC, 0);
1405 if(G.f & G_FACESELECT) allqueue(REDRAWIMAGE, 0);
1407 if (ob->type==OB_ARMATURE){
1408 arm=base->object->data;
1411 error("Can't edit library data");
1416 make_editArmature();
1417 allqueue (REDRAWVIEW3D,0);
1419 else if(ob->type==OB_IKA) { /* grab type */
1423 if(base->object->type==OB_IKA) {
1424 ika= base->object->data;
1425 if(ika->flag & IK_GRABEFF) ika->flag &= ~IK_GRABEFF;
1426 else ika->flag |= IK_GRABEFF;
1431 allqueue(REDRAWVIEW3D, 0);
1433 else if(ob->type==OB_FONT) {
1438 else if(ob->type==OB_MBALL) {
1443 else if(ob->type==OB_LATTICE) {
1448 else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
1453 allqueue(REDRAWBUTSEDIT, 0);
1454 allqueue(REDRAWOOPS, 0);
1458 setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
1460 allqueue(REDRAWVIEW3D, 1);
1466 scrarea_queue_headredraw(curarea);
1469 void make_displists_by_parent(Object *ob) {
1472 for (base= FIRSTBASE; base; base= base->next)
1473 if (ob==base->object->parent)
1474 makeDispList(base->object);
1477 void exit_editmode(int freedata) /* freedata==0 at render, 1= freedata, 2= do undo buffer too */
1483 if(G.obedit==NULL) return;
1485 if(G.obedit->type==OB_MESH) {
1490 if(G.totvert>MESH_MAX_VERTS) {
1491 error("Too many vertices");
1494 load_editMesh(); /* makes new displist */
1496 if(freedata) free_editMesh(G.editMesh);
1498 if(G.f & G_FACESELECT) {
1500 allqueue(REDRAWIMAGE, 0);
1503 build_particle_system(G.obedit);
1505 else if (G.obedit->type==OB_ARMATURE){
1506 load_editArmature();
1507 if (freedata) free_editArmature();
1509 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1511 if(freedata) freeNurblist(&editNurb);
1513 else if(G.obedit->type==OB_FONT && freedata) {
1516 else if(G.obedit->type==OB_LATTICE) {
1518 if(freedata) free_editLatt();
1520 else if(G.obedit->type==OB_MBALL) {
1522 if(freedata) BLI_freelistN(&editelems);
1527 /* displist make is different in editmode */
1528 if(freedata) G.obedit= NULL;
1530 // need to be here since
1531 // makeDispList(ob); calls
1532 // int mesh_modifier(Object *ob, char mode)..
1533 // calling object_softbody_step(ob, ctime);
1534 // needs a valid *up to date* softbody object or NULL pointer at "soft" member
1535 // anyhow *new* dependacy graph should take care for that :)
1536 if(ob->softflag & 0x01) object_to_softbody(ob,1.0f);
1540 /* has this influence at other objects? */
1541 if(ob->type==OB_CURVE) {
1543 /* test if ob is use as bevelcurve r textoncurve */
1546 if ELEM(base->object->type, OB_CURVE, OB_FONT) {
1547 cu= base->object->data;
1549 if(cu->textoncurve==ob) {
1550 text_to_curve(base->object, 0);
1551 makeDispList(base->object);
1553 if(cu->bevobj==ob || cu->taperobj==ob) {
1554 makeDispList(base->object);
1561 else if(ob->type==OB_LATTICE) {
1562 make_displists_by_parent(ob);
1566 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
1569 allqueue(REDRAWVIEW3D, 1);
1570 allqueue(REDRAWBUTSEDIT, 0);
1571 allqueue(REDRAWBUTSLOGIC, 0);
1572 allqueue(REDRAWOOPS, 0);
1574 scrarea_queue_headredraw(curarea);
1576 // if(ob->softflag & 0x01) object_to_softbody(ob);
1578 if(G.obedit==NULL && freedata==2)
1579 BIF_undo_push("Editmode");
1582 void check_editmode(int type)
1585 if (G.obedit==0 || G.obedit->type==type) return;
1587 exit_editmode(2); // freedata, and undo
1590 /* 0 == do centre, 1 == centre new, 2 == centre cursor */
1592 void docentre(int centremode)
1594 EditMesh *em = G.editMesh;
1603 float cent[3], centn[3], min[3], max[3], omat[3][3];
1607 if(G.scene->id.lib) return;
1611 INIT_MINMAX(min, max);
1613 if(G.obedit->type==OB_MESH) {
1614 eve= em->verts.first;
1616 DO_MINMAX(eve->co, min, max);
1619 cent[0]= (min[0]+max[0])/2.0f;
1620 cent[1]= (min[1]+max[1])/2.0f;
1621 cent[2]= (min[2]+max[2])/2.0f;
1623 eve= em->verts.first;
1625 VecSubf(eve->co, eve->co, cent);
1634 if TESTBASELIB(base) {
1635 base->object->flag &= ~OB_DONE;
1639 me= G.main->mesh.first;
1641 me->flag &= ~ME_ISDONE;
1648 if TESTBASELIB(base) {
1649 if((base->object->flag & OB_DONE)==0) {
1651 base->object->flag |= OB_DONE;
1653 if(G.obedit==0 && (me=get_mesh(base->object)) ) {
1656 error("Can't change the center of a mesh with vertex keys");
1661 VECCOPY(cent, give_cursor());
1662 Mat4Invert(base->object->imat, base->object->obmat);
1663 Mat4MulVecfl(base->object->imat, cent);
1665 INIT_MINMAX(min, max);
1668 for(a=0; a<me->totvert; a++, mvert++) {
1669 DO_MINMAX(mvert->co, min, max);
1672 cent[0]= (min[0]+max[0])/2.0f;
1673 cent[1]= (min[1]+max[1])/2.0f;
1674 cent[2]= (min[2]+max[2])/2.0f;
1678 for(a=0; a<me->totvert; a++, mvert++) {
1679 VecSubf(mvert->co, mvert->co, cent);
1681 me->flag |= ME_ISDONE;
1684 Mat3CpyMat4(omat, base->object->obmat);
1686 VECCOPY(centn, cent);
1687 Mat3MulVecfl(omat, centn);
1688 base->object->loc[0]+= centn[0];
1689 base->object->loc[1]+= centn[1];
1690 base->object->loc[2]+= centn[2];
1693 ob= G.main->object.first;
1695 if((ob->flag & OB_DONE)==0) {
1700 ob->flag |= OB_DONE;
1702 Mat3CpyMat4(omat, ob->obmat);
1703 VECCOPY(centn, cent);
1704 Mat3MulVecfl(omat, centn);
1705 ob->loc[0]+= centn[0];
1706 ob->loc[1]+= centn[1];
1707 ob->loc[2]+= centn[2];
1709 if(tme && (tme->flag & ME_ISDONE)==0) {
1711 for(a=0; a<tme->totvert; a++, mvert++) {
1712 VecSubf(mvert->co, mvert->co, cent);
1714 tme->flag |= ME_ISDONE;
1723 /* displist of all users, also this one */
1724 makeDispList(base->object);
1726 /* DO: check all users... */
1730 else if ELEM(base->object->type, OB_CURVE, OB_SURF) {
1733 nu1= editNurb.first;
1736 cu= base->object->data;
1737 nu1= cu->nurb.first;
1741 VECCOPY(cent, give_cursor());
1742 Mat4Invert(base->object->imat, base->object->obmat);
1743 Mat4MulVecfl(base->object->imat, cent);
1745 /* Curves need to be 2d, never offset in
1746 * Z. Is a somewhat arbitrary restriction,
1747 * would probably be nice to remove.
1751 INIT_MINMAX(min, max);
1755 minmaxNurb(nu, min, max);
1759 cent[0]= (min[0]+max[0])/2.0f;
1760 cent[1]= (min[1]+max[1])/2.0f;
1761 cent[2]= (min[2]+max[2])/2.0f;
1766 if( (nu->type & 7)==1) {
1769 VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
1770 VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
1771 VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
1775 a= nu->pntsu*nu->pntsv;
1777 VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
1782 if(centremode && G.obedit==0) {
1783 Mat3CpyMat4(omat, base->object->obmat);
1785 Mat3MulVecfl(omat, cent);
1786 base->object->loc[0]+= cent[0];
1787 base->object->loc[1]+= cent[1];
1788 base->object->loc[2]+= cent[2];
1792 makeDispList(G.obedit);
1795 else makeDispList(base->object);
1798 else if(base->object->type==OB_FONT) {
1801 cu= base->object->data;
1802 if(cu->bb==0) return;
1804 cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
1805 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 */
1807 /* not really ok, do this better once! */
1808 cu->xof /= cu->fsize;
1809 cu->yof /= cu->fsize;
1811 text_to_curve(base->object, 0);
1812 makeDispList(base->object);
1814 allqueue(REDRAWBUTSEDIT, 0);
1821 allqueue(REDRAWVIEW3D, 0);
1822 BIF_undo_push("Do Centre");
1825 void docentre_new(void)
1827 if(G.scene->id.lib) return;
1830 error("Unable to center new in Edit Mode");
1837 void docentre_cursor(void)
1839 if(G.scene->id.lib) return;
1842 error("Unable to center cursor in Edit Mode");
1849 void movetolayer(void)
1852 unsigned int lay= 0, local;
1855 if(G.scene->id.lib) return;
1859 if TESTBASE(base) lay |= base->lay;
1865 if( movetolayer_buts(&lay)==0 ) return;
1871 /* upper byte is used for local view */
1872 local= base->lay & 0xFF000000;
1873 base->lay= lay + local;
1874 base->object->lay= lay;
1875 if(base->object->type==OB_LAMP) islamp= 1;
1880 if(islamp && G.vd->drawtype == OB_SHADED) reshadeall_displist();
1883 allqueue(REDRAWBUTSEDIT, 0);
1884 allqueue(REDRAWVIEW3D, 0);
1885 allqueue(REDRAWOOPS, 0);
1886 allqueue(REDRAWINFO, 0);
1888 BIF_undo_push("Move to layer");
1892 void special_editmenu(void)
1894 extern short editbutflag;
1895 extern float doublimit;
1901 if(G.f & G_FACESELECT) {
1902 Mesh *me= get_mesh(OBACT);
1906 if(me==0 || me->tface==0) return;
1908 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");
1910 for(a=me->totface, tface= me->tface; a>0; a--, tface++) {
1911 if(tface->flag & SELECT) {
1914 tface->mode |= TF_TEX; break;
1916 tface->mode |= TF_SHAREDCOL; break;
1918 tface->mode |= TF_LIGHT; break;
1920 tface->mode |= TF_INVISIBLE; break;
1922 tface->mode |= TF_DYNAMIC; break;
1924 tface->mode &= ~TF_TEX;
1928 tface->mode &= ~TF_SHAREDCOL; break;
1930 tface->mode &= ~TF_LIGHT; break;
1932 tface->mode &= ~TF_INVISIBLE; break;
1934 tface->mode &= ~TF_DYNAMIC; break;
1938 allqueue(REDRAWVIEW3D, 0);
1939 allqueue(REDRAWBUTSEDIT, 0);
1940 BIF_undo_push("Change texture face");
1942 else if(G.f & G_VERTEXPAINT) {
1943 Mesh *me= get_mesh(OBACT);
1945 if(me==0 || (me->mcol==NULL && me->tface==NULL) ) return;
1947 nr= pupmenu("Specials%t|Shared VertexCol%x1");
1950 if(me->tface) tface_to_mcol(me);
1952 copy_vpaint_undo( (unsigned int *)me->mcol, me->totface);
1953 do_shared_vertexcol(me);
1955 if(me->tface) mcol_to_tface(me, 1);
1956 BIF_undo_push("Shared VertexCol");
1960 Base *base, *base_select= NULL;
1962 // Get the active object mesh.
1963 Mesh *me= get_mesh(OBACT);
1965 // If the active object is a mesh...
1967 // Bring up a little menu with the boolean operation choices on.
1968 nr= pupmenu("Boolean %t|Intersect%x1|Union%x2|Difference%x3");
1971 // user has made a choice of a menu element.
1972 // All of the boolean functions require 2 mesh objects
1973 // we search through the object list to find the other
1974 // selected item and make sure it is distinct and a mesh.
1978 if(base->flag & SELECT) {
1979 if(base->object != OBACT) base_select= base;
1986 if (get_mesh(base_select->object)) {
1988 ret = NewBooleanMesh(BASACT,base_select,nr);
1990 error("An internal error occurred -- sorry!");
1991 } else if(ret==-1) {
1992 error("Selected meshes must have faces to perform boolean operations");
1994 else BIF_undo_push("Boolean");
1998 error("Please select 2 meshes");
2001 error("Please select 2 meshes");
2005 allqueue(REDRAWVIEW3D, 0);
2009 else if(G.obedit->type==OB_MESH) {
2011 nr= pupmenu("Specials%t|Subdivide%x1|Subdivide Fractal%x2|Subdivide Smooth%x3|Merge%x4|Remove Doubles%x5|Hide%x6|Reveal%x7|Select Swap%x8|Flip Normals %x9|Smooth %x10|Bevel %x11");
2012 if(nr>0) waitcursor(1);
2016 subdivideflag(1, 0.0, editbutflag);
2017 BIF_undo_push("Subdivide");
2021 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
2022 fac= -( (float)randfac )/100;
2023 subdivideflag(1, fac, editbutflag);
2024 BIF_undo_push("Subdivide Fractal");
2027 subdivideflag(1, 0.0, editbutflag | B_SMOOTH);
2028 BIF_undo_push("Subdivide Smooth");
2034 notice("Removed %d Vertices", removedoublesflag(1, doublimit));
2035 BIF_undo_push("Remove Doubles");
2048 BIF_undo_push("Flip Normals");
2058 makeDispList(G.obedit);
2060 if(nr>0) waitcursor(0);
2063 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
2065 nr= pupmenu("Specials%t|Subdivide%x1|Switch Direction%x2");
2072 switchdirectionNurb2();
2078 allqueue(REDRAWVIEW3D, 0);
2082 void convertmenu(void)
2084 Base *base, *basen, *basact;
2090 int ok=0, nr = 0, a;
2092 if(G.scene->id.lib) return;
2096 if(G.obedit) return;
2098 basact= BASACT; /* will be restored */
2100 if(ob->type==OB_FONT) {
2101 nr= pupmenu("Convert Font to%t|Curve");
2104 else if(ob->type==OB_MBALL) {
2105 nr= pupmenu("Convert Metaball to%t|Mesh (keep original)");
2108 else if(ob->type==OB_CURVE) {
2109 nr= pupmenu("Convert Curve to%t|Mesh");
2112 else if(ob->type==OB_SURF) {
2113 nr= pupmenu("Convert Nurbs Surface to%t|Mesh");
2116 else if(ob->type==OB_MESH && mesh_uses_displist((Mesh*) ob->data)) {
2117 nr= pupmenu("Convert SubSurf to%t|Mesh (Keep Original)");
2122 /* don't forget multiple users! */
2127 if TESTBASELIB(base) {
2128 base->object->flag &= ~OB_DONE;
2135 if TESTBASELIB(base) {
2139 if(ob->flag & OB_DONE);
2140 else if(ob->type==OB_MESH) {
2141 Mesh *oldme= ob->data;
2143 if (mesh_uses_displist(oldme)) {
2146 ob->flag |= OB_DONE;
2148 ob1= copy_object(ob);
2150 basen= MEM_mallocN(sizeof(Base), "duplibase");
2152 BLI_addhead(&G.scene->base, basen); /* addhead: otherwise eternal loop */
2154 basen->flag &= ~SELECT;
2159 ob1->data= add_mesh();
2164 me->totcol= oldme->totcol;
2166 me->mat= MEM_dupallocN(oldme->mat);
2167 for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
2170 dlm= subsurf_make_dispListMesh_from_mesh(oldme, NULL, oldme->subdiv, oldme->flag);
2171 displistmesh_to_mesh(dlm, ob1->data);
2172 displistmesh_free(dlm);
2174 /* texspace and normals */
2177 exit_editmode(1); // freedata, but no undo
2181 else if(ob->type==OB_FONT) {
2184 ob->flag |= OB_DONE;
2195 ob1= G.main->object.first;
2197 if(ob1->data==cu) ob1->type= OB_CURVE;
2203 else if ELEM(ob->type, OB_CURVE, OB_SURF) {
2206 ob->flag |= OB_DONE;
2210 if(dl==0) makeDispList(ob);
2212 nurbs_to_mesh(ob); /* also does users */
2214 /* texspace and normals */
2217 exit_editmode(1); // freedata, but no undo
2221 else if(ob->type==OB_MBALL) {
2224 ob= find_basis_mball(ob);
2226 if(ob->disp.first && !(ob->flag&OB_DONE)) {
2228 ob->flag |= OB_DONE;
2230 ob1= copy_object(ob);
2232 basen= MEM_mallocN(sizeof(Base), "duplibase");
2234 BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2236 basen->flag &= ~SELECT;
2241 ob1->data= add_mesh();
2246 me->totcol= mb->totcol;
2248 me->mat= MEM_dupallocN(mb->mat);
2249 for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
2252 mball_to_mesh(&ob->disp, ob1->data);
2261 allqueue(REDRAWVIEW3D, 0);
2262 allqueue(REDRAWOOPS, 0);
2263 allqueue(REDRAWBUTSEDIT, 0);
2264 BIF_undo_push("Convert Object");
2267 /* Change subdivision properties of mesh object ob, if
2268 * level==-1 then toggle subsurf, else set to level.
2270 void flip_subdivison(Object *ob, int level)
2272 Mesh *me = ob->data;
2275 me->flag ^= ME_SUBSURF;
2280 allqueue(REDRAWVIEW3D, 0);
2281 allqueue(REDRAWOOPS, 0);
2282 allqueue(REDRAWBUTSEDIT, 0);
2285 BIF_undo_push("Switch subsurf on/off");
2288 void copymenu_properties(Object *ob)
2290 bProperty *prop, *propn, *propc;
2295 prop= ob->prop.first;
2302 error("No properties in the active object to copy");
2306 str= MEM_callocN(24+32*tot, "copymenu prop");
2308 strcpy(str, "Copy Property %t");
2311 prop= ob->prop.first;
2315 strcat(str, prop->name);
2322 prop= ob->prop.first;
2333 if(base != BASACT) {
2334 if(TESTBASELIB(base)) {
2335 prop= get_property(base->object, propc->name);
2337 free_property(prop);
2338 BLI_remlink(&base->object->prop, prop);
2340 propn= copy_property(propc);
2341 BLI_addtail(&base->object->prop, propn);
2349 allqueue(REDRAWVIEW3D, 0);
2351 BIF_undo_push("Copy properties");
2354 void copymenu_logicbricks(Object *ob)
2360 if(base->object != ob) {
2361 if(TESTBASELIB(base)) {
2363 /* first: free all logic */
2364 free_sensors(&base->object->sensors);
2365 unlink_controllers(&base->object->controllers);
2366 free_controllers(&base->object->controllers);
2367 unlink_actuators(&base->object->actuators);
2368 free_actuators(&base->object->actuators);
2370 /* now copy it, this also works without logicbricks! */
2371 clear_sca_new_poins_ob(ob);
2372 copy_sensors(&base->object->sensors, &ob->sensors);
2373 copy_controllers(&base->object->controllers, &ob->controllers);
2374 copy_actuators(&base->object->actuators, &ob->actuators);
2375 set_sca_new_poins_ob(base->object);
2377 /* some menu settings */
2378 base->object->scavisflag= ob->scavisflag;
2379 base->object->scaflag= ob->scaflag;
2385 BIF_undo_push("Copy logic");
2388 void copy_attr_menu()
2394 /* If you change this menu, don't forget to update the menu in header_view3d.c
2395 * view3d_edit_object_copyattrmenu() and in toolbox.c
2397 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");
2399 if(!(ob=OBACT)) return;
2401 strcat (str, "|Object Constraints%x22");
2403 if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
2404 strcat(str, "|Texture Space%x17");
2407 if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
2408 if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19");
2410 if(ob->type==OB_MESH){
2411 strcat(str, "|Subdiv%x21");
2414 if( give_parteff(ob) ) strcat(str, "|Particle Settings%x20");
2416 event= pupmenu(str);
2417 if(event<= 0) return;
2422 void copy_attr(short event)
2427 void *poin1, *poin2=0;
2429 if(G.scene->id.lib) return;
2431 if(!(ob=OBACT)) return;
2434 /* obedit_copymenu(); */
2438 if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
2439 if(ob->type==OB_MESH) poin2= &(((Mesh *)ob->data)->texflag);
2440 else if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) poin2= &(((Curve *)ob->data)->texflag);
2441 else if(ob->type==OB_MBALL) poin2= &(((MetaBall *)ob->data)->texflag);
2445 copymenu_properties(ob);
2448 else if(event==10) {
2449 copymenu_logicbricks(ob);
2455 if(base != BASACT) {
2456 if(TESTBASELIB(base)) {
2458 if(event==1) { /* loc */
2459 VECCOPY(base->object->loc, ob->loc);
2460 VECCOPY(base->object->dloc, ob->dloc);
2462 else if(event==2) { /* rot */
2463 VECCOPY(base->object->rot, ob->rot);
2464 VECCOPY(base->object->drot, ob->drot);
2465 VECCOPY(base->object->quat, ob->quat);
2466 VECCOPY(base->object->dquat, ob->dquat);
2468 else if(event==3) { /* size */
2469 VECCOPY(base->object->size, ob->size);
2470 VECCOPY(base->object->dsize, ob->dsize);
2472 else if(event==4) { /* drawtype */
2473 base->object->dt= ob->dt;
2474 base->object->dtx= ob->dtx;
2476 else if(event==5) { /* time offs */
2477 base->object->sf= ob->sf;
2479 else if(event==6) { /* dupli */
2480 base->object->dupon= ob->dupon;
2481 base->object->dupoff= ob->dupoff;
2482 base->object->dupsta= ob->dupsta;
2483 base->object->dupend= ob->dupend;
2485 base->object->transflag &= ~OB_DUPLI;
2486 base->object->transflag |= (ob->transflag & OB_DUPLI);
2488 else if(event==7) { /* mass */
2489 base->object->mass= ob->mass;
2491 else if(event==8) { /* damping */
2492 base->object->damping= ob->damping;
2493 base->object->rdamping= ob->rdamping;
2495 else if(event==17) { /* tex space */
2498 if(obt->type==OB_MESH) poin1= &(((Mesh *)obt->data)->texflag);
2499 else if ELEM3(obt->type, OB_CURVE, OB_SURF, OB_FONT) poin1= &(((Curve *)obt->data)->texflag);
2500 else if(obt->type==OB_MBALL) poin1= &(((MetaBall *)obt->data)->texflag);
2503 memcpy(poin1, poin2, 4+12+12+12);
2505 if(obt->type==OB_MESH) tex_space_mesh(obt->data);
2506 else if(obt->type==OB_MBALL) tex_space_mball(obt);
2507 else tex_space_curve(obt->data);
2510 else if(event==18) { /* font settings */
2512 if(base->object->type==ob->type) {
2514 cu1= base->object->data;
2516 cu1->spacemode= cu->spacemode;
2517 cu1->spacing= cu->spacing;
2518 cu1->linedist= cu->linedist;
2519 cu1->shear= cu->shear;
2520 cu1->fsize= cu->fsize;
2523 cu1->textoncurve= cu->textoncurve;
2524 if(cu1->vfont) cu1->vfont->id.us--;
2525 cu1->vfont= cu->vfont;
2526 id_us_plus((ID *)cu1->vfont);
2527 text_to_curve(base->object, 0);
2529 strcpy(cu1->family, cu->family);
2531 makeDispList(base->object);
2534 else if(event==19) { /* bevel settings */
2536 if ELEM(base->object->type, OB_CURVE, OB_FONT) {
2538 cu1= base->object->data;
2540 cu1->bevobj= cu->bevobj;
2541 cu1->taperobj= cu->taperobj;
2542 cu1->width= cu->width;
2543 cu1->bevresol= cu->bevresol;
2544 cu1->ext1= cu->ext1;
2545 cu1->ext2= cu->ext2;
2547 makeDispList(base->object);
2550 else if(event==20) { /* particle settings */
2554 pa1= give_parteff(ob);
2555 pa2= give_parteff(base->object);
2558 BLI_remlink( &(base->object->effect), pa2);
2559 free_effect( (Effect *) pa2);
2561 else if(pa1 && pa2==0) {
2562 free_effects(&(base->object->effect));
2563 copy_effects(&(base->object->effect), &ob->effect);
2564 build_particle_system(base->object);
2566 else if(pa1 && pa2) {
2567 if(pa2->keys) MEM_freeN(pa2->keys);
2569 p1= (char *)pa1; p2= (char *)pa2;
2570 memcpy( p2+8, p1+8, sizeof(PartEff) - 8);
2573 build_particle_system(base->object);
2577 if (base->object->type==OB_MESH) {
2578 Mesh *targetme= base->object->data;
2579 Mesh *sourceme= ob->data;
2581 targetme->flag= (targetme->flag&~ME_SUBSURF) | (sourceme->flag&ME_SUBSURF);
2582 targetme->subsurftype = sourceme->subsurftype;
2583 targetme->subdiv= sourceme->subdiv;
2584 targetme->subdivr= sourceme->subdivr;
2585 makeDispList(base->object);
2589 /* Clear the constraints on the target */
2590 free_constraints(&base->object->constraints);
2591 free_constraint_channels(&base->object->constraintChannels);
2593 /* Copy the constraint channels over */
2594 copy_constraints(&base->object->constraints, &ob->constraints);
2595 if (U.dupflag& USER_DUP_IPO)
2596 copy_constraint_channels(&base->object->constraintChannels, &ob->constraintChannels);
2598 clone_constraint_channels (&base->object->constraintChannels, &ob->constraintChannels, NULL);
2600 base->object->activecon = NULL;
2607 allqueue(REDRAWVIEW3D, 0);
2609 allqueue(REDRAWBUTSOBJECT, 0);
2612 BIF_undo_push("Copy attributes");
2615 void link_to_scene(unsigned short nr)
2617 Scene *sce= (Scene*) BLI_findlink(&G.main->scene, G.curscreen->scenenr-1);
2621 if(sce->id.lib) return;
2625 if(TESTBASE(base)) {
2627 nbase= MEM_mallocN( sizeof(Base), "newbase");
2629 BLI_addhead( &(sce->base), nbase);
2630 id_us_plus((ID *)base->object);
2636 void make_links_menu()
2642 if(!(ob=OBACT)) return;
2644 strcpy(str, "Make Links %t|To Scene...%x1|%l|Object Ipo%x4");
2646 if(ob->type==OB_MESH)
2647 strcat(str, "|Mesh Data%x2|Materials%x3");
2648 else if(ob->type==OB_CURVE)
2649 strcat(str, "|Curve Data%x2|Materials%x3");
2650 else if(ob->type==OB_FONT)
2651 strcat(str, "|Text Data%x2|Materials%x3");
2652 else if(ob->type==OB_SURF)
2653 strcat(str, "|Surface Data%x2|Materials%x3");
2654 else if(ob->type==OB_MBALL)
2655 strcat(str, "|Materials%x3");
2656 else if(ob->type==OB_CAMERA)
2657 strcat(str, "|Camera Data%x2");
2658 else if(ob->type==OB_LAMP)
2659 strcat(str, "|Lamp Data%x2");
2660 else if(ob->type==OB_LATTICE)
2661 strcat(str, "|Lattice Data%x2");
2662 else if(ob->type==OB_ARMATURE)
2663 strcat(str, "|Armature Data%x2");
2665 event= pupmenu(str);
2667 if(event<= 0) return;
2672 void make_links(short event)
2675 Base *base, *nbase, *sbase;
2678 Material ***matarar, ***obmatarar, **matar1, **matar2;
2683 if(!(ob=OBACT)) return;
2686 IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), 0, &nr);
2688 if(strncmp(strp, "DataBrow", 8)==0) {
2691 activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE, &(G.curscreen->scenenr), link_to_scene );
2696 event= pupmenu(strp);
2699 if(event<= 0) return;
2702 sce= G.main->scene.first;
2704 if(nr==event) break;
2709 error("This is the current scene");
2712 if(sce==0 || sce->id.lib) return;
2714 /* remember: is needed below */
2721 if(event==1 || base != BASACT) {
2725 if(TESTBASE(base)) {
2727 if(event==1) { /* to scene */
2729 /* test if already linked */
2730 sbase= sce->base.first;
2732 if(sbase->object==base->object) break;
2735 if(sbase) { /* remove */
2740 nbase= MEM_mallocN( sizeof(Base), "newbase");
2742 BLI_addhead( &(sce->base), nbase);
2743 id_us_plus((ID *)base->object);
2746 if(TESTBASELIB(base)) {
2747 if(event==2 || event==5) { /* obdata */
2748 if(ob->type==obt->type) {
2757 /* if amount of material indices changed: */
2758 test_object_materials(obt->data);
2761 else if(event==4) { /* ob ipo */
2762 if(obt->ipo) obt->ipo->id.us--;
2765 id_us_plus((ID *)obt->ipo);
2769 else if(event==3) { /* materials */
2771 /* only if obt has no material: make arrays */
2772 /* from ob to obt! */
2774 obmatarar= give_matarar(ob);
2775 matarar= give_matarar(obt);
2776 totcolp= give_totcolp(obt);
2778 /* if one of the two is zero: no render-able object */
2779 if( matarar && obmatarar) {
2781 /* take care of users! so first a copy of original: */
2784 matar1= MEM_dupallocN(ob->mat);
2785 matar2= MEM_dupallocN(*obmatarar);
2791 /* remove links from obt */
2792 for(a=0; a<obt->totcol; a++) {
2793 if(obt->mat[a]) obt->mat[a]->id.us--;
2794 if( (*matarar)[a]) (*matarar)[a]->id.us--;
2798 if(obt->mat) MEM_freeN(obt->mat);
2799 if(*matarar) MEM_freeN(*matarar);
2801 /* connect a copy */
2804 obt->totcol= ob->totcol;
2805 *totcolp= ob->totcol;
2807 /* increase users */
2808 for(a=0; a<obt->totcol; a++) {
2809 if(obt->mat[a]) id_us_plus((ID *)obt->mat[a]);
2810 if( (*matarar)[a]) id_us_plus((ID *)(*matarar)[a]);
2813 obt->colbits= ob->colbits;
2815 /* if amount of material indices changed: */
2816 test_object_materials(obt->data);
2824 allqueue(REDRAWVIEW3D, 0);
2825 allqueue(REDRAWOOPS, 0);
2826 allqueue(REDRAWBUTSHEAD, 0);
2828 BIF_undo_push("Create links");
2831 void make_duplilist_real()
2835 extern ListBase duplilist;
2837 if(okee("Make dupli objects real")==0) return;
2841 if TESTBASELIB(base) {
2843 if(base->object->transflag & OB_DUPLI) {
2845 make_duplilist(G.scene, base->object);
2846 ob= duplilist.first;
2849 /* font duplis can have a totcol without material, we get them from parent
2850 * should be implemented better...
2852 if(ob->mat==0) ob->totcol= 0;
2854 basen= MEM_dupallocN(base);
2855 basen->flag &= ~OB_FROMDUPLI;
2856 BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2857 ob->ipo= 0; /* make sure apply works */
2858 ob->parent= ob->track= 0;
2859 ob->disp.first= ob->disp.last= 0;
2860 ob->transflag &= ~OB_DUPLI;
2861 basen->object= copy_object(ob);
2863 apply_obmat(basen->object);
2869 base->object->transflag &= ~OB_DUPLI;
2875 allqueue(REDRAWVIEW3D, 0);
2876 allqueue(REDRAWOOPS, 0);
2878 BIF_undo_push("Make duplicates real");
2883 Base *base, *basact;
2894 if(G.scene->id.lib) return;
2895 if(G.obedit) return;
2898 if(G.qual & LR_SHIFTKEY) {