Cleanup: Grease Pencil: Simplify get_bone_mat utility function
This commit is contained in:
@@ -36,25 +36,21 @@
|
||||
namespace blender::ed::greasepencil {
|
||||
|
||||
/* This utility function is modified from `BKE_object_get_parent_matrix()`. */
|
||||
static void get_bone_mat(const Object *parent, const char *parsubstr, float4x4 &r_mat)
|
||||
static float4x4 get_bone_mat(const Object *parent, const char *parsubstr)
|
||||
{
|
||||
if (parent->type != OB_ARMATURE) {
|
||||
r_mat = float4x4::identity();
|
||||
return;
|
||||
return float4x4::identity();
|
||||
}
|
||||
|
||||
const bPoseChannel *pchan = BKE_pose_channel_find_name(parent->pose, parsubstr);
|
||||
if (!pchan || !pchan->bone) {
|
||||
r_mat = float4x4::identity();
|
||||
return;
|
||||
return float4x4::identity();
|
||||
}
|
||||
|
||||
if (pchan->bone->flag & BONE_RELATIVE_PARENTING) {
|
||||
r_mat = float4x4(pchan->chan_mat);
|
||||
}
|
||||
else {
|
||||
r_mat = float4x4(pchan->pose_mat);
|
||||
return float4x4(pchan->chan_mat);
|
||||
}
|
||||
return float4x4(pchan->pose_mat);
|
||||
}
|
||||
|
||||
bool grease_pencil_layer_parent_set(bke::greasepencil::Layer &layer,
|
||||
@@ -70,13 +66,12 @@ bool grease_pencil_layer_parent_set(bke::greasepencil::Layer &layer,
|
||||
layer.parsubstr = BLI_strdup_null(bone.c_str());
|
||||
/* Calculate inverse parent matrix. */
|
||||
if (parent) {
|
||||
copy_m4_m4(layer.parentinv, parent->world_to_object().ptr());
|
||||
float4x4 inverse = parent->world_to_object();
|
||||
if (layer.parsubstr) {
|
||||
float4x4 bone_mat;
|
||||
get_bone_mat(parent, layer.parsubstr, bone_mat);
|
||||
float4x4 bone_inverse = math::invert(bone_mat) * float4x4(layer.parentinv);
|
||||
copy_m4_m4(layer.parentinv, bone_inverse.ptr());
|
||||
const float4x4 bone_mat = get_bone_mat(parent, layer.parsubstr);
|
||||
inverse = math::invert(bone_mat) * inverse;
|
||||
}
|
||||
copy_m4_m4(layer.parentinv, inverse.ptr());
|
||||
}
|
||||
else {
|
||||
unit_m4(layer.parentinv);
|
||||
|
||||
Reference in New Issue
Block a user