Blender V5.3
object_hook.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11
12#include "MEM_guardedalloc.h"
13
14#include "BLI_listbase.hh"
15#include "BLI_math_matrix_c.hh"
16#include "BLI_math_vector_c.hh"
17#include "BLI_string_utf8.hh"
18#include "BLI_utildefines.hh"
19
20#include "DNA_armature_types.h"
21#include "DNA_curve_types.h"
22#include "DNA_lattice_types.h"
23#include "DNA_mesh_types.h"
24#include "DNA_object_types.h"
25#include "DNA_scene_types.h"
26
27#include "BKE_action.hh"
28#include "BKE_context.hh"
29#include "BKE_deform.hh"
30#include "BKE_editmesh.hh"
31#include "BKE_layer.hh"
32#include "BKE_mesh_types.hh"
33#include "BKE_modifier.hh"
34#include "BKE_object.hh"
35#include "BKE_report.hh"
36
37#include "DEG_depsgraph.hh"
40
41#include "RNA_access.hh"
42#include "RNA_define.hh"
43#include "RNA_enum_types.hh"
44#include "RNA_prototypes.hh"
45
46#include "ED_curve.hh"
47#include "ED_mesh.hh"
48#include "ED_screen.hh"
49
50#include "WM_api.hh"
51#include "WM_types.hh"
52
53#include "UI_resources.hh"
54
55#include "object_intern.hh"
56
57namespace blender::ed::object {
58
60 int *r_indexar_num,
61 int **r_indexar,
62 float r_cent[3])
63{
65 BMVert *eve;
66 BMIter iter;
67 int *index, nr, indexar_num = 0;
68
69 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
71 indexar_num++;
72 }
73 }
74 if (indexar_num == 0) {
75 return 0;
76 }
77
78 *r_indexar = index = MEM_new_array_uninitialized<int>(indexar_num, "hook indexar");
79 *r_indexar_num = indexar_num;
80 nr = 0;
81 zero_v3(r_cent);
82
83 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
85 *index = nr;
86 index++;
87 add_v3_v3(r_cent, eve->co);
88 }
89 nr++;
90 }
91
92 mul_v3_fl(r_cent, 1.0f / float(indexar_num));
93
94 return indexar_num;
95}
96
97static bool return_editmesh_vgroup(Object *obedit, Mesh &mesh, char *r_name, float r_cent[3])
98{
100 const int active_index = BKE_object_defgroup_active_index_get(obedit);
101 const int cd_dvert_offset = active_index ? CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT) :
102 -1;
103
104 if (cd_dvert_offset != -1) {
105 const int defgrp_index = active_index - 1;
106 int indexar_num = 0;
107
108 MDeformVert *dvert;
109 BMVert *eve;
110 BMIter iter;
111
112 /* find the vertices */
113 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
114 dvert = static_cast<MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset));
115
116 if (BKE_defvert_find_weight(dvert, defgrp_index) > 0.0f) {
117 add_v3_v3(r_cent, eve->co);
118 indexar_num++;
119 }
120 }
121 if (indexar_num) {
122 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(obedit);
123 bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, defgrp_index));
124 BLI_strncpy_utf8(r_name, dg->name, sizeof(dg->name));
125 mul_v3_fl(r_cent, 1.0f / float(indexar_num));
126 return true;
127 }
128 }
129
130 return false;
131}
132
134{
135 Mesh *mesh = id_cast<Mesh *>(ob->data);
136 BMEditMesh *em = mesh->runtime->edit_mesh.get();
138 BMVert *eve;
139 BMIter iter;
140 int index = 0, nr = 0;
141
142 if (hmd->indexar == nullptr) {
143 return;
144 }
145
146 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
147 if (nr == hmd->indexar[index]) {
148 BM_vert_select_set(bm, eve, true);
149 if (index < hmd->indexar_num - 1) {
150 index++;
151 }
152 }
153
154 nr++;
155 }
156
158}
159
161 int **r_indexar,
162 int *r_indexar_num,
163 float r_cent[3])
164{
165 BPoint *bp;
166 int *index, nr, indexar_num = 0, a;
167
168 /* count */
169 a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw;
170 bp = editlatt->def;
171 while (a--) {
172 if (bp->f1 & SELECT) {
173 if (bp->hide == 0) {
174 indexar_num++;
175 }
176 }
177 bp++;
178 }
179
180 if (indexar_num == 0) {
181 return 0;
182 }
183
184 *r_indexar = index = MEM_new_array_uninitialized<int>(indexar_num, "hook indexar");
185 *r_indexar_num = indexar_num;
186 nr = 0;
187 zero_v3(r_cent);
188
189 a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw;
190 bp = editlatt->def;
191 while (a--) {
192 if (bp->f1 & SELECT) {
193 if (bp->hide == 0) {
194 *index = nr;
195 index++;
196 add_v3_v3(r_cent, bp->vec);
197 }
198 }
199 bp++;
200 nr++;
201 }
202
203 mul_v3_fl(r_cent, 1.0f / float(indexar_num));
204
205 return indexar_num;
206}
207
209{
210 Lattice *lt = id_cast<Lattice *>(obedit->data), *editlt;
211 BPoint *bp;
212 int index = 0, nr = 0, a;
213
214 editlt = lt->editlatt->latt;
215 /* count */
216 a = editlt->pntsu * editlt->pntsv * editlt->pntsw;
217 bp = editlt->def;
218 while (a--) {
219 if (hmd->indexar[index] == nr) {
220 bp->f1 |= SELECT;
221 if (index < hmd->indexar_num - 1) {
222 index++;
223 }
224 }
225 nr++;
226 bp++;
227 }
228}
229
231 int **r_indexar,
232 int *r_indexar_num,
233 float r_cent[3])
234{
235 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
236 BPoint *bp;
237 BezTriple *bezt;
238 int *index, a, nr, indexar_num = 0;
239
240 for (Nurb &nu : *editnurb) {
241 if (nu.type == CU_BEZIER) {
242 bezt = nu.bezt;
243 a = nu.pntsu;
244 while (a--) {
245 if (bezt->f1 & SELECT) {
246 indexar_num++;
247 }
248 if (bezt->f2 & SELECT) {
249 indexar_num++;
250 }
251 if (bezt->f3 & SELECT) {
252 indexar_num++;
253 }
254 bezt++;
255 }
256 }
257 else {
258 bp = nu.bp;
259 a = nu.pntsu * nu.pntsv;
260 while (a--) {
261 if (bp->f1 & SELECT) {
262 indexar_num++;
263 }
264 bp++;
265 }
266 }
267 }
268 if (indexar_num == 0) {
269 return 0;
270 }
271
272 *r_indexar = index = MEM_new_array_uninitialized<int>(indexar_num, "hook indexar");
273 *r_indexar_num = indexar_num;
274 nr = 0;
275 zero_v3(r_cent);
276
277 for (Nurb &nu : *editnurb) {
278 if (nu.type == CU_BEZIER) {
279 bezt = nu.bezt;
280 a = nu.pntsu;
281 while (a--) {
282 if (bezt->f1 & SELECT) {
283 *index = nr;
284 index++;
285 add_v3_v3(r_cent, bezt->vec[0]);
286 }
287 nr++;
288 if (bezt->f2 & SELECT) {
289 *index = nr;
290 index++;
291 add_v3_v3(r_cent, bezt->vec[1]);
292 }
293 nr++;
294 if (bezt->f3 & SELECT) {
295 *index = nr;
296 index++;
297 add_v3_v3(r_cent, bezt->vec[2]);
298 }
299 nr++;
300 bezt++;
301 }
302 }
303 else {
304 bp = nu.bp;
305 a = nu.pntsu * nu.pntsv;
306 while (a--) {
307 if (bp->f1 & SELECT) {
308 *index = nr;
309 index++;
310 add_v3_v3(r_cent, bp->vec);
311 }
312 nr++;
313 bp++;
314 }
315 }
316 }
317
318 mul_v3_fl(r_cent, 1.0f / float(indexar_num));
319
320 return indexar_num;
321}
322
323static bool object_hook_index_array(Main *bmain,
324 Scene *scene,
325 Object *obedit,
326 int **r_indexar,
327 int *r_indexar_num,
328 char *r_name,
329 float r_cent[3])
330{
331 *r_indexar = nullptr;
332 *r_indexar_num = 0;
333 r_name[0] = 0;
334
335 switch (obedit->type) {
336 case OB_MESH: {
337 Mesh *mesh = id_cast<Mesh *>(obedit->data);
338
339 EDBM_mesh_load(bmain, obedit);
340 EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
341
342 DEG_id_tag_update(obedit->data, 0);
343
344 BMEditMesh *em = mesh->runtime->edit_mesh.get();
345
347
348 /* check selected vertices first */
349 if (return_editmesh_indexar(*mesh, r_indexar_num, r_indexar, r_cent) == 0) {
350 return return_editmesh_vgroup(obedit, *mesh, r_name, r_cent);
351 }
352 return true;
353 }
354 case OB_CURVES_LEGACY:
355 case OB_SURF:
356 ED_curve_editnurb_load(bmain, obedit);
358 return return_editcurve_indexar(obedit, r_indexar, r_indexar_num, r_cent);
359 case OB_LATTICE: {
360 Lattice *lt = id_cast<Lattice *>(obedit->data);
361 return return_editlattice_indexar(lt->editlatt->latt, r_indexar, r_indexar_num, r_cent);
362 }
363 default:
364 return false;
365 }
366}
367
369{
370 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
371 BPoint *bp;
372 BezTriple *bezt;
373 int index = 0, a, nr = 0;
374
375 for (Nurb &nu : *editnurb) {
376 if (nu.type == CU_BEZIER) {
377 bezt = nu.bezt;
378 a = nu.pntsu;
379 while (a--) {
380 if (nr == hmd->indexar[index]) {
381 bezt->f1 |= BEZT_FLAG_SELECT;
382 if (index < hmd->indexar_num - 1) {
383 index++;
384 }
385 }
386 nr++;
387 if (nr == hmd->indexar[index]) {
388 bezt->f2 |= BEZT_FLAG_SELECT;
389 if (index < hmd->indexar_num - 1) {
390 index++;
391 }
392 }
393 nr++;
394 if (nr == hmd->indexar[index]) {
395 bezt->f3 |= BEZT_FLAG_SELECT;
396 if (index < hmd->indexar_num - 1) {
397 index++;
398 }
399 }
400 nr++;
401
402 bezt++;
403 }
404 }
405 else {
406 bp = nu.bp;
407 a = nu.pntsu * nu.pntsv;
408 while (a--) {
409 if (nr == hmd->indexar[index]) {
410 bp->f1 |= SELECT;
411 if (index < hmd->indexar_num - 1) {
412 index++;
413 }
414 }
415 nr++;
416 bp++;
417 }
418 }
419 }
420}
421
423 bContext *C, PointerRNA *ptr, const int num, Object **r_ob, HookModifierData **r_hmd)
424{
425 Object *ob;
426 HookModifierData *hmd;
427
428 if (*ptr) { /* if modifier context is available, use that */
429 ob = id_cast<Object *>(ptr->owner_id);
430 hmd = static_cast<HookModifierData *>(ptr->data);
431 }
432 else { /* use the provided property */
434 hmd = static_cast<HookModifierData *>(BLI_findlink(&ob->modifiers, num));
435 }
436
437 if (ob && hmd && (hmd->modifier.type == eModifierType_Hook)) {
438 *r_ob = ob;
439 *r_hmd = hmd;
440 }
441 else {
442 *r_ob = nullptr;
443 *r_hmd = nullptr;
444 }
445}
446
448{
449 if (hmd->indexar == nullptr) {
450 return;
451 }
452
453 if (ob->type == OB_MESH) {
454 select_editbmesh_hook(ob, hmd);
455 }
456 else if (ob->type == OB_LATTICE) {
458 }
459 else if (ob->type == OB_CURVES_LEGACY) {
460 select_editcurve_hook(ob, hmd);
461 }
462 else if (ob->type == OB_SURF) {
463 select_editcurve_hook(ob, hmd);
464 }
465}
466
467/* special poll operators for hook operators */
468/* TODO: check for properties window modifier context too as alternative? */
470{
471 Object *obedit = CTX_data_edit_object(C);
472
473 if (obedit) {
474 if (ED_operator_editmesh(C)) {
475 return true;
476 }
478 return true;
479 }
481 return true;
482 }
483 // if (ED_operator_editmball(C)) return true;
484 }
485
486 return false;
487}
488
490 Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, Object *obedit)
491{
492 Base *basedit;
493 Object *ob;
494 ob = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, nullptr);
495 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
496 Base *basact = BKE_view_layer_active_base_get(view_layer);
497 BLI_assert(basact->object == ob);
498 if (v3d && v3d->localvd) {
499 basact->local_view_bits |= v3d->local_view_uid;
500 }
501
502 /* icky, BKE_object_add sets new base as active.
503 * so set it back to the original edit object */
504 basedit = BKE_view_layer_base_find(view_layer, obedit);
505 view_layer->basact = basedit;
506
507 return ob;
508}
509
510static int add_hook_object(const bContext *C,
511 Main *bmain,
512 Scene *scene,
513 ViewLayer *view_layer,
514 View3D *v3d,
515 Object *obedit,
516 Object *ob,
517 int mode,
518 ReportList *reports)
519{
520 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
521 HookModifierData *hmd = nullptr;
522 float cent[3];
523 float pose_mat[4][4];
524 int indexar_num, ok, *indexar;
525 char name[MAX_NAME];
526
527 ok = object_hook_index_array(bmain, scene, obedit, &indexar, &indexar_num, name, cent);
528
529 if (!ok) {
530 BKE_report(reports, RPT_ERROR, "Requires selected vertices or active vertex group");
531 return false;
532 }
533
534 if (mode == OBJECT_ADDHOOK_NEWOB && !ob) {
535
536 ob = add_hook_object_new(bmain, scene, view_layer, v3d, obedit);
537
538 /* transform cent to global coords for loc */
539 mul_v3_m4v3(ob->loc, obedit->object_to_world().ptr(), cent);
540 }
541
542 hmd = reinterpret_cast<HookModifierData *>(BKE_modifier_new(eModifierType_Hook));
544 SNPRINTF_UTF8(hmd->modifier.name, "Hook-%s", ob->id.name + 2);
545 BKE_modifier_unique_name(&obedit->modifiers, reinterpret_cast<ModifierData *>(hmd));
547
548 hmd->object = ob;
549 hmd->indexar = indexar;
550 copy_v3_v3(hmd->cent, cent);
551 hmd->indexar_num = indexar_num;
552 STRNCPY_UTF8(hmd->name, name);
553
554 unit_m4(pose_mat);
555
556 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
557 if (mode == OBJECT_ADDHOOK_NEWOB) {
558 /* pass */
559 }
560 else {
561 /* may overwrite with pose-bone location, below */
562 mul_v3_m4v3(cent, obedit->world_to_object().ptr(), ob->object_to_world().location());
563 }
564
565 if (mode == OBJECT_ADDHOOK_SELOB_BONE) {
566 bArmature *arm = id_cast<bArmature *>(ob->data);
568 if (arm->act_bone) {
569 bPoseChannel *pchan_act;
570
571 STRNCPY_UTF8(hmd->subtarget, arm->act_bone->name);
572
574 if (pchan_act) [[likely]] {
575 invert_m4_m4(pose_mat, pchan_act->pose_mat);
576 mul_v3_m4v3(cent, ob->object_to_world().ptr(), pchan_act->pose_mat[3]);
577 mul_v3_m4v3(cent, obedit->world_to_object().ptr(), cent);
578 }
579 }
580 else {
581 BKE_report(reports, RPT_WARNING, "Armature has no active object bone");
582 }
583 }
584
585 copy_v3_v3(hmd->cent, cent);
586
587 /* matrix calculus */
588 /* vert x (obmat x hook->world_to_object) x hook->object_to_world().ptr() x ob->world_to_object
589 */
590 /* (parentinv) */
591 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
592 Object *object_eval = DEG_get_evaluated(depsgraph, ob);
593 BKE_object_transform_copy(object_eval, ob);
594 BKE_object_where_is_calc(depsgraph, scene_eval, object_eval);
595
596 invert_m4_m4(object_eval->runtime->world_to_object.ptr(), object_eval->object_to_world().ptr());
597 /* apparently this call goes from right to left... */
599 pose_mat,
600 object_eval->world_to_object().ptr(),
601 obedit->object_to_world().ptr());
602
605
606 return true;
607}
608
610{
611 Main *bmain = CTX_data_main(C);
612 Scene *scene = CTX_data_scene(C);
613 ViewLayer *view_layer = CTX_data_view_layer(C);
614 Object *obedit = CTX_data_edit_object(C);
615 Object *obsel = nullptr;
616 const bool use_bone = RNA_boolean_get(op->ptr, "use_bone");
617 const int mode = use_bone ? OBJECT_ADDHOOK_SELOB_BONE : OBJECT_ADDHOOK_SELOB;
618
619 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
620 if (ob != obedit) {
621 obsel = ob;
622 break;
623 }
624 }
626
627 if (!obsel) {
628 BKE_report(op->reports, RPT_ERROR, "Cannot add hook with no other selected objects");
629 return OPERATOR_CANCELLED;
630 }
631
632 if (use_bone && obsel->type != OB_ARMATURE) {
633 BKE_report(op->reports, RPT_ERROR, "Cannot add hook bone for a non armature object");
634 return OPERATOR_CANCELLED;
635 }
636
637 if (add_hook_object(C, bmain, scene, view_layer, nullptr, obedit, obsel, mode, op->reports)) {
639 return OPERATOR_FINISHED;
640 }
641 return OPERATOR_CANCELLED;
642}
643
645{
646 /* identifiers */
647 ot->name = "Hook to Selected Object";
648 ot->description = "Hook selected vertices to the first selected object";
649 ot->idname = "OBJECT_OT_hook_add_selob";
650
651 /* API callbacks. */
654
655 /* flags */
657
659 "use_bone",
660 false,
661 "Active Bone",
662 "Assign the hook to the hook object's active bone");
663}
664
666{
667 Main *bmain = CTX_data_main(C);
668 Scene *scene = CTX_data_scene(C);
669 ViewLayer *view_layer = CTX_data_view_layer(C);
670 View3D *v3d = CTX_wm_view3d(C);
671 Object *obedit = CTX_data_edit_object(C);
672
673 if (add_hook_object(
674 C, bmain, scene, view_layer, v3d, obedit, nullptr, OBJECT_ADDHOOK_NEWOB, op->reports))
675 {
679 return OPERATOR_FINISHED;
680 }
681 return OPERATOR_CANCELLED;
682}
683
685{
686 /* identifiers */
687 ot->name = "Hook to New Object";
688 ot->description = "Hook selected vertices to a newly created object";
689 ot->idname = "OBJECT_OT_hook_add_newob";
690
691 /* API callbacks. */
694
695 /* flags */
697}
698
700{
701 int num = RNA_enum_get(op->ptr, "modifier");
703 ModifierData *md = static_cast<ModifierData *>(BLI_findlink(&ob->modifiers, num));
704 if (!(md && md->type == eModifierType_Hook)) {
705 BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
706 return OPERATOR_CANCELLED;
707 }
708
709 /* remove functionality */
710
713
717
718 return OPERATOR_FINISHED;
719}
720
722 PointerRNA * /*ptr*/,
723 PropertyRNA * /*prop*/,
724 bool *r_free)
725{
726 Object *ob = (C) ? CTX_data_edit_object(C) : nullptr;
727 EnumPropertyItem tmp = {0, "", 0, "", ""};
728 EnumPropertyItem *item = nullptr;
729 ModifierData *md = nullptr;
730 int a, totitem = 0;
731
732 if (!ob) {
734 }
735
736 for (a = 0, md = ob->modifiers.first(); md; md = md->next, a++) {
737 if (md->type == eModifierType_Hook) {
738 tmp.value = a;
739 tmp.icon = ICON_HOOK;
740 tmp.identifier = md->name;
741 tmp.name = md->name;
742 RNA_enum_item_add(&item, &totitem, &tmp);
743 }
744 }
745
746 RNA_enum_item_end(&item, &totitem);
747 *r_free = true;
748
749 return item;
750}
751
753{
754 PropertyRNA *prop;
755
756 /* identifiers */
757 ot->name = "Remove Hook";
758 ot->idname = "OBJECT_OT_hook_remove";
759 ot->description = "Remove a hook from the active object";
760
761 /* API callbacks. */
765
766 /* flags */
767 /* this operator removes modifier which isn't stored in local undo stack, * so redoing it from
768 * redo panel gives totally weird results. */
769 ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
770
771 /* properties */
772 prop = RNA_def_enum(
773 ot->srna, "modifier", rna_enum_dummy_NULL_items, 0, "Modifier", "Modifier number to remove");
776 ot->prop = prop;
777}
778
780{
781 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_HookModifier);
782 int num = RNA_enum_get(op->ptr, "modifier");
783 Object *ob = nullptr;
784 HookModifierData *hmd = nullptr;
785
786 object_hook_from_context(C, &ptr, num, &ob, &hmd);
787 if (hmd == nullptr) {
788 BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
789 return OPERATOR_CANCELLED;
790 }
791
793
796
797 return OPERATOR_FINISHED;
798}
799
801{
802 PropertyRNA *prop;
803
804 /* identifiers */
805 ot->name = "Reset Hook";
806 ot->description = "Recalculate and clear offset transformation";
807 ot->idname = "OBJECT_OT_hook_reset";
808
809 /* callbacks */
812
813 /* flags */
815
816 /* properties */
817 prop = RNA_def_enum(ot->srna,
818 "modifier",
820 0,
821 "Modifier",
822 "Modifier number to assign to");
825}
826
828{
829 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_HookModifier);
830 int num = RNA_enum_get(op->ptr, "modifier");
831 Object *ob = nullptr;
832 HookModifierData *hmd = nullptr;
833 Scene *scene = CTX_data_scene(C);
834 float bmat[3][3], imat[3][3];
835
836 object_hook_from_context(C, &ptr, num, &ob, &hmd);
837 if (hmd == nullptr) {
838 BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
839 return OPERATOR_CANCELLED;
840 }
841
842 /* recenter functionality */
843 copy_m3_m4(bmat, ob->object_to_world().ptr());
844 invert_m3_m3(imat, bmat);
845
846 sub_v3_v3v3(hmd->cent, scene->cursor.location, ob->object_to_world().location());
847 mul_m3_v3(imat, hmd->cent);
848
851
852 return OPERATOR_FINISHED;
853}
854
856{
857 PropertyRNA *prop;
858
859 /* identifiers */
860 ot->name = "Recenter Hook";
861 ot->description = "Set hook center to cursor position";
862 ot->idname = "OBJECT_OT_hook_recenter";
863
864 /* callbacks */
867
868 /* flags */
870
871 /* properties */
872 prop = RNA_def_enum(ot->srna,
873 "modifier",
875 0,
876 "Modifier",
877 "Modifier number to assign to");
880}
881
883{
884 Main *bmain = CTX_data_main(C);
885 Scene *scene = CTX_data_scene(C);
886 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_HookModifier);
887 int num = RNA_enum_get(op->ptr, "modifier");
888 Object *ob = nullptr;
889 HookModifierData *hmd = nullptr;
890 float cent[3];
891 char name[MAX_NAME];
892 int *indexar, indexar_num;
893
894 object_hook_from_context(C, &ptr, num, &ob, &hmd);
895 if (hmd == nullptr) {
896 BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
897 return OPERATOR_CANCELLED;
898 }
899
900 /* assign functionality */
901
902 if (!object_hook_index_array(bmain, scene, ob, &indexar, &indexar_num, name, cent)) {
903 BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group");
904 return OPERATOR_CANCELLED;
905 }
906 if (hmd->indexar) {
907 MEM_delete(hmd->indexar);
908 }
909
910 copy_v3_v3(hmd->cent, cent);
911 hmd->indexar = indexar;
912 hmd->indexar_num = indexar_num;
913
916
917 return OPERATOR_FINISHED;
918}
919
921{
922 PropertyRNA *prop;
923
924 /* identifiers */
925 ot->name = "Assign to Hook";
926 ot->description = "Assign the selected vertices to a hook";
927 ot->idname = "OBJECT_OT_hook_assign";
928
929 /* callbacks */
932
933 /* flags */
934 /* this operator changes data stored in modifier which doesn't get pushed to undo stack, * so
935 * redoing it from redo panel gives totally weird results. */
936 ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
937
938 /* properties */
939 prop = RNA_def_enum(ot->srna,
940 "modifier",
942 0,
943 "Modifier",
944 "Modifier number to assign to");
947}
948
950{
951 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_HookModifier);
952 int num = RNA_enum_get(op->ptr, "modifier");
953 Object *ob = nullptr;
954 HookModifierData *hmd = nullptr;
955
956 object_hook_from_context(C, &ptr, num, &ob, &hmd);
957 if (hmd == nullptr) {
958 BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
959 return OPERATOR_CANCELLED;
960 }
961
962 /* select functionality */
963 object_hook_select(ob, hmd);
964
967
968 return OPERATOR_FINISHED;
969}
970
972{
973 PropertyRNA *prop;
974
975 /* identifiers */
976 ot->name = "Select Hook";
977 ot->description = "Select affected vertices on mesh";
978 ot->idname = "OBJECT_OT_hook_select";
979
980 /* callbacks */
983
984 /* flags */
986
987 /* properties */
988 prop = RNA_def_enum(
989 ot->srna, "modifier", rna_enum_dummy_NULL_items, 0, "Modifier", "Modifier number to remove");
992}
993
994} // namespace blender::ed::object
Blender kernel action and pose functionality.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
support for deformation groups and hooks.
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
#define mul_m4_series(...)
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define MAX_NAME
Definition DNA_defs.h:63
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_MODIFIER
Definition WM_types.hh:503
#define ND_SELECT
Definition WM_types.hh:551
#define NC_OBJECT
Definition WM_types.hh:392
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
void OBJECT_OT_hook_select(wmOperatorType *ot)
static wmOperatorStatus object_hook_select_exec(bContext *C, wmOperator *op)
static int return_editcurve_indexar(Object *obedit, int **r_indexar, int *r_indexar_num, float r_cent[3])
static Object * add_hook_object_new(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, Object *obedit)
static const EnumPropertyItem * hook_mod_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
void OBJECT_OT_hook_remove(wmOperatorType *ot)
static void select_editbmesh_hook(Object *ob, HookModifierData *hmd)
void OBJECT_OT_hook_add_selob(wmOperatorType *ot)
static int return_editmesh_indexar(Mesh &mesh, int *r_indexar_num, int **r_indexar, float r_cent[3])
static int return_editlattice_indexar(Lattice *editlatt, int **r_indexar, int *r_indexar_num, float r_cent[3])
static wmOperatorStatus object_hook_remove_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_add_hook_selob_exec(bContext *C, wmOperator *op)
static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, Object *obedit, Object *ob, int mode, ReportList *reports)
void OBJECT_OT_hook_add_newob(wmOperatorType *ot)
static void object_hook_select(Object *ob, HookModifierData *hmd)
static wmOperatorStatus object_hook_assign_exec(bContext *C, wmOperator *op)
static bool hook_op_edit_poll(bContext *C)
static void select_editlattice_hook(Object *obedit, HookModifierData *hmd)
void OBJECT_OT_hook_assign(wmOperatorType *ot)
static wmOperatorStatus object_add_hook_newob_exec(bContext *C, wmOperator *op)
static bool return_editmesh_vgroup(Object *obedit, Mesh &mesh, char *r_name, float r_cent[3])
static void object_hook_from_context(bContext *C, PointerRNA *ptr, const int num, Object **r_ob, HookModifierData **r_hmd)
void OBJECT_OT_hook_recenter(wmOperatorType *ot)
void OBJECT_OT_hook_reset(wmOperatorType *ot)
static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
static bool object_hook_index_array(Main *bmain, Scene *scene, Object *obedit, int **r_indexar, int *r_indexar_num, char *r_name, float r_cent[3])
static wmOperatorStatus object_hook_recenter_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_hook_reset_exec(bContext *C, wmOperator *op)
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
void mul_m3_v3(const float M[3][3], float r[3])
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name) ATTR_NONNULL(1
Definition object.cc:2296
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ RPT_WARNING
Definition BKE_report.hh:40
const ListBaseT< bDeformGroup > * BKE_object_defgroup_list(const Object *ob)
Definition deform.cc:591
void ED_curve_editnurb_load(Main *bmain, Object *obedit)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool ED_operator_editlattice(bContext *C)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
ViewLayer * CTX_data_view_layer(const bContext *C)
MINLINE void mul_v3_fl(float r[3], float f)
void BKE_modifier_unique_name(ListBaseT< ModifierData > *modifiers, ModifierData *md)
float BKE_defvert_find_weight(const MDeformVert *dvert, int defgroup)
Definition deform.cc:779
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool ED_operator_editmesh(bContext *C)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void BKE_modifiers_add_at_end_if_possible(Object *ob, ModifierData *new_md)
ModifierData * BKE_modifier_new(int type)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
Object * CTX_data_edit_object(const bContext *C)
void BKE_modifier_free(ModifierData *md)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_editmesh_looptris_and_normals_calc(BMEditMesh *em, BMesh *bm)
Definition editmesh.cc:122
bool ED_operator_editsurfcurve(bContext *C)
void unit_m4(float m[4][4])
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
ATTR_WARN_UNUSED_RESULT const size_t num
void BKE_modifier_remove_from_list(Object *ob, ModifierData *md)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
ListBaseT< Nurb > * object_editcurve_get(Object *ob)
Definition editcurve.cc:95
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
MINLINE void zero_v3(float r[3])
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void EDBM_mesh_load(Main *bmain, Object *ob)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
Definition object.cc:2648
MINLINE void add_v3_v3(float r[3], const float a[3])
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void EDBM_mesh_make(Object *ob, int select_mode, bool add_key_index)
Main * CTX_data_main(const bContext *C)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
void ED_curve_editnurb_make(Object *obedit)
void DEG_relations_tag_update(Main *bmain)
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:3577
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void EDBM_select_flush_from_verts(BMesh *bm, short selectmode, bool select)
void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd)
Definition object.cc:1365
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
View3D * CTX_wm_view3d(const bContext *C)
int BKE_object_defgroup_active_index_get(const Object *ob)
Definition deform.cc:613
CustomData vdata
struct Object * object
unsigned short local_view_bits
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
struct Lattice * latt
char name[258]
Definition DNA_ID.h:433
struct EditLatt * editlatt
struct BPoint * def
const c_style_mat & ptr() const
struct ModifierData * next
ListBaseT< ModifierData > modifiers
bke::ObjectRuntime * runtime
View3DCursor cursor
struct ToolSettings * toolsettings
struct View3D * localvd
unsigned short local_view_uid
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports