Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_hook.c
| Show First 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | if (obedit) { | ||||
| if (ED_operator_editsurfcurve(C)) return 1; | if (ED_operator_editsurfcurve(C)) return 1; | ||||
| if (ED_operator_editlattice(C)) return 1; | if (ED_operator_editlattice(C)) return 1; | ||||
| //if (ED_operator_editmball(C)) return 1; | //if (ED_operator_editmball(C)) return 1; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static Object *add_hook_object_new(Main *bmain, Scene *scene, Object *obedit) | static Object *add_hook_object_new(Main *bmain, Scene *scene, SceneLayer *sl, Object *obedit) | ||||
| { | { | ||||
| Base *base, *basedit; | Base *base, *basedit; | ||||
| Object *ob; | Object *ob; | ||||
| ob = BKE_object_add(bmain, scene, OB_EMPTY, NULL); | ob = BKE_object_add(bmain, scene, sl, OB_EMPTY, NULL); | ||||
| basedit = BKE_scene_base_find(scene, obedit); | basedit = BKE_scene_base_find(scene, obedit); | ||||
| base = scene->basact; | base = scene->basact; | ||||
| base->lay = ob->lay = obedit->lay; | base->lay = ob->lay = obedit->lay; | ||||
| BLI_assert(scene->basact->object == ob); | BLI_assert(scene->basact->object == ob); | ||||
| /* icky, BKE_object_add sets new base as active. | /* icky, BKE_object_add sets new base as active. | ||||
| * so set it back to the original edit object */ | * so set it back to the original edit object */ | ||||
| scene->basact = basedit; | scene->basact = basedit; | ||||
| return ob; | return ob; | ||||
| } | } | ||||
| static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob, int mode, ReportList *reports) | static int add_hook_object(Main *bmain, Scene *scene, SceneLayer *sl, Object *obedit, Object *ob, int mode, ReportList *reports) | ||||
| { | { | ||||
| ModifierData *md = NULL; | ModifierData *md = NULL; | ||||
| HookModifierData *hmd = NULL; | HookModifierData *hmd = NULL; | ||||
| float cent[3]; | float cent[3]; | ||||
| float pose_mat[4][4]; | float pose_mat[4][4]; | ||||
| int tot, ok, *indexar; | int tot, ok, *indexar; | ||||
| char name[MAX_NAME]; | char name[MAX_NAME]; | ||||
| ok = object_hook_index_array(scene, obedit, &tot, &indexar, name, cent); | ok = object_hook_index_array(scene, obedit, &tot, &indexar, name, cent); | ||||
| if (!ok) { | if (!ok) { | ||||
| BKE_report(reports, RPT_ERROR, "Requires selected vertices or active vertex group"); | BKE_report(reports, RPT_ERROR, "Requires selected vertices or active vertex group"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (mode == OBJECT_ADDHOOK_NEWOB && !ob) { | if (mode == OBJECT_ADDHOOK_NEWOB && !ob) { | ||||
| ob = add_hook_object_new(bmain, scene, obedit); | ob = add_hook_object_new(bmain, scene, sl, obedit); | ||||
| /* transform cent to global coords for loc */ | /* transform cent to global coords for loc */ | ||||
| mul_v3_m4v3(ob->loc, obedit->obmat, cent); | mul_v3_m4v3(ob->loc, obedit->obmat, cent); | ||||
| } | } | ||||
| md = obedit->modifiers.first; | md = obedit->modifiers.first; | ||||
| while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) { | while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) { | ||||
| md = md->next; | md = md->next; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static int add_hook_object(Main *bmain, Scene *scene, SceneLayer *sl, Object *obedit, Object *ob, int mode, ReportList *reports) | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int object_add_hook_selob_exec(bContext *C, wmOperator *op) | static int object_add_hook_selob_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | |||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Object *obsel = NULL; | Object *obsel = NULL; | ||||
| const bool use_bone = RNA_boolean_get(op->ptr, "use_bone"); | const bool use_bone = RNA_boolean_get(op->ptr, "use_bone"); | ||||
| const int mode = use_bone ? OBJECT_ADDHOOK_SELOB_BONE : OBJECT_ADDHOOK_SELOB; | const int mode = use_bone ? OBJECT_ADDHOOK_SELOB_BONE : OBJECT_ADDHOOK_SELOB; | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_objects) | CTX_DATA_BEGIN (C, Object *, ob, selected_objects) | ||||
| { | { | ||||
| if (ob != obedit) { | if (ob != obedit) { | ||||
| obsel = ob; | obsel = ob; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| if (!obsel) { | if (!obsel) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Cannot add hook with no other selected objects"); | BKE_report(op->reports, RPT_ERROR, "Cannot add hook with no other selected objects"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (use_bone && obsel->type != OB_ARMATURE) { | if (use_bone && obsel->type != OB_ARMATURE) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Cannot add hook bone for a non armature object"); | BKE_report(op->reports, RPT_ERROR, "Cannot add hook bone for a non armature object"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (add_hook_object(bmain, scene, obedit, obsel, mode, op->reports)) { | if (add_hook_object(bmain, scene, sl, obedit, obsel, mode, op->reports)) { | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| Show All 14 Lines | void OBJECT_OT_hook_add_selob(wmOperatorType *ot) | ||||
| RNA_def_boolean(ot->srna, "use_bone", false, "Active Bone", | RNA_def_boolean(ot->srna, "use_bone", false, "Active Bone", | ||||
| "Assign the hook to the hook objects active bone"); | "Assign the hook to the hook objects active bone"); | ||||
| } | } | ||||
| static int object_add_hook_newob_exec(bContext *C, wmOperator *op) | static int object_add_hook_newob_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | |||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| if (add_hook_object(bmain, scene, obedit, NULL, OBJECT_ADDHOOK_NEWOB, op->reports)) { | if (add_hook_object(bmain, scene, sl, obedit, NULL, OBJECT_ADDHOOK_NEWOB, op->reports)) { | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | ||||
| WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); | WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 288 Lines • Show Last 20 Lines | |||||