Fix #129024: GPv3: Renaming a vertex group removes group assignment
GPv3 stores the vertex group inside `CurvesGeometry`. When the object level vertex group name is changed, we have to loop over the vertex group list of each drawing. If a matching name is found, copy the new name to the vertex group in `CurvesGeometry`. A separate function is created to handle this: `BKE_grease_pencil_vgroup_name_update`. Pull Request: https://projects.blender.org/blender/blender/pulls/129038
This commit is contained in:
committed by
Falk David
parent
0753f7f78c
commit
ceea1a4d99
@@ -92,6 +92,7 @@ int *BKE_object_defgroup_flip_map_single(const Object *ob,
|
||||
int BKE_object_defgroup_flip_index(const Object *ob, int index, bool use_default);
|
||||
int BKE_object_defgroup_name_index(const Object *ob, blender::StringRef name);
|
||||
void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob);
|
||||
void BKE_object_defgroup_set_name(bDeformGroup *dg, Object *ob, const char *new_name);
|
||||
|
||||
MDeformWeight *BKE_defvert_find_index(const MDeformVert *dv, int defgroup);
|
||||
/**
|
||||
|
||||
@@ -1047,6 +1047,8 @@ void BKE_grease_pencil_copy_layer_group_parameters(
|
||||
void BKE_grease_pencil_nomain_to_grease_pencil(GreasePencil *grease_pencil_src,
|
||||
GreasePencil *grease_pencil_dst);
|
||||
|
||||
void BKE_grease_pencil_vgroup_name_update(Object *ob, const char *old_name, const char *new_name);
|
||||
|
||||
void BKE_grease_pencil_data_update(Depsgraph *depsgraph, Scene *scene, Object *object);
|
||||
void BKE_grease_pencil_duplicate_drawing_array(const GreasePencil *grease_pencil_src,
|
||||
GreasePencil *grease_pencil_dst);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_string_utf8.h"
|
||||
#include "BLI_string_utils.hh"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
@@ -754,6 +755,18 @@ void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
|
||||
BLI_uniquename_cb(defgroup_unique_check, &data, DATA_("Group"), '.', dg->name, sizeof(dg->name));
|
||||
}
|
||||
|
||||
void BKE_object_defgroup_set_name(bDeformGroup *dg, Object *ob, const char *new_name)
|
||||
{
|
||||
std::string old_name = dg->name;
|
||||
STRNCPY_UTF8(dg->name, new_name);
|
||||
BKE_object_defgroup_unique_name(dg, ob);
|
||||
|
||||
if (ob->type == OB_GREASE_PENCIL) {
|
||||
/* Update vgroup names stored in CurvesGeometry */
|
||||
BKE_grease_pencil_vgroup_name_update(ob, old_name.c_str(), dg->name);
|
||||
}
|
||||
}
|
||||
|
||||
float BKE_defvert_find_weight(const MDeformVert *dvert, const int defgroup)
|
||||
{
|
||||
MDeformWeight *dw = BKE_defvert_find_index(dvert, defgroup);
|
||||
|
||||
@@ -1890,6 +1890,21 @@ void BKE_grease_pencil_nomain_to_grease_pencil(GreasePencil *grease_pencil_src,
|
||||
BKE_id_free(nullptr, grease_pencil_src);
|
||||
}
|
||||
|
||||
void BKE_grease_pencil_vgroup_name_update(Object *ob, const char *old_name, const char *new_name)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob->data);
|
||||
for (GreasePencilDrawingBase *base : grease_pencil.drawings()) {
|
||||
Drawing &drawing = reinterpret_cast<GreasePencilDrawing *>(base)->wrap();
|
||||
CurvesGeometry &curves = drawing.strokes_for_write();
|
||||
LISTBASE_FOREACH (bDeformGroup *, vgroup, &curves.vertex_group_names) {
|
||||
if (strcmp(vgroup->name, old_name) == 0) {
|
||||
STRNCPY(vgroup->name, new_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void grease_pencil_evaluate_modifiers(Depsgraph *depsgraph,
|
||||
Scene *scene,
|
||||
Object *object,
|
||||
|
||||
@@ -902,8 +902,7 @@ static void rna_VertexGroup_name_set(PointerRNA *ptr, const char *value)
|
||||
}
|
||||
|
||||
bDeformGroup *dg = static_cast<bDeformGroup *>(ptr->data);
|
||||
STRNCPY_UTF8(dg->name, value);
|
||||
BKE_object_defgroup_unique_name(dg, ob);
|
||||
BKE_object_defgroup_set_name(dg, ob, value);
|
||||
}
|
||||
|
||||
static int rna_VertexGroup_index_get(PointerRNA *ptr)
|
||||
|
||||
Reference in New Issue
Block a user