Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/rigidbody_object.c
| Show First 20 Lines • Show All 514 Lines • ▼ Show 20 Lines | if (changed) { | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL); | WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL); | ||||
| /* done */ | /* done */ | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| static bool mass_calculate_poll_property(const bContext *UNUSED(C), | |||||
| wmOperator *op, | |||||
| const PropertyRNA *prop) | |||||
| { | |||||
| const char *prop_id = RNA_property_identifier(prop); | |||||
| /* Disable density input when not using the 'Custom' preset. */ | |||||
| if (STREQ(prop_id, "density")) { | |||||
| int material = RNA_enum_get(op->ptr, "material"); | |||||
| if (material >= 0) { | |||||
| RNA_def_property_clear_flag((PropertyRNA *)prop, PROP_EDITABLE); | |||||
| } | |||||
| else { | |||||
| RNA_def_property_flag((PropertyRNA *)prop, PROP_EDITABLE); | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| void RIGIDBODY_OT_mass_calculate(wmOperatorType *ot) | void RIGIDBODY_OT_mass_calculate(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->idname = "RIGIDBODY_OT_mass_calculate"; | ot->idname = "RIGIDBODY_OT_mass_calculate"; | ||||
| ot->name = "Calculate Mass"; | ot->name = "Calculate Mass"; | ||||
| ot->description = "Automatically calculate mass values for Rigid Body Objects based on volume"; | ot->description = "Automatically calculate mass values for Rigid Body Objects based on volume"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->invoke = WM_menu_invoke; /* XXX */ | ot->invoke = WM_menu_invoke; /* XXX */ | ||||
| ot->exec = rigidbody_objects_calc_mass_exec; | ot->exec = rigidbody_objects_calc_mass_exec; | ||||
| ot->poll = ED_operator_rigidbody_active_poll; | ot->poll = ED_operator_rigidbody_active_poll; | ||||
| ot->poll_property = mass_calculate_poll_property; | |||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = prop = RNA_def_enum( | ot->prop = prop = RNA_def_enum( | ||||
| ot->srna, | ot->srna, | ||||
| "material", | "material", | ||||
| DummyRNA_DEFAULT_items, | DummyRNA_DEFAULT_items, | ||||
| 0, | 0, | ||||
| "Material Preset", | "Material Preset", | ||||
| "Type of material that objects are made of (determines material density)"); | "Type of material that objects are made of (determines material density)"); | ||||
| RNA_def_enum_funcs(prop, rigidbody_materials_itemf); | RNA_def_enum_funcs(prop, rigidbody_materials_itemf); | ||||
| RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | ||||
| RNA_def_float(ot->srna, | RNA_def_float(ot->srna, | ||||
| "density", | "density", | ||||
| 1.0, | 1.0, | ||||
| FLT_MIN, | FLT_MIN, | ||||
| FLT_MAX, | FLT_MAX, | ||||
| "Density", | "Density", | ||||
| "Custom density value (kg/m^3) to use instead of material preset", | "Density value (kg/m^3), allows custom value if the 'Custom' preset is used", | ||||
| 1.0f, | 1.0f, | ||||
| 2500.0f); | 2500.0f); | ||||
| } | } | ||||
| /* ********************************************** */ | /* ********************************************** */ | ||||