Fix #135071: Vertex Parenting: Provide Index Access Options

When using vertex parenting, an option for using the parent object
final evaluated indices is exposed in the Object Properties: Relations
panel. This allows the calculation of the parent vertex position to
ignore the the CD_ORIGINDEX layer and instead use the final indices
that may have been altered by the node tree evaluation.

The indices that will be used for the vertex parenting are also exposed
to the UI in the same panel, allowing them to be altered after the
vertex parent has been created.
This commit is contained in:
Johnny Matthews
2025-03-21 23:43:48 +01:00
parent 61783caa7f
commit 633b8d30db
4 changed files with 25 additions and 7 deletions

View File

@@ -126,6 +126,12 @@ class OBJECT_PT_relations(ObjectButtonsPanel, Panel):
parent = ob.parent
if parent and ob.parent_type == 'BONE' and parent.type == 'ARMATURE':
sub.prop_search(ob, "parent_bone", parent.data, "bones")
elif ob.parent_type == 'VERTEX':
col.prop(ob, "parent_vertices", text="Parent Vertex", index=0)
sub.prop(ob, "use_parent_final_indices")
elif ob.parent_type == 'VERTEX_3':
col.prop(ob, "parent_vertices", text="Parent Vertices")
sub.prop(ob, "use_parent_final_indices")
sub.active = (parent is not None)
sub.prop(ob, "use_camera_lock_parent")

View File

@@ -3040,7 +3040,7 @@ static void ob_parbone(const Object *ob, const Object *par, float r_mat[4][4])
}
}
static void give_parvert(const Object *par, int nr, float vec[3])
static void give_parvert(const Object *par, int nr, float vec[3], const bool use_evaluated_indices)
{
zero_v3(vec);
@@ -3082,7 +3082,8 @@ static void give_parvert(const Object *par, int nr, float vec[3])
count++;
}
}
else if (CustomData_has_layer(&mesh_eval->vert_data, CD_ORIGINDEX)) {
else if (use_evaluated_indices && CustomData_has_layer(&mesh_eval->vert_data, CD_ORIGINDEX))
{
const int *index = (const int *)CustomData_get_layer(&mesh_eval->vert_data, CD_ORIGINDEX);
/* Get the average of all verts with (original index == nr). */
for (int i = 0; i < numVerts; i++) {
@@ -3166,10 +3167,11 @@ static void ob_parvert3(const Object *ob, const Object *par, float r_mat[4][4])
/* in local ob space */
if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
float cmat[3][3], v1[3], v2[3], v3[3], q[4];
const bool use_evaluated_indices = !(ob->transflag & OB_PARENT_USE_FINAL_INDICES);
give_parvert(par, ob->par1, v1);
give_parvert(par, ob->par2, v2);
give_parvert(par, ob->par3, v3);
give_parvert(par, ob->par1, v1, use_evaluated_indices);
give_parvert(par, ob->par2, v2, use_evaluated_indices);
give_parvert(par, ob->par3, v3, use_evaluated_indices);
tri_to_quat(q, v1, v2, v3);
quat_to_mat3(cmat, q);
@@ -3186,7 +3188,7 @@ void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentm
{
float tmat[4][4];
float vec[3];
const bool use_evaluated_indices = !(ob->transflag & OB_PARENT_USE_FINAL_INDICES);
switch (ob->partype & PARTYPE) {
case PAROBJECT: {
bool ok = false;
@@ -3212,7 +3214,7 @@ void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentm
case PARVERT1:
unit_m4(r_parentmat);
give_parvert(par, ob->par1, vec);
give_parvert(par, ob->par1, vec, use_evaluated_indices);
mul_v3_m4v3(r_parentmat[3], par->object_to_world().ptr(), vec);
break;
case PARVERT3:

View File

@@ -572,6 +572,8 @@ enum {
OB_TRANSFLAG_UNUSED_12 = 1 << 12, /* cleared */
/* runtime constraints disable */
OB_NO_CONSTRAINTS = 1 << 13,
/* when calculating vertex parent position, ignore CD_ORIGINDEX layer */
OB_PARENT_USE_FINAL_INDICES = 1 << 14,
OB_DUPLI = OB_DUPLIVERTS | OB_DUPLICOLLECTION | OB_DUPLIFACES | OB_DUPLIPARTS,
};

View File

@@ -2955,6 +2955,14 @@ static void rna_def_object(BlenderRNA *brna)
prop, "Parent Bone", "Name of parent bone in case of a bone parenting relation");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
prop = RNA_def_property(srna, "use_parent_final_indices", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "transflag", OB_PARENT_USE_FINAL_INDICES);
RNA_def_property_ui_text(
prop,
"Use Final Indices",
"Use the final evaluated indices rather than the original mesh indices");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
prop = RNA_def_property(srna, "use_camera_lock_parent", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(
prop, nullptr, "transflag", OB_TRANSFORM_ADJUST_ROOT_PARENT_FOR_VIEW_LOCK);