Fix #120459: GPv3: Issue in conversion for layer parents #120462

Merged
Falk David merged 1 commits from filedescriptor/blender:fix-120459 into main 2024-04-10 12:41:39 +02:00
4 changed files with 18 additions and 2 deletions

View File

@ -514,6 +514,8 @@ class Layer : public ::GreasePencilLayer {
SortedKeysIterator remove_leading_null_frames_in_range(SortedKeysIterator begin,
SortedKeysIterator end);
float4x4 parent_inverse() const;
/**
* The local transform of the layer (in layer space, not object space).
*/

View File

@ -911,6 +911,7 @@ Layer::Layer()
this->parent = nullptr;
this->parsubstr = nullptr;
unit_m4(this->parentinv);
zero_v3(this->translation);
zero_v3(this->rotation);
@ -944,6 +945,7 @@ Layer::Layer(const Layer &other) : Layer()
this->parent = other.parent;
this->set_parent_bone_name(other.parsubstr);
copy_m4_m4(this->parentinv, other.parentinv);
copy_v3_v3(this->translation, other.translation);
copy_v3_v3(this->rotation, other.rotation);
@ -1225,7 +1227,7 @@ float4x4 Layer::to_world_space(const Object &object) const
return object.object_to_world() * this->local_transform();
}
const Object &parent = *this->parent;
return this->parent_to_world(parent) * this->local_transform();
return this->parent_to_world(parent) * this->parent_inverse() * this->local_transform();
}
float4x4 Layer::to_object_space(const Object &object) const
@ -1234,7 +1236,8 @@ float4x4 Layer::to_object_space(const Object &object) const
return this->local_transform();
}
const Object &parent = *this->parent;
return object.world_to_object() * this->parent_to_world(parent) * this->local_transform();
return object.world_to_object() * this->parent_to_world(parent) * this->parent_inverse() *
this->local_transform();
}
StringRefNull Layer::parent_bone_name() const
@ -1263,6 +1266,11 @@ float4x4 Layer::parent_to_world(const Object &parent) const
return parent_object_to_world;
}
float4x4 Layer::parent_inverse() const
{
return float4x4_view(this->parentinv);
}
float4x4 Layer::local_transform() const
{
return math::from_loc_rot_scale<float4x4, math::EulerXYZ>(

View File

@ -586,6 +586,7 @@ void legacy_gpencil_to_grease_pencil(Main &bmain, GreasePencil &grease_pencil, b
new_layer.parent = gpl->parent;
new_layer.set_parent_bone_name(gpl->parsubstr);
copy_m4_m4(new_layer.parentinv, gpl->inverse);
copy_v3_v3(new_layer.translation, gpl->location);
copy_v3_v3(new_layer.rotation, gpl->rotation);

View File

@ -300,6 +300,11 @@ typedef struct GreasePencilLayer {
*/
struct Object *parent;
char *parsubstr;
/**
* Stores the inverse of the parent during parenting to keep the layer in its position.
* Also referred to as the "keep transform" parenting elsewhere.
*/
float parentinv[4][4];
/**
* Layer transform UI settings. These should *not* be used to do any computation.
* Use the functions is the `bke::greasepencil::Layer` class instead.