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 e9203fa1972..5963e4b769b 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -79,17 +79,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++; @@ -97,9 +97,9 @@ static int return_editmesh_indexar( } nr++; } - + mul_v3_fl(r_cent, 1.0f / (float)totvert); - + return totvert; } @@ -133,9 +133,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) { @@ -144,10 +144,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); @@ -166,7 +166,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; @@ -178,12 +178,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--) { @@ -196,9 +196,9 @@ static int return_editlattice_indexar( bp++; nr++; } - + mul_v3_fl(r_cent, 1.0f / (float)totvert); - + return totvert; } @@ -231,7 +231,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; @@ -253,12 +253,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; @@ -295,9 +295,9 @@ static int return_editcurve_indexar( } } } - + mul_v3_fl(r_cent, 1.0f / (float)totvert); - + return totvert; } @@ -307,7 +307,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: { @@ -353,7 +353,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; @@ -374,7 +374,7 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) if (index < hmd->totindex - 1) index++; } nr++; - + bezt++; } } @@ -418,11 +418,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); @@ -434,14 +434,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; } @@ -451,12 +451,12 @@ static Object *add_hook_object_new(Main *bmain, Scene *scene, Object *obedit) Object *ob; ob = BKE_object_add(bmain, scene, OB_EMPTY, NULL); - + basedit = BKE_scene_base_find(scene, obedit); base = scene->basact; base->lay = ob->lay = obedit->lay; BLI_assert(scene->basact->object == ob); - + /* icky, BKE_object_add sets new base as active. * so set it back to the original edit object */ scene->basact = basedit; @@ -472,7 +472,7 @@ static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob 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) { @@ -481,29 +481,29 @@ static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob } if (mode == OBJECT_ADDHOOK_NEWOB && !ob) { - + ob = add_hook_object_new(bmain, scene, 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); @@ -542,11 +542,11 @@ static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ /* (parentinv ) */ BKE_object_where_is_calc(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); - + DAG_relations_tag_update(bmain); return true; @@ -560,7 +560,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) { @@ -569,7 +569,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; @@ -579,7 +579,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(bmain, scene, obedit, obsel, mode, op->reports)) { WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); return OPERATOR_FINISHED; @@ -595,11 +595,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; @@ -629,11 +629,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; } @@ -649,29 +649,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); - + DAG_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; @@ -681,32 +681,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); @@ -731,26 +731,26 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op) DAG_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); @@ -765,42 +765,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, ob->obmat[3]); mul_m3_v3(imat, hmd->cent); - + DAG_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); @@ -817,50 +817,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; - + DAG_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); @@ -873,37 +873,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); |