diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-06-28 17:03:35 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-07-01 10:44:07 +0300 |
commit | e4bf58e2852856e5c9d81ce04e6e9bb967795054 (patch) | |
tree | 933372cbcfa63a97a2e336b17d10cbbdf6a7658a /source/blender/editors/space_clip | |
parent | 72b9e07cf26ddeb26ea8773004b951a7f1bff7c5 (diff) |
Tracking: Image from Plane Marker operators
There are two operators added, which are available via a special
content menu next to the plane track image selector:
- New Image from Plane Marker
- Update Image from Plane Marker
The former one creates an image from pixels which the active plane
track marker "sees" at the current frame and sets it as the plane
track's image.
The latter one instead of creating the new image data-block updates
the image in-place.
This allows to create unwarped texture from a billboard from footage.
The intent is to allow this image to be touched up and re-projected
back to the footage with an updated content.
Available from a plane track image context menu, as well as from the
Track menu.
{F13243219}
The demo of the feature from Sebastian Koenig: https://www.youtube.com/watch?v=PDphO-w2SsA
Differential Revision: https://developer.blender.org/D15312
Diffstat (limited to 'source/blender/editors/space_clip')
-rw-r--r-- | source/blender/editors/space_clip/clip_intern.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_clip/space_clip.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops.c | 145 |
3 files changed, 151 insertions, 0 deletions
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 7f9cf61b748..2efd6b6b473 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -251,6 +251,9 @@ void CLIP_OT_slide_plane_marker(struct wmOperatorType *ot); void CLIP_OT_keyframe_insert(struct wmOperatorType *ot); void CLIP_OT_keyframe_delete(struct wmOperatorType *ot); +void CLIP_OT_new_image_from_plane_marker(struct wmOperatorType *ot); +void CLIP_OT_update_image_from_plane_marker(struct wmOperatorType *ot); + /* tracking_select.c */ void CLIP_OT_select(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index a73883e7624..ce6409a7784 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -515,6 +515,9 @@ static void clip_operatortypes(void) WM_operatortype_append(CLIP_OT_keyframe_insert); WM_operatortype_append(CLIP_OT_keyframe_delete); + WM_operatortype_append(CLIP_OT_new_image_from_plane_marker); + WM_operatortype_append(CLIP_OT_update_image_from_plane_marker); + /* ** clip_graph_ops.c ** */ /* graph editing */ diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 7f113108b02..cba4157d044 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -16,6 +16,7 @@ #include "BLI_utildefines.h" #include "BKE_context.h" +#include "BKE_image.h" #include "BKE_movieclip.h" #include "BKE_report.h" #include "BKE_tracking.h" @@ -33,6 +34,9 @@ #include "BLT_translation.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + #include "clip_intern.h" #include "tracking_ops_intern.h" @@ -2213,3 +2217,144 @@ void CLIP_OT_keyframe_delete(wmOperatorType *ot) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Image from plane track marker + * \{ */ + +static ImBuf *sample_plane_marker_image_for_operator(bContext *C) +{ + SpaceClip *space_clip = CTX_wm_space_clip(C); + const int clip_frame_number = ED_space_clip_get_clip_frame_number(space_clip); + + MovieClip *clip = ED_space_clip_get_clip(space_clip); + + MovieTracking *tracking = &clip->tracking; + MovieTrackingPlaneTrack *plane_track = tracking->act_plane_track; + const MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, + clip_frame_number); + + ImBuf *frame_ibuf = ED_space_clip_get_buffer(space_clip); + if (frame_ibuf == NULL) { + return NULL; + } + + ImBuf *plane_ibuf = BKE_tracking_get_plane_imbuf(frame_ibuf, plane_marker); + + IMB_freeImBuf(frame_ibuf); + + return plane_ibuf; +} + +static bool new_image_from_plane_marker_poll(bContext *C) +{ + if (!ED_space_clip_tracking_poll(C)) { + return false; + } + + SpaceClip *space_clip = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(space_clip); + const MovieTracking *tracking = &clip->tracking; + + if (tracking->act_plane_track == NULL) { + return false; + } + + return true; +} + +static int new_image_from_plane_marker_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *space_clip = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(space_clip); + MovieTracking *tracking = &clip->tracking; + MovieTrackingPlaneTrack *plane_track = tracking->act_plane_track; + + ImBuf *plane_ibuf = sample_plane_marker_image_for_operator(C); + if (plane_ibuf == NULL) { + return OPERATOR_CANCELLED; + } + + plane_track->image = BKE_image_add_from_imbuf(CTX_data_main(C), plane_ibuf, plane_track->name); + + IMB_freeImBuf(plane_ibuf); + + WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); + + return OPERATOR_FINISHED; +} + +void CLIP_OT_new_image_from_plane_marker(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "New Image from Plane Marker"; + ot->description = "Create new image from the content of the plane marker"; + ot->idname = "CLIP_OT_new_image_from_plane_marker"; + + /* api callbacks */ + ot->poll = new_image_from_plane_marker_poll; + ot->exec = new_image_from_plane_marker_exec; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +static bool update_image_from_plane_marker_poll(bContext *C) +{ + if (!ED_space_clip_tracking_poll(C)) { + return false; + } + + SpaceClip *space_clip = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(space_clip); + const MovieTracking *tracking = &clip->tracking; + + if (tracking->act_plane_track == NULL || tracking->act_plane_track->image == NULL) { + return false; + } + + const Image *image = tracking->act_plane_track->image; + return image->type == IMA_TYPE_IMAGE && ELEM(image->source, IMA_SRC_FILE, IMA_SRC_GENERATED); +} + +static int update_image_from_plane_marker_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *space_clip = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(space_clip); + MovieTracking *tracking = &clip->tracking; + MovieTrackingPlaneTrack *plane_track = tracking->act_plane_track; + + ImBuf *plane_ibuf = sample_plane_marker_image_for_operator(C); + if (plane_ibuf == NULL) { + return OPERATOR_CANCELLED; + } + + BKE_image_replace_imbuf(plane_track->image, plane_ibuf); + + IMB_freeImBuf(plane_ibuf); + + WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); + WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, plane_track->image); + + BKE_image_partial_update_mark_full_update(plane_track->image); + + return OPERATOR_FINISHED; +} + +void CLIP_OT_update_image_from_plane_marker(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Update Image from Plane Marker"; + ot->description = + "Update current image used by plane marker from the content of the plane marker"; + ot->idname = "CLIP_OT_update_image_from_plane_marker"; + + /* api callbacks */ + ot->poll = update_image_from_plane_marker_poll; + ot->exec = update_image_from_plane_marker_exec; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/** \} */ |