Fix #128055: parentinv matrix uninitialized in old GPv2 files
In GPv2 the parentinv matrix is zero initially and only becomes valid after setting the layer parent. This matrix must not be copied to the GPv3 layers unless the parent is set. In addition the parentinv matrix should also be computed when changing the layer parent. This has been nominally added, except that a full computation isn't possible without the actual grease pencil Object. This means a local RNA property cannot update the parentinv matrix, this needs to become a full-blown operator. The behavior now should be the same as in GPv2 at least. Pull Request: https://projects.blender.org/blender/blender/pulls/129304
This commit is contained in:
@@ -1064,7 +1064,10 @@ static void legacy_gpencil_to_grease_pencil(ConversionData &conversion_data,
|
||||
|
||||
new_layer.parent = gpl->parent;
|
||||
new_layer.set_parent_bone_name(gpl->parsubstr);
|
||||
copy_m4_m4(new_layer.parentinv, gpl->inverse);
|
||||
/* GPv2 parent inverse matrix is only valid when parent is set. */
|
||||
if (gpl->parent) {
|
||||
copy_m4_m4(new_layer.parentinv, gpl->inverse);
|
||||
}
|
||||
|
||||
copy_v3_v3(new_layer.translation, gpl->location);
|
||||
copy_v3_v3(new_layer.rotation, gpl->rotation);
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
* \ingroup edgreasepencil
|
||||
*/
|
||||
|
||||
#include "BLI_math_matrix.h"
|
||||
#include "BLI_math_matrix.hh"
|
||||
#include "BLI_string.h"
|
||||
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_object.hh"
|
||||
#include "BKE_report.hh"
|
||||
|
||||
#include "BLT_translation.hh"
|
||||
@@ -18,6 +23,7 @@
|
||||
|
||||
#include "RNA_access.hh"
|
||||
#include "RNA_define.hh"
|
||||
|
||||
#include "UI_interface.hh"
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
@@ -26,6 +32,43 @@
|
||||
|
||||
namespace blender::ed::greasepencil {
|
||||
|
||||
bool grease_pencil_layer_parent_set(bke::greasepencil::Layer &layer,
|
||||
Object *parent,
|
||||
StringRefNull bone,
|
||||
const bool keep_transform)
|
||||
{
|
||||
if (keep_transform) {
|
||||
/* TODO apply current transform to geometry. */
|
||||
}
|
||||
|
||||
layer.parent = parent;
|
||||
BLI_strncpy(layer.parsubstr, bone.c_str(), sizeof(layer.parsubstr));
|
||||
/* Calculate inverse parent matrix. */
|
||||
if (parent) {
|
||||
copy_m4_m4(layer.parentinv, parent->world_to_object().ptr());
|
||||
}
|
||||
else {
|
||||
unit_m4(layer.parentinv);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void grease_pencil_layer_parent_clear(bke::greasepencil::Layer &layer, const bool keep_transform)
|
||||
{
|
||||
if (layer.parent == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (keep_transform) {
|
||||
/* TODO apply current transform to geometry. */
|
||||
}
|
||||
|
||||
layer.parent = nullptr;
|
||||
layer.parsubstr[0] = 0;
|
||||
|
||||
copy_m4_m4(layer.parentinv, float4x4::identity().ptr());
|
||||
}
|
||||
|
||||
void select_layer_channel(GreasePencil &grease_pencil, bke::greasepencil::Layer *layer)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
|
||||
@@ -235,6 +235,13 @@ struct KeyframeClipboard {
|
||||
}
|
||||
};
|
||||
|
||||
bool grease_pencil_layer_parent_set(bke::greasepencil::Layer &layer,
|
||||
Object *parent,
|
||||
StringRefNull bone,
|
||||
bool keep_transform);
|
||||
|
||||
void grease_pencil_layer_parent_clear(bke::greasepencil::Layer &layer, bool keep_transform);
|
||||
|
||||
bool grease_pencil_copy_keyframes(bAnimContext *ac, KeyframeClipboard &clipboard);
|
||||
|
||||
bool grease_pencil_paste_keyframes(bAnimContext *ac,
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
# include "DEG_depsgraph.hh"
|
||||
# include "DEG_depsgraph_build.hh"
|
||||
|
||||
# include "ED_grease_pencil.hh"
|
||||
|
||||
static GreasePencil *rna_grease_pencil(const PointerRNA *ptr)
|
||||
{
|
||||
return reinterpret_cast<GreasePencil *>(ptr->owner_id);
|
||||
@@ -357,6 +359,25 @@ static void rna_GreasePencilLayer_pass_index_set(PointerRNA *ptr, int value)
|
||||
layer_passes.finish();
|
||||
}
|
||||
|
||||
static void rna_GreasePencilLayer_parent_set(PointerRNA *ptr,
|
||||
PointerRNA value,
|
||||
ReportList * /*reports*/)
|
||||
{
|
||||
using namespace blender;
|
||||
bke::greasepencil::Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap();
|
||||
Object *parent = static_cast<Object *>(value.data);
|
||||
|
||||
ed::greasepencil::grease_pencil_layer_parent_set(layer, parent, layer.parsubstr, false);
|
||||
}
|
||||
|
||||
static void rna_GreasePencilLayer_bone_set(PointerRNA *ptr, const char *value)
|
||||
{
|
||||
using namespace blender;
|
||||
bke::greasepencil::Layer &layer = static_cast<GreasePencilLayer *>(ptr->data)->wrap();
|
||||
|
||||
ed::greasepencil::grease_pencil_layer_parent_set(layer, layer.parent, value, false);
|
||||
}
|
||||
|
||||
static void rna_GreasePencilLayer_tint_color_get(PointerRNA *ptr, float *values)
|
||||
{
|
||||
using namespace blender;
|
||||
@@ -933,6 +954,8 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
|
||||
|
||||
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_struct_type(prop, "Object");
|
||||
RNA_def_property_pointer_funcs(
|
||||
prop, nullptr, "rna_GreasePencilLayer_parent_set", nullptr, nullptr);
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
|
||||
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
|
||||
RNA_def_property_ui_text(prop, "Parent", "Parent object");
|
||||
@@ -940,6 +963,7 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
|
||||
|
||||
prop = RNA_def_property(srna, "parent_bone", PROP_STRING, PROP_NONE);
|
||||
RNA_def_property_string_sdna(prop, nullptr, "parsubstr");
|
||||
RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_GreasePencilLayer_bone_set");
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Parent Bone",
|
||||
|
||||
Reference in New Issue
Block a user