Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-09-10 18:41:04 +0300
committerJacques Lucke <jacques@blender.org>2020-09-10 18:41:04 +0300
commit133b7c34dd1c457ee921302e88594654ac64ba9f (patch)
treecbe7cd65cc441ad50d918ad04f2870892818af65 /source
parent0c7e77d416cac85d6b50778115d8cae4c3d64a6c (diff)
Refactor: move Armature .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/armature.c130
-rw-r--r--source/blender/blenloader/intern/readfile.c82
-rw-r--r--source/blender/blenloader/intern/writefile.c48
3 files changed, 129 insertions, 131 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,
};
/** \} */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b8697734013..e30df56c2ec 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2787,61 +2787,6 @@ static void lib_link_pose(BlendLibReader *reader, Object *ob, bPose *pose)
}
}
-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 lib_link_armature(BlendLibReader *reader, bArmature *arm)
-{
- LISTBASE_FOREACH (Bone *, curbone, &arm->bonebase) {
- lib_link_bones(reader, curbone);
- }
-}
-
-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 direct_link_armature(BlendDataReader *reader, bArmature *arm)
-{
- 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);
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -6776,9 +6721,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_GR:
direct_link_collection(&reader, (Collection *)id);
break;
- case ID_AR:
- direct_link_armature(&reader, (bArmature *)id);
- break;
case ID_PA:
direct_link_particlesettings(&reader, (ParticleSettings *)id);
break;
@@ -6823,6 +6765,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_WO:
case ID_MSK:
case ID_SPK:
+ case ID_AR:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -7461,9 +7404,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_CF:
lib_link_cachefiles(&reader, (CacheFile *)id);
break;
- case ID_AR:
- lib_link_armature(&reader, (bArmature *)id);
- break;
case ID_HA:
lib_link_hair(&reader, (Hair *)id);
break;
@@ -7512,6 +7452,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_WO:
case ID_MSK:
case ID_SPK:
+ case ID_AR:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8243,22 +8184,6 @@ static void expand_pose(BlendExpander *expander, bPose *pose)
}
}
-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 expand_armature(BlendExpander *expander, bArmature *arm)
-{
- LISTBASE_FOREACH (Bone *, curBone, &arm->bonebase) {
- expand_bones(expander, curBone);
- }
-}
-
static void expand_object_expandModifiers(void *userData,
Object *UNUSED(ob),
ID **idpoin,
@@ -8586,9 +8511,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_LP:
expand_lightprobe(&expander, (LightProbe *)id);
break;
- case ID_AR:
- expand_armature(&expander, (bArmature *)id);
- break;
case ID_GR:
expand_collection(&expander, (Collection *)id);
break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 9a423ab6906..9fc8fb75ea0 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2143,50 +2143,6 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad
}
}
-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 write_armature(BlendWriter *writer, bArmature *arm, const void *id_address)
-{
- 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 write_sound(BlendWriter *writer, bSound *sound, const void *id_address)
{
if (sound->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2661,9 +2617,6 @@ static bool write_file_handle(Main *mainvar,
case ID_GR:
write_collection(&writer, (Collection *)id_buffer, id);
break;
- case ID_AR:
- write_armature(&writer, (bArmature *)id_buffer, id);
- break;
case ID_OB:
write_object(&writer, (Object *)id_buffer, id);
break;
@@ -2711,6 +2664,7 @@ static bool write_file_handle(Main *mainvar,
case ID_WO:
case ID_MSK:
case ID_SPK:
+ case ID_AR:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: