Refactor: move Material .blend I/O to IDTypeInfo callbacks
This commit is contained in:
parent
94c533ac35
commit
ea1094bdb0
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue