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 17:23:53 +0300
committerJacques Lucke <jacques@blender.org>2020-09-10 17:23:53 +0300
commitea1094bdb0419b97174dd95a5887cd6cf2732d22 (patch)
treea2ab492975f0cdc3b175453624d8aba43b1e1c54 /source
parent94c533ac35d4ad5d944c214d4809011b61be4a94 (diff)
Refactor: move Material .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/material.c90
-rw-r--r--source/blender/blenloader/intern/readfile.c59
-rw-r--r--source/blender/blenloader/intern/writefile.c34
3 files changed, 89 insertions, 94 deletions
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
@@ -3115,43 +3115,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: