diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 15:53:11 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 15:53:29 +0300 |
commit | eecd3705d7cb5545433c25b00d15d4e545664bc8 (patch) | |
tree | c560384e7410e6ede277dcda4f04d22b0f1c20dd /source/blender | |
parent | 0f0e7239f02720a4077ee10dea0e3de6e605417d (diff) |
Refactor: move MovieClip .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 185 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 118 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 77 |
3 files changed, 185 insertions, 195 deletions
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index b70b1ff036b..3ea0f800178 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -35,6 +35,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_constraint_types.h" #include "DNA_gpencil_types.h" #include "DNA_movieclip_types.h" @@ -54,6 +57,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_idtype.h" @@ -74,6 +78,8 @@ #include "GPU_texture.h" +#include "BLO_read_write.h" + #ifdef WITH_OPENEXR # include "intern/openexr/openexr_multi.h" #endif @@ -146,6 +152,179 @@ static void movie_clip_foreach_cache(ID *id, function_callback(id, &key, (void **)&movie_clip->tracking.camera.intrinsics, 0, user_data); } +static void write_movieTracks(BlendWriter *writer, ListBase *tracks) +{ + MovieTrackingTrack *track; + + track = tracks->first; + while (track) { + BLO_write_struct(writer, MovieTrackingTrack, track); + + if (track->markers) { + BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers); + } + + track = track->next; + } +} + +static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) +{ + MovieTrackingPlaneTrack *plane_track; + + for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); + + BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); + BLO_write_struct_array( + writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); + } +} + +static void write_movieReconstruction(BlendWriter *writer, + MovieTrackingReconstruction *reconstruction) +{ + if (reconstruction->camnr) { + BLO_write_struct_array( + writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); + } +} + +static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + MovieClip *clip = (MovieClip *)id; + if (clip->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + clip->anim = NULL; + clip->tracking_context = NULL; + clip->tracking.stats = NULL; + + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *object; + + BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); + BKE_id_blend_write(writer, &clip->id); + + if (clip->adt) { + BKE_animdata_blend_write(writer, clip->adt); + } + + write_movieTracks(writer, &tracking->tracks); + write_moviePlaneTracks(writer, &tracking->plane_tracks); + write_movieReconstruction(writer, &tracking->reconstruction); + + object = tracking->objects.first; + while (object) { + BLO_write_struct(writer, MovieTrackingObject, object); + + write_movieTracks(writer, &object->tracks); + write_moviePlaneTracks(writer, &object->plane_tracks); + write_movieReconstruction(writer, &object->reconstruction); + + object = object->next; + } + } +} + +static void direct_link_movieReconstruction(BlendDataReader *reader, + MovieTrackingReconstruction *reconstruction) +{ + BLO_read_data_address(reader, &reconstruction->cameras); +} + +static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) +{ + BLO_read_list(reader, tracksbase); + + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + BLO_read_data_address(reader, &track->markers); + } +} + +static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) +{ + BLO_read_list(reader, plane_tracks_base); + + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { + BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); + for (int i = 0; i < plane_track->point_tracksnr; i++) { + BLO_read_data_address(reader, &plane_track->point_tracks[i]); + } + + BLO_read_data_address(reader, &plane_track->markers); + } +} + +static void movieclip_blend_read_data(BlendDataReader *reader, ID *id) +{ + MovieClip *clip = (MovieClip *)id; + MovieTracking *tracking = &clip->tracking; + + BLO_read_data_address(reader, &clip->adt); + + direct_link_movieTracks(reader, &tracking->tracks); + direct_link_moviePlaneTracks(reader, &tracking->plane_tracks); + direct_link_movieReconstruction(reader, &tracking->reconstruction); + + BLO_read_data_address(reader, &clip->tracking.act_track); + BLO_read_data_address(reader, &clip->tracking.act_plane_track); + + clip->anim = NULL; + clip->tracking_context = NULL; + clip->tracking.stats = NULL; + + /* TODO we could store those in undo cache storage as well, and preserve them instead of + * re-creating them... */ + BLI_listbase_clear(&clip->runtime.gputextures); + + /* Needed for proper versioning, will be NULL for all newer files anyway. */ + BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track); + + clip->tracking.dopesheet.ok = 0; + BLI_listbase_clear(&clip->tracking.dopesheet.channels); + BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments); + + BLO_read_list(reader, &tracking->objects); + + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + direct_link_movieTracks(reader, &object->tracks); + direct_link_moviePlaneTracks(reader, &object->plane_tracks); + direct_link_movieReconstruction(reader, &object->reconstruction); + } +} + +static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) +{ + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + BLO_read_id_address(reader, clip->id.lib, &track->gpd); + } +} + +static void lib_link_moviePlaneTracks(BlendLibReader *reader, + MovieClip *clip, + ListBase *tracksbase) +{ + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { + BLO_read_id_address(reader, clip->id.lib, &plane_track->image); + } +} + +static void movieclip_blend_read_lib(BlendLibReader *reader, ID *id) +{ + MovieClip *clip = (MovieClip *)id; + MovieTracking *tracking = &clip->tracking; + + BLO_read_id_address(reader, clip->id.lib, &clip->gpd); + + lib_link_movieTracks(reader, clip, &tracking->tracks); + lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks); + + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + lib_link_movieTracks(reader, clip, &object->tracks); + lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks); + } +} + IDTypeInfo IDType_ID_MC = { .id_code = ID_MC, .id_filter = FILTER_ID_MC, @@ -163,9 +342,9 @@ IDTypeInfo IDType_ID_MC = { .foreach_id = movie_clip_foreach_id, .foreach_cache = movie_clip_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, + .blend_write = movieclip_blend_write, + .blend_read_data = movieclip_blend_read_data, + .blend_read_lib = movieclip_blend_read_lib, .blend_read_expand = NULL, }; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4f1cb4e0ecc..1c638079230 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6921,109 +6921,6 @@ static void lib_link_sound(BlendLibReader *reader, bSound *sound) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Movie Clip - * \{ */ - -static void direct_link_movieReconstruction(BlendDataReader *reader, - MovieTrackingReconstruction *reconstruction) -{ - BLO_read_data_address(reader, &reconstruction->cameras); -} - -static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) -{ - BLO_read_list(reader, tracksbase); - - LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { - BLO_read_data_address(reader, &track->markers); - } -} - -static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) -{ - BLO_read_list(reader, plane_tracks_base); - - LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { - BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); - for (int i = 0; i < plane_track->point_tracksnr; i++) { - BLO_read_data_address(reader, &plane_track->point_tracks[i]); - } - - BLO_read_data_address(reader, &plane_track->markers); - } -} - -static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip) -{ - MovieTracking *tracking = &clip->tracking; - - BLO_read_data_address(reader, &clip->adt); - - direct_link_movieTracks(reader, &tracking->tracks); - direct_link_moviePlaneTracks(reader, &tracking->plane_tracks); - direct_link_movieReconstruction(reader, &tracking->reconstruction); - - BLO_read_data_address(reader, &clip->tracking.act_track); - BLO_read_data_address(reader, &clip->tracking.act_plane_track); - - clip->anim = NULL; - clip->tracking_context = NULL; - clip->tracking.stats = NULL; - - /* TODO we could store those in undo cache storage as well, and preserve them instead of - * re-creating them... */ - BLI_listbase_clear(&clip->runtime.gputextures); - - /* Needed for proper versioning, will be NULL for all newer files anyway. */ - BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track); - - clip->tracking.dopesheet.ok = 0; - BLI_listbase_clear(&clip->tracking.dopesheet.channels); - BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments); - - BLO_read_list(reader, &tracking->objects); - - LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { - direct_link_movieTracks(reader, &object->tracks); - direct_link_moviePlaneTracks(reader, &object->plane_tracks); - direct_link_movieReconstruction(reader, &object->reconstruction); - } -} - -static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) -{ - LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { - BLO_read_id_address(reader, clip->id.lib, &track->gpd); - } -} - -static void lib_link_moviePlaneTracks(BlendLibReader *reader, - MovieClip *clip, - ListBase *tracksbase) -{ - LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { - BLO_read_id_address(reader, clip->id.lib, &plane_track->image); - } -} - -static void lib_link_movieclip(BlendLibReader *reader, MovieClip *clip) -{ - MovieTracking *tracking = &clip->tracking; - - BLO_read_id_address(reader, clip->id.lib, &clip->gpd); - - lib_link_movieTracks(reader, clip, &tracking->tracks); - lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks); - - LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { - lib_link_movieTracks(reader, clip, &object->tracks); - lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks); - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: Masks * \{ */ @@ -7435,9 +7332,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_GD: direct_link_gpencil(&reader, (bGPdata *)id); break; - case ID_MC: - direct_link_movieclip(&reader, (MovieClip *)id); - break; case ID_MSK: direct_link_mask(&reader, (Mask *)id); break; @@ -7472,6 +7366,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_LS: case ID_TXT: case ID_VF: + case ID_MC: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8098,9 +7993,6 @@ static void lib_link_all(FileData *fd, Main *bmain) * 3D viewport may contains pointers to other ID data (like bgpic)! See T41411. */ lib_link_screen(&reader, (bScreen *)id); break; - case ID_MC: - lib_link_movieclip(&reader, (MovieClip *)id); - break; case ID_WO: lib_link_world(&reader, (World *)id); break; @@ -8187,6 +8079,7 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_LS: case ID_TXT: case ID_VF: + case ID_MC: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -9229,10 +9122,6 @@ static void expand_lightprobe(BlendExpander *UNUSED(expander), LightProbe *UNUSE { } -static void expand_movieclip(BlendExpander *UNUSED(expander), MovieClip *UNUSED(clip)) -{ -} - static void expand_mask_parent(BlendExpander *expander, MaskParent *parent) { if (parent->id) { @@ -9397,9 +9286,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_PA: expand_particlesettings(&expander, (ParticleSettings *)id); break; - case ID_MC: - expand_movieclip(&expander, (MovieClip *)id); - break; case ID_MSK: expand_mask(&expander, (Mask *)id); break; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 6ede8711138..82cf8887396 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2506,79 +2506,6 @@ static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id } } -static void write_movieTracks(BlendWriter *writer, ListBase *tracks) -{ - MovieTrackingTrack *track; - - track = tracks->first; - while (track) { - BLO_write_struct(writer, MovieTrackingTrack, track); - - if (track->markers) { - BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers); - } - - track = track->next; - } -} - -static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) -{ - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { - BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); - - BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); - BLO_write_struct_array( - writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); - } -} - -static void write_movieReconstruction(BlendWriter *writer, - MovieTrackingReconstruction *reconstruction) -{ - if (reconstruction->camnr) { - BLO_write_struct_array( - writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); - } -} - -static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id_address) -{ - if (clip->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - clip->anim = NULL; - clip->tracking_context = NULL; - clip->tracking.stats = NULL; - - MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *object; - - BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); - BKE_id_blend_write(writer, &clip->id); - - if (clip->adt) { - BKE_animdata_blend_write(writer, clip->adt); - } - - write_movieTracks(writer, &tracking->tracks); - write_moviePlaneTracks(writer, &tracking->plane_tracks); - write_movieReconstruction(writer, &tracking->reconstruction); - - object = tracking->objects.first; - while (object) { - BLO_write_struct(writer, MovieTrackingObject, object); - - write_movieTracks(writer, &object->tracks); - write_moviePlaneTracks(writer, &object->plane_tracks); - write_movieReconstruction(writer, &object->reconstruction); - - object = object->next; - } - } -} - static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) { if (mask->id.us > 0 || BLO_write_is_undo(writer)) { @@ -3056,9 +2983,6 @@ static bool write_file_handle(Main *mainvar, case ID_SCR: write_screen(&writer, (bScreen *)id_buffer, id); break; - case ID_MC: - write_movieclip(&writer, (MovieClip *)id_buffer, id); - break; case ID_MSK: write_mask(&writer, (Mask *)id_buffer, id); break; @@ -3147,6 +3071,7 @@ static bool write_file_handle(Main *mainvar, case ID_LS: case ID_TXT: case ID_VF: + case ID_MC: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: |