Refactor: move Camera .blend I/O to IDTypeInfo callbacks
This commit is contained in:
@@ -24,6 +24,9 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* Allow using deprecated functionality for .blend file I/O. */
|
||||||
|
#define DNA_DEPRECATED_ALLOW
|
||||||
|
|
||||||
#include "DNA_ID.h"
|
#include "DNA_ID.h"
|
||||||
#include "DNA_camera_types.h"
|
#include "DNA_camera_types.h"
|
||||||
#include "DNA_defaults.h"
|
#include "DNA_defaults.h"
|
||||||
@@ -38,6 +41,7 @@
|
|||||||
#include "BLI_string.h"
|
#include "BLI_string.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
|
#include "BKE_anim_data.h"
|
||||||
#include "BKE_camera.h"
|
#include "BKE_camera.h"
|
||||||
#include "BKE_idtype.h"
|
#include "BKE_idtype.h"
|
||||||
#include "BKE_layer.h"
|
#include "BKE_layer.h"
|
||||||
@@ -54,6 +58,8 @@
|
|||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
|
#include "BLO_read_write.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/** \name Camera Data-Block
|
/** \name Camera Data-Block
|
||||||
* \{ */
|
* \{ */
|
||||||
@@ -113,6 +119,67 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||||
|
{
|
||||||
|
Camera *cam = (Camera *)id;
|
||||||
|
if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||||
|
/* write LibData */
|
||||||
|
BLO_write_id_struct(writer, Camera, id_address, &cam->id);
|
||||||
|
BKE_id_blend_write(writer, &cam->id);
|
||||||
|
|
||||||
|
if (cam->adt) {
|
||||||
|
BKE_animdata_blend_write(writer, cam->adt);
|
||||||
|
}
|
||||||
|
|
||||||
|
LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
|
||||||
|
BLO_write_struct(writer, CameraBGImage, bgpic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void camera_blend_read_data(BlendDataReader *reader, ID *id)
|
||||||
|
{
|
||||||
|
Camera *ca = (Camera *)id;
|
||||||
|
BLO_read_data_address(reader, &ca->adt);
|
||||||
|
BKE_animdata_blend_read_data(reader, ca->adt);
|
||||||
|
|
||||||
|
BLO_read_list(reader, &ca->bg_images);
|
||||||
|
|
||||||
|
LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
|
||||||
|
bgpic->iuser.ok = 1;
|
||||||
|
bgpic->iuser.scene = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void camera_blend_read_lib(BlendLibReader *reader, ID *id)
|
||||||
|
{
|
||||||
|
Camera *ca = (Camera *)id;
|
||||||
|
BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */
|
||||||
|
|
||||||
|
BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */
|
||||||
|
BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object);
|
||||||
|
|
||||||
|
LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
|
||||||
|
BLO_read_id_address(reader, ca->id.lib, &bgpic->ima);
|
||||||
|
BLO_read_id_address(reader, ca->id.lib, &bgpic->clip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void camera_blend_read_expand(BlendExpander *expander, ID *id)
|
||||||
|
{
|
||||||
|
Camera *ca = (Camera *)id;
|
||||||
|
BLO_expand(expander, ca->ipo); // XXX deprecated - old animation system
|
||||||
|
|
||||||
|
LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
|
||||||
|
if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
|
||||||
|
BLO_expand(expander, bgpic->ima);
|
||||||
|
}
|
||||||
|
else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
|
||||||
|
BLO_expand(expander, bgpic->ima);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IDTypeInfo IDType_ID_CA = {
|
IDTypeInfo IDType_ID_CA = {
|
||||||
.id_code = ID_CA,
|
.id_code = ID_CA,
|
||||||
.id_filter = FILTER_ID_CA,
|
.id_filter = FILTER_ID_CA,
|
||||||
@@ -130,10 +197,10 @@ IDTypeInfo IDType_ID_CA = {
|
|||||||
.foreach_id = camera_foreach_id,
|
.foreach_id = camera_foreach_id,
|
||||||
.foreach_cache = NULL,
|
.foreach_cache = NULL,
|
||||||
|
|
||||||
.blend_write = NULL,
|
.blend_write = camera_blend_write,
|
||||||
.blend_read_data = NULL,
|
.blend_read_data = camera_blend_read_data,
|
||||||
.blend_read_lib = NULL,
|
.blend_read_lib = camera_blend_read_lib,
|
||||||
.blend_read_expand = NULL,
|
.blend_read_expand = camera_blend_read_expand,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|||||||
@@ -2844,38 +2844,6 @@ static void direct_link_armature(BlendDataReader *reader, bArmature *arm)
|
|||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/** \name Read ID: Camera
|
|
||||||
* \{ */
|
|
||||||
|
|
||||||
static void lib_link_camera(BlendLibReader *reader, Camera *ca)
|
|
||||||
{
|
|
||||||
BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */
|
|
||||||
|
|
||||||
BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */
|
|
||||||
BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object);
|
|
||||||
|
|
||||||
LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
|
|
||||||
BLO_read_id_address(reader, ca->id.lib, &bgpic->ima);
|
|
||||||
BLO_read_id_address(reader, ca->id.lib, &bgpic->clip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void direct_link_camera(BlendDataReader *reader, Camera *ca)
|
|
||||||
{
|
|
||||||
BLO_read_data_address(reader, &ca->adt);
|
|
||||||
BKE_animdata_blend_read_data(reader, ca->adt);
|
|
||||||
|
|
||||||
BLO_read_list(reader, &ca->bg_images);
|
|
||||||
|
|
||||||
LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
|
|
||||||
bgpic->iuser.ok = 1;
|
|
||||||
bgpic->iuser.scene = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/** \name Read ID: Shape Keys
|
/** \name Read ID: Shape Keys
|
||||||
* \{ */
|
* \{ */
|
||||||
@@ -6927,9 +6895,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||||||
case ID_LI:
|
case ID_LI:
|
||||||
direct_link_library(fd, (Library *)id, main);
|
direct_link_library(fd, (Library *)id, main);
|
||||||
break;
|
break;
|
||||||
case ID_CA:
|
|
||||||
direct_link_camera(&reader, (Camera *)id);
|
|
||||||
break;
|
|
||||||
case ID_SPK:
|
case ID_SPK:
|
||||||
direct_link_speaker(&reader, (Speaker *)id);
|
direct_link_speaker(&reader, (Speaker *)id);
|
||||||
break;
|
break;
|
||||||
@@ -6988,6 +6953,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
|||||||
case ID_MA:
|
case ID_MA:
|
||||||
case ID_MB:
|
case ID_MB:
|
||||||
case ID_CU:
|
case ID_CU:
|
||||||
|
case ID_CA:
|
||||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -7632,9 +7598,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||||||
case ID_SO:
|
case ID_SO:
|
||||||
lib_link_sound(&reader, (bSound *)id);
|
lib_link_sound(&reader, (bSound *)id);
|
||||||
break;
|
break;
|
||||||
case ID_CA:
|
|
||||||
lib_link_camera(&reader, (Camera *)id);
|
|
||||||
break;
|
|
||||||
case ID_CF:
|
case ID_CF:
|
||||||
lib_link_cachefiles(&reader, (CacheFile *)id);
|
lib_link_cachefiles(&reader, (CacheFile *)id);
|
||||||
break;
|
break;
|
||||||
@@ -7685,6 +7648,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
|||||||
case ID_MA:
|
case ID_MA:
|
||||||
case ID_MB:
|
case ID_MB:
|
||||||
case ID_CU:
|
case ID_CU:
|
||||||
|
case ID_CA:
|
||||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -8644,20 +8608,6 @@ static void expand_scene(BlendExpander *expander, Scene *sce)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void expand_camera(BlendExpander *expander, Camera *ca)
|
|
||||||
{
|
|
||||||
BLO_expand(expander, ca->ipo); // XXX deprecated - old animation system
|
|
||||||
|
|
||||||
LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
|
|
||||||
if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
|
|
||||||
BLO_expand(expander, bgpic->ima);
|
|
||||||
}
|
|
||||||
else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
|
|
||||||
BLO_expand(expander, bgpic->ima);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(cache_file))
|
static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(cache_file))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -8801,9 +8751,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
|
|||||||
case ID_KE:
|
case ID_KE:
|
||||||
expand_key(&expander, (Key *)id);
|
expand_key(&expander, (Key *)id);
|
||||||
break;
|
break;
|
||||||
case ID_CA:
|
|
||||||
expand_camera(&expander, (Camera *)id);
|
|
||||||
break;
|
|
||||||
case ID_SPK:
|
case ID_SPK:
|
||||||
expand_speaker(&expander, (Speaker *)id);
|
expand_speaker(&expander, (Speaker *)id);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1414,23 +1414,6 @@ static void write_key(BlendWriter *writer, Key *key, const void *id_address)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_camera(BlendWriter *writer, Camera *cam, const void *id_address)
|
|
||||||
{
|
|
||||||
if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
|
|
||||||
/* write LibData */
|
|
||||||
BLO_write_id_struct(writer, Camera, id_address, &cam->id);
|
|
||||||
BKE_id_blend_write(writer, &cam->id);
|
|
||||||
|
|
||||||
if (cam->adt) {
|
|
||||||
BKE_animdata_blend_write(writer, cam->adt);
|
|
||||||
}
|
|
||||||
|
|
||||||
LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
|
|
||||||
BLO_write_struct(writer, CameraBGImage, bgpic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
|
static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
|
||||||
{
|
{
|
||||||
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
|
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||||
@@ -2754,9 +2737,6 @@ static bool write_file_handle(Main *mainvar,
|
|||||||
case ID_SCE:
|
case ID_SCE:
|
||||||
write_scene(&writer, (Scene *)id_buffer, id);
|
write_scene(&writer, (Scene *)id_buffer, id);
|
||||||
break;
|
break;
|
||||||
case ID_CA:
|
|
||||||
write_camera(&writer, (Camera *)id_buffer, id);
|
|
||||||
break;
|
|
||||||
case ID_KE:
|
case ID_KE:
|
||||||
write_key(&writer, (Key *)id_buffer, id);
|
write_key(&writer, (Key *)id_buffer, id);
|
||||||
break;
|
break;
|
||||||
@@ -2821,6 +2801,7 @@ static bool write_file_handle(Main *mainvar,
|
|||||||
case ID_MA:
|
case ID_MA:
|
||||||
case ID_MB:
|
case ID_MB:
|
||||||
case ID_CU:
|
case ID_CU:
|
||||||
|
case ID_CA:
|
||||||
/* Do nothing, handled in IDTypeInfo callback. */
|
/* Do nothing, handled in IDTypeInfo callback. */
|
||||||
break;
|
break;
|
||||||
case ID_LI:
|
case ID_LI:
|
||||||
|
|||||||
Reference in New Issue
Block a user