Fix #130840: Grease Pencil: Use vgroup count to guard invalid defnr
Inside legacy GP -> GPv3 conversion, legacy vertex group `def_nr` was incorrectly guarded by the group count of each vertex, which can lead to missing groups since not all vertices will have weights in all groups. This fix use the total vertex group count to guard invalid `def_nr` values. Pull Request: https://projects.blender.org/blender/blender/pulls/130886
This commit is contained in:
@@ -637,11 +637,11 @@ class AnimDataConvertor {
|
||||
* - Array of indices in the new vertex group list for remapping
|
||||
*/
|
||||
static void find_used_vertex_groups(const bGPDframe &gpf,
|
||||
const ListBase &all_names,
|
||||
const ListBase &vertex_group_names,
|
||||
const int num_vertex_groups,
|
||||
ListBase &r_vertex_group_names,
|
||||
Array<int> &r_indices)
|
||||
{
|
||||
const int num_vertex_groups = BLI_listbase_count(&all_names);
|
||||
Array<int> is_group_used(num_vertex_groups, false);
|
||||
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf.strokes) {
|
||||
if (!gps->dvert) {
|
||||
@@ -650,7 +650,7 @@ static void find_used_vertex_groups(const bGPDframe &gpf,
|
||||
Span<MDeformVert> dverts = {gps->dvert, gps->totpoints};
|
||||
for (const MDeformVert &dvert : dverts) {
|
||||
for (const MDeformWeight &weight : Span<MDeformWeight>{dvert.dw, dvert.totweight}) {
|
||||
if (weight.def_nr >= dvert.totweight) {
|
||||
if (weight.def_nr >= num_vertex_groups) {
|
||||
/* Ignore invalid deform weight group indices. */
|
||||
continue;
|
||||
}
|
||||
@@ -662,7 +662,7 @@ static void find_used_vertex_groups(const bGPDframe &gpf,
|
||||
r_indices.reinitialize(num_vertex_groups);
|
||||
int new_group_i = 0;
|
||||
int old_group_i;
|
||||
LISTBASE_FOREACH_INDEX (const bDeformGroup *, def_group, &all_names, old_group_i) {
|
||||
LISTBASE_FOREACH_INDEX (const bDeformGroup *, def_group, &vertex_group_names, old_group_i) {
|
||||
if (!is_group_used[old_group_i]) {
|
||||
r_indices[old_group_i] = -1;
|
||||
continue;
|
||||
@@ -842,7 +842,9 @@ static Drawing legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gp
|
||||
/* Find used vertex groups in this drawing. */
|
||||
ListBase stroke_vertex_group_names;
|
||||
Array<int> stroke_def_nr_map;
|
||||
find_used_vertex_groups(gpf, vertex_group_names, stroke_vertex_group_names, stroke_def_nr_map);
|
||||
const int num_vertex_groups = BLI_listbase_count(&vertex_group_names);
|
||||
find_used_vertex_groups(
|
||||
gpf, vertex_group_names, num_vertex_groups, stroke_vertex_group_names, stroke_def_nr_map);
|
||||
BLI_assert(BLI_listbase_is_empty(&curves.vertex_group_names));
|
||||
curves.vertex_group_names = stroke_vertex_group_names;
|
||||
const bool use_dverts = !BLI_listbase_is_empty(&curves.vertex_group_names);
|
||||
@@ -853,7 +855,7 @@ static Drawing legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gp
|
||||
dst_dvert.dw = static_cast<MDeformWeight *>(MEM_dupallocN(src_dvert.dw));
|
||||
const MutableSpan<MDeformWeight> vertex_weights = {dst_dvert.dw, dst_dvert.totweight};
|
||||
for (MDeformWeight &weight : vertex_weights) {
|
||||
if (weight.def_nr >= dst_dvert.totweight) {
|
||||
if (weight.def_nr >= num_vertex_groups) {
|
||||
/* Ignore invalid deform weight group indices. */
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user