4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation, 2002-2008 full recode
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/object/object_edit.c
38 #include <stddef.h> //for offsetof
40 #include "MEM_guardedalloc.h"
42 #include "BLI_blenlib.h"
44 #include "BLI_utildefines.h"
45 #include "BLI_editVert.h"
46 #include "BLI_ghash.h"
49 #include "DNA_armature_types.h"
50 #include "DNA_curve_types.h"
51 #include "DNA_group_types.h"
52 #include "DNA_lattice_types.h"
53 #include "DNA_material_types.h"
54 #include "DNA_meta_types.h"
55 #include "DNA_property_types.h"
56 #include "DNA_scene_types.h"
57 #include "DNA_object_types.h"
58 #include "DNA_object_force.h"
59 #include "DNA_meshdata_types.h"
60 #include "DNA_vfont_types.h"
62 #include "IMB_imbuf_types.h"
65 #include "BKE_constraint.h"
66 #include "BKE_context.h"
67 #include "BKE_curve.h"
68 #include "BKE_effect.h"
69 #include "BKE_depsgraph.h"
71 #include "BKE_image.h"
72 #include "BKE_library.h"
74 #include "BKE_material.h"
75 #include "BKE_mball.h"
77 #include "BKE_object.h"
78 #include "BKE_paint.h"
79 #include "BKE_pointcache.h"
80 #include "BKE_property.h"
82 #include "BKE_softbody.h"
83 #include "BKE_modifier.h"
84 #include "BKE_tessmesh.h"
86 #include "ED_armature.h"
90 #include "ED_lattice.h"
91 #include "ED_object.h"
92 #include "ED_screen.h"
96 #include "RNA_access.h"
97 #include "RNA_define.h"
98 #include "RNA_enum_types.h"
100 /* for menu/popup icons etc etc*/
102 #include "UI_interface.h"
104 #include "WM_types.h"
106 #include "object_intern.h" // own include
108 /* ************* XXX **************** */
109 static void error(const char *UNUSED(arg)) {}
110 static void waitcursor(int UNUSED(val)) {}
111 static int pupmenu(const char *UNUSED(msg)) {return 0;}
114 static bContext *evil_C;
115 static void error_libdata(void) {}
118 /* find the correct active object per context
119 * note: context can be NULL when called from a enum with PROP_ENUM_NO_CONTEXT */
120 Object *ED_object_active_context(bContext *C)
124 ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
125 if (!ob) ob= CTX_data_active_object(C);
131 /* ********* clear/set restrict view *********/
132 static int object_hide_view_clear_exec(bContext *C, wmOperator *UNUSED(op))
134 Main *bmain= CTX_data_main(C);
135 ScrArea *sa= CTX_wm_area(C);
136 View3D *v3d= sa->spacedata.first;
137 Scene *scene= CTX_data_scene(C);
141 /* XXX need a context loop to handle such cases */
142 for(base = FIRSTBASE; base; base=base->next){
143 if((base->lay & v3d->lay) && base->object->restrictflag & OB_RESTRICT_VIEW) {
144 base->flag |= SELECT;
145 base->object->flag = base->flag;
146 base->object->restrictflag &= ~OB_RESTRICT_VIEW;
151 DAG_scene_sort(bmain, scene);
152 WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
155 return OPERATOR_FINISHED;
158 void OBJECT_OT_hide_view_clear(wmOperatorType *ot)
162 ot->name= "Clear Restrict View";
163 ot->description = "Reveal the object by setting the hide flag";
164 ot->idname= "OBJECT_OT_hide_view_clear";
167 ot->exec= object_hide_view_clear_exec;
168 ot->poll= ED_operator_view3d_active;
171 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
174 static int object_hide_view_set_exec(bContext *C, wmOperator *op)
176 Main *bmain= CTX_data_main(C);
177 Scene *scene= CTX_data_scene(C);
179 const int unselected= RNA_boolean_get(op->ptr, "unselected");
181 CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
183 if (base->flag & SELECT){
184 base->flag &= ~SELECT;
185 base->object->flag = base->flag;
186 base->object->restrictflag |= OB_RESTRICT_VIEW;
189 ED_base_object_activate(C, NULL);
194 if (!(base->flag & SELECT)){
195 base->object->restrictflag |= OB_RESTRICT_VIEW;
203 DAG_scene_sort(bmain, scene);
205 WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
209 return OPERATOR_FINISHED;
212 void OBJECT_OT_hide_view_set(wmOperatorType *ot)
215 ot->name= "Set Restrict View";
216 ot->description = "Hide the object by setting the hide flag";
217 ot->idname= "OBJECT_OT_hide_view_set";
220 ot->exec= object_hide_view_set_exec;
221 ot->poll= ED_operator_view3d_active;
224 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
226 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects.");
230 /* 99% same as above except no need for scene refreshing (TODO, update render preview) */
231 static int object_hide_render_clear_exec(bContext *C, wmOperator *UNUSED(op))
235 /* XXX need a context loop to handle such cases */
236 CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
237 if(ob->restrictflag & OB_RESTRICT_RENDER) {
238 ob->restrictflag &= ~OB_RESTRICT_RENDER;
245 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_OUTLINER, NULL);
247 return OPERATOR_FINISHED;
250 void OBJECT_OT_hide_render_clear(wmOperatorType *ot)
254 ot->name= "Clear Restrict Render";
255 ot->description = "Reveal the render object by setting the hide render flag";
256 ot->idname= "OBJECT_OT_hide_render_clear";
259 ot->exec= object_hide_render_clear_exec;
260 ot->poll= ED_operator_view3d_active;
263 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
266 static int object_hide_render_set_exec(bContext *C, wmOperator *op)
268 const int unselected= RNA_boolean_get(op->ptr, "unselected");
270 CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
272 if (base->flag & SELECT){
273 base->object->restrictflag |= OB_RESTRICT_RENDER;
277 if (!(base->flag & SELECT)){
278 base->object->restrictflag |= OB_RESTRICT_RENDER;
283 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_OUTLINER, NULL);
284 return OPERATOR_FINISHED;
287 void OBJECT_OT_hide_render_set(wmOperatorType *ot)
290 ot->name= "Set Restrict Render";
291 ot->description = "Hide the render object by setting the hide render flag";
292 ot->idname= "OBJECT_OT_hide_render_set";
295 ot->exec= object_hide_render_set_exec;
296 ot->poll= ED_operator_view3d_active;
299 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
301 RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects.");
304 /* ******************* toggle editmode operator ***************** */
306 void ED_object_exit_editmode(bContext *C, int flag)
308 /* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */
310 Scene *scene= CTX_data_scene(C);
311 Object *obedit= CTX_data_edit_object(C);
312 int freedata = flag & EM_FREEDATA;
314 if(obedit==NULL) return;
316 if(flag & EM_WAITCURSOR) waitcursor(1);
317 if(obedit->type==OB_MESH) {
318 Mesh *me= obedit->data;
320 // if(EM_texFaceCheck())
322 // if(retopo_mesh_paint_check())
323 // retopo_end_okee();
325 if(me->edit_btmesh->bm->totvert>MESH_MAX_VERTS) {
326 error("Too many vertices");
330 EDBM_LoadEditBMesh(scene, obedit);
333 EDBM_FreeEditBMesh(me->edit_btmesh);
334 MEM_freeN(me->edit_btmesh);
335 me->edit_btmesh= NULL;
338 if(obedit->restore_mode & OB_MODE_WEIGHT_PAINT) {
339 mesh_octree_table(NULL, NULL, NULL, 'e');
340 mesh_mirrtopo_table(NULL, 'e');
344 else if (obedit->type==OB_ARMATURE) {
345 ED_armature_from_edit(obedit);
347 ED_armature_edit_free(obedit);
349 else if(ELEM(obedit->type, OB_CURVE, OB_SURF)) {
350 load_editNurb(obedit);
351 if(freedata) free_editNurb(obedit);
353 else if(obedit->type==OB_FONT && freedata) {
354 load_editText(obedit);
355 if(freedata) free_editText(obedit);
357 else if(obedit->type==OB_LATTICE) {
358 load_editLatt(obedit);
359 if(freedata) free_editLatt(obedit);
361 else if(obedit->type==OB_MBALL) {
362 load_editMball(obedit);
363 if(freedata) free_editMball(obedit);
366 /* freedata only 0 now on file saves and render */
371 /* for example; displist make is different in editmode */
372 scene->obedit= NULL; // XXX for context
374 /* flag object caches as outdated */
375 BKE_ptcache_ids_from_object(&pidlist, obedit, NULL, 0);
376 for(pid=pidlist.first; pid; pid=pid->next) {
377 if(pid->type != PTCACHE_TYPE_PARTICLES) /* particles don't need reset on geometry change */
378 pid->cache->flag |= PTCACHE_OUTDATED;
380 BLI_freelistN(&pidlist);
382 BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_DEPSGRAPH);
384 /* also flush ob recalc, doesn't take much overhead, but used for particles */
385 DAG_id_tag_update(&obedit->id, OB_RECALC_OB|OB_RECALC_DATA);
387 if(flag & EM_DO_UNDO)
388 ED_undo_push(C, "Editmode");
390 if(flag & EM_WAITCURSOR) waitcursor(0);
392 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
394 obedit->mode &= ~OB_MODE_EDIT;
399 void ED_object_enter_editmode(bContext *C, int flag)
401 Scene *scene= CTX_data_scene(C);
404 ScrArea *sa= CTX_wm_area(C);
408 if(scene->id.lib) return;
410 if(sa && sa->spacetype==SPACE_VIEW3D)
411 v3d= sa->spacedata.first;
413 if((flag & EM_IGNORE_LAYER)==0) {
414 base= CTX_data_active_base(C); /* active layer checked here for view3d */
416 if(base==NULL) return;
417 else if(v3d && (base->lay & v3d->lay)==0) return;
418 else if(!v3d && (base->lay & scene->lay)==0) return;
424 if (ELEM3(NULL, base, base->object, base->object->data)) return;
428 if (object_data_is_libdata(ob)) {
433 if(flag & EM_WAITCURSOR) waitcursor(1);
435 ob->restore_mode = ob->mode;
437 /* note, when switching scenes the object can have editmode data but
438 * not be scene->obedit: bug 22954, this avoids calling self eternally */
439 if((ob->restore_mode & OB_MODE_EDIT)==0)
440 ED_object_toggle_modes(C, ob->mode);
442 ob->mode= OB_MODE_EDIT;
444 if(ob->type==OB_MESH) {
447 if(me->pv) mesh_pmv_off(me);
449 scene->obedit= ob; // context sees this
451 EDBM_MakeEditBMesh(CTX_data_tool_settings(C), scene, ob);
453 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MESH, scene);
455 else if (ob->type==OB_ARMATURE){
456 bArmature *arm= base->object->data;
459 * The function object_data_is_libdata make a problem here, the
460 * check for ob->proxy return 0 and let blender enter to edit mode
461 * this causa a crash when you try leave the edit mode.
462 * The problem is that i can't remove the ob->proxy check from
463 * object_data_is_libdata that prevent the bugfix #6614, so
464 * i add this little hack here.
472 ED_armature_to_edit(ob);
473 /* to ensure all goes in restposition and without striding */
474 DAG_id_tag_update(&ob->id, OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME); // XXX: should this be OB_RECALC_DATA?
476 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_ARMATURE, scene);
478 else if(ob->type==OB_FONT) {
479 scene->obedit= ob; // XXX for context
483 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_TEXT, scene);
485 else if(ob->type==OB_MBALL) {
486 scene->obedit= ob; // XXX for context
490 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MBALL, scene);
492 else if(ob->type==OB_LATTICE) {
493 scene->obedit= ob; // XXX for context
497 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_LATTICE, scene);
499 else if(ob->type==OB_SURF || ob->type==OB_CURVE) {
501 scene->obedit= ob; // XXX for context
504 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_CURVE, scene);
508 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
511 scene->obedit= NULL; // XXX for context
512 ob->mode &= ~OB_MODE_EDIT;
513 WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
516 if(flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
517 if(flag & EM_WAITCURSOR) waitcursor(0);
520 static int editmode_toggle_exec(bContext *C, wmOperator *UNUSED(op))
522 if(!CTX_data_edit_object(C))
523 ED_object_enter_editmode(C, EM_WAITCURSOR);
525 ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* had EM_DO_UNDO but op flag calls undo too [#24685] */
527 return OPERATOR_FINISHED;
530 static int editmode_toggle_poll(bContext *C)
532 Object *ob = CTX_data_active_object(C);
534 /* covers proxies too */
535 if(ELEM(NULL, ob, ob->data) || ((ID *)ob->data)->lib)
538 if (ob->restrictflag & OB_RESTRICT_VIEW)
541 return (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
542 ob->type == OB_FONT || ob->type == OB_MBALL ||
543 ob->type == OB_LATTICE || ob->type == OB_SURF ||
544 ob->type == OB_CURVE);
547 void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
551 ot->name= "Toggle Editmode";
552 ot->description = "Toggle object's editmode";
553 ot->idname= "OBJECT_OT_editmode_toggle";
556 ot->exec= editmode_toggle_exec;
558 ot->poll= editmode_toggle_poll;
561 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
564 /* *************************** */
566 static int posemode_exec(bContext *C, wmOperator *UNUSED(op))
568 Base *base= CTX_data_active_base(C);
570 if(base->object->type==OB_ARMATURE) {
571 if(base->object==CTX_data_edit_object(C)) {
572 ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
573 ED_armature_enter_posemode(C, base);
575 else if(base->object->mode & OB_MODE_POSE)
576 ED_armature_exit_posemode(C, base);
578 ED_armature_enter_posemode(C, base);
580 return OPERATOR_FINISHED;
583 return OPERATOR_PASS_THROUGH;
586 void OBJECT_OT_posemode_toggle(wmOperatorType *ot)
589 ot->name= "Toggle Pose Mode";
590 ot->idname= "OBJECT_OT_posemode_toggle";
591 ot->description= "Enables or disables posing/selecting bones";
594 ot->exec= posemode_exec;
595 ot->poll= ED_operator_object_active_editable;
598 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
601 /* *********************** */
604 // XXX should be in view3d?
606 /* context: ob = lamp */
607 /* code should be replaced with proper (custom) transform handles for lamp properties */
608 static void spot_interactive(Object *ob, int mode)
611 float transfac, dx, dy, ratio, origval;
612 int keep_running= 1, center2d[2];
613 int mval[2], mvalo[2];
615 // getmouseco_areawin(mval);
616 // getmouseco_areawin(mvalo);
618 project_int(ob->obmat[3], center2d);
619 if( center2d[0] > 100000 ) { /* behind camera */
620 // center2d[0]= curarea->winx/2;
621 // center2d[1]= curarea->winy/2;
624 // helpline(mval, center2d);
626 /* ratio is like scaling */
627 dx = (float)(center2d[0] - mval[0]);
628 dy = (float)(center2d[1] - mval[1]);
629 transfac = (float)sqrt( dx*dx + dy*dy);
630 if(transfac==0.0f) transfac= 1.0f;
633 origval= la->spotsize;
637 origval= la->clipsta;
639 origval= la->clipend;
641 while (keep_running>0) {
643 // getmouseco_areawin(mval);
645 /* essential for idling subloop */
646 if(mval[0]==mvalo[0] && mval[1]==mvalo[1]) {
652 dx = (float)(center2d[0] - mval[0]);
653 dy = (float)(center2d[1] - mval[1]);
654 ratio = (float)(sqrt( dx*dx + dy*dy))/transfac;
658 if(mode==1) { /* spot */
659 la->spotsize = ratio*origval;
660 CLAMP(la->spotsize, 1.0f, 180.0f);
661 sprintf(str, "Spot size %.2f\n", la->spotsize);
663 else if(mode==2) { /* dist */
664 la->dist = ratio*origval;
665 CLAMP(la->dist, 0.01f, 5000.0f);
666 sprintf(str, "Distance %.2f\n", la->dist);
668 else if(mode==3) { /* sta */
669 la->clipsta = ratio*origval;
670 CLAMP(la->clipsta, 0.001f, 5000.0f);
671 sprintf(str, "Distance %.2f\n", la->clipsta);
673 else if(mode==4) { /* end */
674 la->clipend = ratio*origval;
675 CLAMP(la->clipend, 0.1f, 5000.0f);
676 sprintf(str, "Clip End %.2f\n", la->clipend);
683 /* handle shaded mode */
684 // XXX shade_buttons_change_3d();
688 force_draw_plus(SPACE_BUTS, 0);
690 // helpline(mval, center2d);
695 unsigned short event= extern_qread(&val);
713 if(keep_running==0) {
715 la->spotsize= origval;
719 la->clipsta= origval;
721 la->clipend= origval;
727 static void UNUSED_FUNCTION(special_editmenu)(Scene *scene, View3D *v3d)
729 // XXX static short numcuts= 2;
731 Object *obedit= NULL; // XXX
738 if(ob->mode & OB_MODE_POSE) {
739 // XXX pose_special_editmenu();
741 else if(paint_facesel_test(ob)) {
742 Mesh *me= get_mesh(ob);
747 if(me==NULL || me->mtface==NULL) return;
749 nr= pupmenu("Specials%t|Set Tex%x1| Shared%x2| Light%x3| Invisible%x4| Collision%x5| TwoSide%x6|Clr Tex%x7| Shared%x8| Light%x9| Invisible%x10| Collision%x11| TwoSide%x12");
753 for(a=me->totface; a>0; a--, tface++, mface++) {
754 if(mface->flag & ME_FACE_SEL) {
757 tface->mode |= TF_TEX; break;
759 tface->mode |= TF_SHAREDCOL; break;
761 tface->mode |= TF_LIGHT; break;
763 tface->mode |= TF_INVISIBLE; break;
765 tface->mode |= TF_DYNAMIC; break;
767 tface->mode |= TF_TWOSIDE; break;
769 tface->mode &= ~TF_TEX;
773 tface->mode &= ~TF_SHAREDCOL; break;
775 tface->mode &= ~TF_LIGHT; break;
777 tface->mode &= ~TF_INVISIBLE; break;
779 tface->mode &= ~TF_DYNAMIC; break;
781 tface->mode &= ~TF_TWOSIDE; break;
785 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
787 else if(ob->mode & OB_MODE_VERTEX_PAINT) {
788 Mesh *me= get_mesh(ob);
790 if(me==NULL || (me->mcol==NULL && me->mtface==NULL) ) return;
792 nr= pupmenu("Specials%t|Shared VertexCol%x1");
795 // XXX do_shared_vertexcol(me);
797 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
800 else if(ob->mode & OB_MODE_WEIGHT_PAINT) {
801 Object *par= modifiers_isDeformedByArmature(ob);
803 if(par && (par->mode & OB_MODE_POSE)) {
804 nr= pupmenu("Specials%t|Apply Bone Envelopes to Vertex Groups %x1|Apply Bone Heat Weights to Vertex Groups %x2");
806 // XXX if(nr==1 || nr==2)
807 // XXX pose_adds_vgroups(ob, (nr == 2));
810 else if(ob->mode & OB_MODE_PARTICLE_EDIT) {
813 ParticleSystem *psys = PE_get_current(ob);
814 ParticleEditSettings *pset = PE_settings();
819 if(pset->selectmode & SCE_SELECT_POINT)
820 nr= pupmenu("Specials%t|Rekey%x1|Subdivide%x2|Select First%x3|Select Last%x4|Remove Doubles%x5");
822 nr= pupmenu("Specials%t|Rekey%x1|Remove Doubles%x5");
826 // XXX if(button(&pset->totrekey, 2, 100, "Number of Keys:")==0) return;
844 DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
846 if(nr>0) waitcursor(0);
850 Base *base, *base_select= NULL;
852 /* Get the active object mesh. */
853 Mesh *me= get_mesh(ob);
855 /* Booleans, if the active object is a mesh... */
856 if (me && ob->id.lib==NULL) {
858 /* Bring up a little menu with the boolean operation choices on. */
859 nr= pupmenu("Boolean Tools%t|Intersect%x1|Union%x2|Difference%x3|Add Intersect Modifier%x4|Add Union Modifier%x5|Add Difference Modifier%x6");
862 /* user has made a choice of a menu element.
863 All of the boolean functions require 2 mesh objects
864 we search through the object list to find the other
865 selected item and make sure it is distinct and a mesh. */
867 for(base= FIRSTBASE; base; base= base->next) {
868 if(TESTBASELIB(v3d, base)) {
869 if(base->object != ob) base_select= base;
874 if (get_mesh(base_select->object)) {
877 // XXX ret = NewBooleanMesh(BASACT,base_select,nr);
879 error("An internal error occurred");
881 error("Selected meshes must have faces to perform boolean operations");
882 } else if (ret==-2) {
883 error("Both meshes must be a closed mesh");
887 BooleanModifierData *bmd = NULL;
888 bmd = (BooleanModifierData *)modifier_new(eModifierType_Boolean);
889 BLI_addtail(&ob->modifiers, bmd);
890 modifier_unique_name(&ob->modifiers, (ModifierData*)bmd);
891 bmd->object = base_select->object;
892 bmd->modifier.mode |= eModifierMode_Realtime;
894 case 4: bmd->operation = eBooleanModifierOp_Intersect; break;
895 case 5: bmd->operation = eBooleanModifierOp_Union; break;
896 case 6: bmd->operation = eBooleanModifierOp_Difference; break;
898 // XXX do_common_editbuts(B_CHANGEDEP);
901 error("Please select 2 meshes");
904 error("Please select 2 meshes");
909 else if (ob->type == OB_FONT) {
910 /* removed until this gets a decent implementation (ton) */
911 /* nr= pupmenu("Split %t|Characters%x1");
914 case 1: split_font();
921 else if(obedit->type==OB_MESH) {
923 else if(ELEM(obedit->type, OB_CURVE, OB_SURF)) {
925 else if(obedit->type==OB_ARMATURE) {
926 nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Switch Direction%x7|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6");
928 // XXX subdivide_armature(1);
930 // XXX if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
932 // XXX subdivide_armature(numcuts);
935 // XXX armature_flip_names();
936 else if(ELEM3(nr, 4, 5, 6)) {
937 // XXX armature_autoside_names(nr-4);
940 // XXX switch_direction_armature();
942 else if(obedit->type==OB_LATTICE) {
943 Lattice *lt= obedit->data;
944 static float weight= 1.0f;
946 // XXX if(fbutton(&weight, 0.0f, 1.0f, 10, 10, "Set Weight")) {
947 Lattice *editlt= lt->editlatt->latt;
948 int a= editlt->pntsu*editlt->pntsv*editlt->pntsw;
949 BPoint *bp= editlt->def;
961 static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob)
963 //XXX no longer used - to be removed - replaced by game_properties_copy_exec
969 prop= ob->prop.first;
975 str= MEM_callocN(50 + 33*tot, "copymenu prop");
978 strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
980 strcpy(str, "Copy Property %t|Clear All (no properties on active)");
983 prop= ob->prop.first;
987 strcat(str, prop->name);
993 if ( nr==1 || nr==2 ) {
994 for(base= FIRSTBASE; base; base= base->next) {
995 if((base != BASACT) &&(TESTBASELIB(v3d, base))) {
996 if (nr==1) { /* replace */
997 copy_properties( &base->object->prop, &ob->prop );
999 for(prop = ob->prop.first; prop; prop= prop->next ) {
1000 set_ob_property(base->object, prop);
1006 prop = BLI_findlink(&ob->prop, nr-4); /* account for first 3 menu items & menu index starting at 1*/
1009 for(base= FIRSTBASE; base; base= base->next) {
1010 if((base != BASACT) &&(TESTBASELIB(v3d, base))) {
1011 set_ob_property(base->object, prop);
1020 static void copymenu_logicbricks(Scene *scene, View3D *v3d, Object *ob)
1022 //XXX no longer used - to be removed - replaced by logicbricks_copy_exec
1025 for(base= FIRSTBASE; base; base= base->next) {
1026 if(base->object != ob) {
1027 if(TESTBASELIB(v3d, base)) {
1029 /* first: free all logic */
1030 free_sensors(&base->object->sensors);
1031 unlink_controllers(&base->object->controllers);
1032 free_controllers(&base->object->controllers);
1033 unlink_actuators(&base->object->actuators);
1034 free_actuators(&base->object->actuators);
1036 /* now copy it, this also works without logicbricks! */
1037 clear_sca_new_poins_ob(ob);
1038 copy_sensors(&base->object->sensors, &ob->sensors);
1039 copy_controllers(&base->object->controllers, &ob->controllers);
1040 copy_actuators(&base->object->actuators, &ob->actuators);
1041 set_sca_new_poins_ob(base->object);
1043 /* some menu settings */
1044 base->object->scavisflag= ob->scavisflag;
1045 base->object->scaflag= ob->scaflag;
1047 /* set the initial state */
1048 base->object->state= ob->state;
1049 base->object->init_state= ob->init_state;
1055 /* both pointers should exist */
1056 static void copy_texture_space(Object *to, Object *ob)
1058 float *poin1= NULL, *poin2= NULL;
1061 if(ob->type==OB_MESH) {
1062 texflag= ((Mesh *)ob->data)->texflag;
1063 poin2= ((Mesh *)ob->data)->loc;
1065 else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
1066 texflag= ((Curve *)ob->data)->texflag;
1067 poin2= ((Curve *)ob->data)->loc;
1069 else if(ob->type==OB_MBALL) {
1070 texflag= ((MetaBall *)ob->data)->texflag;
1071 poin2= ((MetaBall *)ob->data)->loc;
1076 if(to->type==OB_MESH) {
1077 ((Mesh *)to->data)->texflag= texflag;
1078 poin1= ((Mesh *)to->data)->loc;
1080 else if (ELEM3(to->type, OB_CURVE, OB_SURF, OB_FONT)) {
1081 ((Curve *)to->data)->texflag= texflag;
1082 poin1= ((Curve *)to->data)->loc;
1084 else if(to->type==OB_MBALL) {
1085 ((MetaBall *)to->data)->texflag= texflag;
1086 poin1= ((MetaBall *)to->data)->loc;
1091 memcpy(poin1, poin2, 9*sizeof(float)); /* this was noted in DNA_mesh, curve, mball */
1093 if(to->type==OB_MESH) ;
1094 else if(to->type==OB_MBALL) tex_space_mball(to);
1095 else tex_space_curve(to->data);
1099 /* UNUSED, keep incase we want to copy functionality for use elsewhere */
1100 static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
1106 int do_scene_sort= 0;
1108 if(scene->id.lib) return;
1110 if(!(ob=OBACT)) return;
1112 if(scene->obedit) { // XXX get from context
1113 /* obedit_copymenu(); */
1117 copymenu_properties(scene, v3d, ob);
1120 else if(event==10) {
1121 copymenu_logicbricks(scene, v3d, ob);
1124 else if(event==24) {
1125 /* moved to object_link_modifiers */
1126 /* copymenu_modifiers(bmain, scene, v3d, ob); */
1130 for(base= FIRSTBASE; base; base= base->next) {
1131 if(base != BASACT) {
1132 if(TESTBASELIB(v3d, base)) {
1133 base->object->recalc |= OB_RECALC_OB;
1135 if(event==1) { /* loc */
1136 VECCOPY(base->object->loc, ob->loc);
1137 VECCOPY(base->object->dloc, ob->dloc);
1139 else if(event==2) { /* rot */
1140 VECCOPY(base->object->rot, ob->rot);
1141 VECCOPY(base->object->drot, ob->drot);
1143 QUATCOPY(base->object->quat, ob->quat);
1144 QUATCOPY(base->object->dquat, ob->dquat);
1146 else if(event==3) { /* size */
1147 VECCOPY(base->object->size, ob->size);
1148 VECCOPY(base->object->dsize, ob->dsize);
1150 else if(event==4) { /* drawtype */
1151 base->object->dt= ob->dt;
1152 base->object->dtx= ob->dtx;
1153 base->object->empty_drawtype= ob->empty_drawtype;
1154 base->object->empty_drawsize= ob->empty_drawsize;
1156 else if(event==5) { /* time offs */
1157 base->object->sf= ob->sf;
1159 else if(event==6) { /* dupli */
1160 base->object->dupon= ob->dupon;
1161 base->object->dupoff= ob->dupoff;
1162 base->object->dupsta= ob->dupsta;
1163 base->object->dupend= ob->dupend;
1165 base->object->transflag &= ~OB_DUPLI;
1166 base->object->transflag |= (ob->transflag & OB_DUPLI);
1168 base->object->dup_group= ob->dup_group;
1170 id_lib_extern(&ob->dup_group->id);
1172 else if(event==7) { /* mass */
1173 base->object->mass= ob->mass;
1175 else if(event==8) { /* damping */
1176 base->object->damping= ob->damping;
1177 base->object->rdamping= ob->rdamping;
1179 else if(event==11) { /* all physical attributes */
1180 base->object->gameflag = ob->gameflag;
1181 base->object->inertia = ob->inertia;
1182 base->object->formfactor = ob->formfactor;
1183 base->object->damping= ob->damping;
1184 base->object->rdamping= ob->rdamping;
1185 base->object->min_vel= ob->min_vel;
1186 base->object->max_vel= ob->max_vel;
1187 if (ob->gameflag & OB_BOUNDS) {
1188 base->object->boundtype = ob->boundtype;
1190 base->object->margin= ob->margin;
1191 base->object->bsoft= copy_bulletsoftbody(ob->bsoft);
1194 else if(event==17) { /* tex space */
1195 copy_texture_space(base->object, ob);
1197 else if(event==18) { /* font settings */
1199 if(base->object->type==ob->type) {
1201 cu1= base->object->data;
1203 cu1->spacemode= cu->spacemode;
1204 cu1->spacing= cu->spacing;
1205 cu1->linedist= cu->linedist;
1206 cu1->shear= cu->shear;
1207 cu1->fsize= cu->fsize;
1210 cu1->textoncurve= cu->textoncurve;
1211 cu1->wordspace= cu->wordspace;
1212 cu1->ulpos= cu->ulpos;
1213 cu1->ulheight= cu->ulheight;
1214 if(cu1->vfont) cu1->vfont->id.us--;
1215 cu1->vfont= cu->vfont;
1216 id_us_plus((ID *)cu1->vfont);
1217 if(cu1->vfontb) cu1->vfontb->id.us--;
1218 cu1->vfontb= cu->vfontb;
1219 id_us_plus((ID *)cu1->vfontb);
1220 if(cu1->vfonti) cu1->vfonti->id.us--;
1221 cu1->vfonti= cu->vfonti;
1222 id_us_plus((ID *)cu1->vfonti);
1223 if(cu1->vfontbi) cu1->vfontbi->id.us--;
1224 cu1->vfontbi= cu->vfontbi;
1225 id_us_plus((ID *)cu1->vfontbi);
1227 BKE_text_to_curve(scene, base->object, 0); /* needed? */
1230 BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
1232 base->object->recalc |= OB_RECALC_DATA;
1235 else if(event==19) { /* bevel settings */
1237 if(ELEM(base->object->type, OB_CURVE, OB_FONT)) {
1239 cu1= base->object->data;
1241 cu1->bevobj= cu->bevobj;
1242 cu1->taperobj= cu->taperobj;
1243 cu1->width= cu->width;
1244 cu1->bevresol= cu->bevresol;
1245 cu1->ext1= cu->ext1;
1246 cu1->ext2= cu->ext2;
1248 base->object->recalc |= OB_RECALC_DATA;
1251 else if(event==25) { /* curve resolution */
1253 if(ELEM(base->object->type, OB_CURVE, OB_FONT)) {
1255 cu1= base->object->data;
1257 cu1->resolu= cu->resolu;
1258 cu1->resolu_ren= cu->resolu_ren;
1260 nu= cu1->nurb.first;
1263 nu->resolu= cu1->resolu;
1267 base->object->recalc |= OB_RECALC_DATA;
1271 if (base->object->type==OB_MESH) {
1272 ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);
1275 ModifierData *tmd = modifiers_findByType(base->object, eModifierType_Subsurf);
1278 tmd = modifier_new(eModifierType_Subsurf);
1279 BLI_addtail(&base->object->modifiers, tmd);
1282 modifier_copyData(md, tmd);
1283 base->object->recalc |= OB_RECALC_DATA;
1287 else if(event==22) {
1288 /* Copy the constraint channels over */
1289 copy_constraints(&base->object->constraints, &ob->constraints, TRUE);
1293 else if(event==23) {
1294 base->object->softflag= ob->softflag;
1295 if(base->object->soft) sbFree(base->object->soft);
1297 base->object->soft= copy_softbody(ob->soft);
1299 if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
1300 BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));
1303 else if(event==26) {
1304 #if 0 // XXX old animation system
1305 copy_nlastrips(&base->object->nlastrips, &ob->nlastrips);
1306 #endif // XXX old animation system
1308 else if(event==27) { /* autosmooth */
1309 if (base->object->type==OB_MESH) {
1311 Mesh *cme= base->object->data;
1312 cme->smoothresh= me->smoothresh;
1313 if(me->flag & ME_AUTOSMOOTH)
1314 cme->flag |= ME_AUTOSMOOTH;
1316 cme->flag &= ~ME_AUTOSMOOTH;
1319 else if(event==28) { /* UV orco */
1320 if(ELEM(base->object->type, OB_CURVE, OB_SURF)) {
1322 cu1= base->object->data;
1324 if(cu->flag & CU_UV_ORCO)
1325 cu1->flag |= CU_UV_ORCO;
1327 cu1->flag &= ~CU_UV_ORCO;
1330 else if(event==29) { /* protected bits */
1331 base->object->protectflag= ob->protectflag;
1333 else if(event==30) { /* index object */
1334 base->object->index= ob->index;
1336 else if(event==31) { /* object color */
1337 QUATCOPY(base->object->col, ob->col);
1344 DAG_scene_sort(bmain, scene);
1346 DAG_ids_flush_update(bmain, 0);
1349 static void UNUSED_FUNCTION(copy_attr_menu)(Main *bmain, Scene *scene, View3D *v3d)
1355 if(!(ob=OBACT)) return;
1357 if (scene->obedit) { // XXX get from context
1358 // if (ob->type == OB_MESH)
1359 // XXX mesh_copy_menu();
1365 /* If you change this menu, don't forget to update the menu in header_view3d.c
1366 * view3d_edit_object_copyattrmenu() and in toolbox.c
1369 strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|Time Offset%x5|Dupli%x6|Object Color%x31|%l|Mass%x7|Damping%x8|All Physical Attributes%x11|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l");
1371 strcat (str, "|Object Constraints%x22");
1372 strcat (str, "|NLA Strips%x26");
1374 // XXX if (OB_SUPPORT_MATERIAL(ob)) {
1375 // strcat(str, "|Texture Space%x17");
1378 if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
1379 if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19|UV Orco%x28");
1381 if((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
1382 strcat(str, "|Curve Resolution%x25");
1385 if(ob->type==OB_MESH){
1386 strcat(str, "|Subsurf Settings%x21|AutoSmooth%x27");
1389 if(ob->soft) strcat(str, "|Soft Body Settings%x23");
1391 strcat(str, "|Pass Index%x30");
1393 if(ob->type==OB_MESH || ob->type==OB_CURVE || ob->type==OB_LATTICE || ob->type==OB_SURF){
1394 strcat(str, "|Modifiers ...%x24");
1397 event= pupmenu(str);
1398 if(event<= 0) return;
1400 copy_attr(bmain, scene, v3d, event);
1403 /* ******************* force field toggle operator ***************** */
1405 static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
1407 Object *ob = CTX_data_active_object(C);
1410 ob->pd = object_add_collision_fields(PFIELD_FORCE);
1412 if(ob->pd->forcefield == 0)
1413 ob->pd->forcefield = PFIELD_FORCE;
1415 ob->pd->forcefield = 0;
1417 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, NULL);
1419 return OPERATOR_FINISHED;
1422 void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
1426 ot->name= "Toggle Force Field";
1427 ot->description = "Toggle object's force field";
1428 ot->idname= "OBJECT_OT_forcefield_toggle";
1431 ot->exec= forcefield_toggle_exec;
1432 ot->poll= ED_operator_object_active_editable;
1435 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1438 /* ********************************************** */
1441 /* For the object with pose/action: update paths for those that have got them
1442 * This should selectively update paths that exist...
1444 * To be called from various tools that do incremental updates
1446 void ED_objects_recalculate_paths(bContext *C, Scene *scene)
1448 ListBase targets = {NULL, NULL};
1450 /* loop over objects in scene */
1451 CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
1453 /* set flag to force recalc, then grab the relevant bones to target */
1454 ob->avs.recalc |= ANIMVIZ_RECALC_PATHS;
1455 animviz_get_object_motionpaths(ob, &targets);
1459 /* recalculate paths, then free */
1460 animviz_calc_motionpaths(scene, &targets);
1461 BLI_freelistN(&targets);
1464 /* For the object with pose/action: create path curves for selected bones
1465 * This recalculates the WHOLE path within the pchan->pathsf and pchan->pathef range
1467 static int object_calculate_paths_exec (bContext *C, wmOperator *UNUSED(op))
1469 Scene *scene= CTX_data_scene(C);
1471 /* set up path data for bones being calculated */
1472 CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
1474 /* verify makes sure that the selected bone has a bone with the appropriate settings */
1475 animviz_verify_motionpaths(scene, ob, NULL);
1479 /* calculate the bones that now have motionpaths... */
1480 // TODO: only make for the selected bones?
1481 ED_objects_recalculate_paths(C, scene);
1483 /* notifiers for updates */
1484 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
1486 return OPERATOR_FINISHED;
1489 void OBJECT_OT_paths_calculate (wmOperatorType *ot)
1492 ot->name= "Calculate Object Paths";
1493 ot->idname= "OBJECT_OT_paths_calculate";
1494 ot->description= "Calculate paths for the selected bones";
1497 ot->exec= object_calculate_paths_exec;
1498 ot->poll= ED_operator_object_active_editable;
1501 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1506 /* for the object with pose/action: clear path curves for selected bones only */
1507 void ED_objects_clear_paths(bContext *C)
1509 /* loop over objects in scene */
1510 CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects)
1513 animviz_free_motionpath(ob->mpath);
1515 ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS;
1521 /* operator callback for this */
1522 static int object_clear_paths_exec (bContext *C, wmOperator *UNUSED(op))
1524 /* use the backend function for this */
1525 ED_objects_clear_paths(C);
1527 /* notifiers for updates */
1528 WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
1530 return OPERATOR_FINISHED;
1533 void OBJECT_OT_paths_clear (wmOperatorType *ot)
1536 ot->name= "Clear Object Paths";
1537 ot->idname= "OBJECT_OT_paths_clear";
1538 ot->description= "Clear path caches for selected bones";
1541 ot->exec= object_clear_paths_exec;
1542 ot->poll= ED_operator_object_active_editable;
1545 ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
1549 /********************** Smooth/Flat *********************/
1551 static int shade_smooth_exec(bContext *C, wmOperator *op)
1555 int clear= (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0);
1558 CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
1560 if(ob->type==OB_MESH) {
1561 mesh_set_smooth_flag(ob, !clear);
1563 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1564 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
1568 else if ELEM(ob->type, OB_SURF, OB_CURVE) {
1571 for(nu=cu->nurb.first; nu; nu=nu->next) {
1572 if(!clear) nu->flag |= ME_SMOOTH;
1573 else nu->flag &= ~ME_SMOOTH;
1576 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
1577 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
1584 return (done)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
1587 static int shade_poll(bContext *C)
1589 return (ED_operator_object_active_editable(C) && !ED_operator_editmesh(C));
1592 void OBJECT_OT_shade_flat(wmOperatorType *ot)
1595 ot->name= "Shade Flat";
1596 ot->description= "Display faces 'flat'";
1597 ot->idname= "OBJECT_OT_shade_flat";
1600 ot->poll= shade_poll;
1601 ot->exec= shade_smooth_exec;
1604 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1607 void OBJECT_OT_shade_smooth(wmOperatorType *ot)
1610 ot->name= "Shade Smooth";
1611 ot->description= "Display faces 'smooth' (using vertex normals)";
1612 ot->idname= "OBJECT_OT_shade_smooth";
1615 ot->poll= shade_poll;
1616 ot->exec= shade_smooth_exec;
1619 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1622 /* ********************** */
1624 static void UNUSED_FUNCTION(image_aspect)(Scene *scene, View3D *v3d)
1626 /* all selected objects with an image map: scale in image aspect */
1634 if(scene->obedit) return; // XXX get from context
1635 if(scene->id.lib) return;
1637 for(base= FIRSTBASE; base; base= base->next) {
1638 if(TESTBASELIB(v3d, base)) {
1642 for(a=1; a<=ob->totcol; a++) {
1643 ma= give_current_material(ob, a);
1645 for(b=0; b<MAX_MTEX; b++) {
1646 if(ma->mtex[b] && ma->mtex[b]->tex) {
1647 tex= ma->mtex[b]->tex;
1648 if(tex->type==TEX_IMAGE && tex->ima) {
1649 ImBuf *ibuf= BKE_image_get_ibuf(tex->ima, NULL);
1653 if(ob->type==OB_MESH) {
1655 mesh_get_texspace(ob->data, NULL, NULL, size);
1656 space= size[0]/size[1];
1658 else if(ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
1659 Curve *cu= ob->data;
1660 space= cu->size[0]/cu->size[1];
1666 if(x>y) ob->size[0]= ob->size[1]*x/y;
1667 else ob->size[1]= ob->size[0]*y/x;
1670 DAG_id_tag_update(&ob->id, OB_RECALC_OB);
1683 static int vergbaseco(const void *a1, const void *a2)
1690 if( (*x1)->sy > (*x2)->sy ) return 1;
1691 else if( (*x1)->sy < (*x2)->sy) return -1;
1692 else if( (*x1)->sx > (*x2)->sx ) return 1;
1693 else if( (*x1)->sx < (*x2)->sx ) return -1;
1699 static void UNUSED_FUNCTION(auto_timeoffs)(Scene *scene, View3D *v3d)
1701 Base *base, **basesort, **bs;
1706 if(BASACT==NULL || v3d==NULL) return;
1707 // XXX if(button(&offset, 0, 1000,"Total time")==0) return;
1709 /* make array of all bases, xco yco (screen) */
1710 for(base= FIRSTBASE; base; base= base->next) {
1711 if(TESTBASELIB(v3d, base)) {
1716 delta= (float)offset/(float)tot;
1719 bs= basesort= MEM_mallocN(sizeof(void *)*tot,"autotimeoffs");
1720 for(base= FIRSTBASE; base; base= base->next) {
1721 if(TESTBASELIB(v3d, base)) {
1726 qsort(basesort, tot, sizeof(void *), vergbaseco);
1729 for(a=0; a<tot; a++) {
1731 (*bs)->object->sf= start;
1736 MEM_freeN(basesort);
1740 static void UNUSED_FUNCTION(ofs_timeoffs)(Scene *scene, View3D *v3d)
1744 if(BASACT==NULL || v3d==NULL) return;
1746 // XXX if(fbutton(&offset, -10000.0f, 10000.0f, 10, 10, "Offset")==0) return;
1748 /* make array of all bases, xco yco (screen) */
1749 CTX_DATA_BEGIN(evil_C, Object*, ob, selected_editable_objects) {
1751 if (ob->sf < -MAXFRAMEF) ob->sf = -MAXFRAMEF;
1752 else if (ob->sf > MAXFRAMEF) ob->sf = MAXFRAMEF;
1759 static void UNUSED_FUNCTION(rand_timeoffs)(Scene *scene, View3D *v3d)
1762 float rand_ofs=0.0f;
1764 if(BASACT==NULL || v3d==NULL) return;
1766 // XXX if(fbutton(&rand_ofs, 0.0f, 10000.0f, 10, 10, "Randomize")==0) return;
1770 for(base= FIRSTBASE; base; base= base->next) {
1771 if(TESTBASELIB(v3d, base)) {
1772 base->object->sf += ((float)BLI_drand()-0.5f) * rand_ofs;
1773 if (base->object->sf < -MAXFRAMEF) base->object->sf = -MAXFRAMEF;
1774 else if (base->object->sf > MAXFRAMEF) base->object->sf = MAXFRAMEF;
1780 static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
1782 EnumPropertyItem *input = object_mode_items;
1783 EnumPropertyItem *item= NULL;
1787 if(!C) /* needed for docs */
1788 return object_mode_items;
1790 ob = CTX_data_active_object(C);
1791 while(ob && input->identifier) {
1792 if((input->value == OB_MODE_EDIT && ((ob->type == OB_MESH) || (ob->type == OB_ARMATURE) ||
1793 (ob->type == OB_CURVE) || (ob->type == OB_SURF) ||
1794 (ob->type == OB_FONT) || (ob->type == OB_MBALL) || (ob->type == OB_LATTICE))) ||
1795 (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
1796 (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) ||
1797 ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT ||
1798 input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
1799 (input->value == OB_MODE_OBJECT))
1800 RNA_enum_item_add(&item, &totitem, input);
1804 RNA_enum_item_end(&item, &totitem);
1811 static const char *object_mode_op_string(int mode)
1813 if(mode & OB_MODE_EDIT)
1814 return "OBJECT_OT_editmode_toggle";
1815 if(mode == OB_MODE_SCULPT)
1816 return "SCULPT_OT_sculptmode_toggle";
1817 if(mode == OB_MODE_VERTEX_PAINT)
1818 return "PAINT_OT_vertex_paint_toggle";
1819 if(mode == OB_MODE_WEIGHT_PAINT)
1820 return "PAINT_OT_weight_paint_toggle";
1821 if(mode == OB_MODE_TEXTURE_PAINT)
1822 return "PAINT_OT_texture_paint_toggle";
1823 if(mode == OB_MODE_PARTICLE_EDIT)
1824 return "PARTICLE_OT_particle_edit_toggle";
1825 if(mode == OB_MODE_POSE)
1826 return "OBJECT_OT_posemode_toggle";
1830 /* checks the mode to be set is compatible with the object
1831 * should be made into a generic function */
1832 static int object_mode_set_compat(bContext *UNUSED(C), wmOperator *op, Object *ob)
1834 ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1836 if(mode == OB_MODE_OBJECT)
1847 if(mode & (OB_MODE_EDIT|OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT|OB_MODE_PARTICLE_EDIT))
1854 if(mode & (OB_MODE_OBJECT|OB_MODE_EDIT))
1858 if(mode & (OB_MODE_OBJECT|OB_MODE_EDIT|OB_MODE_WEIGHT_PAINT))
1861 if(mode & (OB_MODE_OBJECT|OB_MODE_EDIT|OB_MODE_POSE))
1869 static int object_mode_set_exec(bContext *C, wmOperator *op)
1871 Object *ob= CTX_data_active_object(C);
1872 ObjectMode mode = RNA_enum_get(op->ptr, "mode");
1873 ObjectMode restore_mode = (ob) ? ob->mode : OB_MODE_OBJECT;
1874 int toggle = RNA_boolean_get(op->ptr, "toggle");
1876 if(!ob || !object_mode_set_compat(C, op, ob))
1877 return OPERATOR_CANCELLED;
1879 /* Exit current mode if it's not the mode we're setting */
1880 if(ob->mode != OB_MODE_OBJECT && ob->mode != mode)
1881 WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL);
1883 if(mode != OB_MODE_OBJECT) {
1884 /* Enter new mode */
1885 if(ob->mode != mode || toggle)
1886 WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL);
1889 if(ob->mode == mode)
1890 /* For toggling, store old mode so we know what to go back to */
1891 ob->restore_mode = restore_mode;
1892 else if(ob->restore_mode != OB_MODE_OBJECT && ob->restore_mode != mode) {
1893 WM_operator_name_call(C, object_mode_op_string(ob->restore_mode), WM_OP_EXEC_REGION_WIN, NULL);
1898 return OPERATOR_FINISHED;
1901 void OBJECT_OT_mode_set(wmOperatorType *ot)
1906 ot->name= "Set Object Mode";
1907 ot->description = "Sets the object interaction mode";
1908 ot->idname= "OBJECT_OT_mode_set";
1911 ot->exec= object_mode_set_exec;
1913 ot->poll= ED_operator_object_active_editable;
1916 ot->flag= 0; /* no register/undo here, leave it to operators being called */
1918 prop= RNA_def_enum(ot->srna, "mode", object_mode_items, 0, "Mode", "");
1919 RNA_def_enum_funcs(prop, object_mode_set_itemsf);
1921 RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
1926 void ED_object_toggle_modes(bContext *C, int mode)
1928 if(mode & OB_MODE_SCULPT)
1929 WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1930 if(mode & OB_MODE_VERTEX_PAINT)
1931 WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1932 if(mode & OB_MODE_WEIGHT_PAINT)
1933 WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1934 if(mode & OB_MODE_TEXTURE_PAINT)
1935 WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1936 if(mode & OB_MODE_PARTICLE_EDIT)
1937 WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1938 if(mode & OB_MODE_POSE)
1939 WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1940 if(mode & OB_MODE_EDIT)
1941 WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
1944 /************************ Game Properties ***********************/
1946 static int game_property_new(bContext *C, wmOperator *UNUSED(op))
1948 Object *ob= CTX_data_active_object(C);
1952 return OPERATOR_CANCELLED;
1954 prop= new_property(PROP_FLOAT);
1955 BLI_addtail(&ob->prop, prop);
1956 unique_property(NULL, prop, 0); // make_unique_prop_names(prop->name);
1958 WM_event_add_notifier(C, NC_LOGIC, NULL);
1959 return OPERATOR_FINISHED;
1963 void OBJECT_OT_game_property_new(wmOperatorType *ot)
1966 ot->name= "New Game Property";
1967 ot->description= "Create a new property available to the game engine";
1968 ot->idname= "OBJECT_OT_game_property_new";
1971 ot->exec= game_property_new;
1972 ot->poll= ED_operator_object_active_editable;
1975 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
1978 static int game_property_remove(bContext *C, wmOperator *op)
1980 Object *ob= CTX_data_active_object(C);
1982 int index= RNA_int_get(op->ptr, "index");
1985 return OPERATOR_CANCELLED;
1987 prop= BLI_findlink(&ob->prop, index);
1990 BLI_remlink(&ob->prop, prop);
1991 free_property(prop);
1993 WM_event_add_notifier(C, NC_LOGIC, NULL);
1994 return OPERATOR_FINISHED;
1997 return OPERATOR_CANCELLED;
2001 void OBJECT_OT_game_property_remove(wmOperatorType *ot)
2004 ot->name= "Remove Game Property";
2005 ot->description= "Remove game property";
2006 ot->idname= "OBJECT_OT_game_property_remove";
2009 ot->exec= game_property_remove;
2010 ot->poll= ED_operator_object_active_editable;
2013 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2015 RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
2018 #define COPY_PROPERTIES_REPLACE 1
2019 #define COPY_PROPERTIES_MERGE 2
2020 #define COPY_PROPERTIES_COPY 3
2022 static EnumPropertyItem game_properties_copy_operations[] ={
2023 {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
2024 {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
2025 {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
2026 {0, NULL, 0, NULL, NULL}};
2028 static EnumPropertyItem gameprops_items[]= {
2029 {0, NULL, 0, NULL, NULL}};
2031 static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
2033 Object *ob= ED_object_active_context(C);
2034 EnumPropertyItem tmp = {0, "", 0, "", ""};
2035 EnumPropertyItem *item= NULL;
2040 return gameprops_items;
2042 for(a=1, prop= ob->prop.first; prop; prop=prop->next, a++) {
2044 tmp.identifier= prop->name;
2045 tmp.name= prop->name;
2046 RNA_enum_item_add(&item, &totitem, &tmp);
2049 RNA_enum_item_end(&item, &totitem);
2055 static int game_property_copy_exec(bContext *C, wmOperator *op)
2057 Object *ob=ED_object_active_context(C);
2059 int type = RNA_enum_get(op->ptr, "operation");
2060 int propid= RNA_enum_get(op->ptr, "property");
2062 if(propid > 0) { /* copy */
2063 prop = BLI_findlink(&ob->prop, propid-1);
2066 CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
2067 if (ob != ob_iter) {
2068 if (ob->data != ob_iter->data)
2069 set_ob_property(ob_iter, prop);
2076 CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
2077 if (ob != ob_iter) {
2078 if (ob->data != ob_iter->data){
2079 if (type == COPY_PROPERTIES_REPLACE)
2080 copy_properties( &ob_iter->prop, &ob->prop );
2082 /* merge - the default when calling with no argument */
2084 for(prop = ob->prop.first; prop; prop= prop->next ) {
2085 set_ob_property(ob_iter, prop);
2094 return OPERATOR_FINISHED;
2097 void OBJECT_OT_game_property_copy(wmOperatorType *ot)
2101 ot->name= "Copy Game Property";
2102 ot->idname= "OBJECT_OT_game_property_copy";
2105 ot->exec= game_property_copy_exec;
2106 ot->poll= ED_operator_object_active_editable;
2109 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2111 RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
2112 prop=RNA_def_enum(ot->srna, "property", gameprops_items, 0, "Property", "Properties to copy");
2113 RNA_def_enum_funcs(prop, gameprops_itemf);
2117 static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op))
2119 CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
2120 free_properties(&ob_iter->prop);
2124 WM_event_add_notifier(C, NC_LOGIC, NULL);
2125 return OPERATOR_FINISHED;
2127 void OBJECT_OT_game_property_clear(wmOperatorType *ot)
2130 ot->name= "Clear Game Property";
2131 ot->idname= "OBJECT_OT_game_property_clear";
2134 ot->exec= game_property_clear_exec;
2135 ot->poll= ED_operator_object_active_editable;
2138 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
2141 /************************ Copy Logic Bricks ***********************/
2143 static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op))
2145 Object *ob=ED_object_active_context(C);
2147 CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
2149 /* first: free all logic */
2150 free_sensors(&ob_iter->sensors);
2151 unlink_controllers(&ob_iter->controllers);
2152 free_controllers(&ob_iter->controllers);
2153 unlink_actuators(&ob_iter->actuators);
2154 free_actuators(&ob_iter->actuators);
2156 /* now copy it, this also works without logicbricks! */
2157 clear_sca_new_poins_ob(ob);
2158 copy_sensors(&ob_iter->sensors, &ob->sensors);
2159 copy_controllers(&ob_iter->controllers, &ob->controllers);
2160 copy_actuators(&ob_iter->actuators, &ob->actuators);
2161 set_sca_new_poins_ob(ob_iter);
2163 /* some menu settings */
2164 ob_iter->scavisflag= ob->scavisflag;
2165 ob_iter->scaflag= ob->scaflag;
2167 /* set the initial state */
2168 ob_iter->state= ob->state;
2169 ob_iter->init_state= ob->init_state;
2171 if(ob_iter->totcol==ob->totcol) {
2172 ob_iter->actcol= ob->actcol;
2173 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_iter);
2179 WM_event_add_notifier(C, NC_LOGIC, NULL);
2181 return OPERATOR_FINISHED;
2184 void OBJECT_OT_logic_bricks_copy(wmOperatorType *ot)
2187 ot->name= "Copy Logic Bricks to Selected";
2188 ot->description = "Copy logic bricks to other selected objects.";
2189 ot->idname= "OBJECT_OT_logic_bricks_copy";
2192 ot->exec= logicbricks_copy_exec;
2193 ot->poll= ED_operator_object_active_editable;
2196 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;