[Bf-blender-cvs] [ea1094bdb04] master: Refactor: move Material .blend I/O to IDTypeInfo callbacks

Jacques Lucke noreply at git.blender.org
Thu Sep 10 16:24:07 CEST 2020


Commit: ea1094bdb0419b97174dd95a5887cd6cf2732d22
Author: Jacques Lucke
Date:   Thu Sep 10 16:23:53 2020 +0200
Branches: master
https://developer.blender.org/rBea1094bdb0419b97174dd95a5887cd6cf2732d22

Refactor: move Material .blend I/O to IDTypeInfo callbacks

===================================================================

M	source/blender/blenkernel/intern/material.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 245cf19846e..885cc1baefc 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -29,6 +29,9 @@
 
 #include "MEM_guardedalloc.h"
 
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
 #include "DNA_ID.h"
 #include "DNA_anim_types.h"
 #include "DNA_collection_types.h"
@@ -54,6 +57,7 @@
 
 #include "BLT_translation.h"
 
+#include "BKE_anim_data.h"
 #include "BKE_brush.h"
 #include "BKE_curve.h"
 #include "BKE_displist.h"
@@ -78,6 +82,8 @@
 
 #include "NOD_shader.h"
 
+#include "BLO_read_write.h"
+
 static CLG_LogRef LOG = {"bke.material"};
 
 static void material_init_data(ID *id)
@@ -160,6 +166,82 @@ static void material_foreach_id(ID *id, LibraryForeachIDData *data)
   }
 }
 
+static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+  Material *ma = (Material *)id;
+  if (ma->id.us > 0 || BLO_write_is_undo(writer)) {
+    /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+    ma->texpaintslot = NULL;
+    BLI_listbase_clear(&ma->gpumaterial);
+
+    /* write LibData */
+    BLO_write_id_struct(writer, Material, id_address, &ma->id);
+    BKE_id_blend_write(writer, &ma->id);
+
+    if (ma->adt) {
+      BKE_animdata_blend_write(writer, ma->adt);
+    }
+
+    /* nodetree is integral part of material, no libdata */
+    if (ma->nodetree) {
+      BLO_write_struct(writer, bNodeTree, ma->nodetree);
+      ntreeBlendWrite(writer, ma->nodetree);
+    }
+
+    BKE_previewimg_blend_write(writer, ma->preview);
+
+    /* grease pencil settings */
+    if (ma->gp_style) {
+      BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
+    }
+  }
+}
+
+static void material_blend_read_data(BlendDataReader *reader, ID *id)
+{
+  Material *ma = (Material *)id;
+  BLO_read_data_address(reader, &ma->adt);
+  BKE_animdata_blend_read_data(reader, ma->adt);
+
+  ma->texpaintslot = NULL;
+
+  BLO_read_data_address(reader, &ma->preview);
+  BKE_previewimg_blend_read(reader, ma->preview);
+
+  BLI_listbase_clear(&ma->gpumaterial);
+
+  BLO_read_data_address(reader, &ma->gp_style);
+}
+
+static void material_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+  Material *ma = (Material *)id;
+  BLO_read_id_address(reader, ma->id.lib, &ma->ipo);  // XXX deprecated - old animation system
+
+  /* relink grease pencil settings */
+  if (ma->gp_style != NULL) {
+    MaterialGPencilStyle *gp_style = ma->gp_style;
+    if (gp_style->sima != NULL) {
+      BLO_read_id_address(reader, ma->id.lib, &gp_style->sima);
+    }
+    if (gp_style->ima != NULL) {
+      BLO_read_id_address(reader, ma->id.lib, &gp_style->ima);
+    }
+  }
+}
+
+static void material_blend_read_expand(BlendExpander *expander, ID *id)
+{
+  Material *ma = (Material *)id;
+  BLO_expand(expander, ma->ipo);  // XXX deprecated - old animation system
+
+  if (ma->gp_style) {
+    MaterialGPencilStyle *gp_style = ma->gp_style;
+    BLO_expand(expander, gp_style->sima);
+    BLO_expand(expander, gp_style->ima);
+  }
+}
+
 IDTypeInfo IDType_ID_MA = {
     .id_code = ID_MA,
     .id_filter = FILTER_ID_MA,
@@ -177,10 +259,10 @@ IDTypeInfo IDType_ID_MA = {
     .foreach_id = material_foreach_id,
     .foreach_cache = NULL,
 
-    .blend_write = NULL,
-    .blend_read_data = NULL,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
+    .blend_write = material_blend_write,
+    .blend_read_data = material_blend_read_data,
+    .blend_read_lib = material_blend_read_lib,
+    .blend_read_expand = material_blend_read_expand,
 };
 
 void BKE_gpencil_material_attr_init(Material *ma)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 85b7c1e5623..277ccce3560 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3114,43 +3114,6 @@ static void direct_link_texture(BlendDataReader *reader, Tex *tex)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Read ID: Material
- * \{ */
-
-static void lib_link_material(BlendLibReader *reader, Material *ma)
-{
-  BLO_read_id_address(reader, ma->id.lib, &ma->ipo);  // XXX deprecated - old animation system
-
-  /* relink grease pencil settings */
-  if (ma->gp_style != NULL) {
-    MaterialGPencilStyle *gp_style = ma->gp_style;
-    if (gp_style->sima != NULL) {
-      BLO_read_id_address(reader, ma->id.lib, &gp_style->sima);
-    }
-    if (gp_style->ima != NULL) {
-      BLO_read_id_address(reader, ma->id.lib, &gp_style->ima);
-    }
-  }
-}
-
-static void direct_link_material(BlendDataReader *reader, Material *ma)
-{
-  BLO_read_data_address(reader, &ma->adt);
-  BKE_animdata_blend_read_data(reader, ma->adt);
-
-  ma->texpaintslot = NULL;
-
-  BLO_read_data_address(reader, &ma->preview);
-  BKE_previewimg_blend_read(reader, ma->preview);
-
-  BLI_listbase_clear(&ma->gpumaterial);
-
-  BLO_read_data_address(reader, &ma->gp_style);
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Particle Settings
  * \{ */
@@ -7079,9 +7042,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_MB:
       direct_link_mball(&reader, (MetaBall *)id);
       break;
-    case ID_MA:
-      direct_link_material(&reader, (Material *)id);
-      break;
     case ID_TE:
       direct_link_texture(&reader, (Tex *)id);
       break;
@@ -7155,6 +7115,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_BR:
     case ID_IM:
     case ID_LA:
+    case ID_MA:
       /* Do nothing. Handled by IDTypeInfo callback. */
       break;
   }
@@ -7823,9 +7784,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_VO:
         lib_link_volume(&reader, (Volume *)id);
         break;
-      case ID_MA:
-        lib_link_material(&reader, (Material *)id);
-        break;
       case ID_TE:
         lib_link_texture(&reader, (Tex *)id);
         break;
@@ -7858,6 +7816,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_BR:
       case ID_IM:
       case ID_LA:
+      case ID_MA:
         /* Do nothing. Handled by IDTypeInfo callback. */
         break;
     }
@@ -8554,17 +8513,6 @@ static void expand_texture(BlendExpander *expander, Tex *tex)
   BLO_expand(expander, tex->ipo);  // XXX deprecated - old animation system
 }
 
-static void expand_material(BlendExpander *expander, Material *ma)
-{
-  BLO_expand(expander, ma->ipo);  // XXX deprecated - old animation system
-
-  if (ma->gp_style) {
-    MaterialGPencilStyle *gp_style = ma->gp_style;
-    BLO_expand(expander, gp_style->sima);
-    BLO_expand(expander, gp_style->ima);
-  }
-}
-
 static void expand_world(BlendExpander *expander, World *wrld)
 {
   BLO_expand(expander, wrld->ipo);  // XXX deprecated - old animation system
@@ -9006,9 +8954,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
             case ID_SCE:
               expand_scene(&expander, (Scene *)id);
               break;
-            case ID_MA:
-              expand_material(&expander, (Material *)id);
-              break;
             case ID_TE:
               expand_texture(&expander, (Tex *)id);
               break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 24ca503b895..acf4e1ca635 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1531,36 +1531,6 @@ static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
   }
 }
 
-static void write_material(BlendWriter *writer, Material *ma, const void *id_address)
-{
-  if (ma->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* Clean up, important in undo case to reduce false detection of changed datablocks. */
-    ma->texpaintslot = NULL;
-    BLI_listbase_clear(&ma->gpumaterial);
-
-    /* write LibData */
-    BLO_write_id_struct(writer, Material, id_address, &ma->id);
-    BKE_id_blend_write(writer, &ma->id);
-
-    if (ma->adt) {
-      BKE_animdata_blend_write(writer, ma->adt);
-    }
-
-    /* nodetree is integral part of material, no libdata */
-    if (ma->nodetree) {
-      BLO_write_struct(writer, bNodeTree, ma->nodetree);
-      ntreeBlendWrite(writer, ma->nodetree);
-    }
-
-    BKE_previewimg_blend_write(writer, ma->preview);
-
-    /* grease pencil settings */
-    if (ma->gp_style) {
-      BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
-    }
-  }
-}
-
 static void write_world(BlendWriter *writer, World *wrld, const void *id_address)
 {
   if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2891,9 +2861,6 @@ static bool write_file_handle(Main *mainvar,
           case ID_OB:
             write_object(&writer, (Object *)id_buffer, id);
             break;
-          case ID_MA:
-            write_material(&writer, (Material *)id_buffer, id);
-            break;
           case ID_TE:
             write_texture(&writer, (Tex *)id_buffer, id);
             break;
@@ -2931,6 +2898,7 @@ static bool write_file_handle(Main *mainvar,
           case ID_BR:
           case ID_IM:
           case ID_LA:
+          case ID_MA:
             /* Do nothing, handled in IDTypeInfo callback. */
             break;
           case ID_LI:



More information about the Bf-blender-cvs mailing list