diff options
Diffstat (limited to 'source/blender/editors/object/object_hook.c')
-rw-r--r-- | source/blender/editors/object/object_hook.c | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index 8c68431c19a..7687bd476b9 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -82,17 +82,17 @@ static int return_editmesh_indexar( BMVert *eve; BMIter iter; int *index, nr, totvert = 0; - + BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) totvert++; } if (totvert == 0) return 0; - + *r_indexar = index = MEM_mallocN(4 * totvert, "hook indexar"); *r_tot = totvert; nr = 0; zero_v3(r_cent); - + BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { *index = nr; index++; @@ -100,9 +100,9 @@ static int return_editmesh_indexar( } nr++; } - + mul_v3_fl(r_cent, 1.0f / (float)totvert); - + return totvert; } @@ -136,9 +136,9 @@ static bool return_editmesh_vgroup(Object *obedit, BMEditMesh *em, char *r_name, return true; } } - + return false; -} +} static void select_editbmesh_hook(Object *ob, HookModifierData *hmd) { @@ -147,10 +147,10 @@ static void select_editbmesh_hook(Object *ob, HookModifierData *hmd) BMVert *eve; BMIter iter; int index = 0, nr = 0; - + if (hmd->indexar == NULL) return; - + BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (nr == hmd->indexar[index]) { BM_vert_select_set(em->bm, eve, true); @@ -169,7 +169,7 @@ static int return_editlattice_indexar( { BPoint *bp; int *index, nr, totvert = 0, a; - + /* count */ a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw; bp = editlatt->def; @@ -181,12 +181,12 @@ static int return_editlattice_indexar( } if (totvert == 0) return 0; - + *r_indexar = index = MEM_mallocN(4 * totvert, "hook indexar"); *r_tot = totvert; nr = 0; zero_v3(r_cent); - + a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw; bp = editlatt->def; while (a--) { @@ -199,9 +199,9 @@ static int return_editlattice_indexar( bp++; nr++; } - + mul_v3_fl(r_cent, 1.0f / (float)totvert); - + return totvert; } @@ -234,7 +234,7 @@ static int return_editcurve_indexar( BPoint *bp; BezTriple *bezt; int *index, a, nr, totvert = 0; - + for (nu = editnurb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { bezt = nu->bezt; @@ -256,12 +256,12 @@ static int return_editcurve_indexar( } } if (totvert == 0) return 0; - + *r_indexar = index = MEM_mallocN(sizeof(*index) * totvert, "hook indexar"); *r_tot = totvert; nr = 0; zero_v3(r_cent); - + for (nu = editnurb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { bezt = nu->bezt; @@ -298,9 +298,9 @@ static int return_editcurve_indexar( } } } - + mul_v3_fl(r_cent, 1.0f / (float)totvert); - + return totvert; } @@ -310,7 +310,7 @@ static bool object_hook_index_array(Scene *scene, Object *obedit, *r_indexar = NULL; *r_tot = 0; r_name[0] = 0; - + switch (obedit->type) { case OB_MESH: { @@ -356,7 +356,7 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) BPoint *bp; BezTriple *bezt; int index = 0, a, nr = 0; - + for (nu = editnurb->first; nu; nu = nu->next) { if (nu->type == CU_BEZIER) { bezt = nu->bezt; @@ -377,7 +377,7 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) if (index < hmd->totindex - 1) index++; } nr++; - + bezt++; } } @@ -421,11 +421,11 @@ static void object_hook_from_context(bContext *C, PointerRNA *ptr, const int num } } -static void object_hook_select(Object *ob, HookModifierData *hmd) +static void object_hook_select(Object *ob, HookModifierData *hmd) { if (hmd->indexar == NULL) return; - + if (ob->type == OB_MESH) select_editbmesh_hook(ob, hmd); else if (ob->type == OB_LATTICE) select_editlattice_hook(ob, hmd); else if (ob->type == OB_CURVE) select_editcurve_hook(ob, hmd); @@ -437,14 +437,14 @@ static void object_hook_select(Object *ob, HookModifierData *hmd) static int hook_op_edit_poll(bContext *C) { Object *obedit = CTX_data_edit_object(C); - + if (obedit) { if (ED_operator_editmesh(C)) return 1; if (ED_operator_editsurfcurve(C)) return 1; if (ED_operator_editlattice(C)) return 1; //if (ED_operator_editmball(C)) return 1; } - + return 0; } @@ -454,12 +454,12 @@ static Object *add_hook_object_new(Main *bmain, Scene *scene, ViewLayer *view_la Object *ob; ob = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, NULL); - + basedit = BKE_view_layer_base_find(view_layer, obedit); base = view_layer->basact; base->lay = ob->lay = obedit->lay; BLI_assert(view_layer->basact->object == ob); - + /* icky, BKE_object_add sets new base as active. * so set it back to the original edit object */ view_layer->basact = basedit; @@ -475,7 +475,7 @@ static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLay float pose_mat[4][4]; int tot, ok, *indexar; char name[MAX_NAME]; - + ok = object_hook_index_array(scene, obedit, &tot, &indexar, name, cent); if (!ok) { @@ -484,29 +484,29 @@ static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLay } if (mode == OBJECT_ADDHOOK_NEWOB && !ob) { - + ob = add_hook_object_new(bmain, scene, view_layer, obedit); - + /* transform cent to global coords for loc */ mul_v3_m4v3(ob->loc, obedit->obmat, cent); } - + md = obedit->modifiers.first; while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) { md = md->next; } - + hmd = (HookModifierData *) modifier_new(eModifierType_Hook); BLI_insertlinkbefore(&obedit->modifiers, md, hmd); BLI_snprintf(hmd->modifier.name, sizeof(hmd->modifier.name), "Hook-%s", ob->id.name + 2); modifier_unique_name(&obedit->modifiers, (ModifierData *)hmd); - + hmd->object = ob; hmd->indexar = indexar; copy_v3_v3(hmd->cent, cent); hmd->totindex = tot; BLI_strncpy(hmd->name, name, sizeof(hmd->name)); - + unit_m4(pose_mat); invert_m4_m4(obedit->imat, obedit->obmat); @@ -545,11 +545,11 @@ static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLay /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ /* (parentinv ) */ BKE_object_where_is_calc(CTX_data_depsgraph(C), scene, ob); - + invert_m4_m4(ob->imat, ob->obmat); /* apparently this call goes from right to left... */ mul_m4_series(hmd->parentinv, pose_mat, ob->imat, obedit->obmat); - + DEG_relations_tag_update(bmain); return true; @@ -564,7 +564,7 @@ static int object_add_hook_selob_exec(bContext *C, wmOperator *op) Object *obsel = NULL; const bool use_bone = RNA_boolean_get(op->ptr, "use_bone"); const int mode = use_bone ? OBJECT_ADDHOOK_SELOB_BONE : OBJECT_ADDHOOK_SELOB; - + CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { if (ob != obedit) { @@ -573,7 +573,7 @@ static int object_add_hook_selob_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; - + if (!obsel) { BKE_report(op->reports, RPT_ERROR, "Cannot add hook with no other selected objects"); return OPERATOR_CANCELLED; @@ -583,7 +583,7 @@ static int object_add_hook_selob_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "Cannot add hook bone for a non armature object"); return OPERATOR_CANCELLED; } - + if (add_hook_object(C, bmain, scene, view_layer, obedit, obsel, mode, op->reports)) { WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); return OPERATOR_FINISHED; @@ -599,11 +599,11 @@ void OBJECT_OT_hook_add_selob(wmOperatorType *ot) ot->name = "Hook to Selected Object"; ot->description = "Hook selected vertices to the first selected object"; ot->idname = "OBJECT_OT_hook_add_selob"; - + /* api callbacks */ ot->exec = object_add_hook_selob_exec; ot->poll = hook_op_edit_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -634,11 +634,11 @@ void OBJECT_OT_hook_add_newob(wmOperatorType *ot) ot->name = "Hook to New Object"; ot->description = "Hook selected vertices to a newly created object"; ot->idname = "OBJECT_OT_hook_add_newob"; - + /* api callbacks */ ot->exec = object_add_hook_newob_exec; ot->poll = hook_op_edit_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -654,29 +654,29 @@ static int object_hook_remove_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); return OPERATOR_CANCELLED; } - + /* remove functionality */ - + BLI_remlink(&ob->modifiers, (ModifierData *)hmd); modifier_free((ModifierData *)hmd); - + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); - + return OPERATOR_FINISHED; } static const EnumPropertyItem *hook_mod_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) -{ +{ Object *ob = CTX_data_edit_object(C); EnumPropertyItem tmp = {0, "", 0, "", ""}; EnumPropertyItem *item = NULL; ModifierData *md = NULL; int a, totitem = 0; - + if (!ob) return DummyRNA_NULL_items; - + for (a = 0, md = ob->modifiers.first; md; md = md->next, a++) { if (md->type == eModifierType_Hook) { tmp.value = a; @@ -686,32 +686,32 @@ static const EnumPropertyItem *hook_mod_itemf(bContext *C, PointerRNA *UNUSED(pt RNA_enum_item_add(&item, &totitem, &tmp); } } - + RNA_enum_item_end(&item, &totitem); *r_free = true; - + return item; } void OBJECT_OT_hook_remove(wmOperatorType *ot) { PropertyRNA *prop; - + /* identifiers */ ot->name = "Remove Hook"; ot->idname = "OBJECT_OT_hook_remove"; ot->description = "Remove a hook from the active object"; - + /* api callbacks */ ot->exec = object_hook_remove_exec; ot->invoke = WM_menu_invoke; ot->poll = hook_op_edit_poll; - + /* flags */ /* this operator removes modifier which isn't stored in local undo stack, * so redoing it from redo panel gives totally weird results */ ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO; - + /* properties */ prop = RNA_def_enum(ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to remove"); RNA_def_enum_funcs(prop, hook_mod_itemf); @@ -736,26 +736,26 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); - + return OPERATOR_FINISHED; } void OBJECT_OT_hook_reset(wmOperatorType *ot) { PropertyRNA *prop; - + /* identifiers */ ot->name = "Reset Hook"; ot->description = "Recalculate and clear offset transformation"; ot->idname = "OBJECT_OT_hook_reset"; - + /* callbacks */ ot->exec = object_hook_reset_exec; ot->poll = hook_op_edit_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* properties */ prop = RNA_def_enum(ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to assign to"); RNA_def_enum_funcs(prop, hook_mod_itemf); @@ -770,42 +770,42 @@ static int object_hook_recenter_exec(bContext *C, wmOperator *op) HookModifierData *hmd = NULL; Scene *scene = CTX_data_scene(C); float bmat[3][3], imat[3][3]; - + object_hook_from_context(C, &ptr, num, &ob, &hmd); if (hmd == NULL) { BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); return OPERATOR_CANCELLED; } - + /* recenter functionality */ copy_m3_m4(bmat, ob->obmat); invert_m3_m3(imat, bmat); - + sub_v3_v3v3(hmd->cent, scene->cursor.location, ob->obmat[3]); mul_m3_v3(imat, hmd->cent); - + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); - + return OPERATOR_FINISHED; } void OBJECT_OT_hook_recenter(wmOperatorType *ot) { PropertyRNA *prop; - + /* identifiers */ ot->name = "Recenter Hook"; ot->description = "Set hook center to cursor position"; ot->idname = "OBJECT_OT_hook_recenter"; - + /* callbacks */ ot->exec = object_hook_recenter_exec; ot->poll = hook_op_edit_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* properties */ prop = RNA_def_enum(ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to assign to"); RNA_def_enum_funcs(prop, hook_mod_itemf); @@ -822,50 +822,50 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op) float cent[3]; char name[MAX_NAME]; int *indexar, tot; - + object_hook_from_context(C, &ptr, num, &ob, &hmd); if (hmd == NULL) { BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); return OPERATOR_CANCELLED; } - + /* assign functionality */ - + if (!object_hook_index_array(scene, ob, &tot, &indexar, name, cent)) { BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group"); return OPERATOR_CANCELLED; } if (hmd->indexar) MEM_freeN(hmd->indexar); - + copy_v3_v3(hmd->cent, cent); hmd->indexar = indexar; hmd->totindex = tot; - + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); - + return OPERATOR_FINISHED; } void OBJECT_OT_hook_assign(wmOperatorType *ot) { PropertyRNA *prop; - + /* identifiers */ ot->name = "Assign to Hook"; ot->description = "Assign the selected vertices to a hook"; ot->idname = "OBJECT_OT_hook_assign"; - + /* callbacks */ ot->exec = object_hook_assign_exec; ot->poll = hook_op_edit_poll; - + /* flags */ /* this operator changes data stored in modifier which doesn't get pushed to undo stack, * so redoing it from redo panel gives totally weird results */ ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO; - + /* properties */ prop = RNA_def_enum(ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to assign to"); RNA_def_enum_funcs(prop, hook_mod_itemf); @@ -878,37 +878,37 @@ static int object_hook_select_exec(bContext *C, wmOperator *op) int num = RNA_enum_get(op->ptr, "modifier"); Object *ob = NULL; HookModifierData *hmd = NULL; - + object_hook_from_context(C, &ptr, num, &ob, &hmd); if (hmd == NULL) { BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); return OPERATOR_CANCELLED; } - + /* select functionality */ object_hook_select(ob, hmd); - + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); - + return OPERATOR_FINISHED; } void OBJECT_OT_hook_select(wmOperatorType *ot) { PropertyRNA *prop; - + /* identifiers */ ot->name = "Select Hook"; ot->description = "Select affected vertices on mesh"; ot->idname = "OBJECT_OT_hook_select"; - + /* callbacks */ ot->exec = object_hook_select_exec; ot->poll = hook_op_edit_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* properties */ prop = RNA_def_enum(ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to remove"); RNA_def_enum_funcs(prop, hook_mod_itemf); |