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

This commit is contained in:
2020-09-11 11:20:57 +02:00
parent 1b6dd42803
commit ff4578a6e7
3 changed files with 67 additions and 76 deletions

View File

@@ -47,6 +47,8 @@
#include "DEG_depsgraph_query.h"
#include "BLO_read_write.h"
/* PointCloud datablock */
static void pointcloud_random(PointCloud *pointcloud);
@@ -111,6 +113,64 @@ static void pointcloud_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
PointCloud *pointcloud = (PointCloud *)id;
if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(
&pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
/* Write LibData */
BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
BKE_id_blend_write(writer, &pointcloud->id);
/* Direct data */
CustomData_blend_write(
writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
if (pointcloud->adt) {
BKE_animdata_blend_write(writer, pointcloud->adt);
}
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
}
}
static void pointcloud_blend_read_data(BlendDataReader *reader, ID *id)
{
PointCloud *pointcloud = (PointCloud *)id;
BLO_read_data_address(reader, &pointcloud->adt);
BKE_animdata_blend_read_data(reader, pointcloud->adt);
/* Geometry */
CustomData_blend_read(reader, &pointcloud->pdata, pointcloud->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud);
/* Materials */
BLO_read_pointer_array(reader, (void **)&pointcloud->mat);
}
static void pointcloud_blend_read_lib(BlendLibReader *reader, ID *id)
{
PointCloud *pointcloud = (PointCloud *)id;
for (int a = 0; a < pointcloud->totcol; a++) {
BLO_read_id_address(reader, pointcloud->id.lib, &pointcloud->mat[a]);
}
}
static void pointcloud_blend_read_expand(BlendExpander *expander, ID *id)
{
PointCloud *pointcloud = (PointCloud *)id;
for (int a = 0; a < pointcloud->totcol; a++) {
BLO_expand(expander, pointcloud->mat[a]);
}
}
IDTypeInfo IDType_ID_PT = {
.id_code = ID_PT,
.id_filter = FILTER_ID_PT,
@@ -128,10 +188,10 @@ IDTypeInfo IDType_ID_PT = {
.foreach_id = pointcloud_foreach_id,
.foreach_cache = NULL,
.blend_write = NULL,
.blend_read_data = NULL,
.blend_read_lib = NULL,
.blend_read_expand = NULL,
.blend_write = pointcloud_blend_write,
.blend_read_data = pointcloud_blend_read_data,
.blend_read_lib = pointcloud_blend_read_lib,
.blend_read_expand = pointcloud_blend_read_expand,
};
static void pointcloud_random(PointCloud *pointcloud)

View File

@@ -6238,32 +6238,6 @@ static void lib_link_sound(BlendLibReader *reader, bSound *sound)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Read ID: Point Cloud
* \{ */
static void lib_link_pointcloud(BlendLibReader *reader, PointCloud *pointcloud)
{
for (int a = 0; a < pointcloud->totcol; a++) {
BLO_read_id_address(reader, pointcloud->id.lib, &pointcloud->mat[a]);
}
}
static void direct_link_pointcloud(BlendDataReader *reader, PointCloud *pointcloud)
{
BLO_read_data_address(reader, &pointcloud->adt);
BKE_animdata_blend_read_data(reader, pointcloud->adt);
/* Geometry */
CustomData_blend_read(reader, &pointcloud->pdata, pointcloud->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud);
/* Materials */
BLO_read_pointer_array(reader, (void **)&pointcloud->mat);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Read ID: Volume
* \{ */
@@ -6505,9 +6479,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_WS:
direct_link_workspace(&reader, (WorkSpace *)id, main);
break;
case ID_PT:
direct_link_pointcloud(&reader, (PointCloud *)id);
break;
case ID_VO:
direct_link_volume(&reader, (Volume *)id);
break;
@@ -6540,6 +6511,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
case ID_TE:
case ID_GD:
case ID_HA:
case ID_PT:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -7175,9 +7147,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_CF:
lib_link_cachefiles(&reader, (CacheFile *)id);
break;
case ID_PT:
lib_link_pointcloud(&reader, (PointCloud *)id);
break;
case ID_VO:
lib_link_volume(&reader, (Volume *)id);
break;
@@ -7217,6 +7186,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_TE:
case ID_GD:
case ID_HA:
case ID_PT:
/* Do nothing. Handled by IDTypeInfo callback. */
break;
}
@@ -8160,13 +8130,6 @@ static void expand_workspace(BlendExpander *expander, WorkSpace *workspace)
}
}
static void expand_pointcloud(BlendExpander *expander, PointCloud *pointcloud)
{
for (int a = 0; a < pointcloud->totcol; a++) {
BLO_expand(expander, pointcloud->mat[a]);
}
}
static void expand_volume(BlendExpander *expander, Volume *volume)
{
for (int a = 0; a < volume->totcol; a++) {
@@ -8248,9 +8211,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_WS:
expand_workspace(&expander, (WorkSpace *)id);
break;
case ID_PT:
expand_pointcloud(&expander, (PointCloud *)id);
break;
case ID_VO:
expand_volume(&expander, (Volume *)id);
break;

View File

@@ -2104,33 +2104,6 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi
}
}
static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const void *id_address)
{
if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(
&pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
/* Write LibData */
BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id);
BKE_id_blend_write(writer, &pointcloud->id);
/* Direct data */
CustomData_blend_write(
writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id);
BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat);
if (pointcloud->adt) {
BKE_animdata_blend_write(writer, pointcloud->adt);
}
/* Remove temporary data. */
if (players && players != players_buff) {
MEM_freeN(players);
}
}
}
static void write_volume(BlendWriter *writer, Volume *volume, const void *id_address)
{
if (volume->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2488,9 +2461,6 @@ static bool write_file_handle(Main *mainvar,
case ID_CF:
write_cachefile(&writer, (CacheFile *)id_buffer, id);
break;
case ID_PT:
write_pointcloud(&writer, (PointCloud *)id_buffer, id);
break;
case ID_VO:
write_volume(&writer, (Volume *)id_buffer, id);
break;
@@ -2523,6 +2493,7 @@ static bool write_file_handle(Main *mainvar,
case ID_TE:
case ID_GD:
case ID_HA:
case ID_PT:
/* Do nothing, handled in IDTypeInfo callback. */
break;
case ID_LI: