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_camera_types.h"
61 #include "DNA_curve_types.h"
62 #include "DNA_effect_types.h"
63 #include "DNA_ika_types.h"
64 #include "DNA_image_types.h"
65 #include "DNA_ipo_types.h"
66 #include "DNA_key_types.h"
67 #include "DNA_lamp_types.h"
68 #include "DNA_lattice_types.h"
69 #include "DNA_mesh_types.h"
70 #include "DNA_meshdata_types.h"
71 #include "DNA_meta_types.h"
72 #include "DNA_object_types.h"
73 #include "DNA_scene_types.h"
74 #include "DNA_screen_types.h"
75 #include "DNA_texture_types.h"
76 #include "DNA_view3d_types.h"
77 #include "DNA_world_types.h"
78 #include "DNA_userdef_types.h"
79 #include "DNA_property_types.h"
80 #include "DNA_vfont_types.h"
81 #include "DNA_constraint_types.h"
83 #include "BLI_blenlib.h"
84 #include "BLI_arithb.h"
85 #include "BLI_editVert.h"
86 #include "BLI_ghash.h"
89 #include "BKE_blender.h"
90 #include "BKE_booleanops.h"
91 #include "BKE_curve.h"
92 #include "BKE_displist.h"
93 #include "BKE_effect.h"
95 #include "BKE_global.h"
99 #include "BKE_lattice.h"
100 #include "BKE_library.h"
101 #include "BKE_main.h"
102 #include "BKE_material.h"
103 #include "BKE_mball.h"
104 #include "BKE_mesh.h"
106 #include "BKE_object.h"
107 #include "BKE_property.h"
109 #include "BKE_scene.h"
110 #include "BKE_subsurf.h"
111 #include "BKE_texture.h"
112 #include "BKE_utildefines.h"
115 #include "BIF_graphics.h"
116 #include "BIF_interface.h"
117 #include "BIF_mywindow.h"
118 #include "BIF_toolbox.h"
119 #include "BIF_screen.h"
120 #include "BIF_space.h"
121 #include "BIF_toets.h"
122 #include "BIF_butspace.h"
123 #include "BIF_editdeform.h"
124 #include "BIF_editfont.h"
125 #include "BIF_editika.h"
126 #include "BIF_editlattice.h"
127 #include "BIF_editmesh.h"
128 #include "BIF_editoops.h"
129 #include "BIF_editview.h"
130 #include "BIF_editarmature.h"
131 #include "BIF_resources.h"
133 #include "BSE_edit.h"
134 #include "BSE_editaction.h"
135 #include "BSE_editipo.h"
136 #include "BSE_filesel.h" /* For activate_databrowse() */
137 #include "BSE_view.h"
138 #include "BSE_trans_types.h"
139 #include "BSE_editipo_types.h"
141 #include "BDR_vpaint.h"
142 #include "BDR_editmball.h"
143 #include "BDR_editobject.h"
144 #include "BDR_drawobject.h"
145 #include "BDR_editcurve.h"
146 #include "BDR_unwrapper.h"
150 #include "mydevice.h"
155 #include "BKE_constraint.h"
156 #include "BIF_editconstraint.h"
158 #include "BKE_action.h"
159 #include "DNA_action_types.h"
160 #include "BKE_armature.h"
161 #include "DNA_armature_types.h"
162 #include "BIF_poseobject.h"
164 /* extern Lattice *copy_lattice(Lattice *lt); */
165 extern ListBase editNurb;
166 extern ListBase editelems;
168 TransOb *transmain= 0;
169 TransVert *transvmain= 0;
170 int tottrans=0, transmode=0; /* 1: texspace */
172 float prop_size= 1.0;
176 /* used in editipo, editcurve and here */
177 #define BEZSELECTED(bezt) (((bezt)->f1 & 1) || ((bezt)->f2 & 1) || ((bezt)->f3 & 1))
181 #define KEYFLAG_ROT 0x00000001
182 #define KEYFLAG_LOC 0x00000002
183 #define KEYFLAG_SIZE 0x00000004
185 float centre[3], centroid[3];
187 void mirrormenu(void);
189 void add_object_draw(int type) /* for toolbox */
193 G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT);
194 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
196 if ELEM3(curarea->spacetype, SPACE_VIEW3D, SPACE_BUTS, SPACE_INFO) {
197 if (G.obedit) exit_editmode(2); // freedata, and undo
198 ob= add_object(type);
199 base_init_from_view3d(BASACT, G.vd);
201 allqueue(REDRAWVIEW3D, 0);
204 redraw_test_buttons(BASACT);
206 allqueue(REDRAWALL, 0);
208 deselect_all_area_oops();
209 set_select_flag_oops();
210 allqueue(REDRAWINFO, 1); /* 1, because header->win==0! */
214 void free_and_unlink_base(Base *base)
219 BLI_remlink(&G.scene->base, base);
220 free_libblock_us(&G.main->object, base->object);
224 void delete_obj(int ok)
230 if(G.scene->id.lib) return;
234 Base *nbase= base->next;
237 if(ok==0 && (ok=okee("Erase selected"))==0) return;
239 free_and_unlink_base(base);
246 G.f &= ~(G_VERTEXPAINT+G_FACESELECT+G_TEXTUREPAINT+G_WEIGHTPAINT);
247 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
249 test_scene_constraints();
250 allqueue(REDRAWVIEW3D, 0);
251 redraw_test_buttons(BASACT);
252 allqueue (REDRAWACTION, 0);
253 allqueue(REDRAWIPO, 0);
254 allqueue(REDRAWDATASELECT, 0);
255 allqueue(REDRAWOOPS, 0);
256 allqueue(REDRAWACTION, 0);
257 allqueue(REDRAWNLA, 0);
259 BIF_undo_push("Delete object(s)");
262 int return_editmesh_indexar(int **indexar, float *cent)
264 EditMesh *em = G.editMesh;
266 int *index, nr, totvert=0;
268 for(eve= em->verts.first; eve; eve= eve->next) {
269 if(eve->f & SELECT) totvert++;
271 if(totvert==0) return 0;
273 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
275 cent[0]= cent[1]= cent[2]= 0.0;
277 for(eve= em->verts.first; eve; eve= eve->next) {
278 if(eve->f & SELECT) {
280 VecAddf(cent, cent, eve->co);
285 VecMulf(cent, 1.0/(float)totvert);
290 static void select_editmesh_hook(ObHook *hook)
292 EditMesh *em = G.editMesh;
296 for(eve= em->verts.first; eve; eve= eve->next, nr++) {
297 if(nr==hook->indexar[index]) {
299 if(index < hook->totindex-1) index++;
304 int return_editlattice_indexar(int **indexar, float *cent)
307 int *index, nr, totvert=0, a;
310 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
313 if(bp->f1 & SELECT) {
314 if(bp->hide==0) totvert++;
319 if(totvert==0) return 0;
321 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
323 cent[0]= cent[1]= cent[2]= 0.0;
325 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
328 if(bp->f1 & SELECT) {
331 VecAddf(cent, cent, bp->vec);
338 VecMulf(cent, 1.0/(float)totvert);
343 static void select_editlattice_hook(ObHook *hook)
346 int index=0, nr=0, a;
349 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
352 if(hook->indexar[index]==nr) {
354 if(index < hook->totindex-1) index++;
361 int return_editcurve_indexar(int **indexar, float *cent)
363 extern ListBase editNurb;
367 int *index, a, nr, totvert=0;
369 for(nu= editNurb.first; nu; nu= nu->next) {
370 if((nu->type & 7)==CU_BEZIER) {
374 if(bezt->f1 & SELECT) totvert++;
375 if(bezt->f2 & SELECT) totvert++;
376 if(bezt->f3 & SELECT) totvert++;
382 a= nu->pntsu*nu->pntsv;
384 if(bp->f1 & SELECT) totvert++;
389 if(totvert==0) return 0;
391 *indexar= index= MEM_mallocN(4*totvert, "hook indexar");
393 cent[0]= cent[1]= cent[2]= 0.0;
395 for(nu= editNurb.first; nu; nu= nu->next) {
396 if((nu->type & 7)==CU_BEZIER) {
400 if(bezt->f1 & SELECT) {
402 VecAddf(cent, cent, bezt->vec[0]);
405 if(bezt->f2 & SELECT) {
407 VecAddf(cent, cent, bezt->vec[1]);
410 if(bezt->f3 & SELECT) {
412 VecAddf(cent, cent, bezt->vec[2]);
420 a= nu->pntsu*nu->pntsv;
422 if(bp->f1 & SELECT) {
424 VecAddf(cent, cent, bp->vec);
432 VecMulf(cent, 1.0/(float)totvert);
437 static void select_editcurve_hook(ObHook *hook)
439 extern ListBase editNurb;
443 int index=0, a, nr=0;
445 for(nu= editNurb.first; nu; nu= nu->next) {
446 if((nu->type & 7)==CU_BEZIER) {
450 if(nr == hook->indexar[index]) {
452 if(index<hook->totindex-1) index++;
455 if(nr == hook->indexar[index]) {
457 if(index<hook->totindex-1) index++;
460 if(nr == hook->indexar[index]) {
462 if(index<hook->totindex-1) index++;
471 a= nu->pntsu*nu->pntsv;
473 if(nr == hook->indexar[index]) {
475 if(index<hook->totindex-1) index++;
489 int tot=0, *indexar, mode;
491 if(G.obedit==NULL) return;
493 if(G.obedit->hooks.first)
494 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");
496 mode= pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
502 if(mode==2) { // selected object
503 Base *base= FIRSTBASE;
505 if TESTBASELIB(base) {
514 error("Requires selected Object");
522 // make pupmenu with hooks
523 for(hook= G.obedit->hooks.first; hook; hook= hook->next) maxlen+=32;
526 error("Object has no hooks yet");
530 cp= MEM_callocN(maxlen+32, "temp string");
531 if(mode==3) strcpy(cp, "Remove %t|");
532 else if(mode==4) strcpy(cp, "Reassign %t|");
533 else if(mode==5) strcpy(cp, "Select %t|");
534 else if(mode==6) strcpy(cp, "Clear Offset %t|");
536 for(hook= G.obedit->hooks.first; hook; hook= hook->next) {
537 strcat(cp, hook->name);
547 for(hook= G.obedit->hooks.first; hook; hook= hook->next, a++) {
553 /* do it, new hooks or reassign */
554 if(mode==1 || mode==2 || mode==4) {
556 switch(G.obedit->type) {
558 tot= return_editmesh_indexar(&indexar, cent);
562 tot= return_editcurve_indexar(&indexar, cent);
565 tot= return_editlattice_indexar(&indexar, cent);
570 error("Requires selected vertices");
577 ob= add_object(OB_EMPTY);
578 /* transform cent to global coords for loc */
579 VecMat4MulVecfl(ob->loc, G.obedit->obmat, cent);
581 /* restore, add_object sets active */
584 /* if mode is 2 or 4, ob has been set */
587 if(mode==1 || mode==2) {
588 hook= MEM_callocN(sizeof(ObHook), "new hook");
589 BLI_addtail(&G.obedit->hooks, hook);
590 strncpy(hook->name, ob->id.name+2, 30);
593 else MEM_freeN(hook->indexar); // reassign, hook was set
596 hook->indexar= indexar;
597 VECCOPY(hook->cent, cent);
600 if(mode==1 || mode==2) {
601 /* matrix calculus */
602 /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
607 Mat4Invert(ob->imat, ob->obmat);
608 /* apparently this call goes from right to left... */
609 Mat4MulSerie(hook->parentinv, ob->imat, G.obedit->obmat, NULL,
610 NULL, NULL, NULL, NULL, NULL);
614 else if(mode==3) { // remove
615 BLI_remlink(&G.obedit->hooks, hook);
616 MEM_freeN(hook->indexar);
619 else if(mode==5) { // select
620 if(G.obedit->type==OB_MESH) select_editmesh_hook(hook);
621 else if(G.obedit->type==OB_LATTICE) select_editlattice_hook(hook);
622 else if(G.obedit->type==OB_CURVE) select_editcurve_hook(hook);
623 else if(G.obedit->type==OB_SURF) select_editcurve_hook(hook);
625 else if(mode==6) { // clear offset
626 where_is_object(ob); // ob is hook->parent
628 Mat4Invert(ob->imat, ob->obmat);
629 /* this call goes from right to left... */
630 Mat4MulSerie(hook->parentinv, ob->imat, G.obedit->obmat, NULL,
631 NULL, NULL, NULL, NULL, NULL);
634 allqueue(REDRAWVIEW3D, 0);
635 allqueue(REDRAWBUTSOBJECT, 0);
636 BIF_undo_push("Add hook");
639 void make_track(void)
644 if(G.scene->id.lib) return;
648 if(BASACT==0) return;
650 mode= pupmenu("Make Track %t|TrackTo Constraint %x1|LockTrack Constraint %x2|Old Track %x3");
656 bTrackToConstraint *data;
660 if TESTBASELIB(base) {
662 con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
663 strcpy (con->name, "AutoTrack");
666 data->tar = BASACT->object;
668 /* Lamp and Camera track differently by default */
669 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
670 data->reserved1 = TRACK_nZ;
671 data->reserved2 = UP_Y;
674 add_constraint_to_object(con, base->object);
680 test_scene_constraints();
681 allqueue(REDRAWVIEW3D, 0);
682 sort_baselist(G.scene);
686 bLockTrackConstraint *data;
690 if TESTBASELIB(base) {
692 con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
693 strcpy (con->name, "AutoTrack");
696 data->tar = BASACT->object;
698 /* Lamp and Camera track differently by default */
699 if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
700 data->trackflag = TRACK_nZ;
701 data->lockflag = LOCK_Y;
704 add_constraint_to_object(con, base->object);
710 test_scene_constraints();
711 allqueue(REDRAWVIEW3D, 0);
712 sort_baselist(G.scene);
717 if TESTBASELIB(base) {
720 base->object->track= BASACT->object;
726 test_scene_constraints();
727 allqueue(REDRAWVIEW3D, 0);
728 allqueue(REDRAWOOPS, 0);
729 sort_baselist(G.scene);
731 BIF_undo_push("make Track");
734 void apply_obmat(Object *ob)
736 float mat[3][3], imat[3][3], tmat[3][3];
738 /* from obmat to loc rot size */
741 Mat3CpyMat4(mat, ob->obmat);
743 VECCOPY(ob->loc, ob->obmat[3]);
745 if(ob->transflag & OB_QUAT) {
746 Mat3ToQuat(mat, ob->quat);
747 QuatToMat3(ob->quat, tmat);
750 Mat3ToEul(mat, ob->rot);
751 EulToMat3(ob->rot, tmat);
755 Mat3MulMat3(tmat, imat, mat);
757 ob->size[0]= tmat[0][0];
758 ob->size[1]= tmat[1][1];
759 ob->size[2]= tmat[2][2];
763 void clear_parent(void)
770 if(G.scene->id.lib) return;
772 mode= pupmenu("OK? %t|Clear Parent %x1|Clear and Keep Transformation (Clear Track) %x2|Clear Parent Inverse %x3");
778 if TESTBASELIB(base) {
780 if(mode==1 || mode==2) {
781 if(base->object->type==OB_IKA) {
782 Ika *ika= base->object->data;
785 par= base->object->parent;
786 base->object->parent= 0;
789 base->object->track= 0;
790 apply_obmat(base->object);
794 Mat4One(base->object->parentinv);
798 if(par->type==OB_LATTICE) makeDispList(base->object);
799 if(par->type==OB_IKA) makeDispList(base->object);
800 if(par->type==OB_ARMATURE) makeDispList(base->object);
806 test_scene_constraints();
807 allqueue(REDRAWVIEW3D, 0);
808 allqueue(REDRAWOOPS, 0);
810 BIF_undo_push("Clear Parent");
813 void clear_track(void)
819 if(G.scene->id.lib) return;
821 mode= pupmenu("OK? %t|Clear Track %x1| Clear Track and Keep Transform %x2");
827 if TESTBASELIB(base) {
828 base->object->track= 0;
831 apply_obmat(base->object);
836 test_scene_constraints();
837 allqueue(REDRAWVIEW3D, 0);
838 allqueue(REDRAWOOPS, 0);
840 BIF_undo_push("Clear Track");
843 void clear_object(char mode)
847 float *v1, *v3, mat[3][3];
851 if(G.scene->id.lib) return;
853 if(mode=='r') str= "Clear rotation";
854 else if(mode=='g') str= "Clear location";
855 else if(mode=='s') str= "Clear size";
856 else if(mode=='o') str= "Clear origin";
859 if(okee(str)==0) return;
863 switch (G.obpose->type){
865 clear_armature (G.obpose, mode);
867 clear_pose_constraint_status(G.obpose);
868 make_displists_by_armature (G.obpose);
873 allqueue(REDRAWVIEW3D, 0);
880 if TESTBASELIB(base) {
884 memset(ob->rot, 0, 3*sizeof(float));
885 memset(ob->drot, 0, 3*sizeof(float));
890 memset(ob->loc, 0, 3*sizeof(float));
891 memset(ob->dloc, 0, 3*sizeof(float));
894 memset(ob->dsize, 0, 3*sizeof(float));
902 v3= ob->parentinv[3];
904 Mat3CpyMat4(mat, ob->parentinv);
909 Mat3MulVecfl(mat, v3);
913 if(ob->parent && ob->partype==PARSKEL)
914 freedisplist(&ob->disp);
915 else if(ob->hooks.first)
916 freedisplist(&ob->disp);
921 allqueue(REDRAWVIEW3D, 0);
925 void reset_slowparents(void)
927 /* back to original locations */
932 if(base->object->parent) {
933 if(base->object->partype & PARSLOW) {
934 base->object->partype -= PARSLOW;
935 where_is_object(base->object);
936 base->object->partype |= PARSLOW;
943 void set_slowparent(void)
947 if( okee("Set slow parent")==0 ) return;
951 if TESTBASELIB(base) {
952 if(base->object->parent) base->object->partype |= PARSLOW;
956 BIF_undo_push("Slow parent");
959 void make_vertex_parent(void)
961 EditMesh *em = G.editMesh;
968 int a, v1=0, v2=0, v3=0, nr=1;
970 /* we need 1 to 3 selected vertices */
972 if(G.obedit->type==OB_MESH) {
973 eve= em->verts.first;
977 else if(v2==0) v2= nr;
978 else if(v3==0) v3= nr;
985 else if ELEM(G.obedit->type, OB_SURF, OB_CURVE) {
988 if((nu->type & 7)==CU_BEZIER) {
992 if(BEZSELECTED(bezt)) {
994 else if(v2==0) v2= nr;
995 else if(v3==0) v3= nr;
1004 a= nu->pntsu*nu->pntsv;
1006 if(bp->f1 & SELECT) {
1008 else if(v2==0) v2= nr;
1009 else if(v3==0) v3= nr;
1021 if( !(v1 && v2==0 && v3==0) && !(v1 && v2 && v3) ) {
1022 error("Select either 1 or 3 vertices to parent to");
1026 if(okee("Make vertex parent")==0) return;
1030 if TESTBASELIB(base) {
1033 par= BASACT->object->parent;
1040 error("Loop in parents");
1043 ob->parent= BASACT->object;
1045 ob->partype= PARVERT3;
1050 /* inverse parent matrix */
1051 what_does_parent(ob);
1052 Mat4Invert(ob->parentinv, workob.obmat);
1056 ob->partype= PARVERT1;
1059 /* inverse parent matrix */
1060 what_does_parent(ob);
1061 Mat4Invert(ob->parentinv, workob.obmat);
1069 allqueue(REDRAWVIEW3D, 0);
1071 // BIF_undo_push(str); not, conflicts with editmode undo...
1074 int test_parent_loop(Object *par, Object *ob)
1076 /* test if 'ob' is a parent somewhere in par's parents */
1078 if(par==0) return 0;
1079 if(ob == par) return 1;
1081 if(par->type==OB_IKA) {
1082 Ika *ika= par->data;
1084 if( ob == ika->parent ) return 1;
1085 if( test_parent_loop(ika->parent, ob) ) return 1;
1088 return test_parent_loop(par->parent, ob);
1092 void make_parent(void)
1096 short qual, mode=0, limbnr=0, effchild=0;
1101 if(G.scene->id.lib) return;
1103 if ELEM3(G.obedit->type, OB_MESH, OB_CURVE, OB_SURF) make_vertex_parent();
1104 else if (G.obedit->type==OB_ARMATURE) make_bone_parent();
1107 if(BASACT==0) return;
1110 par= BASACT->object;
1112 if(par->type == OB_CURVE){
1114 bFollowPathConstraint *data;
1116 mode= pupmenu("Make Parent %t|Normal Parent %x1|Follow Path %x2|Curve Deform %x3");
1130 if TESTBASELIB(base) {
1132 float cmat[4][4], vec[3], size[3];
1134 con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1135 strcpy (con->name, "AutoPath");
1138 data->tar = BASACT->object;
1140 add_constraint_to_object(con, base->object);
1142 get_constraint_target_matrix(con, TARGET_OBJECT, NULL, cmat, size, G.scene->r.cfra - base->object->sf);
1143 VecSubf(vec, base->object->obmat[3], cmat[3]);
1145 base->object->loc[0] = vec[0];
1146 base->object->loc[1] = vec[1];
1147 base->object->loc[2] = vec[2];
1153 test_scene_constraints();
1154 allqueue(REDRAWVIEW3D, 0);
1155 sort_baselist(G.scene);
1156 BIF_undo_push("make Parent");
1160 else if(par->type == OB_ARMATURE){
1164 if TESTBASELIB(base) {
1166 if(base->object->type==OB_MESH) {
1167 mode= pupmenu("Make Parent To%t|Bone %x1|Armature %x2|Object %x3");
1171 mode= pupmenu("Make Parent To %t|Bone %x1|Object %x3");
1182 /* Make bone popup menu */
1184 bonestr = make_bone_menu(get_armature(par));
1185 // if(mbutton(&bone, bonestr, 1, 24, "Bone: ")==0) {
1187 bonenr= pupmenu_col(bonestr, 20);
1189 MEM_freeN (bonestr);
1192 allqueue(REDRAWVIEW3D, 0);
1196 apply_pose_armature(get_armature(par), par->pose, 0);
1197 bone=get_indexed_bone(get_armature(par), bonenr);
1199 // error ("Invalid bone!");
1200 allqueue(REDRAWVIEW3D, 0);
1216 if(qual & LR_SHIFTKEY) {
1217 if(okee("Make parent without inverse")==0) return;
1220 if(qual & LR_ALTKEY) {
1221 if(okee("Make vertex parent")==0) return;
1223 else if(okee("Make parent")==0) return;
1228 if TESTBASELIB(base) {
1229 if(base->object->type==OB_IKA && base->object != par) {
1231 if(okee("Effector as Child")) effchild= 1;
1240 /* now we'll clearparentandkeeptransform all objects */
1243 if TESTBASELIB(base) {
1244 if(base!=BASACT && base->object->parent) {
1245 if(base->object->type==OB_IKA && effchild==1);
1247 base->object->parent= 0;
1248 apply_obmat(base->object);
1260 if TESTBASELIB(base) {
1263 if( test_parent_loop(par, base->object) ) {
1264 error("Loop in parents");
1268 /* the ifs below are horrible code (ton) */
1270 if(par->type==OB_IKA){
1271 base->object->partype= mode;
1272 base->object->par1= limbnr;
1274 else if (par->type==OB_ARMATURE){
1275 base->object->partype= mode;
1277 strcpy (base->object->parsubstr, bone->name);
1279 base->object->parsubstr[0]=0;
1282 if(qual & LR_ALTKEY) {
1283 base->object->partype= PARVERT1;
1285 else if(par->type==OB_CURVE) {
1286 base->object->partype= mode;
1289 base->object->partype= PAROBJECT;
1292 base->object->parent= par;
1294 /* calculate inverse parent matrix? */
1295 if( (qual & LR_SHIFTKEY) ) {
1297 Mat4One(base->object->parentinv);
1298 memset(base->object->loc, 0, 3*sizeof(float));
1301 if(mode==PARSKEL && par->type == OB_ARMATURE) {
1302 /* Prompt the user as to whether he wants to
1303 * add some vertex groups based on the bones
1304 * in the parent armature.
1306 create_vgroups_from_armature(base->object,
1309 base->object->partype= PAROBJECT;
1310 what_does_parent(base->object);
1311 Mat4One (base->object->parentinv);
1312 base->object->partype= mode;
1315 what_does_parent(base->object);
1316 Mat4Invert(base->object->parentinv, workob.obmat);
1319 if(par->type==OB_LATTICE) makeDispList(base->object);
1320 if(par->type==OB_CURVE && mode==PARSKEL) makeDispList(base->object);
1321 if(par->type==OB_ARMATURE && mode == PARSKEL){
1322 verify_defgroups(base->object);
1323 makeDispList(base->object);
1330 allqueue(REDRAWVIEW3D, 0);
1331 allqueue(REDRAWOOPS, 0);
1333 test_scene_constraints();
1334 sort_baselist(G.scene);
1336 BIF_undo_push("make Parent");
1340 void enter_editmode(void)
1350 if(G.scene->id.lib) return;
1353 if((base->lay & G.vd->lay)==0) return;
1356 if(ob->data==0) return;
1360 error("Can't edit library data");
1364 if(ob->type==OB_MESH) {
1368 error("Can't edit library data");
1374 allqueue(REDRAWBUTSLOGIC, 0);
1375 if(G.f & G_FACESELECT) allqueue(REDRAWIMAGE, 0);
1377 if (ob->type==OB_ARMATURE){
1378 arm=base->object->data;
1381 error("Can't edit library data");
1386 make_editArmature();
1387 allqueue (REDRAWVIEW3D,0);
1389 else if(ob->type==OB_IKA) { /* grab type */
1393 if(base->object->type==OB_IKA) {
1394 ika= base->object->data;
1395 if(ika->flag & IK_GRABEFF) ika->flag &= ~IK_GRABEFF;
1396 else ika->flag |= IK_GRABEFF;
1401 allqueue(REDRAWVIEW3D, 0);
1403 else if(ob->type==OB_FONT) {
1408 else if(ob->type==OB_MBALL) {
1413 else if(ob->type==OB_LATTICE) {
1418 else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
1423 allqueue(REDRAWBUTSEDIT, 0);
1427 setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
1429 allqueue(REDRAWVIEW3D, 0);
1435 scrarea_queue_headredraw(curarea);
1438 void make_displists_by_parent(Object *ob) {
1441 for (base= FIRSTBASE; base; base= base->next)
1442 if (ob==base->object->parent)
1443 makeDispList(base->object);
1446 void exit_editmode(int freedata) /* freedata==0 at render, 1= freedata, 2= do undo buffer too */
1452 if(G.obedit==NULL) return;
1454 if(G.obedit->type==OB_MESH) {
1459 if(G.totvert>MESH_MAX_VERTS) {
1460 error("Too many vertices");
1463 load_editMesh(); /* makes new displist */
1465 if(freedata) free_editMesh();
1467 if(G.f & G_FACESELECT) {
1469 allqueue(REDRAWIMAGE, 0);
1472 build_particle_system(G.obedit);
1474 else if (G.obedit->type==OB_ARMATURE){
1475 load_editArmature();
1476 if (freedata) free_editArmature();
1478 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
1480 if(freedata) freeNurblist(&editNurb);
1482 else if(G.obedit->type==OB_FONT && freedata==1) {
1485 else if(G.obedit->type==OB_LATTICE) {
1487 if(freedata) free_editLatt();
1489 else if(G.obedit->type==OB_MBALL) {
1491 if(freedata) BLI_freelistN(&editelems);
1496 /* displist make is different in editmode */
1497 if(freedata) G.obedit= NULL;
1500 /* has this influence at other objects? */
1501 if(ob->type==OB_CURVE) {
1503 /* test if ob is use as bevelcurve r textoncurve */
1506 if ELEM(base->object->type, OB_CURVE, OB_FONT) {
1507 cu= base->object->data;
1509 if(cu->textoncurve==ob) {
1510 text_to_curve(base->object, 0);
1511 makeDispList(base->object);
1513 if(cu->bevobj==ob || cu->taperobj==ob) {
1514 makeDispList(base->object);
1521 else if(ob->type==OB_LATTICE) {
1522 make_displists_by_parent(ob);
1526 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
1529 allqueue(REDRAWVIEW3D, 0);
1530 allqueue(REDRAWBUTSEDIT, 0);
1531 allqueue(REDRAWBUTSLOGIC, 0);
1533 scrarea_queue_headredraw(curarea);
1535 if(G.obedit==NULL && freedata==2)
1536 BIF_undo_push("Editmode");
1539 void check_editmode(int type)
1542 if (G.obedit==0 || G.obedit->type==type) return;
1544 exit_editmode(2); // freedata, and undo
1547 /* 0 == do centre, 1 == centre new, 2 == centre cursor */
1549 void docentre(int centremode)
1551 EditMesh *em = G.editMesh;
1560 float cent[3], centn[3], min[3], max[3], omat[3][3];
1564 if(G.scene->id.lib) return;
1568 INIT_MINMAX(min, max);
1570 if(G.obedit->type==OB_MESH) {
1571 eve= em->verts.first;
1573 DO_MINMAX(eve->co, min, max);
1576 cent[0]= (min[0]+max[0])/2.0f;
1577 cent[1]= (min[1]+max[1])/2.0f;
1578 cent[2]= (min[2]+max[2])/2.0f;
1580 eve= em->verts.first;
1582 VecSubf(eve->co, eve->co, cent);
1591 if TESTBASELIB(base) {
1592 base->object->flag &= ~OB_DONE;
1596 me= G.main->mesh.first;
1598 me->flag &= ~ME_ISDONE;
1605 if TESTBASELIB(base) {
1606 if((base->object->flag & OB_DONE)==0) {
1608 base->object->flag |= OB_DONE;
1610 if(G.obedit==0 && (me=get_mesh(base->object)) ) {
1613 error("Can't change the center of a mesh with vertex keys");
1618 VECCOPY(cent, give_cursor());
1619 Mat4Invert(base->object->imat, base->object->obmat);
1620 Mat4MulVecfl(base->object->imat, cent);
1622 INIT_MINMAX(min, max);
1625 for(a=0; a<me->totvert; a++, mvert++) {
1626 DO_MINMAX(mvert->co, min, max);
1629 cent[0]= (min[0]+max[0])/2.0f;
1630 cent[1]= (min[1]+max[1])/2.0f;
1631 cent[2]= (min[2]+max[2])/2.0f;
1635 for(a=0; a<me->totvert; a++, mvert++) {
1636 VecSubf(mvert->co, mvert->co, cent);
1638 me->flag |= ME_ISDONE;
1641 Mat3CpyMat4(omat, base->object->obmat);
1643 VECCOPY(centn, cent);
1644 Mat3MulVecfl(omat, centn);
1645 base->object->loc[0]+= centn[0];
1646 base->object->loc[1]+= centn[1];
1647 base->object->loc[2]+= centn[2];
1650 ob= G.main->object.first;
1652 if((ob->flag & OB_DONE)==0) {
1657 ob->flag |= OB_DONE;
1659 Mat3CpyMat4(omat, ob->obmat);
1660 VECCOPY(centn, cent);
1661 Mat3MulVecfl(omat, centn);
1662 ob->loc[0]+= centn[0];
1663 ob->loc[1]+= centn[1];
1664 ob->loc[2]+= centn[2];
1666 if(tme && (tme->flag & ME_ISDONE)==0) {
1668 for(a=0; a<tme->totvert; a++, mvert++) {
1669 VecSubf(mvert->co, mvert->co, cent);
1671 tme->flag |= ME_ISDONE;
1680 /* displist of all users, also this one */
1681 makeDispList(base->object);
1683 /* DO: check all users... */
1687 else if ELEM(base->object->type, OB_CURVE, OB_SURF) {
1690 nu1= editNurb.first;
1693 cu= base->object->data;
1694 nu1= cu->nurb.first;
1698 VECCOPY(cent, give_cursor());
1699 Mat4Invert(base->object->imat, base->object->obmat);
1700 Mat4MulVecfl(base->object->imat, cent);
1702 /* Curves need to be 2d, never offset in
1703 * Z. Is a somewhat arbitrary restriction,
1704 * would probably be nice to remove.
1708 INIT_MINMAX(min, max);
1712 minmaxNurb(nu, min, max);
1716 cent[0]= (min[0]+max[0])/2.0f;
1717 cent[1]= (min[1]+max[1])/2.0f;
1718 cent[2]= (min[2]+max[2])/2.0f;
1723 if( (nu->type & 7)==1) {
1726 VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
1727 VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
1728 VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
1732 a= nu->pntsu*nu->pntsv;
1734 VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
1739 if(centremode && G.obedit==0) {
1740 Mat3CpyMat4(omat, base->object->obmat);
1742 Mat3MulVecfl(omat, cent);
1743 base->object->loc[0]+= cent[0];
1744 base->object->loc[1]+= cent[1];
1745 base->object->loc[2]+= cent[2];
1749 makeDispList(G.obedit);
1752 else makeDispList(base->object);
1755 else if(base->object->type==OB_FONT) {
1758 cu= base->object->data;
1759 if(cu->bb==0) return;
1761 cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
1762 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 */
1764 /* not really ok, do this better once! */
1765 cu->xof /= cu->fsize;
1766 cu->yof /= cu->fsize;
1768 text_to_curve(base->object, 0);
1769 makeDispList(base->object);
1771 allqueue(REDRAWBUTSEDIT, 0);
1778 allqueue(REDRAWVIEW3D, 0);
1779 BIF_undo_push("Do Centre");
1782 void docentre_new(void)
1784 if(G.scene->id.lib) return;
1787 error("Unable to center new in Edit Mode");
1794 void docentre_cursor(void)
1796 if(G.scene->id.lib) return;
1799 error("Unable to center cursor in Edit Mode");
1806 void movetolayer(void)
1809 unsigned int lay= 0, local;
1811 if(G.scene->id.lib) return;
1815 if TESTBASE(base) lay |= base->lay;
1821 if( movetolayer_buts(&lay)==0 ) return;
1827 local= base->lay & 0xFF000000;
1828 base->lay= lay + local;
1830 base->object->lay= lay;
1835 allqueue(REDRAWBUTSEDIT, 0);
1836 allqueue(REDRAWVIEW3D, 0);
1837 allqueue(REDRAWOOPS, 0);
1838 allqueue(REDRAWINFO, 0);
1840 BIF_undo_push("Move to layer");
1844 void special_editmenu(void)
1846 extern short editbutflag;
1847 extern float doublimit;
1853 if(G.f & G_FACESELECT) {
1854 Mesh *me= get_mesh(OBACT);
1858 if(me==0 || me->tface==0) return;
1860 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");
1862 for(a=me->totface, tface= me->tface; a>0; a--, tface++) {
1863 if(tface->flag & SELECT) {
1866 tface->mode |= TF_TEX; break;
1868 tface->mode |= TF_SHAREDCOL; break;
1870 tface->mode |= TF_LIGHT; break;
1872 tface->mode |= TF_INVISIBLE; break;
1874 tface->mode |= TF_DYNAMIC; break;
1876 tface->mode &= ~TF_TEX;
1880 tface->mode &= ~TF_SHAREDCOL; break;
1882 tface->mode &= ~TF_LIGHT; break;
1884 tface->mode &= ~TF_INVISIBLE; break;
1886 tface->mode &= ~TF_DYNAMIC; break;
1890 allqueue(REDRAWVIEW3D, 0);
1891 allqueue(REDRAWBUTSEDIT, 0);
1892 BIF_undo_push("Change texture face");
1894 else if(G.f & G_VERTEXPAINT) {
1895 Mesh *me= get_mesh(OBACT);
1897 if(me==0 || (me->mcol==NULL && me->tface==NULL) ) return;
1899 nr= pupmenu("Specials%t|Shared VertexCol%x1");
1902 if(me->tface) tface_to_mcol(me);
1904 copy_vpaint_undo( (unsigned int *)me->mcol, me->totface);
1905 do_shared_vertexcol(me);
1907 if(me->tface) mcol_to_tface(me, 1);
1908 BIF_undo_push("Shared VertexCol");
1912 Base *base, *base_select= NULL;
1914 // Get the active object mesh.
1915 Mesh *me= get_mesh(OBACT);
1917 // If the active object is a mesh...
1919 // Bring up a little menu with the boolean operation choices on.
1920 nr= pupmenu("Boolean %t|Intersect%x1|Union%x2|Difference%x3");
1923 // user has made a choice of a menu element.
1924 // All of the boolean functions require 2 mesh objects
1925 // we search through the object list to find the other
1926 // selected item and make sure it is distinct and a mesh.
1930 if(base->flag & SELECT) {
1931 if(base->object != OBACT) base_select= base;
1938 if (get_mesh(base_select->object)) {
1940 ret = NewBooleanMesh(BASACT,base_select,nr);
1942 error("An internal error occurred -- sorry!");
1943 } else if(ret==-1) {
1944 error("Selected meshes must have faces to perform boolean operations");
1946 else BIF_undo_push("Boolean");
1950 error("Please select 2 meshes");
1953 error("Please select 2 meshes");
1957 allqueue(REDRAWVIEW3D, 0);
1961 else if(G.obedit->type==OB_MESH) {
1963 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");
1964 if(nr>0) waitcursor(1);
1968 undo_push_mesh("Subdivide");
1969 subdivideflag(1, 0.0, editbutflag);
1973 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
1974 fac= -( (float)randfac )/100;
1975 undo_push_mesh("Subdivide Fractal");
1976 subdivideflag(1, fac, editbutflag);
1979 undo_push_mesh("Subdivide Smooth");
1980 subdivideflag(1, 0.0, editbutflag | B_SMOOTH);
1986 undo_push_mesh("Remove Doubles");
1987 notice("Removed %d Vertices", removedoublesflag(1, doublimit));
1999 undo_push_mesh("Flip Normals");
2003 undo_push_mesh("Smooth");
2011 makeDispList(G.obedit);
2013 if(nr>0) waitcursor(0);
2016 else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
2018 nr= pupmenu("Specials%t|Subdivide%x1|Switch Direction%x2");
2025 switchdirectionNurb2();
2031 allqueue(REDRAWVIEW3D, 0);
2035 void convertmenu(void)
2037 Base *base, *basen, *basact;
2043 int ok=0, nr = 0, a;
2045 if(G.scene->id.lib) return;
2049 if(G.obedit) return;
2051 basact= BASACT; /* will be restored */
2053 if(ob->type==OB_FONT) {
2054 nr= pupmenu("Convert Font to%t|Curve");
2057 else if(ob->type==OB_MBALL) {
2058 nr= pupmenu("Convert Metaball to%t|Mesh (keep original)");
2061 else if(ob->type==OB_CURVE) {
2062 nr= pupmenu("Convert Curve to%t|Mesh");
2065 else if(ob->type==OB_SURF) {
2066 nr= pupmenu("Convert Nurbs Surface to%t|Mesh");
2069 else if(ob->type==OB_MESH && mesh_uses_displist((Mesh*) ob->data)) {
2070 nr= pupmenu("Convert SubSurf to%t|Mesh (Keep Original)");
2075 /* don't forget multiple users! */
2080 if TESTBASELIB(base) {
2081 base->object->flag &= ~OB_DONE;
2088 if TESTBASELIB(base) {
2092 if(ob->flag & OB_DONE);
2093 else if(ob->type==OB_MESH) {
2094 Mesh *oldme= ob->data;
2096 if (mesh_uses_displist(oldme)) {
2099 ob->flag |= OB_DONE;
2101 ob1= copy_object(ob);
2103 basen= MEM_mallocN(sizeof(Base), "duplibase");
2105 BLI_addhead(&G.scene->base, basen); /* addhead: otherwise eternal loop */
2107 basen->flag &= ~SELECT;
2112 ob1->data= add_mesh();
2117 me->totcol= oldme->totcol;
2119 me->mat= MEM_dupallocN(oldme->mat);
2120 for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
2123 dlm= subsurf_make_dispListMesh_from_mesh(oldme, NULL, oldme->subdiv, oldme->flag);
2124 displistmesh_to_mesh(dlm, ob1->data);
2125 displistmesh_free(dlm);
2130 else if(ob->type==OB_FONT) {
2133 ob->flag |= OB_DONE;
2144 ob1= G.main->object.first;
2146 if(ob1->data==cu) ob1->type= OB_CURVE;
2152 else if ELEM(ob->type, OB_CURVE, OB_SURF) {
2155 ob->flag |= OB_DONE;
2159 if(dl==0) makeDispList(ob);
2161 nurbs_to_mesh(ob); /* also does users */
2163 /* texspace and normals */
2166 exit_editmode(1); // freedata, but no undo
2170 else if(ob->type==OB_MBALL) {
2173 ob= find_basis_mball(ob);
2175 if(ob->disp.first && !(ob->flag&OB_DONE)) {
2177 ob->flag |= OB_DONE;
2179 ob1= copy_object(ob);
2181 basen= MEM_mallocN(sizeof(Base), "duplibase");
2183 BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2185 basen->flag &= ~SELECT;
2190 ob1->data= add_mesh();
2195 me->totcol= mb->totcol;
2197 me->mat= MEM_dupallocN(mb->mat);
2198 for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
2201 mball_to_mesh(&ob->disp, ob1->data);
2210 allqueue(REDRAWVIEW3D, 0);
2211 allqueue(REDRAWOOPS, 0);
2212 allqueue(REDRAWBUTSEDIT, 0);
2213 BIF_undo_push("Convert Object");
2216 /* Change subdivision properties of mesh object ob, if
2217 * level==-1 then toggle subsurf, else set to level.
2219 void flip_subdivison(Object *ob, int level)
2221 Mesh *me = ob->data;
2224 me->flag ^= ME_SUBSURF;
2229 allqueue(REDRAWVIEW3D, 0);
2230 allqueue(REDRAWOOPS, 0);
2231 allqueue(REDRAWBUTSEDIT, 0);
2234 BIF_undo_push("Switch subsurf on/off");
2237 void copymenu_properties(Object *ob)
2239 bProperty *prop, *propn, *propc;
2244 prop= ob->prop.first;
2251 error("No properties in the active object to copy");
2255 str= MEM_callocN(24+32*tot, "copymenu prop");
2257 strcpy(str, "Copy Property %t");
2260 prop= ob->prop.first;
2264 strcat(str, prop->name);
2271 prop= ob->prop.first;
2282 if(base != BASACT) {
2283 if(TESTBASELIB(base)) {
2284 prop= get_property(base->object, propc->name);
2286 free_property(prop);
2287 BLI_remlink(&base->object->prop, prop);
2289 propn= copy_property(propc);
2290 BLI_addtail(&base->object->prop, propn);
2298 allqueue(REDRAWVIEW3D, 0);
2300 BIF_undo_push("Copy properties");
2303 void copymenu_logicbricks(Object *ob)
2309 if(base->object != ob) {
2310 if(TESTBASELIB(base)) {
2312 /* first: free all logic */
2313 free_sensors(&base->object->sensors);
2314 unlink_controllers(&base->object->controllers);
2315 free_controllers(&base->object->controllers);
2316 unlink_actuators(&base->object->actuators);
2317 free_actuators(&base->object->actuators);
2319 /* now copy it, this also works without logicbricks! */
2320 clear_sca_new_poins_ob(ob);
2321 copy_sensors(&base->object->sensors, &ob->sensors);
2322 copy_controllers(&base->object->controllers, &ob->controllers);
2323 copy_actuators(&base->object->actuators, &ob->actuators);
2324 set_sca_new_poins_ob(base->object);
2326 /* some menu settings */
2327 base->object->scavisflag= ob->scavisflag;
2328 base->object->scaflag= ob->scaflag;
2334 BIF_undo_push("Copy logic");
2337 void copy_attr_menu()
2343 /* If you change this menu, don't forget to update the menu in header_view3d.c
2344 * view3d_edit_object_copyattrmenu() and in toolbox.c
2346 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");
2348 if(!(ob=OBACT)) return;
2350 strcat (str, "|Object Constraints%x22");
2352 if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
2353 strcat(str, "|Texture Space%x17");
2356 if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
2357 if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19");
2359 if(ob->type==OB_MESH){
2360 strcat(str, "|Subdiv%x21");
2363 if( give_parteff(ob) ) strcat(str, "|Particle Settings%x20");
2365 event= pupmenu(str);
2366 if(event<= 0) return;
2371 void copy_attr(short event)
2376 void *poin1, *poin2=0;
2378 if(G.scene->id.lib) return;
2380 if(!(ob=OBACT)) return;
2383 /* obedit_copymenu(); */
2387 if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
2388 if(ob->type==OB_MESH) poin2= &(((Mesh *)ob->data)->texflag);
2389 else if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) poin2= &(((Curve *)ob->data)->texflag);
2390 else if(ob->type==OB_MBALL) poin2= &(((MetaBall *)ob->data)->texflag);
2394 copymenu_properties(ob);
2397 else if(event==10) {
2398 copymenu_logicbricks(ob);
2404 if(base != BASACT) {
2405 if(TESTBASELIB(base)) {
2407 if(event==1) { /* loc */
2408 VECCOPY(base->object->loc, ob->loc);
2409 VECCOPY(base->object->dloc, ob->dloc);
2411 else if(event==2) { /* rot */
2412 VECCOPY(base->object->rot, ob->rot);
2413 VECCOPY(base->object->drot, ob->drot);
2414 VECCOPY(base->object->quat, ob->quat);
2415 VECCOPY(base->object->dquat, ob->dquat);
2417 else if(event==3) { /* size */
2418 VECCOPY(base->object->size, ob->size);
2419 VECCOPY(base->object->dsize, ob->dsize);
2421 else if(event==4) { /* drawtype */
2422 base->object->dt= ob->dt;
2423 base->object->dtx= ob->dtx;
2425 else if(event==5) { /* time offs */
2426 base->object->sf= ob->sf;
2428 else if(event==6) { /* dupli */
2429 base->object->dupon= ob->dupon;
2430 base->object->dupoff= ob->dupoff;
2431 base->object->dupsta= ob->dupsta;
2432 base->object->dupend= ob->dupend;
2434 base->object->transflag &= ~OB_DUPLI;
2435 base->object->transflag |= (ob->transflag & OB_DUPLI);
2437 else if(event==7) { /* mass */
2438 base->object->mass= ob->mass;
2440 else if(event==8) { /* damping */
2441 base->object->damping= ob->damping;
2442 base->object->rdamping= ob->rdamping;
2444 else if(event==17) { /* tex space */
2447 if(obt->type==OB_MESH) poin1= &(((Mesh *)obt->data)->texflag);
2448 else if ELEM3(obt->type, OB_CURVE, OB_SURF, OB_FONT) poin1= &(((Curve *)obt->data)->texflag);
2449 else if(obt->type==OB_MBALL) poin1= &(((MetaBall *)obt->data)->texflag);
2452 memcpy(poin1, poin2, 4+12+12+12);
2454 if(obt->type==OB_MESH) tex_space_mesh(obt->data);
2455 else if(obt->type==OB_MBALL) tex_space_mball(obt);
2456 else tex_space_curve(obt->data);
2459 else if(event==18) { /* font settings */
2461 if(base->object->type==ob->type) {
2463 cu1= base->object->data;
2465 cu1->spacemode= cu->spacemode;
2466 cu1->spacing= cu->spacing;
2467 cu1->linedist= cu->linedist;
2468 cu1->shear= cu->shear;
2469 cu1->fsize= cu->fsize;
2472 cu1->textoncurve= cu->textoncurve;
2473 if(cu1->vfont) cu1->vfont->id.us--;
2474 cu1->vfont= cu->vfont;
2475 id_us_plus((ID *)cu1->vfont);
2476 text_to_curve(base->object, 0);
2478 strcpy(cu1->family, cu->family);
2480 makeDispList(base->object);
2483 else if(event==19) { /* bevel settings */
2485 if ELEM(base->object->type, OB_CURVE, OB_FONT) {
2487 cu1= base->object->data;
2489 cu1->bevobj= cu->bevobj;
2490 cu1->taperobj= cu->taperobj;
2491 cu1->width= cu->width;
2492 cu1->bevresol= cu->bevresol;
2493 cu1->ext1= cu->ext1;
2494 cu1->ext2= cu->ext2;
2496 makeDispList(base->object);
2499 else if(event==20) { /* particle settings */
2503 pa1= give_parteff(ob);
2504 pa2= give_parteff(base->object);
2507 BLI_remlink( &(base->object->effect), pa2);
2508 free_effect( (Effect *) pa2);
2510 else if(pa1 && pa2==0) {
2511 free_effects(&(base->object->effect));
2512 copy_effects(&(base->object->effect), &ob->effect);
2513 build_particle_system(base->object);
2515 else if(pa1 && pa2) {
2516 if(pa2->keys) MEM_freeN(pa2->keys);
2518 p1= (char *)pa1; p2= (char *)pa2;
2519 memcpy( p2+8, p1+8, sizeof(PartEff) - 8);
2522 build_particle_system(base->object);
2526 if (base->object->type==OB_MESH) {
2527 Mesh *targetme= base->object->data;
2528 Mesh *sourceme= ob->data;
2530 targetme->flag= (targetme->flag&~ME_SUBSURF) | (sourceme->flag&ME_SUBSURF);
2531 targetme->subsurftype = sourceme->subsurftype;
2532 targetme->subdiv= sourceme->subdiv;
2533 targetme->subdivr= sourceme->subdivr;
2534 makeDispList(base->object);
2538 /* Clear the constraints on the target */
2539 free_constraints(&base->object->constraints);
2540 free_constraint_channels(&base->object->constraintChannels);
2542 /* Copy the constraint channels over */
2543 copy_constraints(&base->object->constraints, &ob->constraints);
2544 if (U.dupflag& USER_DUP_IPO)
2545 copy_constraint_channels(&base->object->constraintChannels, &ob->constraintChannels);
2547 clone_constraint_channels (&base->object->constraintChannels, &ob->constraintChannels, NULL);
2549 base->object->activecon = NULL;
2556 allqueue(REDRAWVIEW3D, 0);
2558 allqueue(REDRAWBUTSOBJECT, 0);
2561 BIF_undo_push("Copy attributes");
2564 void link_to_scene(unsigned short nr)
2566 Scene *sce= (Scene*) BLI_findlink(&G.main->scene, G.curscreen->scenenr-1);
2570 if(sce->id.lib) return;
2574 if(TESTBASE(base)) {
2576 nbase= MEM_mallocN( sizeof(Base), "newbase");
2578 BLI_addhead( &(sce->base), nbase);
2579 id_us_plus((ID *)base->object);
2585 void make_links_menu()
2591 if(!(ob=OBACT)) return;
2593 strcpy(str, "Make Links %t|To Scene...%x1|%l|Object Ipo%x4");
2595 if(ob->type==OB_MESH)
2596 strcat(str, "|Mesh Data%x2|Materials%x3");
2597 else if(ob->type==OB_CURVE)
2598 strcat(str, "|Curve Data%x2|Materials%x3");
2599 else if(ob->type==OB_FONT)
2600 strcat(str, "|Text Data%x2|Materials%x3");
2601 else if(ob->type==OB_SURF)
2602 strcat(str, "|Surface Data%x2|Materials%x3");
2603 else if(ob->type==OB_MBALL)
2604 strcat(str, "|Materials%x3");
2605 else if(ob->type==OB_CAMERA)
2606 strcat(str, "|Camera Data%x2");
2607 else if(ob->type==OB_LAMP)
2608 strcat(str, "|Lamp Data%x2");
2609 else if(ob->type==OB_LATTICE)
2610 strcat(str, "|Lattice Data%x2");
2611 else if(ob->type==OB_ARMATURE)
2612 strcat(str, "|Armature Data%x2");
2614 event= pupmenu(str);
2616 if(event<= 0) return;
2621 void make_links(short event)
2624 Base *base, *nbase, *sbase;
2627 Material ***matarar, ***obmatarar, **matar1, **matar2;
2632 if(!(ob=OBACT)) return;
2635 IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), 0, &nr);
2637 if(strncmp(strp, "DataBrow", 8)==0) {
2640 activate_databrowse((ID *)G.scene, ID_SCE, 0, B_INFOSCE, &(G.curscreen->scenenr), link_to_scene );
2645 event= pupmenu(strp);
2648 if(event<= 0) return;
2651 sce= G.main->scene.first;
2653 if(nr==event) break;
2658 error("This is the current scene");
2661 if(sce==0 || sce->id.lib) return;
2663 /* remember: is needed below */
2670 if(event==1 || base != BASACT) {
2674 if(TESTBASE(base)) {
2676 if(event==1) { /* to scene */
2678 /* test if already linked */
2679 sbase= sce->base.first;
2681 if(sbase->object==base->object) break;
2684 if(sbase) { /* remove */
2689 nbase= MEM_mallocN( sizeof(Base), "newbase");
2691 BLI_addhead( &(sce->base), nbase);
2692 id_us_plus((ID *)base->object);
2695 if(TESTBASELIB(base)) {
2696 if(event==2 || event==5) { /* obdata */
2697 if(ob->type==obt->type) {
2706 /* if amount of material indices changed: */
2707 test_object_materials(obt->data);
2710 else if(event==4) { /* ob ipo */
2711 if(obt->ipo) obt->ipo->id.us--;
2714 id_us_plus((ID *)obt->ipo);
2718 else if(event==3) { /* materials */
2720 /* only if obt has no material: make arrays */
2721 /* from ob to obt! */
2723 obmatarar= give_matarar(ob);
2724 matarar= give_matarar(obt);
2725 totcolp= give_totcolp(obt);
2727 /* if one of the two is zero: no render-able object */
2728 if( matarar && obmatarar) {
2730 /* take care of users! so first a copy of original: */
2733 matar1= MEM_dupallocN(ob->mat);
2734 matar2= MEM_dupallocN(*obmatarar);
2740 /* remove links from obt */
2741 for(a=0; a<obt->totcol; a++) {
2742 if(obt->mat[a]) obt->mat[a]->id.us--;
2743 if( (*matarar)[a]) (*matarar)[a]->id.us--;
2747 if(obt->mat) MEM_freeN(obt->mat);
2748 if(*matarar) MEM_freeN(*matarar);
2750 /* connect a copy */
2753 obt->totcol= ob->totcol;
2754 *totcolp= ob->totcol;
2756 /* increase users */
2757 for(a=0; a<obt->totcol; a++) {
2758 if(obt->mat[a]) id_us_plus((ID *)obt->mat[a]);
2759 if( (*matarar)[a]) id_us_plus((ID *)(*matarar)[a]);
2762 obt->colbits= ob->colbits;
2764 /* if amount of material indices changed: */
2765 test_object_materials(obt->data);
2773 allqueue(REDRAWVIEW3D, 0);
2774 allqueue(REDRAWOOPS, 0);
2775 allqueue(REDRAWBUTSHEAD, 0);
2777 BIF_undo_push("Create links");
2780 void make_duplilist_real()
2784 extern ListBase duplilist;
2786 if(okee("Make dupli objects real")==0) return;
2790 if TESTBASELIB(base) {
2792 if(base->object->transflag & OB_DUPLI) {
2794 make_duplilist(G.scene, base->object);
2795 ob= duplilist.first;
2798 /* font duplis can have a totcol without material, we get them from parent
2799 * should be implemented better...
2801 if(ob->mat==0) ob->totcol= 0;
2803 basen= MEM_dupallocN(base);
2804 basen->flag &= ~OB_FROMDUPLI;
2805 BLI_addhead(&G.scene->base, basen); /* addhead: othwise eternal loop */
2806 ob->ipo= 0; /* make sure apply works */
2807 ob->parent= ob->track= 0;
2808 ob->disp.first= ob->disp.last= 0;
2809 ob->transflag &= ~OB_DUPLI;
2810 basen->object= copy_object(ob);
2812 apply_obmat(basen->object);
2818 base->object->transflag &= ~OB_DUPLI;
2824 allqueue(REDRAWVIEW3D, 0);
2825 allqueue(REDRAWOOPS, 0);
2827 BIF_undo_push("Make duplicates real");
2832 Base *base, *basact;
2843 if(G.scene->id.lib) return;
2844 if(G.obedit) return;
2847 if(G.qual & LR_SHIFTKEY) {
2851 if(ob->transflag & OB_DUPLI) make_duplilist_real();
2852 else if(ob->parent && ob->parent->type==OB_LATTICE) apply_lattice();
2857 if(okee("Apply size and rotation")==0) return;
2861 if TESTBASELIB(base) {
2864 if(ob->type==OB_MESH) {
2865 object_to_mat3(ob, mat);
2869 error("Can't apply to a multi user mesh");
2873 error("Can't apply to a mesh with vertex keys");
2878 for(a=0; a<me->totvert; a++, mvert++) {
2879 Mat3MulVecfl(mat, mvert->co);
2881 ob->size[0]= ob->size[1]= ob->size[2]= 1.0;
2882 ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0;
2885 where_is_object(ob);
2887 /* texspace and normals */