Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_clip/tracking_ops.c')
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c154
1 files changed, 150 insertions, 4 deletions
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index ca224b04da5..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"
@@ -1267,7 +1271,8 @@ static int frame_jump_exec(bContext *C, wmOperator *op)
}
delta = pos == 1 ? 1 : -1;
- while (sc->user.framenr + delta >= SFRA && sc->user.framenr + delta <= EFRA) {
+ while (sc->user.framenr + delta >= scene->r.sfra &&
+ sc->user.framenr + delta <= scene->r.efra) {
int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr + delta);
MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, framenr);
@@ -1286,7 +1291,7 @@ static int frame_jump_exec(bContext *C, wmOperator *op)
delta = pos == 3 ? 1 : -1;
framenr += delta;
- while (framenr + delta >= SFRA && framenr + delta <= EFRA) {
+ while (framenr + delta >= scene->r.sfra && framenr + delta <= scene->r.efra) {
MovieReconstructedCamera *cam = BKE_tracking_camera_get_reconstructed(
tracking, object, framenr);
@@ -1300,8 +1305,8 @@ static int frame_jump_exec(bContext *C, wmOperator *op)
}
}
- if (CFRA != sc->user.framenr) {
- CFRA = sc->user.framenr;
+ if (scene->r.cfra != sc->user.framenr) {
+ scene->r.cfra = sc->user.framenr;
DEG_id_tag_update(&scene->id, ID_RECALC_FRAME_CHANGE);
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
@@ -2212,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;
+}
+
+/** \} */