Blender V5.3
object_deform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
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 "BLT_translation.hh"
15
16#include "BLI_ghash.hh"
17#include "BLI_listbase.hh"
18#include "BLI_string_utils.hh"
19#include "BLI_utildefines.hh"
20
21#include "DNA_armature_types.h"
22#include "DNA_cloth_types.h"
23#include "DNA_curve_types.h"
25#include "DNA_lattice_types.h"
26#include "DNA_mesh_types.h"
27#include "DNA_meshdata_types.h"
28#include "DNA_modifier_types.h"
30#include "DNA_object_types.h"
31#include "DNA_particle_types.h"
32#include "DNA_scene_types.h"
33
34#include "BKE_action.hh"
35#include "BKE_armature.hh"
36#include "BKE_deform.hh"
37#include "BKE_editmesh.hh"
39#include "BKE_mesh.hh"
40#include "BKE_modifier.hh"
41#include "BKE_object.hh"
42#include "BKE_object_deform.h" /* own include */
43
44namespace blender {
45
46/* -------------------------------------------------------------------- */
49
51{
52 Lattice *lt = id_cast<Lattice *>(id);
53 BLI_assert(GS(id->name) == ID_LT);
54 return (lt->editlatt) ? lt->editlatt->latt : lt;
55}
56
58{
59 /* these cases don't use names to refer to vertex groups, so when
60 * they get removed the numbers get out of sync, this corrects that */
61
62 if (ob->soft) {
63 ob->soft->vertgroup = map[ob->soft->vertgroup];
64 }
65
66 for (ModifierData &md : ob->modifiers) {
67 if (md.type == eModifierType_Explode) {
68 ExplodeModifierData *emd = reinterpret_cast<ExplodeModifierData *>(&md);
69 emd->vgroup = map[emd->vgroup];
70 }
71 else if (md.type == eModifierType_Cloth) {
72 ClothModifierData *clmd = reinterpret_cast<ClothModifierData *>(&md);
73 ClothSimSettings *clsim = clmd->sim_parms;
74 ClothCollSettings *clcoll = clmd->coll_parms;
75
76 if (clsim) {
77 clsim->vgroup_mass = map[clsim->vgroup_mass];
78 clsim->vgroup_shrink = map[clsim->vgroup_shrink];
79 clsim->vgroup_struct = map[clsim->vgroup_struct];
80 clsim->vgroup_shear = map[clsim->vgroup_shear];
81 clsim->vgroup_bend = map[clsim->vgroup_bend];
82 clsim->vgroup_intern = map[clsim->vgroup_intern];
83 clsim->vgroup_pressure = map[clsim->vgroup_pressure];
84 clcoll->vgroup_selfcol = map[clcoll->vgroup_selfcol];
85 clcoll->vgroup_objcol = map[clcoll->vgroup_objcol];
86 }
87 }
88 }
89
90 for (ParticleSystem &psys : ob->particlesystem) {
91 for (int a = 0; a < PSYS_TOT_VG; a++) {
92 psys.vgroup[a] = map[psys.vgroup[a]];
93 }
94 }
95}
96
98
99/* -------------------------------------------------------------------- */
102
104{
105 bDeformGroup *defgroup;
106
107 if (!ob || !OB_TYPE_SUPPORT_VGROUP(ob->type)) {
108 return nullptr;
109 }
110
111 defgroup = BKE_object_defgroup_new(ob, name);
113
114 return defgroup;
115}
116
121
123{
124 if (GS(id->name) == ID_ME) {
125 return (id_cast<Mesh *>(id))->deform_verts_for_write().data();
126 }
127 if (GS(id->name) == ID_LT) {
128 Lattice *lt = id_cast<Lattice *>(id);
130 size_t(lt->pntsu) * size_t(lt->pntsv) * size_t(lt->pntsw), "lattice deformVert");
131 return lt->dvert;
132 }
133
134 return nullptr;
135}
136
138
139/* -------------------------------------------------------------------- */
142
143bool BKE_object_defgroup_clear(Object *ob, bDeformGroup *dg, const bool use_selection)
144{
145 using namespace blender::bke;
146 MDeformVert *dv;
147 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
148 const int def_nr = BLI_findindex(defbase, dg);
149 bool changed = false;
150
151 if (ob->type == OB_MESH) {
152 Mesh *mesh = id_cast<Mesh *>(ob->data);
153
155 const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
156
157 if (cd_dvert_offset != -1) {
158 BMVert *eve;
159 BMIter iter;
160
161 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
162 dv = static_cast<MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset));
163
164 if (dv && dv->dw && (!use_selection || BM_elem_flag_test(eve, BM_ELEM_SELECT))) {
165 MDeformWeight *dw = BKE_defvert_find_index(dv, def_nr);
166 BKE_defvert_remove_group(dv, dw); /* dw can be nullptr */
167 changed = true;
168 }
169 }
170 }
171 }
172 else {
173 if (mesh->deform_verts().data()) {
174 const AttributeAccessor attributes = mesh->attributes();
175 const VArray select_vert = *attributes.lookup_or_default<bool>(
176 ".select_vert", AttrDomain::Point, false);
177 int i;
178
179 dv = mesh->deform_verts_for_write().data();
180
181 for (i = 0; i < mesh->verts_num; i++, dv++) {
182 if (dv->dw && (!use_selection || select_vert[i])) {
183 MDeformWeight *dw = BKE_defvert_find_index(dv, def_nr);
184 BKE_defvert_remove_group(dv, dw); /* dw can be nullptr */
185 changed = true;
186 }
187 }
188 }
189 }
190 }
191 else if (ob->type == OB_LATTICE) {
193
194 if (lt->dvert) {
195 BPoint *bp;
196 int i, tot = lt->pntsu * lt->pntsv * lt->pntsw;
197
198 for (i = 0, bp = lt->def; i < tot; i++, bp++) {
199 if (!use_selection || (bp->f1 & SELECT)) {
200 MDeformWeight *dw;
201
202 dv = &lt->dvert[i];
203
204 dw = BKE_defvert_find_index(dv, def_nr);
205 BKE_defvert_remove_group(dv, dw); /* dw can be nullptr */
206 changed = true;
207 }
208 }
209 }
210 }
211
212 return changed;
213}
214
215bool BKE_object_defgroup_clear_all(Object *ob, const bool use_selection)
216{
217 bool changed = false;
218
219 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
220
221 for (bDeformGroup &dg : *defbase) {
222 if (BKE_object_defgroup_clear(ob, &dg, use_selection)) {
223 changed = true;
224 }
225 }
226
227 return changed;
228}
229
231
232/* -------------------------------------------------------------------- */
235
236static void object_defgroup_remove_update_users(Object *ob, const int idx)
237{
238 int i, defbase_tot = BKE_object_defgroup_count(ob) + 1;
239 int *map = MEM_new_array_uninitialized<int>(size_t(defbase_tot), "vgroup del");
240
241 map[idx] = map[0] = 0;
242 for (i = 1; i < idx; i++) {
243 map[i] = i;
244 }
245 for (i = idx + 1; i < defbase_tot; i++) {
246 map[i] = i - 1;
247 }
248
250 MEM_delete(map);
251}
252
253static void object_defgroup_remove_common(Object *ob, bDeformGroup *dg, const int def_nr)
254{
256
257 /* Remove the group */
258 ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list_mutable(ob);
259
260 BLI_freelinkN(defbase, dg);
261
262 /* Update the active deform index if necessary */
263 const int active_index = BKE_object_defgroup_active_index_get(ob);
264 if (active_index > def_nr) {
265 BKE_object_defgroup_active_index_set(ob, active_index - 1);
266 }
267
268 /* Remove all deform-verts. */
269 if (defbase->is_empty()) {
270 if (ob->type == OB_MESH) {
271 Mesh *mesh = id_cast<Mesh *>(ob->data);
273 }
274 else if (ob->type == OB_LATTICE) {
276 MEM_SAFE_DELETE(lt->dvert);
277 }
278 else if (ob->type == OB_GREASE_PENCIL) {
279 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
281 }
282 }
283 else if (BKE_object_defgroup_active_index_get(ob) < 1) {
284 /* Keep a valid active index if we still have some vgroups. */
286 }
287}
288
290{
291 MDeformVert *dvert_array = nullptr;
292 int dvert_tot = 0;
293 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
294
295 const int def_nr = BLI_findindex(defbase, dg);
296
297 BLI_assert(def_nr != -1);
298
299 BKE_object_defgroup_array_get(ob->data, &dvert_array, &dvert_tot);
300
301 if (dvert_array) {
302 int i, j;
303 MDeformVert *dv;
304 for (i = 0, dv = dvert_array; i < dvert_tot; i++, dv++) {
305 MDeformWeight *dw;
306
307 dw = BKE_defvert_find_index(dv, def_nr);
308 BKE_defvert_remove_group(dv, dw); /* dw can be nullptr */
309
310 /* inline, make into a function if anything else needs to do this */
311 for (j = 0; j < dv->totweight; j++) {
312 if (dv->dw[j].def_nr > def_nr) {
313 dv->dw[j].def_nr--;
314 }
315 }
316 /* done */
317 }
318 }
319
320 object_defgroup_remove_common(ob, dg, def_nr);
321}
322
324{
325 int i;
326 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
327 const int def_nr = BLI_findindex(defbase, dg);
328
329 BLI_assert(def_nr != -1);
330
331 /* Make sure that no verts are using this group - if none were removed,
332 * we can skip next per-vert update. */
333 if (!BKE_object_defgroup_clear(ob, dg, false)) {
334 /* Nothing to do. */
335 }
336 /* Else, make sure that any groups with higher indices are adjusted accordingly */
337 else if (ob->type == OB_MESH) {
338 Mesh *mesh = id_cast<Mesh *>(ob->data);
340 const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
341
342 BMIter iter;
343 BMVert *eve;
344 MDeformVert *dvert;
345
346 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
347 dvert = static_cast<MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset));
348
349 if (dvert) {
350 for (i = 0; i < dvert->totweight; i++) {
351 if (dvert->dw[i].def_nr > def_nr) {
352 dvert->dw[i].def_nr--;
353 }
354 }
355 }
356 }
357 }
358 else if (ob->type == OB_LATTICE) {
359 Lattice *lt = (id_cast<Lattice *>(ob->data))->editlatt->latt;
360 MDeformVert *dvert = lt->dvert;
361 int a, tot;
362
363 if (dvert) {
364 tot = lt->pntsu * lt->pntsv * lt->pntsw;
365 for (a = 0; a < tot; a++, dvert++) {
366 for (i = 0; i < dvert->totweight; i++) {
367 if (dvert->dw[i].def_nr > def_nr) {
368 dvert->dw[i].def_nr--;
369 }
370 }
371 }
372 }
373 }
374
375 object_defgroup_remove_common(ob, dg, def_nr);
376}
377
379{
382 }
383 else {
385 }
386
387 if (ob->type == OB_GREASE_PENCIL) {
388 bke::greasepencil::validate_drawing_vertex_groups(*id_cast<GreasePencil *>(ob->data));
389 }
390
392}
393
394void BKE_object_defgroup_remove_all_ex(Object *ob, bool only_unlocked)
395{
396 ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list_mutable(ob);
397
398 bDeformGroup *dg = defbase->first();
399 const bool edit_mode = BKE_object_is_in_editmode_vgroup(ob);
400
401 if (dg) {
402 while (dg) {
403 bDeformGroup *next_dg = dg->next;
404
405 if (!only_unlocked || (dg->flag & DG_LOCK_WEIGHT) == 0) {
406 if (edit_mode) {
408 }
409 else {
411 }
412 }
413
414 dg = next_dg;
415 }
416 }
417 else { /* `defbase` is empty. */
418 /* Remove all deform-verts. */
419 if (ob->type == OB_MESH) {
420 Mesh *mesh = id_cast<Mesh *>(ob->data);
422 }
423 else if (ob->type == OB_LATTICE) {
425 MEM_SAFE_DELETE(lt->dvert);
426 }
427 else if (ob->type == OB_GREASE_PENCIL) {
428 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
430 }
431 /* Fix counters/indices */
433 }
434}
435
440
441int *BKE_object_defgroup_index_map_create(Object *ob_src, Object *ob_dst, int *r_map_len)
442{
443 const ListBaseT<bDeformGroup> *src_defbase = BKE_object_defgroup_list(ob_src);
444 const ListBaseT<bDeformGroup> *dst_defbase = BKE_object_defgroup_list(ob_dst);
445
446 /* Build src to merged mapping of vgroup indices. */
447 if (src_defbase->is_empty() || dst_defbase->is_empty()) {
448 *r_map_len = 0;
449 return nullptr;
450 }
451
452 bDeformGroup *dg_src;
453 *r_map_len = src_defbase->count();
454 int *vgroup_index_map = MEM_new_array_uninitialized<int>(size_t(*r_map_len),
455 "defgroup index map create");
456 bool is_vgroup_remap_needed = false;
457 int i;
458
459 for (dg_src = src_defbase->first(), i = 0; dg_src; dg_src = dg_src->next, i++) {
460 vgroup_index_map[i] = BKE_object_defgroup_name_index(ob_dst, dg_src->name);
461 is_vgroup_remap_needed = is_vgroup_remap_needed || (vgroup_index_map[i] != i);
462 }
463
464 if (!is_vgroup_remap_needed) {
465 MEM_delete(vgroup_index_map);
466 vgroup_index_map = nullptr;
467 *r_map_len = 0;
468 }
469
470 return vgroup_index_map;
471}
472
474 int dvert_len,
475 const int *map,
476 int map_len)
477{
478 if (map == nullptr || map_len == 0) {
479 return;
480 }
481
482 MDeformVert *dv = dvert;
483 for (int i = 0; i < dvert_len; i++, dv++) {
484 int totweight = dv->totweight;
485 for (int j = 0; j < totweight; j++) {
486 int def_nr = dv->dw[j].def_nr;
487 if (uint(def_nr) < uint(map_len) && map[def_nr] != -1) {
488 dv->dw[j].def_nr = map[def_nr];
489 }
490 else {
491 totweight--;
492 dv->dw[j] = dv->dw[totweight];
493 j--;
494 }
495 }
496 if (totweight != dv->totweight) {
497 if (totweight) {
498 dv->dw = static_cast<MDeformWeight *>(
499 MEM_realloc_uninitialized(dv->dw, sizeof(*dv->dw) * totweight));
500 }
501 else {
502 MEM_SAFE_DELETE(dv->dw);
503 }
504 dv->totweight = totweight;
505 }
506 }
507}
508
509bool BKE_object_defgroup_array_get(ID *id, MDeformVert **dvert_arr, int *dvert_tot)
510{
511 if (id) {
512 switch (GS(id->name)) {
513 case ID_ME: {
514 Mesh *mesh = id_cast<Mesh *>(id);
515 *dvert_arr = mesh->deform_verts_for_write().data();
516 *dvert_tot = mesh->verts_num;
517 return true;
518 }
519 case ID_LT: {
521 *dvert_arr = lt->dvert;
522 *dvert_tot = lt->pntsu * lt->pntsv * lt->pntsw;
523 return true;
524 }
525 case ID_GP:
526 /* Should not be used with grease pencil objects. */
527 dvert_arr = nullptr;
528 return false;
529 default:
530 break;
531 }
532 }
533
534 *dvert_arr = nullptr;
535 *dvert_tot = 0;
536 return false;
537}
538
540
541/* --- functions for getting vgroup aligned maps --- */
542
543bool *BKE_object_defgroup_lock_flags_get(Object *ob, const int defbase_tot)
544{
545 bool is_locked = false;
546 int i;
547 ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list_mutable(ob);
548 bool *lock_flags = MEM_new_array_uninitialized<bool>(size_t(defbase_tot), "defflags");
549 bDeformGroup *defgroup;
550
551 for (i = 0, defgroup = defbase->first(); i < defbase_tot && defgroup;
552 defgroup = defgroup->next, i++)
553 {
554 lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0);
555 is_locked |= lock_flags[i];
556 }
557 if (is_locked) {
558 return lock_flags;
559 }
560
561 MEM_delete(lock_flags);
562 return nullptr;
563}
564
565bool *BKE_object_defgroup_validmap_get(Object *ob, const int defbase_tot)
566{
567 bDeformGroup *dg;
568 ModifierData *md;
569 bool *defgroup_validmap;
570 GHash *gh;
571 int i, step1 = 1;
572 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
573 VirtualModifierData virtual_modifier_data;
574
575 if (defbase->is_empty()) {
576 return nullptr;
577 }
578
579 gh = BLI_ghash_str_new_ex(__func__, defbase_tot);
580
581 /* add all names to a hash table */
582 for (bDeformGroup &dg : *defbase) {
583 BLI_ghash_insert(gh, dg.name, nullptr);
584 }
585
586 BLI_assert(BLI_ghash_len(gh) == defbase_tot);
587
588 /* now loop through the armature modifiers and identify deform bones */
589 for (md = ob->modifiers.first(); md; md = !md->next && step1 ? (step1 = 0),
590 BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data) :
591 md->next)
592 {
594 continue;
595 }
596
598 Object *object = (md->type == eModifierType_Armature) ?
599 (reinterpret_cast<ArmatureModifierData *>(md))->object :
600 (reinterpret_cast<GreasePencilArmatureModifierData *>(md))->object;
601 if (object && object->pose) {
602 bPose *pose = object->pose;
603 bArmature *armature = id_cast<bArmature *>(object->data);
605 for (bPoseChannel &chan : pose->chanbase) {
606 void **val_p;
607 if (chan.bone_get(*armature)->flag & BONE_NO_DEFORM) {
608 continue;
609 }
610
611 val_p = BLI_ghash_lookup_p(gh, chan.name);
612 if (val_p) {
613 *val_p = POINTER_FROM_INT(1);
614 }
615 }
616 }
617 }
618 }
619
620 defgroup_validmap = MEM_new_array_uninitialized<bool>(size_t(defbase_tot), "wpaint valid map");
621
622 /* add all names to a hash table */
623 for (dg = defbase->first(), i = 0; dg; dg = dg->next, i++) {
624 defgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != nullptr);
625 }
626
627 BLI_assert(i == BLI_ghash_len(gh));
628
629 BLI_ghash_free(gh, nullptr, nullptr);
630
631 return defgroup_validmap;
632}
633
634bool *BKE_object_defgroup_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
635{
636 bool *dg_selection = MEM_new_array_uninitialized<bool>(size_t(defbase_tot), __func__);
637 bDeformGroup *defgroup;
638 uint i;
640 (*r_dg_flags_sel_tot) = 0;
641
642 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
643
644 if (armob) {
645 bPose *pose = armob->pose;
646 for (i = 0, defgroup = defbase->first(); i < defbase_tot && defgroup;
647 defgroup = defgroup->next, i++)
648 {
650 if (pchan && (pchan->flag & POSE_SELECTED)) {
651 dg_selection[i] = true;
652 (*r_dg_flags_sel_tot) += 1;
653 }
654 else {
655 dg_selection[i] = false;
656 }
657 }
658 }
659 else {
660 memset(dg_selection, false, sizeof(*dg_selection) * defbase_tot);
661 }
662
663 return dg_selection;
664}
665
666bool BKE_object_defgroup_check_lock_relative(const bool *lock_flags,
667 const bool *validmap,
668 int index)
669{
670 return validmap && validmap[index] && !(lock_flags && lock_flags[index]);
671}
672
674 const bool *lock_flags,
675 const bool *selected,
676 int sel_tot)
677{
678 if (lock_flags == nullptr) {
679 return true;
680 }
681
682 if (selected == nullptr || sel_tot <= 1) {
683 return true;
684 }
685
686 for (int i = 0; i < defbase_tot; i++) {
687 if (selected[i] && lock_flags[i]) {
688 return false;
689 }
690 }
691
692 return true;
693}
694
696{
697 bDeformGroup *dg;
698 switch (ob->type) {
699 case OB_GREASE_PENCIL: {
700 GreasePencil *grease_pencil = id_cast<GreasePencil *>(ob->data);
701 dg = static_cast<bDeformGroup *>(BLI_findlink(&grease_pencil->vertex_group_names,
702 grease_pencil->vertex_group_active_index - 1));
703 break;
704 }
705 default: {
706 Mesh *mesh = id_cast<Mesh *>(ob->data);
707 dg = static_cast<bDeformGroup *>(
708 BLI_findlink(&mesh->vertex_group_names, mesh->vertex_group_active_index - 1));
709 break;
710 }
711 }
712 return dg->flag & DG_LOCK_WEIGHT;
713}
714
716 int defbase_tot, const bool *locked, const bool *deform, bool *r_locked, bool *r_unlocked)
717{
718 if (!locked) {
719 if (r_unlocked != deform) {
720 memcpy(r_unlocked, deform, sizeof(bool) * defbase_tot);
721 }
722 if (r_locked) {
723 memset(r_locked, 0, sizeof(bool) * defbase_tot);
724 }
725 return;
726 }
727
728 for (int i = 0; i < defbase_tot; i++) {
729 bool is_locked = locked[i];
730 bool is_deform = deform[i];
731
732 r_locked[i] = is_deform && is_locked;
733 r_unlocked[i] = is_deform && !is_locked;
734 }
735}
736
738 int defbase_tot,
739 const bool *dg_selection,
740 bool *dg_flags_sel,
741 int *r_dg_flags_sel_tot)
742{
743 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
744
745 bDeformGroup *defgroup;
746 uint i;
747 int i_mirr;
748
749 for (i = 0, defgroup = defbase->first(); i < defbase_tot && defgroup;
750 defgroup = defgroup->next, i++)
751 {
752 if (dg_selection[i]) {
753 char name_flip[MAXBONENAME];
754
755 BLI_string_flip_side_name(name_flip, defgroup->name, false, sizeof(name_flip));
756 i_mirr = STREQ(name_flip, defgroup->name) ? i :
757 BKE_object_defgroup_name_index(ob, name_flip);
758
759 if ((i_mirr >= 0 && i_mirr < defbase_tot) && (dg_flags_sel[i_mirr] == false)) {
760 dg_flags_sel[i_mirr] = true;
761 (*r_dg_flags_sel_tot) += 1;
762 }
763 }
764 }
765}
766
768 eVGroupSelect subset_type,
769 int *r_defgroup_tot,
770 int *r_subset_count)
771{
772 bool *defgroup_validmap = nullptr;
773
774 *r_defgroup_tot = BKE_object_defgroup_count(ob);
775
776 switch (subset_type) {
777 case WT_VGROUP_ACTIVE: {
778 const int def_nr_active = BKE_object_defgroup_active_index_get(ob) - 1;
779 defgroup_validmap = MEM_new_array_uninitialized<bool>(size_t(*r_defgroup_tot), __func__);
780 memset(defgroup_validmap, false, *r_defgroup_tot * sizeof(*defgroup_validmap));
781 if ((def_nr_active >= 0) && (def_nr_active < *r_defgroup_tot)) {
782 *r_subset_count = 1;
783 defgroup_validmap[def_nr_active] = true;
784 }
785 else {
786 *r_subset_count = 0;
787 }
788 break;
789 }
791 defgroup_validmap = BKE_object_defgroup_selected_get(ob, *r_defgroup_tot, r_subset_count);
792 break;
793 }
795 int i;
796 defgroup_validmap = BKE_object_defgroup_validmap_get(ob, *r_defgroup_tot);
797 *r_subset_count = 0;
798 for (i = 0; i < *r_defgroup_tot; i++) {
799 if (defgroup_validmap[i] == true) {
800 *r_subset_count += 1;
801 }
802 }
803 break;
804 }
806 int i;
807 defgroup_validmap = BKE_object_defgroup_validmap_get(ob, *r_defgroup_tot);
808 *r_subset_count = 0;
809 for (i = 0; i < *r_defgroup_tot; i++) {
810 defgroup_validmap[i] = !defgroup_validmap[i];
811 if (defgroup_validmap[i] == true) {
812 *r_subset_count += 1;
813 }
814 }
815 break;
816 }
817 case WT_VGROUP_ALL:
818 default: {
819 defgroup_validmap = MEM_new_array_uninitialized<bool>(size_t(*r_defgroup_tot), __func__);
820 memset(defgroup_validmap, true, *r_defgroup_tot * sizeof(*defgroup_validmap));
821 *r_subset_count = *r_defgroup_tot;
822 break;
823 }
824 }
825
826 return defgroup_validmap;
827}
828
829void BKE_object_defgroup_subset_to_index_array(const bool *defgroup_validmap,
830 const int defgroup_tot,
831 int *r_defgroup_subset_map)
832{
833 int i, j = 0;
834 for (i = 0; i < defgroup_tot; i++) {
835 if (defgroup_validmap[i]) {
836 r_defgroup_subset_map[j++] = i;
837 }
838 }
839}
840
841} // namespace blender
Blender kernel action and pose functionality.
support for deformation groups and hooks.
Utility functions for vertex groups in grease pencil objects.
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
#define DATA_(msgid)
#define MAXBONENAME
Object is a sort of wrapper for general info.
#define OB_TYPE_SUPPORT_VGROUP(_type)
Read Blender memory allocation and freeing.
#define POINTER_FROM_INT(i)
#define ELEM(...)
#define STREQ(a, b)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define MEM_realloc_uninitialized(vmemh, len)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void clear_vertex_groups(GreasePencil &grease_pencil)
void validate_drawing_vertex_groups(GreasePencil &grease_pencil)
BMesh Iterators.
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
struct MDeformVert * BKE_object_defgroup_data_create(struct ID *id)
bool BKE_object_is_in_editmode_vgroup(const Object *ob)
Definition object.cc:1927
void BKE_object_defgroup_remap_update_users(struct Object *ob, const int *map)
ListBaseT< bDeformGroup > * BKE_object_defgroup_list_mutable(Object *ob)
Definition deform.cc:602
bool CustomData_free_layer_active(CustomData *data, eCustomDataType type)
const ListBaseT< bDeformGroup > * BKE_object_defgroup_list(const Object *ob)
Definition deform.cc:591
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
int BKE_object_defgroup_count(const Object *ob)
Definition deform.cc:608
bool BKE_object_defgroup_array_get(struct ID *id, struct MDeformVert **dvert_arr, int *dvert_tot)
void BKE_object_defgroup_mirror_selection(struct Object *ob, int defbase_tot, const bool *selection, bool *dg_flags_sel, int *r_dg_flags_sel_tot)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:735
bool BKE_object_defgroup_clear_all(struct Object *ob, bool use_selection)
bool * BKE_object_defgroup_validmap_get(struct Object *ob, int defbase_tot)
@ eModifierType_GreasePencilArmature
@ WT_VGROUP_BONE_SELECT
@ WT_VGROUP_BONE_DEFORM
@ WT_VGROUP_BONE_DEFORM_OFF
static void object_defgroup_remove_object_mode(Object *ob, bDeformGroup *dg)
void BKE_object_defgroup_split_locked_validmap(int defbase_tot, const bool *locked, const bool *deform, bool *r_locked, bool *r_unlocked)
void BKE_object_defgroup_active_index_set(Object *ob, int new_index)
Definition deform.cc:618
void BKE_pose_ensure_bone_indices(const Object &pose_object)
void BKE_object_batch_cache_dirty_tag(Object *ob)
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
static void object_defgroup_remove_update_users(Object *ob, const int idx)
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:749
void BKE_object_defgroup_remove_all(struct Object *ob)
bool * BKE_object_defgroup_selected_get(struct Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
static void object_defgroup_remove_common(Object *ob, bDeformGroup *dg, const int def_nr)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
int BKE_object_defgroup_name_index(const Object *ob, StringRef name)
Definition deform.cc:597
void BKE_object_defgroup_index_map_apply(struct MDeformVert *dvert, int dvert_len, const int *map, int map_len)
struct bDeformGroup * BKE_object_defgroup_add_name(struct Object *ob, const char *name)
bool BKE_object_defgroup_clear(struct Object *ob, struct bDeformGroup *dg, bool use_selection)
void BKE_object_defgroup_subset_to_index_array(const bool *defgroup_validmap, int defgroup_tot, int *r_defgroup_subset_map)
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:706
bool * BKE_object_defgroup_lock_flags_get(struct Object *ob, int defbase_tot)
bool BKE_object_defgroup_check_lock_relative_multi(int defbase_tot, const bool *lock_flags, const bool *selected, int sel_tot)
bDeformGroup * BKE_object_defgroup_new(Object *ob, StringRef name)
Definition deform.cc:51
int * BKE_object_defgroup_index_map_create(struct Object *ob_src, struct Object *ob_dst, int *r_map_len)
struct bDeformGroup * BKE_object_defgroup_add(struct Object *ob)
bool BKE_object_defgroup_active_is_locked(const struct Object *ob)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
static void object_defgroup_remove_edit_mode(Object *ob, bDeformGroup *dg)
void BKE_object_defgroup_remove_all_ex(struct Object *ob, bool only_unlocked)
bool * BKE_object_defgroup_subset_from_select_type(struct Object *ob, enum eVGroupSelect subset_type, int *r_defgroup_tot, int *r_subset_count)
void BKE_object_defgroup_remove(struct Object *ob, struct bDeformGroup *defgroup)
bool BKE_object_defgroup_check_lock_relative(const bool *lock_flags, const bool *validmap, int index)
void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
Definition deform.cc:885
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
MDeformWeight * BKE_defvert_find_index(const MDeformVert *dv, int defgroup)
Definition deform.cc:811
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
size_t BLI_string_flip_side_name(char *name_dst, const char *name_src, bool strip_number, size_t name_dst_maxncpy) ATTR_NONNULL(1
static Lattice * object_defgroup_lattice_get(ID *id)
int BKE_object_defgroup_active_index_get(const Object *ob)
Definition deform.cc:613
struct ClothSimSettings * sim_parms
struct ClothCollSettings * coll_parms
struct Lattice * latt
struct EditLatt * editlatt
struct MDeformVert * dvert
struct BPoint * def
struct MDeformWeight * dw
struct ModifierData * next
ListBaseT< ModifierData > modifiers
ListBaseT< struct ParticleSystem > particlesystem
struct bPose * pose
struct SoftBody * soft
struct bDeformGroup * next
ebDeformGroup_Flag flag