Blender V5.3
deform.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 <algorithm>
10#include <cctype>
11#include <cstddef>
12#include <cstdlib>
13#include <cstring>
14
15#include "BLI_math_base.hh"
16#include "MEM_guardedalloc.h"
17
20#include "DNA_lattice_types.h"
21#include "DNA_mesh_types.h"
22#include "DNA_meshdata_types.h"
23#include "DNA_modifier_enums.h"
24#include "DNA_object_types.h"
25
26#include "BLI_listbase.hh"
27#include "BLI_math_vector_c.hh"
28#include "BLI_span.hh"
29#include "BLI_string_utf8.hh"
30#include "BLI_string_utils.hh"
31#include "BLI_utildefines.hh"
32
33#include "PRF_profile.hh"
34
35#include "BLT_translation.hh"
36
37#include "BKE_customdata.hh"
38#include "BKE_deform.hh" /* own include */
39#include "BKE_grease_pencil.hh"
41#include "BKE_mesh.hh"
42#include "BKE_object.hh"
43#include "BKE_object_deform.h"
44
45#include "BLO_read_write.hh"
46
48
49namespace blender {
50
52{
53 bDeformGroup *defgroup;
54
56
57 defgroup = MEM_new<bDeformGroup>(__func__);
58
59 name.copy_utf8_truncated(defgroup->name);
60
61 ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list_mutable(ob);
62
63 BLI_addtail(defbase, defgroup);
65
66 if (ob->type == OB_GREASE_PENCIL) {
67 bke::greasepencil::validate_drawing_vertex_groups(*id_cast<GreasePencil *>(ob->data));
68 }
69
71
72 return defgroup;
73}
74
75void BKE_defgroup_copy_list(ListBaseT<bDeformGroup> *outbase,
76 const ListBaseT<bDeformGroup> *inbase)
77{
78 outbase->clear_no_delete();
79 for (const bDeformGroup &defgroup : *inbase) {
80 bDeformGroup *defgroupn = BKE_defgroup_duplicate(&defgroup);
81 BLI_addtail(outbase, defgroupn);
82 }
83}
84
86{
87 if (!ingroup) {
88 BLI_assert(0);
89 return nullptr;
90 }
91
92 bDeformGroup *outgroup = MEM_new<bDeformGroup>(__func__);
93
94 /* For now, just copy everything over. */
95 memcpy(outgroup, ingroup, sizeof(bDeformGroup));
96
97 outgroup->next = outgroup->prev = nullptr;
98
99 return outgroup;
100}
101
103 const MDeformVert *dvert_src,
104 const bool *vgroup_subset,
105 const int vgroup_num)
106{
107 int defgroup;
108 for (defgroup = 0; defgroup < vgroup_num; defgroup++) {
109 if (vgroup_subset[defgroup]) {
110 BKE_defvert_copy_index(dvert_dst, defgroup, dvert_src, defgroup);
111 }
112 }
113}
114
116 const MDeformVert *dvert_src,
117 const bool *vgroup_subset,
118 const int vgroup_num,
119 const int *flip_map,
120 const int flip_map_num)
121{
122 int defgroup;
123 for (defgroup = 0; defgroup < vgroup_num && defgroup < flip_map_num; defgroup++) {
124 if (vgroup_subset[defgroup] && (dvert_dst != dvert_src || flip_map[defgroup] != defgroup)) {
125 BKE_defvert_copy_index(dvert_dst, flip_map[defgroup], dvert_src, defgroup);
126 }
127 }
128}
129
130void BKE_defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
131{
132 if (dvert_dst->totweight == dvert_src->totweight) {
133 if (dvert_src->totweight) {
134 memcpy(dvert_dst->dw, dvert_src->dw, dvert_src->totweight * sizeof(MDeformWeight));
135 }
136 }
137 else {
138 if (dvert_dst->dw) {
139 MEM_delete(dvert_dst->dw);
140 }
141
142 if (dvert_src->totweight) {
143 dvert_dst->dw = MEM_dupalloc(dvert_src->dw);
144 }
145 else {
146 dvert_dst->dw = nullptr;
147 }
148
149 dvert_dst->totweight = dvert_src->totweight;
150 }
151}
152
154 const int defgroup_dst,
155 const MDeformVert *dvert_src,
156 const int defgroup_src)
157{
158 MDeformWeight *dw_dst;
159
160 const MDeformWeight *dw_src = BKE_defvert_find_index(dvert_src, defgroup_src);
161
162 if (dw_src) {
163 /* Source is valid, ensure destination is created. */
164 dw_dst = BKE_defvert_ensure_index(dvert_dst, defgroup_dst);
165 dw_dst->weight = dw_src->weight;
166 }
167 else {
168 /* Source was nullptr, assign zero (could also remove). */
169 dw_dst = BKE_defvert_find_index(dvert_dst, defgroup_dst);
170
171 if (dw_dst) {
172 dw_dst->weight = 0.0f;
173 }
174 }
175}
176
177void BKE_defvert_sync(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool use_ensure)
178{
179 if (dvert_src->totweight && dvert_dst->totweight) {
180 MDeformWeight *dw_src = dvert_src->dw;
181 for (int i = 0; i < dvert_src->totweight; i++, dw_src++) {
182 MDeformWeight *dw_dst;
183 if (use_ensure) {
184 dw_dst = BKE_defvert_ensure_index(dvert_dst, dw_src->def_nr);
185 }
186 else {
187 dw_dst = BKE_defvert_find_index(dvert_dst, dw_src->def_nr);
188 }
189
190 if (dw_dst) {
191 dw_dst->weight = dw_src->weight;
192 }
193 }
194 }
195}
196
198 const MDeformVert *dvert_src,
199 const int *flip_map,
200 const int flip_map_num,
201 const bool use_ensure)
202{
203 if (dvert_src->totweight && dvert_dst->totweight) {
204 MDeformWeight *dw_src = dvert_src->dw;
205 for (int i = 0; i < dvert_src->totweight; i++, dw_src++) {
206 if (dw_src->def_nr < flip_map_num) {
207 MDeformWeight *dw_dst;
208 if (use_ensure) {
209 dw_dst = BKE_defvert_ensure_index(dvert_dst, flip_map[dw_src->def_nr]);
210 }
211 else {
212 dw_dst = BKE_defvert_find_index(dvert_dst, flip_map[dw_src->def_nr]);
213 }
214
215 if (dw_dst) {
216 dw_dst->weight = dw_src->weight;
217 }
218 }
219 }
220 }
221}
222
223void BKE_defvert_remap(MDeformVert *dvert, const int *map, const int map_len)
224{
225 MDeformWeight *dw = dvert->dw;
226 for (int i = dvert->totweight; i != 0; i--, dw++) {
227 if (dw->def_nr < map_len) {
228 BLI_assert(map[dw->def_nr] >= 0);
229
230 dw->def_nr = map[dw->def_nr];
231 }
232 }
233}
234
236{
237 BKE_defvert_normalize_ex(dvert, subset_flags, {}, {});
238}
239
241{
242 BKE_defvert_normalize_ex(dvert, {}, {}, {});
243}
244
246 Span<bool> subset_flags,
247 Span<bool> lock_flags)
248{
249 BKE_defvert_normalize_ex(dvert, subset_flags, lock_flags, {});
250}
251
253 Span<bool> subset_flags,
254 Span<bool> lock_flags,
255 Span<bool> soft_lock_flags)
256{
257 const bool use_subset = !subset_flags.is_empty();
258 const bool use_locks = !lock_flags.is_empty();
259 const bool use_soft_locks = !soft_lock_flags.is_empty();
260
261 /* Note: confusingly, `totweight` isn't the total weight on the vertex, it's
262 * the number of vertex groups assigned to the vertex. It's a DNA field, so
263 * I'm leaving it named as-is for now despite it being confusing. */
264 if (dvert.totweight == 0) {
265 /* No vertex groups assigned: do nothing. */
266 return;
267 }
268
269 if (dvert.totweight == 1) {
270 /* Only one vertex group is assigned to the vertex.
271 *
272 * TODO: this special case for single-group vertices should be completely
273 * unnecessary. The code further below works just as well for one assigned
274 * group as for twenty. However, the old version of this function was *not*
275 * consistent in its behavior between single-group and multi-group vertices:
276 * single-group vertices would set the group weight to 1.0 even if the
277 * initial weight was zero, whereas multi-group vertices with all weights
278 * set to zero would be left as-is.
279 *
280 * I (Nathan Vegdahl) decided to leave this special case here just in case
281 * any other code depends on this odd behavior. But we should revisit this
282 * at some point to check if that's actually the case, and simply remove
283 * this special case if nothing is depending on it. */
284
285 MDeformWeight *dw = dvert.dw;
286
287 if (use_subset && !subset_flags[dw->def_nr]) {
288 return;
289 }
290
291 const bool is_unlocked = lock_flags.is_empty() || !lock_flags[dw->def_nr];
292 if (is_unlocked) {
293 dw->weight = 1.0f;
294 }
295 return;
296 }
297
298 MutableSpan<MDeformWeight> vertex_weights = MutableSpan(dvert.dw, dvert.totweight);
299
300 /* Collect weights. */
301 float total_locked_weight = 0.0f;
302 float total_soft_locked_weight = 0.0f;
303 float total_regular_weight = 0.0f; /* Neither locked nor soft locked. */
304 int soft_locked_group_count = 0;
305 for (MDeformWeight &dw : vertex_weights) {
306 if (use_subset && !subset_flags[dw.def_nr]) {
307 /* Not part of the subset being normalized. */
308 continue;
309 }
310
311 if (use_locks && lock_flags[dw.def_nr]) {
312 /* Locked. */
313 total_locked_weight += dw.weight;
314 }
315 else if (use_soft_locks && soft_lock_flags[dw.def_nr]) {
316 total_soft_locked_weight += dw.weight;
317 soft_locked_group_count++;
318 }
319 else {
320 total_regular_weight += dw.weight;
321 }
322 }
323
324 const float available_weight = max_ff(0.0f, 1.0f - total_locked_weight);
325
326 /* Special case: all non-hard-locked vertex groups have zero weight.
327 *
328 * Note: conceptually this if condition is checking for `== 0.0`, because
329 * negative weights shouldn't be possible. We're just being paranoid with
330 * the `<=`. */
331 if (total_regular_weight <= 0.0f && total_soft_locked_weight <= 0.0f) {
332 /* There isn't any "right" thing to do here.
333 *
334 * What we choose to do is: if there are any soft-locked groups on the
335 * vertex, distribute the needed weight equally among them. If there are no
336 * soft-locked groups on the vertex, we do nothing. The rationale behind
337 * this is that:
338 *
339 * 1. Zero-weight groups should typically be treated the same as unassigned
340 * groups.
341 * 2. But soft-locked groups can be treated specially: since their intended
342 * use case is indicating vertex groups that have just now had their
343 * weights set, we know they were intentionally set. Therefore even when
344 * zero-weight we can consider them assigned.
345 *
346 * There isn't any deep truth behind this approach, but after discussion
347 * with a few people I (Nathan Vegdahl) think in practice this is likely to
348 * be the least surprising behavior to users (out of several bad options).
349 * In particular, when the user modifies weights with auto-normalize
350 * enabled, they expect Blender to ensure normalized weights whenever
351 * possible (see issue #141024), and this approach achieves that.
352 *
353 * However, this approach is very much worth revisiting if it ends up
354 * causing other problems. */
355
356 if (soft_locked_group_count == 0) {
357 return;
358 }
359
360 const float weight = available_weight / soft_locked_group_count;
361 for (MDeformWeight &dw : vertex_weights) {
362 if (!subset_flags.is_empty() && !subset_flags[dw.def_nr]) {
363 /* Not part of the subset being normalized. */
364 continue;
365 }
366
367 if (!lock_flags.is_empty() && lock_flags[dw.def_nr]) {
368 /* Locked. */
369 continue;
370 }
371
372 if (use_soft_locks && soft_lock_flags[dw.def_nr]) {
373 dw.weight = weight;
374 }
375 }
376
377 return;
378 }
379
380 /* Compute scale factors for soft-locked and regular group weights. */
381 float soft_locked_scale;
382 float regular_scale;
383 const bool must_adjust_soft_locked = total_soft_locked_weight >= available_weight ||
384 total_regular_weight <= 0.0f;
385 if (must_adjust_soft_locked) {
386 soft_locked_scale = available_weight / total_soft_locked_weight;
387 regular_scale = 0.0f;
388 }
389 else {
390 soft_locked_scale = 1.0f;
391 regular_scale = (available_weight - total_soft_locked_weight) / total_regular_weight;
392 }
393
394 /* Normalize the weights via scaling by the appropriate factors. */
395 for (MDeformWeight &dw : vertex_weights) {
396 if (use_subset && !subset_flags[dw.def_nr]) {
397 /* Not part of the subset being normalized. */
398 continue;
399 }
400
401 if (use_locks && lock_flags[dw.def_nr]) {
402 /* Locked. */
403 continue;
404 }
405
406 if (use_soft_locks && soft_lock_flags[dw.def_nr]) {
407 dw.weight *= soft_locked_scale;
408 }
409 else {
410 dw.weight *= regular_scale;
411 }
412
413 /* In case of division errors with very low weights. */
414 CLAMP(dw.weight, 0.0f, 1.0f);
415 }
416}
417
418void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_num)
419{
420 MDeformWeight *dw;
421 int i;
422
423 for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) {
424 if (dw->def_nr < flip_map_num) {
425 if (flip_map[dw->def_nr] >= 0) {
426 dw->def_nr = flip_map[dw->def_nr];
427 }
428 }
429 }
430}
431
432void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int flip_map_num)
433{
434 MDeformWeight *dw, *dw_cpy;
435 float weight;
436 int i, totweight = dvert->totweight;
437
438 /* copy weights */
439 for (dw = dvert->dw, i = 0; i < totweight; dw++, i++) {
440 if (dw->def_nr < flip_map_num) {
441 if (flip_map[dw->def_nr] >= 0) {
442 /* error checkers complain of this but we'll never get nullptr return */
443 dw_cpy = BKE_defvert_ensure_index(dvert, flip_map[dw->def_nr]);
444 dw = &dvert->dw[i]; /* in case array got realloced */
445
446 /* distribute weights: if only one of the vertex groups was
447 * assigned this will halve the weights, otherwise it gets
448 * evened out. this keeps it proportional to other groups */
449 weight = 0.5f * (dw_cpy->weight + dw->weight);
450 dw_cpy->weight = weight;
451 dw->weight = weight;
452 }
453 }
454 }
455}
456
458{
459 if (id == nullptr) {
460 return false;
461 }
462 return ELEM(GS(id->name), ID_ME, ID_LT, ID_GD_LEGACY, ID_GP);
463}
464
466{
467 const ID *id = static_cast<const ID *>(ob->data);
468
470}
471
472const ListBaseT<bDeformGroup> *BKE_id_defgroup_list_get(const ID *id)
473{
474 switch (GS(id->name)) {
475 case ID_ME: {
476 const Mesh *mesh = id_cast<const Mesh *>(id);
477 return &mesh->vertex_group_names;
478 }
479 case ID_LT: {
480 const Lattice *lt = id_cast<const Lattice *>(id);
481 return &lt->vertex_group_names;
482 }
483 case ID_GD_LEGACY: {
484 const bGPdata *gpd = id_cast<const bGPdata *>(id);
485 return &gpd->vertex_group_names;
486 }
487 case ID_GP: {
488 const GreasePencil *grease_pencil = id_cast<const GreasePencil *>(id);
489 return &grease_pencil->vertex_group_names;
490 }
491 default: {
493 }
494 }
495 return nullptr;
496}
497
498static const int *object_defgroup_active_index_get_p(const Object *ob)
499{
501 switch (ob->type) {
502 case OB_MESH: {
503 const Mesh *mesh = id_cast<const Mesh *>(ob->data);
504 return &mesh->vertex_group_active_index;
505 }
506 case OB_LATTICE: {
507 const Lattice *lattice = id_cast<const Lattice *>(ob->data);
508 return &lattice->vertex_group_active_index;
509 }
510 case OB_GPENCIL_LEGACY: {
511 const bGPdata *gpd = id_cast<const bGPdata *>(ob->data);
512 return &gpd->vertex_group_active_index;
513 }
514 case OB_GREASE_PENCIL: {
515 const GreasePencil *grease_pencil = id_cast<const GreasePencil *>(ob->data);
516 return &grease_pencil->vertex_group_active_index;
517 }
518 default:
519 break;
520 }
521 return nullptr;
522}
523
524ListBaseT<bDeformGroup> *BKE_id_defgroup_list_get_mutable(ID *id)
525{
526 /* Cast away const just for the accessor. */
527 return const_cast<ListBaseT<bDeformGroup> *>(BKE_id_defgroup_list_get(id));
528}
529
531{
532 if (name.is_empty()) {
533 return nullptr;
534 }
535 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
536 for (bDeformGroup &group : *defbase) {
537 if (name == group.name) {
538 return &group;
539 }
540 }
541 return nullptr;
542}
543
544int BKE_defgroup_name_index(const ListBaseT<bDeformGroup> *defbase, const StringRef name)
545{
546 if (name.is_empty()) {
547 return -1;
548 }
549 for (const auto [index, group] : defbase->enumerate()) {
550 if (name == group.name) {
551 return index;
552 }
553 }
554 return -1;
555}
556
557int BKE_id_defgroup_name_index(const ID *id, const StringRef name)
558{
560}
561
562bool BKE_defgroup_listbase_name_find(ListBaseT<bDeformGroup> *defbase,
563 const StringRef name,
564 int *r_index,
565 bDeformGroup **r_group)
566{
567 if (name.is_empty()) {
568 return false;
569 }
570
571 for (const auto [index, group] : defbase->enumerate()) {
572 if (name == group.name) {
573 if (r_index != nullptr) {
574 *r_index = index;
575 }
576 if (r_group != nullptr) {
577 *r_group = &group;
578 }
579 return true;
580 }
581 }
582 return false;
583}
584
585bool BKE_id_defgroup_name_find(ID *id, const StringRef name, int *r_index, bDeformGroup **r_group)
586{
588 const_cast<ListBaseT<bDeformGroup> *>(BKE_id_defgroup_list_get(id)), name, r_index, r_group);
589}
590
591const ListBaseT<bDeformGroup> *BKE_object_defgroup_list(const Object *ob)
592{
594 return BKE_id_defgroup_list_get(static_cast<const ID *>(ob->data));
595}
596
598{
599 return BKE_id_defgroup_name_index(ob->data, name);
600}
601
607
612
617
618void BKE_object_defgroup_active_index_set(Object *ob, const int new_index)
619{
620 /* Cast away const just for the accessor. */
621 int *index = const_cast<int *>(object_defgroup_active_index_get_p(ob));
622 *index = new_index;
623}
624
626 const bool use_default,
627 const bool use_only_unlocked,
628 int *r_flip_map_num)
629{
630 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
631 const int defbase_num = defbase->count();
632 *r_flip_map_num = defbase_num;
633
634 if (defbase_num == 0) {
635 return nullptr;
636 }
637
638 bDeformGroup *dg;
639 char name_flip[sizeof(dg->name)];
640 int i, flip_num;
641 int *map = MEM_new_array_uninitialized<int>(size_t(defbase_num), __func__);
642
643 for (i = 0; i < defbase_num; i++) {
644 map[i] = -1;
645 }
646
647 for (dg = defbase->first(), i = 0; dg; dg = dg->next, i++) {
648 if (map[i] == -1) { /* may be calculated previously */
649
650 /* in case no valid value is found, use this */
651 if (use_default) {
652 map[i] = i;
653 }
654
655 if (use_only_unlocked && (dg->flag & DG_LOCK_WEIGHT)) {
656 continue;
657 }
658
659 BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
660
661 if (!STREQ(name_flip, dg->name)) {
662 flip_num = BKE_object_defgroup_name_index(ob, name_flip);
663 if (flip_num != -1) {
664 map[i] = flip_num;
665 map[flip_num] = i; /* save an extra lookup */
666 }
667 }
668 }
669 }
670 return map;
671}
672
673int *BKE_object_defgroup_flip_map(const Object *ob, const bool use_default, int *r_flip_map_num)
674{
675 return object_defgroup_unlocked_flip_map_ex(ob, use_default, false, r_flip_map_num);
676}
677
679 const bool use_default,
680 int *r_flip_map_num)
681{
682 return object_defgroup_unlocked_flip_map_ex(ob, use_default, true, r_flip_map_num);
683}
684
686 const bool use_default,
687 const int defgroup,
688 int *r_flip_map_num)
689{
690 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
691 const int defbase_num = defbase->count();
692 *r_flip_map_num = defbase_num;
693
694 if (defbase_num == 0) {
695 return nullptr;
696 }
697
698 char name_flip[sizeof(bDeformGroup::name)];
699 int i, flip_num, *map = MEM_new_array_uninitialized<int>(size_t(defbase_num), __func__);
700
701 for (i = 0; i < defbase_num; i++) {
702 map[i] = use_default ? i : -1;
703 }
704
705 bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, defgroup));
706
707 BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
708 if (!STREQ(name_flip, dg->name)) {
709 flip_num = BKE_object_defgroup_name_index(ob, name_flip);
710
711 if (flip_num != -1) {
712 map[defgroup] = flip_num;
713 map[flip_num] = defgroup;
714 }
715 }
716
717 return map;
718}
719
720int BKE_object_defgroup_flip_index(const Object *ob, int index, const bool use_default)
721{
722 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
723 bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, index));
724 int flip_index = -1;
725
726 if (dg) {
727 char name_flip[sizeof(dg->name)];
728 BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
729
730 if (!STREQ(name_flip, dg->name)) {
731 flip_index = BKE_object_defgroup_name_index(ob, name_flip);
732 }
733 }
734
735 return (flip_index == -1 && use_default) ? index : flip_index;
736}
737
742
743static bool defgroup_find_name_dupe(const StringRef name, bDeformGroup *dg, Object *ob)
744{
745 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
746
747 for (bDeformGroup &curdef : *defbase) {
748 if (dg != &curdef) {
749 if (curdef.name == name) {
750 return true;
751 }
752 }
753 }
754
755 return false;
756}
757
759{
760 BLI_uniquename_cb([&](const StringRef name) { return defgroup_find_name_dupe(name, dg, ob); },
761 DATA_("Group"),
762 '.',
763 dg->name,
764 sizeof(dg->name));
765}
766
767void BKE_object_defgroup_set_name(bDeformGroup *dg, Object *ob, const char *new_name)
768{
769 std::string old_name = dg->name;
770 STRNCPY_UTF8(dg->name, new_name);
772
773 if (ob->type == OB_GREASE_PENCIL) {
774 /* Update vgroup names stored in CurvesGeometry */
775 BKE_grease_pencil_vgroup_name_update(ob, old_name.c_str(), dg->name);
776 }
777}
778
779float BKE_defvert_find_weight(const MDeformVert *dvert, const int defgroup)
780{
781 MDeformWeight *dw = BKE_defvert_find_index(dvert, defgroup);
782 return dw ? dw->weight : 0.0f;
783}
784
786 const int index,
787 const int defgroup,
788 const bool invert)
789{
790 /* Invalid defgroup index means the vgroup selected is invalid,
791 * does not exist, in that case it is OK to return 1.0
792 * (i.e. maximum weight, as if no vgroup was selected).
793 * But in case of valid defgroup and nullptr dvert data pointer, it means that vgroup **is**
794 * valid, and just totally empty, so we shall return '0.0' (or '1.0' if inverted) value then! */
795 if (defgroup == -1) {
796 return 1.0f;
797 }
798 if (dvert == nullptr) {
799 return invert ? 1.0 : 0.0f;
800 }
801
802 float weight = BKE_defvert_find_weight(dvert + index, defgroup);
803
804 if (invert) {
805 weight = 1.0f - weight;
806 }
807
808 return weight;
809}
810
811MDeformWeight *BKE_defvert_find_index(const MDeformVert *dvert, const int defgroup)
812{
813 if (dvert && defgroup >= 0) {
814 MDeformWeight *dw = dvert->dw;
815 uint i;
816
817 for (i = dvert->totweight; i != 0; i--, dw++) {
818 if (dw->def_nr == defgroup) {
819 return dw;
820 }
821 }
822 }
823 else {
824 BLI_assert(0);
825 }
826
827 return nullptr;
828}
829
831{
832 MDeformWeight *dw_new;
833
834 /* do this check always, this function is used to check for it */
835 if (!dvert || defgroup < 0) {
836 BLI_assert(0);
837 return nullptr;
838 }
839
840 dw_new = BKE_defvert_find_index(dvert, defgroup);
841 if (dw_new) {
842 return dw_new;
843 }
844
845 dw_new = MEM_new_array_uninitialized<MDeformWeight>(size_t(dvert->totweight) + 1, __func__);
846 if (dvert->dw) {
847 memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
848 MEM_delete(dvert->dw);
849 }
850 dvert->dw = dw_new;
851 dw_new += dvert->totweight;
852 dw_new->weight = 0.0f;
853 dw_new->def_nr = defgroup;
854 /* Group index */
855
856 dvert->totweight++;
857
858 return dw_new;
859}
860
861void BKE_defvert_add_index_notest(MDeformVert *dvert, const int defgroup, const float weight)
862{
863 /* TODO: merge with #BKE_defvert_ensure_index! */
864
865 MDeformWeight *dw_new;
866
867 /* do this check always, this function is used to check for it */
868 if (!dvert || defgroup < 0) {
869 BLI_assert(0);
870 return;
871 }
872
873 dw_new = MEM_new_array_zeroed<MDeformWeight>(size_t(dvert->totweight) + 1, __func__);
874 if (dvert->dw) {
875 memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
876 MEM_delete(dvert->dw);
877 }
878 dvert->dw = dw_new;
879 dw_new += dvert->totweight;
880 dw_new->weight = weight;
881 dw_new->def_nr = defgroup;
882 dvert->totweight++;
883}
884
886{
887 if (!dvert || !dw) [[unlikely]] {
888 return;
889 }
890 /* Ensure `dw` is part of `dvert` (security check). */
891 if (uintptr_t(dw - dvert->dw) >= uintptr_t(dvert->totweight)) [[unlikely]] {
892 /* Assert as an invalid `dw` (while supported) isn't likely to do what the caller expected. */
894 return;
895 }
896
897 const int i = dw - dvert->dw;
898 dvert->totweight--;
899 /* If there are still other deform weights attached to this vert then remove
900 * this deform weight, and reshuffle the others. */
901 if (dvert->totweight) {
902 BLI_assert(dvert->dw != nullptr);
903
904 if (i != dvert->totweight) {
905 dvert->dw[i] = dvert->dw[dvert->totweight];
906 }
907
908 dvert->dw = static_cast<MDeformWeight *>(
909 MEM_realloc_uninitialized(dvert->dw, sizeof(MDeformWeight) * dvert->totweight));
910 }
911 else {
912 /* If there are no other deform weights left then just remove this one. */
913 MEM_delete(dvert->dw);
914 dvert->dw = nullptr;
915 }
916}
917
919{
920 MEM_SAFE_DELETE(dvert->dw);
921
922 dvert->totweight = 0;
923}
924
925int BKE_defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert_b)
926{
927 if (dvert_a->totweight && dvert_b->totweight) {
928 MDeformWeight *dw = dvert_a->dw;
929 uint i;
930
931 for (i = dvert_a->totweight; i != 0; i--, dw++) {
932 if (dw->weight > 0.0f && BKE_defvert_find_weight(dvert_b, dw->def_nr) > 0.0f) {
933 return dw->def_nr;
934 }
935 }
936 }
937
938 return -1;
939}
940
941bool BKE_defvert_is_weight_zero(const MDeformVert *dvert, const int defgroup_tot)
942{
943 MDeformWeight *dw = dvert->dw;
944 for (int i = dvert->totweight; i != 0; i--, dw++) {
945 if (dw->weight != 0.0f) {
946 /* check the group is in-range, happens on rare situations */
947 if (dw->def_nr < defgroup_tot) [[likely]] {
948 return false;
949 }
950 }
951 }
952 return true;
953}
954
956 int defbase_num,
957 const bool *defbase_sel)
958{
959 float total = 0.0f;
960 const MDeformWeight *dw = dv->dw;
961
962 if (defbase_sel == nullptr) {
963 return total;
964 }
965
966 for (int i = dv->totweight; i != 0; i--, dw++) {
967 if (dw->def_nr < defbase_num) {
968 if (defbase_sel[dw->def_nr]) {
969 total += dw->weight;
970 }
971 }
972 }
973
974 return total;
975}
976
978 const int defbase_num,
979 const bool *defbase_sel,
980 const int defbase_sel_num,
981 const bool is_normalized)
982{
983 float total = BKE_defvert_total_selected_weight(dv, defbase_num, defbase_sel);
984
985 /* in multipaint, get the average if auto normalize is inactive
986 * get the sum if it is active */
987 if (!is_normalized) {
988 total /= defbase_sel_num;
989 }
990
991 return total;
992}
993
995 float locked_weight,
996 float unlocked_weight)
997{
998 /* First try normalizing unlocked weights. */
999 if (unlocked_weight > 0.0f) {
1000 return weight / unlocked_weight;
1001 }
1002
1003 /* If no unlocked weight exists, take locked into account. */
1004 if (locked_weight <= 0.0f) {
1005 return weight;
1006 }
1007
1008 /* handle division by zero */
1009 if (locked_weight >= 1.0f - VERTEX_WEIGHT_LOCK_EPSILON) {
1010 if (weight != 0.0f) {
1011 return 1.0f;
1012 }
1013
1014 /* resolve 0/0 to 0 */
1015 return 0.0f;
1016 }
1017
1018 /* non-degenerate division */
1019 return weight / (1.0f - locked_weight);
1020}
1021
1022float BKE_defvert_lock_relative_weight(const float weight,
1023 const MDeformVert *dv,
1024 const int defbase_num,
1025 const bool *defbase_locked,
1026 const bool *defbase_unlocked)
1027{
1028 float unlocked = BKE_defvert_total_selected_weight(dv, defbase_num, defbase_unlocked);
1029
1030 if (unlocked > 0.0f) {
1031 return weight / unlocked;
1032 }
1033
1034 float locked = BKE_defvert_total_selected_weight(dv, defbase_num, defbase_locked);
1035
1036 return BKE_defvert_calc_lock_relative_weight(weight, locked, unlocked);
1037}
1038
1039/* -------------------------------------------------------------------- */
1042
1043void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
1044{
1045 /* Assumes dst is already set up */
1046
1047 if (!src || !dst) {
1048 return;
1049 }
1050
1051 memcpy(dst, src, totvert * sizeof(MDeformVert));
1052
1053 for (int i = 0; i < totvert; i++) {
1054 if (src[i].dw) {
1055 dst[i].dw = MEM_new_array_uninitialized<MDeformWeight>(size_t(src[i].totweight), __func__);
1056 memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight);
1057 }
1058 }
1059}
1060
1062{
1063 /* Instead of freeing the verts directly,
1064 * call this function to delete any special
1065 * vert data */
1066
1067 if (!dvert) {
1068 return;
1069 }
1070
1071 /* Free any special data from the verts */
1072 for (int i = 0; i < totvert; i++) {
1073 if (dvert[i].dw) {
1074 MEM_delete(dvert[i].dw);
1075 }
1076 }
1077}
1078
1079void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
1080{
1081 /* Instead of freeing the verts directly,
1082 * call this function to delete any special
1083 * vert data */
1084 if (!dvert) {
1085 return;
1086 }
1087
1088 /* Free any special data from the verts */
1089 BKE_defvert_array_free_elems(dvert, totvert);
1090
1091 MEM_delete(dvert);
1092}
1093
1095 const int defgroup,
1096 const int verts_num,
1097 const bool invert_vgroup,
1098 float *r_weights)
1099{
1100 if (dvert && defgroup != -1) {
1101 int i = verts_num;
1102
1103 while (i--) {
1104 const float w = BKE_defvert_find_weight(&dvert[i], defgroup);
1105 r_weights[i] = invert_vgroup ? (1.0f - w) : w;
1106 }
1107 }
1108 else {
1109 std::fill_n(r_weights, verts_num, invert_vgroup ? 1.0f : 0.0f);
1110 }
1111}
1112
1114 const int defgroup,
1115 const int verts_num,
1116 Span<int2> edges,
1117 const bool invert_vgroup,
1118 float *r_weights)
1119{
1120 if (!dvert || defgroup == -1) [[unlikely]] {
1121 std::fill_n(r_weights, edges.size(), 0.0f);
1122 return;
1123 }
1124
1125 int i = edges.size();
1126 float *tmp_weights = MEM_new_array_uninitialized<float>(size_t(verts_num), __func__);
1127
1129 dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
1130
1131 while (i--) {
1132 const int2 &edge = edges[i];
1133
1134 r_weights[i] = (tmp_weights[edge[0]] + tmp_weights[edge[1]]) * 0.5f;
1135 }
1136
1137 MEM_delete(tmp_weights);
1138}
1139
1141 const int defgroup,
1142 const int verts_num,
1143 const Span<int> corner_verts,
1144 const bool invert_vgroup,
1145 float *r_weights)
1146{
1147 if (!dvert || defgroup == -1) [[unlikely]] {
1148 std::fill_n(r_weights, corner_verts.size(), 0.0f);
1149 return;
1150 }
1151
1152 int i = corner_verts.size();
1153 float *tmp_weights = MEM_new_array_uninitialized<float>(size_t(verts_num), __func__);
1154
1156 dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
1157
1158 while (i--) {
1159 r_weights[i] = tmp_weights[corner_verts[i]];
1160 }
1161
1162 MEM_delete(tmp_weights);
1163}
1164
1166 const int defgroup,
1167 const int verts_num,
1168 const Span<int> corner_verts,
1169 const OffsetIndices<int> faces,
1170 const bool invert_vgroup,
1171 float *r_weights)
1172{
1173 if (!dvert || defgroup == -1) [[unlikely]] {
1174 std::fill_n(r_weights, faces.size(), 0.0f);
1175 return;
1176 }
1177
1178 int i = faces.size();
1179 float *tmp_weights = MEM_new_array_uninitialized<float>(size_t(verts_num), __func__);
1180
1182 dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
1183
1184 while (i--) {
1185 const IndexRange face = faces[i];
1186 const int *corner_vert = &corner_verts[face.start()];
1187 int j = face.size();
1188 float w = 0.0f;
1189
1190 for (; j--; corner_vert++) {
1191 w += tmp_weights[*corner_vert];
1192 }
1193 r_weights[i] = w / float(face.size());
1194 }
1195
1196 MEM_delete(tmp_weights);
1197}
1198
1200
1201/* -------------------------------------------------------------------- */
1204
1206 void *dest,
1207 const void **sources,
1208 const float *weights,
1209 const int count,
1210 const float mix_factor)
1211{
1212 MDeformVert **data_src = reinterpret_cast<MDeformVert **>(const_cast<void **>(sources));
1213 MDeformVert *data_dst = static_cast<MDeformVert *>(dest);
1214 const int idx_src = laymap->data_src_n;
1215 const int idx_dst = laymap->data_dst_n;
1216
1217 const int mix_mode = laymap->mix_mode;
1218
1219 int i, j;
1220
1221 MDeformWeight *dw_dst = BKE_defvert_find_index(data_dst, idx_dst);
1222 float weight_src = 0.0f, weight_dst = 0.0f;
1223
1224 bool has_dw_sources = false;
1225 if (sources) {
1226 for (i = count; i--;) {
1227 for (j = data_src[i]->totweight; j--;) {
1228 const MDeformWeight *dw_src = &data_src[i]->dw[j];
1229 if (dw_src->def_nr == idx_src) {
1230 weight_src += dw_src->weight * weights[i];
1231 has_dw_sources = true;
1232 break;
1233 }
1234 }
1235 }
1236 }
1237
1238 if (dw_dst) {
1239 weight_dst = dw_dst->weight;
1240 }
1241 else if (mix_mode == CDT_MIX_REPLACE_ABOVE_THRESHOLD) {
1242 return; /* Do not affect destination. */
1243 }
1244
1245 weight_src = data_transfer_interp_float_do(mix_mode, weight_dst, weight_src, mix_factor);
1246
1247 CLAMP(weight_src, 0.0f, 1.0f);
1248
1249 /* Do not create a destination MDeformWeight data if we had no sources at all. */
1250 if (!has_dw_sources) {
1251 BLI_assert(weight_src == 0.0f);
1252 if (dw_dst) {
1253 dw_dst->weight = weight_src;
1254 }
1255 }
1256 else if (!dw_dst) {
1257 BKE_defvert_add_index_notest(data_dst, idx_dst, weight_src);
1258 }
1259 else {
1260 dw_dst->weight = weight_src;
1261 }
1262}
1263
1266 const int mix_mode,
1267 const float mix_factor,
1268 const float *mix_weights,
1269 const bool use_create,
1270 const bool use_delete,
1271 Object *ob_dst,
1272 const Mesh &mesh_src,
1273 Mesh &mesh_dst,
1274 const bool /*use_dupref_dst*/,
1275 const int tolayers,
1276 const bool *use_layers_src,
1277 const int num_layers_src)
1278{
1279 int idx_src;
1280 int idx_dst;
1281 const ListBaseT<bDeformGroup> *src_list = &mesh_src.vertex_group_names;
1282 ListBaseT<bDeformGroup> *dst_defbase = &mesh_dst.vertex_group_names;
1283
1284 const int tot_dst = dst_defbase->count();
1285
1286 const size_t elem_size = sizeof(MDeformVert);
1287
1288 switch (tolayers) {
1290 idx_dst = tot_dst;
1291
1292 /* Find last source actually used! */
1293 idx_src = num_layers_src;
1294 while (idx_src-- && !use_layers_src[idx_src]) {
1295 /* pass */
1296 }
1297 idx_src++;
1298
1299 if (idx_dst < idx_src) {
1300 if (use_create) {
1301 /* Create as much vgroups as necessary! */
1302 for (; idx_dst < idx_src; idx_dst++) {
1304 }
1305 }
1306 else {
1307 /* Otherwise, just try to map what we can with existing dst vgroups. */
1308 idx_src = idx_dst;
1309 }
1310 }
1311 else if (use_delete && idx_dst > idx_src) {
1312 while (idx_dst-- > idx_src) {
1313 BKE_object_defgroup_remove(ob_dst, dst_defbase->last());
1314 }
1315 }
1316 if (r_map) {
1317 while (idx_src--) {
1318 if (!use_layers_src[idx_src]) {
1319 continue;
1320 }
1323 mix_mode,
1324 mix_factor,
1325 mix_weights,
1326 mesh_src.deform_verts().data(),
1327 mesh_dst.deform_verts_for_write().data(),
1328 idx_src,
1329 idx_src,
1330 elem_size,
1331 0,
1332 0,
1334 nullptr);
1335 }
1336 }
1337 break;
1338 case DT_LAYERS_NAME_DST: {
1339 bDeformGroup *dg_src, *dg_dst;
1340
1341 if (use_delete) {
1342 /* Remove all unused dst vgroups first, simpler in this case. */
1343 for (dg_dst = dst_defbase->first(); dg_dst;) {
1344 bDeformGroup *dg_dst_next = dg_dst->next;
1345
1346 if (BKE_id_defgroup_name_index(&mesh_src.id, dg_dst->name) == -1) {
1347 BKE_object_defgroup_remove(ob_dst, dg_dst);
1348 }
1349 dg_dst = dg_dst_next;
1350 }
1351 }
1352
1353 for (idx_src = 0, dg_src = src_list->first(); idx_src < num_layers_src;
1354 idx_src++, dg_src = dg_src->next)
1355 {
1356 if (!use_layers_src[idx_src]) {
1357 continue;
1358 }
1359
1360 idx_dst = BKE_object_defgroup_name_index(ob_dst, dg_src->name);
1361 if (idx_dst == -1) {
1362 if (use_create) {
1363 BKE_object_defgroup_add_name(ob_dst, dg_src->name);
1364 idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
1365 }
1366 else {
1367 /* If we are not allowed to create missing dst vgroups, just skip matching src one. */
1368 continue;
1369 }
1370 }
1371 if (r_map) {
1374 mix_mode,
1375 mix_factor,
1376 mix_weights,
1377 mesh_src.deform_verts().data(),
1378 mesh_dst.deform_verts_for_write().data(),
1379 idx_src,
1380 idx_dst,
1381 elem_size,
1382 0,
1383 0,
1385 nullptr);
1386 }
1387 }
1388 break;
1389 }
1390 default:
1391 return false;
1392 }
1393
1394 return true;
1395}
1396
1398 const int mix_mode,
1399 const float mix_factor,
1400 const float *mix_weights,
1401 const bool use_create,
1402 const bool use_delete,
1403 Object *ob_src,
1404 Object *ob_dst,
1405 const Mesh &mesh_src,
1406 Mesh &mesh_dst,
1407 const bool use_dupref_dst,
1408 const int fromlayers,
1409 const int tolayers)
1410{
1411 int idx_src, idx_dst;
1412
1413 const size_t elem_size = sizeof(MDeformVert);
1414
1415 /* NOTE:
1416 * We may have to handle data layout itself while having nullptr data itself,
1417 * and even have to support nullptr data_src in transfer data code
1418 * (we always create a data_dst, though).
1419 */
1420
1421 const ListBaseT<bDeformGroup> *src_defbase = BKE_object_defgroup_list(ob_src);
1422 if (src_defbase->is_empty()) {
1423 if (use_delete) {
1425 }
1426 return true;
1427 }
1428
1429 if (fromlayers == DT_LAYERS_ACTIVE_SRC || fromlayers >= 0) {
1430 /* NOTE: use_delete has not much meaning in this case, ignored. */
1431
1432 if (fromlayers >= 0) {
1433 idx_src = fromlayers;
1434 if (idx_src >= src_defbase->count()) {
1435 /* This can happen when vgroups are removed from source object...
1436 * Remapping would be really tricky here, we'd need to go over all objects in
1437 * Main every time we delete a vgroup... for now, simpler and safer to abort. */
1438 return false;
1439 }
1440 }
1441 else if ((idx_src = BKE_object_defgroup_active_index_get(ob_src) - 1) == -1) {
1442 return false;
1443 }
1444
1445 if (tolayers >= 0) {
1446 /* NOTE: in this case we assume layer exists! */
1447 idx_dst = tolayers;
1448 const ListBaseT<bDeformGroup> *dst_defbase = BKE_object_defgroup_list(ob_dst);
1449 BLI_assert(idx_dst < dst_defbase->count());
1450 UNUSED_VARS_NDEBUG(dst_defbase);
1451 }
1452 else if (tolayers == DT_LAYERS_ACTIVE_DST) {
1453 idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
1454 if (idx_dst == -1) {
1455 bDeformGroup *dg_src;
1456 if (!use_create) {
1457 return true;
1458 }
1459 dg_src = static_cast<bDeformGroup *>(BLI_findlink(src_defbase, idx_src));
1460 BKE_object_defgroup_add_name(ob_dst, dg_src->name);
1461 idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
1462 }
1463 }
1464 else if (tolayers == DT_LAYERS_INDEX_DST) {
1465 int num = src_defbase->count();
1466 idx_dst = idx_src;
1467 if (num <= idx_dst) {
1468 if (!use_create) {
1469 return true;
1470 }
1471 /* Create as much vgroups as necessary! */
1472 for (; num <= idx_dst; num++) {
1474 }
1475 }
1476 }
1477 else if (tolayers == DT_LAYERS_NAME_DST) {
1478 bDeformGroup *dg_src = static_cast<bDeformGroup *>(BLI_findlink(src_defbase, idx_src));
1479 idx_dst = BKE_object_defgroup_name_index(ob_dst, dg_src->name);
1480 if (idx_dst == -1) {
1481 if (!use_create) {
1482 return true;
1483 }
1484 BKE_object_defgroup_add_name(ob_dst, dg_src->name);
1485 idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
1486 }
1487 }
1488 else {
1489 return false;
1490 }
1491
1492 if (r_map) {
1495 mix_mode,
1496 mix_factor,
1497 mix_weights,
1498 mesh_src.deform_verts().data(),
1499 mesh_dst.deform_verts_for_write().data(),
1500 idx_src,
1501 idx_dst,
1502 elem_size,
1503 0,
1504 0,
1506 nullptr);
1507 }
1508 }
1509 else {
1510 int num_src, num_sel_unused;
1511 bool *use_layers_src = nullptr;
1512 bool ret = false;
1513
1514 switch (fromlayers) {
1515 case DT_LAYERS_ALL_SRC:
1517 ob_src, WT_VGROUP_ALL, &num_src, &num_sel_unused);
1518 break;
1521 ob_src, WT_VGROUP_BONE_SELECT, &num_src, &num_sel_unused);
1522 break;
1525 ob_src, WT_VGROUP_BONE_DEFORM, &num_src, &num_sel_unused);
1526 break;
1527 }
1528
1529 if (use_layers_src) {
1531 mix_mode,
1532 mix_factor,
1533 mix_weights,
1534 use_create,
1535 use_delete,
1536 ob_dst,
1537 mesh_src,
1538 mesh_dst,
1539 use_dupref_dst,
1540 tolayers,
1541 use_layers_src,
1542 num_src);
1543 }
1544
1545 MEM_SAFE_DELETE(use_layers_src);
1546 return ret;
1547 }
1548
1549 return true;
1550}
1551
1553
1554/* -------------------------------------------------------------------- */
1557
1558void BKE_defvert_weight_to_rgb(float r_rgb[3], const float weight)
1559{
1560 const float blend = ((weight / 2.0f) + 0.5f);
1561
1562 if (weight <= 0.25f) { /* blue->cyan */
1563 r_rgb[0] = 0.0f;
1564 r_rgb[1] = blend * weight * 4.0f;
1565 r_rgb[2] = blend;
1566 }
1567 else if (weight <= 0.50f) { /* cyan->green */
1568 r_rgb[0] = 0.0f;
1569 r_rgb[1] = blend;
1570 r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f));
1571 }
1572 else if (weight <= 0.75f) { /* green->yellow */
1573 r_rgb[0] = blend * ((weight - 0.50f) * 4.0f);
1574 r_rgb[1] = blend;
1575 r_rgb[2] = 0.0f;
1576 }
1577 else if (weight <= 1.0f) { /* yellow->red */
1578 r_rgb[0] = blend;
1579 r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f));
1580 r_rgb[2] = 0.0f;
1581 }
1582 else {
1583 /* exceptional value, unclamped or nan,
1584 * avoid uninitialized memory use */
1585 r_rgb[0] = 1.0f;
1586 r_rgb[1] = 0.0f;
1587 r_rgb[2] = 1.0f;
1588 }
1589}
1590
1592
1593/* -------------------------------------------------------------------- */
1596
1597void BKE_defbase_blend_write(BlendWriter *writer, const ListBaseT<bDeformGroup> *defbase)
1598{
1599 for (bDeformGroup &defgroup : *defbase) {
1600 writer->write_struct(&defgroup);
1601 }
1602}
1603
1604void BKE_defvert_blend_write(BlendWriter *writer, int count, const MDeformVert *dvlist)
1605{
1606 if (dvlist == nullptr) {
1607 return;
1608 }
1609
1610 /* Write the dvert list */
1611 writer->write_struct_array(count, dvlist);
1612
1613 /* Write deformation data for each dvert */
1614 for (int i = 0; i < count; i++) {
1615 if (dvlist[i].dw) {
1616 writer->write_struct_array(dvlist[i].totweight, dvlist[i].dw);
1617 }
1618 }
1619}
1620
1621void BKE_defvert_blend_read(BlendDataReader *reader, int count, MDeformVert *mdverts)
1622{
1623 if (mdverts == nullptr) {
1624 return;
1625 }
1626
1627 for (int i = count; i > 0; i--, mdverts++) {
1628 /* Convert to vertex group allocation system. */
1629 MDeformWeight *dw = mdverts->dw;
1630 BLO_read_array_and_validate_size(reader, &dw, &mdverts->totweight);
1631 if (dw) {
1632 void *dw_tmp = MEM_new_array_uninitialized<MDeformWeight>(size_t(mdverts->totweight),
1633 __func__);
1634 const size_t dw_len = sizeof(MDeformWeight) * mdverts->totweight;
1635 memcpy(dw_tmp, dw, dw_len);
1636 mdverts->dw = static_cast<MDeformWeight *>(dw_tmp);
1637 MEM_delete(dw);
1638 }
1639 else {
1640 mdverts->dw = nullptr;
1641 mdverts->totweight = 0;
1642 }
1643 }
1644}
1645
1647
1648/* -------------------------------------------------------------------- */
1651
1652namespace bke {
1653
1655 private:
1656 MDeformVert *dverts_;
1657 const int dvert_index_;
1658
1659 public:
1661 : VMutableArrayImpl<float>(dverts.size()), dverts_(dverts.data()), dvert_index_(dvert_index)
1662 {
1663 }
1664
1666 : VMutableArrayImpl<float>(dverts.size()),
1667 dverts_(const_cast<MDeformVert *>(dverts.data())),
1668 dvert_index_(dvert_index)
1669 {
1670 }
1671
1672 float get(const int64_t index) const override
1673 {
1674 if (dverts_ == nullptr) {
1675 return 0.0f;
1676 }
1677 if (const MDeformWeight *weight = this->find_weight_at_index(index)) {
1678 return weight->weight;
1679 }
1680 return 0.0f;
1681 }
1682
1683 void set(const int64_t index, const float value) override
1684 {
1685 MDeformVert &dvert = dverts_[index];
1686 if (value == 0.0f) {
1687 if (MDeformWeight *weight = this->find_weight_at_index(index)) {
1688 weight->weight = 0.0f;
1689 }
1690 }
1691 else {
1692 MDeformWeight *weight = BKE_defvert_ensure_index(&dvert, dvert_index_);
1693 weight->weight = value;
1694 }
1695 }
1696
1697 void set_all(Span<float> src) override
1698 {
1699 PRF_scope_with_name("VArrayImpl_For_VertexWeights::set_all", ProfileCategory::Default);
1700 threading::parallel_for(src.index_range(), 4096, [&](const IndexRange range) {
1701 for (const int64_t i : range) {
1702 this->set(i, src[i]);
1703 }
1704 });
1705 }
1706
1708 float *dst,
1709 const bool /*dst_is_uninitialized*/) const override
1710 {
1711 PRF_scope_with_name("VArrayImpl_For_VertexWeights::materialize", ProfileCategory::Default);
1712 if (dverts_ == nullptr) {
1713 index_mask::masked_fill(MutableSpan(dst, mask.min_array_size()), 0.0f, mask);
1714 }
1715 threading::parallel_for(mask.index_range(), 4096, [&](const IndexRange range) {
1716 mask.slice(range).foreach_index_optimized<int64_t>([&](const int64_t index) {
1717 if (const MDeformWeight *weight = this->find_weight_at_index(index)) {
1718 dst[index] = weight->weight;
1719 }
1720 else {
1721 dst[index] = 0.0f;
1722 }
1723 });
1724 });
1725 }
1726
1727 private:
1728 MDeformWeight *find_weight_at_index(const int64_t index)
1729 {
1730 for (MDeformWeight &weight : MutableSpan(dverts_[index].dw, dverts_[index].totweight)) {
1731 if (weight.def_nr == dvert_index_) {
1732 return &weight;
1733 }
1734 }
1735 return nullptr;
1736 }
1737 const MDeformWeight *find_weight_at_index(const int64_t index) const
1738 {
1739 for (const MDeformWeight &weight : Span(dverts_[index].dw, dverts_[index].totweight)) {
1740 if (weight.def_nr == dvert_index_) {
1741 return &weight;
1742 }
1743 }
1744 return nullptr;
1745 }
1746};
1747
1749{
1750 return VArray<float>::from<VArrayImpl_For_VertexWeights>(dverts, defgroup_index);
1751}
1753 const int defgroup_index)
1754{
1755 return VMutableArray<float>::from<VArrayImpl_For_VertexWeights>(dverts, defgroup_index);
1756}
1757
1758void remove_defgroup_index(MutableSpan<MDeformVert> dverts, const int defgroup_index)
1759{
1761 threading::parallel_for(dverts.index_range(), 1024, [&](IndexRange range) {
1762 for (MDeformVert &dvert : dverts.slice(range)) {
1763 MDeformWeight *weight = BKE_defvert_find_index(&dvert, defgroup_index);
1764 BKE_defvert_remove_group(&dvert, weight);
1765 for (MDeformWeight &weight : MutableSpan(dvert.dw, dvert.totweight)) {
1766 if (weight.def_nr > defgroup_index) {
1767 weight.def_nr--;
1768 }
1769 }
1770 }
1771 });
1772}
1773
1775 const Span<int> indices,
1777{
1778 gather_deform_verts(src, indices, IndexMask(indices.size()), dst);
1779}
1781 const Span<int> indices,
1782 const IndexMask &dst_mask,
1784{
1786 dst_mask.foreach_index(
1787 [&](const int64_t dst_i) {
1788 const int src_i = indices[dst_i];
1789 dst[dst_i].dw = MEM_dupalloc(src[src_i].dw);
1790 dst[dst_i].totweight = src[src_i].totweight;
1791 dst[dst_i].flag = src[src_i].flag;
1792 },
1794}
1796 const IndexMask &indices,
1798{
1800 indices.foreach_index(
1801 [&](const int64_t src_i, const int64_t dst_i) {
1802 dst[dst_i].dw = MEM_dupalloc(src[src_i].dw);
1803 dst[dst_i].totweight = src[src_i].totweight;
1804 dst[dst_i].flag = src[src_i].flag;
1805 },
1807}
1808
1810 const Span<int> indices,
1811 const Span<float> weights,
1812 MDeformWeightSet &dw_buffer)
1813{
1814 BLI_assert(weights.is_empty() || indices.size() == weights.size());
1815 MDeformVert dst_dvert{};
1816
1817 if (indices.size() == 1) {
1818 const MDeformVert &src_dvert = src[indices.first()];
1819 dst_dvert.dw = MEM_new_array_uninitialized<MDeformWeight>(src_dvert.totweight, __func__);
1820 std::copy_n(src_dvert.dw, src_dvert.totweight, dst_dvert.dw);
1821 dst_dvert.totweight = src_dvert.totweight;
1822 return dst_dvert;
1823 }
1824
1825 dw_buffer.clear_and_keep_capacity();
1826 BLI_assert(!indices.is_empty());
1827 const float src_num_inv = math::rcp(float(indices.size()));
1828 for (const int i : indices.index_range()) {
1829 const MDeformVert &src_dvert = src[indices[i]];
1830 for (const MDeformWeight &src_weight : Span(src_dvert.dw, src_dvert.totweight)) {
1831 const int weight_i = dw_buffer.index_of_or_add(MDeformWeight{src_weight.def_nr, 0.0f});
1832 const float factor = weights.is_empty() ? src_num_inv : weights[i];
1833 const_cast<MDeformWeight &>(dw_buffer[weight_i]).weight += src_weight.weight * factor;
1834 }
1835 }
1836
1837 std::sort(const_cast<MDeformWeight *>(dw_buffer.begin()),
1838 const_cast<MDeformWeight *>(dw_buffer.end()),
1839 [](const auto &a, const auto &b) { return a.def_nr < b.def_nr; });
1840
1841 dst_dvert.dw = MEM_new_array_uninitialized<MDeformWeight>(dw_buffer.size(), __func__);
1842 dst_dvert.totweight = dw_buffer.size();
1843 std::copy(dw_buffer.begin(), dw_buffer.end(), dst_dvert.dw);
1844 return dst_dvert;
1845}
1846
1847} // namespace bke
1848
1850
1851} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
#define VERTEX_WEIGHT_LOCK_EPSILON
Low-level operations for grease pencil.
Utility functions for vertex groups in grease pencil objects.
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define STRNCPY_UTF8(dst, src)
#define DATA_(msgid)
Object is a sort of wrapper for general info.
#define OB_TYPE_SUPPORT_VGROUP(_type)
Read Blender memory allocation and freeing.
#define PRF_scope_with_name(ui_name, category)
#define PRF_scope(category)
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define STREQ(a, b)
#define MEM_realloc_uninitialized(vmemh, len)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
constexpr Span()=default
constexpr int64_t size() const
constexpr int64_t start() const
constexpr MutableSpan()=default
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr Span()=default
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
static VArray from(Args &&...args)
static VMutableArray from(Args &&...args)
int64_t index_of_or_add(const Key &key)
const Key * begin() const
int64_t size() const
const Key * end() const
void set_all(Span< float > src) override
Definition deform.cc:1697
float get(const int64_t index) const override
Definition deform.cc:1672
void set(const int64_t index, const float value) override
Definition deform.cc:1683
VArrayImpl_For_VertexWeights(MutableSpan< MDeformVert > dverts, const int dvert_index)
Definition deform.cc:1660
VArrayImpl_For_VertexWeights(Span< MDeformVert > dverts, const int dvert_index)
Definition deform.cc:1665
void materialize(const IndexMask &mask, float *dst, const bool) const override
Definition deform.cc:1707
constexpr bool is_empty() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
Definition string_ref.cc:28
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
float2x2 invert(float2x2 mat)
void validate_drawing_vertex_groups(GreasePencil &grease_pencil)
void remove_defgroup_index(MutableSpan< MDeformVert > dverts, int defgroup_index)
Definition deform.cc:1758
void gather_deform_verts(Span< MDeformVert > src, Span< int > indices, MutableSpan< MDeformVert > dst)
Definition deform.cc:1774
MDeformVert mix_deform_verts(const Span< MDeformVert > src, const Span< int > indices, const Span< float > weights, MDeformWeightSet &dw_buffer)
Definition deform.cc:1809
VMutableArray< float > varray_for_mutable_deform_verts(MutableSpan< MDeformVert > dverts, int defgroup_index)
Definition deform.cc:1752
CustomIDVectorSet< MDeformWeight, WeightIndexGetter, 64 > MDeformWeightSet
VArray< float > varray_for_deform_verts(Span< MDeformVert > dverts, int defgroup_index)
Definition deform.cc:1748
constexpr ParallelGrainSize grain_size(int grain_size)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T rcp(const T &a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
@ CDT_MIX_REPLACE_ABOVE_THRESHOLD
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
Definition deform.cc:758
void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
Definition deform.cc:1079
__int64 int64_t
Definition BKE_text.h:90
bool BKE_defvert_is_weight_zero(const MDeformVert *dvert, int defgroup_tot)
Definition deform.cc:941
ListBaseT< bDeformGroup > * BKE_object_defgroup_list_mutable(Object *ob)
Definition deform.cc:602
static const int * object_defgroup_active_index_get_p(const Object *ob)
Definition deform.cc:498
void BKE_defbase_blend_write(BlendWriter *writer, const ListBaseT< bDeformGroup > *defbase)
Definition deform.cc:1597
bool BKE_defgroup_listbase_name_find(ListBaseT< bDeformGroup > *defbase, StringRef name, int *r_index, bDeformGroup **r_group)
Definition deform.cc:562
const ListBaseT< bDeformGroup > * BKE_object_defgroup_list(const Object *ob)
Definition deform.cc:591
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
void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
Definition deform.cc:1043
int BKE_object_defgroup_count(const Object *ob)
Definition deform.cc:608
void BKE_defvert_remap(MDeformVert *dvert, const int *map, int map_len)
Definition deform.cc:223
bDeformGroup * BKE_object_defgroup_find_name(const Object *ob, StringRef name)
Definition deform.cc:530
void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, int flip_map_num)
Definition deform.cc:432
void BKE_defvert_blend_read(BlendDataReader *reader, int count, MDeformVert *mdverts)
Definition deform.cc:1621
void BKE_defvert_blend_write(BlendWriter *writer, int count, const MDeformVert *dvlist)
Definition deform.cc:1604
const ListBaseT< bDeformGroup > * BKE_id_defgroup_list_get(const ID *id)
Definition deform.cc:472
void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert)
Definition deform.cc:1061
@ WT_VGROUP_BONE_SELECT
@ WT_VGROUP_BONE_DEFORM
static bool defgroup_find_name_dupe(const StringRef name, bDeformGroup *dg, Object *ob)
Definition deform.cc:743
void BKE_defvert_extract_vgroup_to_faceweights(const MDeformVert *dvert, int defgroup, int verts_num, const Span< int > corner_verts, OffsetIndices< int > faces, bool invert_vgroup, float *r_weights)
Definition deform.cc:1165
void BKE_object_defgroup_active_index_set(Object *ob, int new_index)
Definition deform.cc:618
void BKE_defvert_extract_vgroup_to_vertweights(const MDeformVert *dvert, int defgroup, int verts_num, bool invert_vgroup, float *r_weights)
Definition deform.cc:1094
void BKE_defvert_clear(MDeformVert *dvert)
Definition deform.cc:918
int * BKE_object_defgroup_flip_map(const Object *ob, bool use_default, int *r_flip_map_num)
Definition deform.cc:673
int BKE_defgroup_name_index(const ListBaseT< bDeformGroup > *defbase, StringRef name)
Definition deform.cc:544
void BKE_object_batch_cache_dirty_tag(Object *ob)
int BKE_id_defgroup_name_index(const ID *id, StringRef name)
Definition deform.cc:557
void BKE_object_defgroup_remove_all(struct Object *ob)
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
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 BKE_object_supports_vertex_groups(const Object *ob)
Definition deform.cc:465
void BKE_defvert_copy_subset(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool *vgroup_subset, int vgroup_num)
Definition deform.cc:102
VecBase< int32_t, 2 > int2
int * BKE_object_defgroup_flip_map_single(const Object *ob, bool use_default, int defgroup, int *r_flip_map_num)
Definition deform.cc:685
float BKE_defvert_lock_relative_weight(float weight, const MDeformVert *dv, int defbase_num, const bool *defbase_locked, const bool *defbase_unlocked)
Definition deform.cc:1022
float BKE_defvert_calc_lock_relative_weight(float weight, float locked_weight, float unlocked_weight)
Definition deform.cc:994
void BKE_defvert_normalize_ex(MDeformVert &dvert, Span< bool > subset_flags, Span< bool > lock_flags, Span< bool > soft_lock_flags)
Definition deform.cc:252
void BKE_defvert_extract_vgroup_to_edgeweights(const MDeformVert *dvert, int defgroup, int verts_num, Span< int2 > edges, bool invert_vgroup, float *r_weights)
Definition deform.cc:1113
BMesh const char void * data
static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(Vector< CustomDataTransferLayerMap > *r_map, const int mix_mode, const float mix_factor, const float *mix_weights, const bool use_create, const bool use_delete, Object *ob_dst, const Mesh &mesh_src, Mesh &mesh_dst, const bool, const int tolayers, const bool *use_layers_src, const int num_layers_src)
Definition deform.cc:1264
void BKE_defvert_copy_index(MDeformVert *dvert_dst, int defgroup_dst, const MDeformVert *dvert_src, int defgroup_src)
Definition deform.cc:153
bDeformGroup * BKE_defgroup_duplicate(const bDeformGroup *ingroup)
Definition deform.cc:85
void BKE_defvert_extract_vgroup_to_loopweights(const MDeformVert *dvert, int defgroup, int verts_num, Span< int > corner_verts, bool invert_vgroup, float *r_weights)
Definition deform.cc:1140
void BKE_defvert_sync_mapped(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const int *flip_map, int flip_map_num, bool use_ensure)
Definition deform.cc:197
void BKE_defvert_mirror_subset(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool *vgroup_subset, int vgroup_num, const int *flip_map, int flip_map_num)
Definition deform.cc:115
@ DT_LAYERS_VGROUP_SRC_BONE_SELECT
@ DT_LAYERS_VGROUP_SRC_BONE_DEFORM
MDeformWeight * BKE_defvert_ensure_index(MDeformVert *dv, int defgroup)
Definition deform.cc:830
int BKE_object_defgroup_name_index(const Object *ob, StringRef name)
Definition deform.cc:597
bool BKE_id_supports_vertex_groups(const ID *id)
Definition deform.cc:457
void BKE_grease_pencil_vgroup_name_update(Object *ob, const char *old_name, const char *new_name)
float BKE_defvert_array_find_weight_safe(const MDeformVert *dvert, int index, int defgroup, bool invert)
Definition deform.cc:785
struct bDeformGroup * BKE_object_defgroup_add_name(struct Object *ob, const char *name)
void BKE_defvert_normalize(MDeformVert &dvert)
Definition deform.cc:240
int BKE_object_defgroup_flip_index(const Object *ob, int index, bool use_default)
Definition deform.cc:720
bool data_transfer_layersmapping_vgroups(Vector< CustomDataTransferLayerMap > *r_map, int mix_mode, float mix_factor, const float *mix_weights, bool use_create, bool use_delete, Object *ob_src, Object *ob_dst, const Mesh &mesh_src, Mesh &mesh_dst, bool use_dupref_dst, int fromlayers, int tolayers)
Definition deform.cc:1397
void BKE_object_defgroup_set_name(bDeformGroup *dg, Object *ob, const char *new_name)
Definition deform.cc:767
ATTR_WARN_UNUSED_RESULT const size_t num
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:531
_W64 unsigned int uintptr_t
Definition BKE_text.h:120
static void data_transfer_layersmapping_add_item(Vector< CustomDataTransferLayerMap > *r_map, const int cddata_type, const int mix_mode, const float mix_factor, const float *mix_weights, std::variant< const void *, GVArray > data_src, std::variant< void *, bke::GSpanAttributeWriter > data_dst, const int data_src_n, const int data_dst_n, const size_t elem_size, const size_t data_size, const size_t data_offset, cd_datatransfer_interp interp, void *interp_data)
void BKE_defvert_normalize_subset(MDeformVert &dvert, Span< bool > subset_flags)
Definition deform.cc:235
void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, int flip_map_num)
Definition deform.cc:418
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
void BKE_defvert_sync(MDeformVert *dvert_dst, const MDeformVert *dvert_src, bool use_ensure)
Definition deform.cc:177
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bDeformGroup * BKE_object_defgroup_new(Object *ob, StringRef name)
Definition deform.cc:51
struct bDeformGroup * BKE_object_defgroup_add(struct Object *ob)
float data_transfer_interp_float_do(const int mix_mode, const float val_dst, const float val_src, const float mix_factor)
MINLINE float max_ff(float a, float b)
float BKE_defvert_total_selected_weight(const MDeformVert *dv, int defbase_num, const bool *defbase_sel)
Definition deform.cc:955
void BKE_defvert_add_index_notest(MDeformVert *dv, int defgroup, float weight)
Definition deform.cc:861
void BKE_defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
Definition deform.cc:130
ID_Type GS(const char *name)
Definition DNA_ID.h:410
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
static void vgroups_datatransfer_interp(const CustomDataTransferLayerMap *laymap, void *dest, const void **sources, const float *weights, const int count, const float mix_factor)
Definition deform.cc:1205
static int * object_defgroup_unlocked_flip_map_ex(const Object *ob, const bool use_default, const bool use_only_unlocked, int *r_flip_map_num)
Definition deform.cc:625
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)
int BKE_defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert_b)
Definition deform.cc:925
ListBaseT< bDeformGroup > * BKE_id_defgroup_list_get_mutable(ID *id)
Definition deform.cc:524
void BKE_defvert_weight_to_rgb(float r_rgb[3], float weight)
Definition deform.cc:1558
void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
Definition deform.cc:885
bool BKE_id_defgroup_name_find(ID *id, StringRef name, int *r_index, bDeformGroup **r_group)
Definition deform.cc:585
MDeformWeight * BKE_defvert_find_index(const MDeformVert *dv, int defgroup)
Definition deform.cc:811
int * BKE_object_defgroup_flip_map_unlocked(const Object *ob, bool use_default, int *r_flip_map_num)
Definition deform.cc:678
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
float BKE_defvert_multipaint_collective_weight(const MDeformVert *dv, int defbase_num, const bool *defbase_sel, int defbase_sel_num, bool is_normalized)
Definition deform.cc:977
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
void BKE_defvert_normalize_lock_map(MDeformVert &dvert, Span< bool > subset_flags, Span< bool > lock_flags)
Definition deform.cc:245
int BKE_object_defgroup_active_index_get(const Object *ob)
Definition deform.cc:613
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct_array(const int64_t array_size, const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
ListBaseT< struct bDeformGroup > vertex_group_names
struct MDeformWeight * dw
ListBaseT< bDeformGroup > vertex_group_names
struct bDeformGroup * prev
struct bDeformGroup * next
ebDeformGroup_Flag flag
ListBaseT< bDeformGroup > vertex_group_names