diff --git a/release/scripts/ui/properties_physics_cloth.py b/release/scripts/ui/properties_physics_cloth.py index 26670438b3f..f33804c4c6d 100644 --- a/release/scripts/ui/properties_physics_cloth.py +++ b/release/scripts/ui/properties_physics_cloth.py @@ -47,7 +47,7 @@ class PhysicButtonsPanel(): def poll(cls, context): ob = context.object rd = context.scene.render - return (ob and ob.type == 'MESH') and (not rd.use_game_engine) + return (ob and ob.type == 'MESH') and (not rd.use_game_engine) and (context.cloth) class PHYSICS_PT_cloth(PhysicButtonsPanel, bpy.types.Panel): @@ -59,21 +59,6 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, bpy.types.Panel): md = context.cloth ob = context.object - split = layout.split() - - if md: - # remove modifier + settings - split.context_pointer_set("modifier", md) - split.operator("object.modifier_remove", text="Remove") - - row = split.row(align=True) - row.prop(md, "show_render", text="") - row.prop(md, "show_viewport", text="") - else: - # add modifier - split.operator("object.modifier_add", text="Add").type = 'CLOTH' - split.label() - if md: cloth = md.settings diff --git a/release/scripts/ui/properties_physics_common.py b/release/scripts/ui/properties_physics_common.py index 71bf8ae9590..30b9061e982 100644 --- a/release/scripts/ui/properties_physics_common.py +++ b/release/scripts/ui/properties_physics_common.py @@ -20,8 +20,59 @@ import bpy -#cachetype can be 'PSYS' 'HAIR' 'SMOKE' etc +class PhysicButtonsPanel(): + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = "physics" + @classmethod + def poll(cls, context): + rd = context.scene.render + return (context.object) and (not rd.use_game_engine) + +def physics_add(self, layout, md, name, type, typeicon, toggles): + sub = layout.row(align=True) + if md: + sub.context_pointer_set("modifier", md) + sub.operator("object.modifier_remove", text=name, icon='X') + if(toggles): + sub.prop(md, "show_render", text="") + sub.prop(md, "show_viewport", text="") + else: + sub.operator("object.modifier_add", text=name, icon=typeicon).type = type + +class PHYSICS_PT_add(PhysicButtonsPanel, bpy.types.Panel): + bl_label = "" + bl_options = {'HIDE_HEADER'} + + def draw(self, context): + ob = context.object + + layout = self.layout + layout.label("Enable physics for:") + split = layout.split() + col = split.column() + + if(context.object.field.type == 'NONE'): + col.operator("object.forcefield_toggle", text="Force Field", icon='FORCE_FORCE') + else: + col.operator("object.forcefield_toggle", text="Force Field", icon='X') + + if(ob.type == 'MESH'): + physics_add(self, col, context.collision, "Collision", 'COLLISION', 'MOD_PHYSICS', False); + physics_add(self, col, context.cloth, "Cloth", 'CLOTH', 'MOD_CLOTH', True); + + col = split.column() + + if(ob.type == 'MESH' or ob.type == 'LATTICE'or ob.type == 'CURVE'): + physics_add(self, col, context.soft_body, "Soft Body", 'SOFT_BODY', 'MOD_SOFT', True); + + if(ob.type == 'MESH'): + physics_add(self, col, context.fluid, "Fluid", 'FLUID_SIMULATION', 'MOD_FLUIDSIM', True); + physics_add(self, col, context.smoke, "Smoke", 'SMOKE', 'MOD_SMOKE', True); + + +#cachetype can be 'PSYS' 'HAIR' 'SMOKE' etc def point_cache_ui(self, context, cache, enabled, cachetype): layout = self.layout diff --git a/release/scripts/ui/properties_physics_field.py b/release/scripts/ui/properties_physics_field.py index b5005a78c01..584cdaad108 100644 --- a/release/scripts/ui/properties_physics_field.py +++ b/release/scripts/ui/properties_physics_field.py @@ -37,6 +37,12 @@ class PhysicButtonsPanel(): class PHYSICS_PT_field(PhysicButtonsPanel, bpy.types.Panel): bl_label = "Force Fields" + + @classmethod + def poll(cls, context): + ob = context.object + rd = context.scene.render + return (not rd.use_game_engine) and (ob.field) and (ob.field.type != 'NONE') def draw(self, context): layout = self.layout @@ -164,7 +170,7 @@ class PHYSICS_PT_collision(PhysicButtonsPanel, bpy.types.Panel): def poll(cls, context): ob = context.object rd = context.scene.render - return (ob and ob.type == 'MESH') and (not rd.use_game_engine) + return (ob and ob.type == 'MESH') and (not rd.use_game_engine) and (context.collision) def draw(self, context): layout = self.layout @@ -173,24 +179,7 @@ class PHYSICS_PT_collision(PhysicButtonsPanel, bpy.types.Panel): split = layout.split() - if md: - # remove modifier + settings - split.context_pointer_set("modifier", md) - split.operator("object.modifier_remove", text="Remove") - col = split.column() - - #row = split.row(align=True) - #row.prop(md, "show_render", text="") - #row.prop(md, "show_viewport", text="") - - coll = md.settings - - else: - # add modifier - split.operator("object.modifier_add", text="Add").type = 'COLLISION' - split.label() - - coll = None + coll = md.settings if coll: settings = context.object.collision diff --git a/release/scripts/ui/properties_physics_fluid.py b/release/scripts/ui/properties_physics_fluid.py index 177d1c54746..88eb926dfa0 100644 --- a/release/scripts/ui/properties_physics_fluid.py +++ b/release/scripts/ui/properties_physics_fluid.py @@ -29,7 +29,7 @@ class PhysicButtonsPanel(): def poll(cls, context): ob = context.object rd = context.scene.render - return (ob and ob.type == 'MESH') and (not rd.use_game_engine) + return (ob and ob.type == 'MESH') and (not rd.use_game_engine) and (context.fluid) class PHYSICS_PT_fluid(PhysicButtonsPanel, bpy.types.Panel): @@ -40,25 +40,9 @@ class PHYSICS_PT_fluid(PhysicButtonsPanel, bpy.types.Panel): md = context.fluid - split = layout.split() - if md: - # remove modifier + settings - split.context_pointer_set("modifier", md) - split.operator("object.modifier_remove", text="Remove") - - row = split.row(align=True) - row.prop(md, "show_render", text="") - row.prop(md, "show_viewport", text="") - fluid = md.settings - - else: - # add modifier - split.operator("object.modifier_add", text="Add").type = 'FLUID_SIMULATION' - split.label() - - if md: + row = layout.row() if fluid is None: row.label("built without fluids") diff --git a/release/scripts/ui/properties_physics_smoke.py b/release/scripts/ui/properties_physics_smoke.py index 71dd47fe524..0ca5f03f832 100644 --- a/release/scripts/ui/properties_physics_smoke.py +++ b/release/scripts/ui/properties_physics_smoke.py @@ -33,7 +33,7 @@ class PhysicButtonsPanel(): def poll(cls, context): ob = context.object rd = context.scene.render - return (ob and ob.type == 'MESH') and (not rd.use_game_engine) + return (ob and ob.type == 'MESH') and (not rd.use_game_engine) and (context.smoke) class PHYSICS_PT_smoke(PhysicButtonsPanel, bpy.types.Panel): @@ -45,22 +45,6 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel, bpy.types.Panel): md = context.smoke ob = context.object - split = layout.split() - - if md: - # remove modifier + settings - split.context_pointer_set("modifier", md) - split.operator("object.modifier_remove", text="Remove") - - row = split.row(align=True) - row.prop(md, "show_render", text="") - row.prop(md, "show_viewport", text="") - - else: - # add modifier - split.operator("object.modifier_add", text="Add").type = 'SMOKE' - split.label() - if md: layout.prop(md, "smoke_type", expand=True) diff --git a/release/scripts/ui/properties_physics_softbody.py b/release/scripts/ui/properties_physics_softbody.py index a07c6a8e43b..343b198fa84 100644 --- a/release/scripts/ui/properties_physics_softbody.py +++ b/release/scripts/ui/properties_physics_softbody.py @@ -39,7 +39,7 @@ class PhysicButtonsPanel(): rd = context.scene.render # return (ob and ob.type == 'MESH') and (not rd.use_game_engine) # i really hate touching things i do not understand completely .. but i think this should read (bjornmose) - return (ob and (ob.type == 'MESH' or ob.type == 'LATTICE'or ob.type == 'CURVE')) and (not rd.use_game_engine) + return (ob and (ob.type == 'MESH' or ob.type == 'LATTICE'or ob.type == 'CURVE')) and (not rd.use_game_engine) and (context.soft_body) class PHYSICS_PT_softbody(PhysicButtonsPanel, bpy.types.Panel): @@ -51,21 +51,6 @@ class PHYSICS_PT_softbody(PhysicButtonsPanel, bpy.types.Panel): md = context.soft_body ob = context.object - split = layout.split() - - if md: - # remove modifier + settings - split.context_pointer_set("modifier", md) - split.operator("object.modifier_remove", text="Remove") - - row = split.row(align=True) - row.prop(md, "show_render", text="") - row.prop(md, "show_viewport", text="") - else: - # add modifier - split.operator("object.modifier_add", text="Add").type = 'SOFT_BODY' - split.column() - if md: softbody = md.settings diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 1465c231f41..94955e3c815 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -50,6 +50,7 @@ #include "DNA_property_types.h" #include "DNA_scene_types.h" #include "DNA_object_types.h" +#include "DNA_object_force.h" #include "DNA_meshdata_types.h" #include "DNA_vfont_types.h" @@ -59,6 +60,7 @@ #include "BKE_constraint.h" #include "BKE_context.h" #include "BKE_curve.h" +#include "BKE_effect.h" #include "BKE_depsgraph.h" #include "BKE_font.h" #include "BKE_image.h" @@ -1500,6 +1502,39 @@ void copy_attr_menu(Main *bmain, Scene *scene, View3D *v3d) copy_attr(bmain, scene, v3d, event); } +/* ******************* force field toggle operator ***************** */ + +static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Object *ob = CTX_data_active_object(C); + + if(ob->pd == NULL) + ob->pd = object_add_collision_fields(PFIELD_FORCE); + + if(ob->pd->forcefield == 0) + ob->pd->forcefield = PFIELD_FORCE; + else + ob->pd->forcefield = 0; + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_forcefield_toggle(wmOperatorType *ot) +{ + + /* identifiers */ + ot->name= "Toggle Force Field"; + ot->description = "Toggle object's force field"; + ot->idname= "OBJECT_OT_forcefield_toggle"; + + /* api callbacks */ + ot->exec= forcefield_toggle_exec; + ot->poll= ED_operator_object_active_editable; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ********************************************** */ /* Motion Paths */ diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 6c0a154090f..ca441e8d634 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -84,6 +84,7 @@ void OBJECT_OT_shade_smooth(struct wmOperatorType *ot); void OBJECT_OT_shade_flat(struct wmOperatorType *ot); void OBJECT_OT_paths_calculate(struct wmOperatorType *ot); void OBJECT_OT_paths_clear(struct wmOperatorType *ot); +void OBJECT_OT_forcefield_toggle(struct wmOperatorType *ot); void OBJECT_OT_game_property_new(struct wmOperatorType *ot); void OBJECT_OT_game_property_remove(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 903c40026f7..6662d5b5f0a 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -77,6 +77,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_shade_flat); WM_operatortype_append(OBJECT_OT_paths_calculate); WM_operatortype_append(OBJECT_OT_paths_clear); + WM_operatortype_append(OBJECT_OT_forcefield_toggle); WM_operatortype_append(OBJECT_OT_parent_set); WM_operatortype_append(OBJECT_OT_parent_no_inverse_set);