diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 18:41:04 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 18:41:04 +0300 |
commit | 133b7c34dd1c457ee921302e88594654ac64ba9f (patch) | |
tree | cbe7cd65cc441ad50d918ad04f2870892818af65 /source/blender/blenkernel/intern/armature.c | |
parent | 0c7e77d416cac85d6b50778115d8cae4c3d64a6c (diff) |
Refactor: move Armature .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender/blenkernel/intern/armature.c')
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 130 |
1 files changed, 126 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index a653087f961..49ca25aca29 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -45,6 +45,7 @@ #include "DNA_scene_types.h" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_anim_visualization.h" #include "BKE_armature.h" #include "BKE_constraint.h" @@ -62,6 +63,8 @@ #include "BIK_api.h" +#include "BLO_read_write.h" + #include "CLG_log.h" static CLG_LogRef LOG = {"bke.armature"}; @@ -165,6 +168,125 @@ static void armature_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void write_bone(BlendWriter *writer, Bone *bone) +{ + /* PATCH for upward compatibility after 2.37+ armature recode */ + bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; + + /* Write this bone */ + BLO_write_struct(writer, Bone, bone); + + /* Write ID Properties -- and copy this comment EXACTLY for easy finding + * of library blocks that implement this.*/ + if (bone->prop) { + IDP_BlendWrite(writer, bone->prop); + } + + /* Write Children */ + LISTBASE_FOREACH (Bone *, cbone, &bone->childbase) { + write_bone(writer, cbone); + } +} + +static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bArmature *arm = (bArmature *)id; + if (arm->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + arm->bonehash = NULL; + arm->edbo = NULL; + /* Must always be cleared (armatures don't have their own edit-data). */ + arm->needs_flush_to_id = 0; + arm->act_edbone = NULL; + + BLO_write_id_struct(writer, bArmature, id_address, &arm->id); + BKE_id_blend_write(writer, &arm->id); + + if (arm->adt) { + BKE_animdata_blend_write(writer, arm->adt); + } + + /* Direct data */ + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { + write_bone(writer, bone); + } + } +} + +static void direct_link_bones(BlendDataReader *reader, Bone *bone) +{ + BLO_read_data_address(reader, &bone->parent); + BLO_read_data_address(reader, &bone->prop); + IDP_BlendDataRead(reader, &bone->prop); + + BLO_read_data_address(reader, &bone->bbone_next); + BLO_read_data_address(reader, &bone->bbone_prev); + + bone->flag &= ~(BONE_DRAW_ACTIVE | BONE_DRAW_LOCKED_WEIGHT); + + BLO_read_list(reader, &bone->childbase); + + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { + direct_link_bones(reader, child); + } +} + +static void armature_blend_read_data(BlendDataReader *reader, ID *id) +{ + bArmature *arm = (bArmature *)id; + BLO_read_list(reader, &arm->bonebase); + arm->bonehash = NULL; + arm->edbo = NULL; + /* Must always be cleared (armatures don't have their own edit-data). */ + arm->needs_flush_to_id = 0; + + BLO_read_data_address(reader, &arm->adt); + BKE_animdata_blend_read_data(reader, arm->adt); + + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { + direct_link_bones(reader, bone); + } + + BLO_read_data_address(reader, &arm->act_bone); + arm->act_edbone = NULL; + + BKE_armature_bone_hash_make(arm); +} + +static void lib_link_bones(BlendLibReader *reader, Bone *bone) +{ + IDP_BlendReadLib(reader, bone->prop); + + LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) { + lib_link_bones(reader, curbone); + } +} + +static void armature_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bArmature *arm = (bArmature *)id; + LISTBASE_FOREACH (Bone *, curbone, &arm->bonebase) { + lib_link_bones(reader, curbone); + } +} + +static void expand_bones(BlendExpander *expander, Bone *bone) +{ + IDP_BlendReadExpand(expander, bone->prop); + + LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) { + expand_bones(expander, curBone); + } +} + +static void armature_blend_read_expand(BlendExpander *expander, ID *id) +{ + bArmature *arm = (bArmature *)id; + LISTBASE_FOREACH (Bone *, curBone, &arm->bonebase) { + expand_bones(expander, curBone); + } +} + IDTypeInfo IDType_ID_AR = { .id_code = ID_AR, .id_filter = FILTER_ID_AR, @@ -182,10 +304,10 @@ IDTypeInfo IDType_ID_AR = { .foreach_id = armature_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = armature_blend_write, + .blend_read_data = armature_blend_read_data, + .blend_read_lib = armature_blend_read_lib, + .blend_read_expand = armature_blend_read_expand, }; /** \} */ |