Anim: add custom property support for Bone Collections

Pull request: https://projects.blender.org/blender/blender/pulls/109976
This commit is contained in:
Nathan Vegdahl
2023-08-25 16:33:20 +02:00
committed by Nathan Vegdahl
parent 998136f7a7
commit 9eee076a29
8 changed files with 77 additions and 12 deletions

View File

@@ -50,6 +50,8 @@ BoneCollection *ANIM_bonecoll_new(const char *name)
BLI_strncpy(bcoll->name, name, sizeof(bcoll->name));
bcoll->flags = default_flags;
bcoll->prop = nullptr;
return bcoll;
}

View File

@@ -141,6 +141,12 @@ static void armature_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, c
/* Duplicate bone collections & assignments. */
BLI_duplicatelist(&armature_dst->collections, &armature_src->collections);
LISTBASE_FOREACH (BoneCollection *, bcoll, &armature_dst->collections) {
/* ID properties. */
if (bcoll->prop) {
bcoll->prop = IDP_CopyProperty(bcoll->prop);
}
/* Bone references. */
BLI_duplicatelist(&bcoll->bones, &bcoll->bones);
LISTBASE_FOREACH (BoneCollectionMember *, member, &bcoll->bones) {
member->bone = BKE_armature_find_bone_name(armature_dst, member->bone->name);
@@ -160,6 +166,13 @@ static void armature_free_data(ID *id)
/* Free all BoneCollectionMembership objects. */
LISTBASE_FOREACH_MUTABLE (BoneCollection *, bcoll, &armature->collections) {
/* ID properties. */
if (bcoll->prop) {
IDP_FreeProperty(bcoll->prop);
bcoll->prop = nullptr;
}
/* Bone references. */
BLI_freelistN(&bcoll->bones);
}
BLI_freelistN(&armature->collections);
@@ -197,6 +210,16 @@ static void armature_foreach_id_editbone(EditBone *edit_bone, LibraryForeachIDDa
data));
}
static void armature_foreach_id_bone_collection(BoneCollection *bcoll, LibraryForeachIDData *data)
{
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
data,
IDP_foreach_property(bcoll->prop,
IDP_TYPE_FILTER_ID,
BKE_lib_query_idpropertiesForeachIDLink_callback,
data));
}
static void armature_foreach_id(ID *id, LibraryForeachIDData *data)
{
bArmature *arm = (bArmature *)id;
@@ -209,6 +232,11 @@ static void armature_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data, armature_foreach_id_editbone(edit_bone, data));
}
}
LISTBASE_FOREACH (BoneCollection *, bcoll, &arm->collections) {
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data,
armature_foreach_id_bone_collection(bcoll, data));
}
}
static void write_bone(BlendWriter *writer, Bone *bone)
@@ -238,13 +266,14 @@ static void write_bone_collection(BlendWriter *writer, BoneCollection *bcoll)
{
/* Write this bone collection. */
BLO_write_struct(writer, BoneCollection, bcoll);
BLO_write_struct_list(writer, BoneCollectionMember, &bcoll->bones);
// /* Write ID Properties -- and copy this comment EXACTLY for easy finding
// * of library blocks that implement this. */
// if (bcoll->prop) {
// IDP_BlendWrite(writer, bcoll->prop);
// }
/* Write ID Properties -- and copy this comment EXACTLY for easy finding
* of library blocks that implement this. */
if (bcoll->prop) {
IDP_BlendWrite(writer, bcoll->prop);
}
BLO_write_struct_list(writer, BoneCollectionMember, &bcoll->bones);
}
static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
@@ -297,13 +326,13 @@ static void direct_link_bones(BlendDataReader *reader, Bone *bone)
static void direct_link_bone_collection(BlendDataReader *reader, BoneCollection *bcoll)
{
BLO_read_data_address(reader, &bcoll->prop);
IDP_BlendDataRead(reader, &bcoll->prop);
BLO_read_list(reader, &bcoll->bones);
LISTBASE_FOREACH (BoneCollectionMember *, member, &bcoll->bones) {
BLO_read_data_address(reader, &member->bone);
}
// BLO_read_data_address(reader, &bcoll->prop);
// IDP_BlendDataRead(reader, &bcoll->prop);
}
static void armature_blend_read_data(BlendDataReader *reader, ID *id)

View File

@@ -1801,6 +1801,7 @@ void DepsgraphNodeBuilder::build_armature(bArmature *armature)
add_operation_node(
&armature->id, NodeType::ARMATURE, OperationCode::ARMATURE_EVAL, [](::Depsgraph *) {});
build_armature_bones(&armature->bonebase);
build_armature_bone_collections(&armature->collections);
}
void DepsgraphNodeBuilder::build_armature_bones(ListBase *bones)
@@ -1811,6 +1812,13 @@ void DepsgraphNodeBuilder::build_armature_bones(ListBase *bones)
}
}
void DepsgraphNodeBuilder::build_armature_bone_collections(ListBase *collections)
{
LISTBASE_FOREACH (BoneCollection *, bcoll, collections) {
build_idproperties(bcoll->prop);
}
}
void DepsgraphNodeBuilder::build_camera(Camera *camera)
{
if (built_map_.checkIsBuiltAndTag(camera)) {

View File

@@ -246,6 +246,7 @@ class DepsgraphNodeBuilder : public DepsgraphBuilder {
virtual void build_rig(Object *object);
virtual void build_armature(bArmature *armature);
virtual void build_armature_bones(ListBase *bones);
virtual void build_armature_bone_collections(ListBase *collections);
virtual void build_shapekeys(Key *key);
virtual void build_camera(Camera *camera);
virtual void build_light(Light *lamp);

View File

@@ -2716,6 +2716,7 @@ void DepsgraphRelationBuilder::build_armature(bArmature *armature)
build_animdata(&armature->id);
build_parameters(&armature->id);
build_armature_bones(&armature->bonebase);
build_armature_bone_collections(&armature->collections);
}
void DepsgraphRelationBuilder::build_armature_bones(ListBase *bones)
@@ -2726,6 +2727,13 @@ void DepsgraphRelationBuilder::build_armature_bones(ListBase *bones)
}
}
void DepsgraphRelationBuilder::build_armature_bone_collections(ListBase *collections)
{
LISTBASE_FOREACH (BoneCollection *, bcoll, collections) {
build_idproperties(bcoll->prop);
}
}
void DepsgraphRelationBuilder::build_camera(Camera *camera)
{
if (built_map_.checkIsBuiltAndTag(camera)) {

View File

@@ -225,6 +225,7 @@ class DepsgraphRelationBuilder : public DepsgraphBuilder {
virtual void build_shapekeys(Key *key);
virtual void build_armature(bArmature *armature);
virtual void build_armature_bones(ListBase *bones);
virtual void build_armature_bone_collections(ListBase *collections);
virtual void build_camera(Camera *camera);
virtual void build_light(Light *lamp);
virtual void build_nodetree(bNodeTree *ntree);

View File

@@ -226,7 +226,8 @@ typedef struct BoneCollection {
uint8_t flags;
uint8_t _pad0[7];
// TODO: add IDProperties.
/** Custom properties. */
struct IDProperty *prop;
} BoneCollection;
/** Membership relation of a bone with a bone collection. */

View File

@@ -219,6 +219,21 @@ static void rna_BoneCollection_name_set(PointerRNA *ptr, const char *name)
// TODO: notifiers.
}
static char *rna_BoneCollection_path(const PointerRNA *ptr)
{
const BoneCollection *bcoll = (const BoneCollection *)ptr->data;
char name_esc[sizeof(bcoll->name) * 2];
BLI_str_escape(name_esc, bcoll->name, sizeof(name_esc));
return BLI_sprintfN("collections[\"%s\"]", name_esc);
}
static IDProperty **rna_BoneCollection_idprops(PointerRNA *ptr)
{
BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
return &bcoll->prop;
}
/* Bone.collections iterator functions. */
static void rna_Bone_collections_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
@@ -1912,8 +1927,8 @@ static void rna_def_bonecollection(BlenderRNA *brna)
srna = RNA_def_struct(brna, "BoneCollection", NULL);
RNA_def_struct_ui_text(srna, "BoneCollection", "Bone collection in an Armature data-block");
// RNA_def_struct_path_func(srna, "rna_BoneCollection_path");
// RNA_def_struct_idprops_func(srna, "rna_BoneCollection_idprops");
RNA_def_struct_path_func(srna, "rna_BoneCollection_path");
RNA_def_struct_idprops_func(srna, "rna_BoneCollection_idprops");
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "name");