[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46761] branches/soc-2011-tomato: Rotation support for motion tracking markers

Sergey Sharybin sergey.vfx at gmail.com
Fri May 18 11:33:50 CEST 2012


Revision: 46761
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46761
Author:   nazgul
Date:     2012-05-18 09:33:50 +0000 (Fri, 18 May 2012)
Log Message:
-----------
Rotation support for motion tracking markers

Implemented general transformation tool Rotation for motion tracking data.
Mainly used to rotate pattern of markers.

To achieve most of usability, added configurable pivot point which is in fact
was median point before, but now can be chosen from boundbox center, median point
or individual centers. Individual centers means transformation would be performed
around marker's position, which is useful for rotation and scale.

Also implemented alternative scaling transformation -- hit S, S leads to
scaling of pattern area only.

TODO:
- clamping in some cases isn't working well, but that's easier to be resolved
  after moving search are to marker.
- Update startup.blend so clip editor in Motion Tracking screen would be set to
  Individual Centers by default.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/include/ED_clip.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform_generics.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-05-18 09:33:50 UTC (rev 46761)
@@ -54,7 +54,8 @@
         if clip:
             if sc.view == 'CLIP':
                 layout.prop(sc, "mode", text="")
-            if sc.view == 'GRAPH':
+                layout.prop(sc, "pivot_point", text="", icon_only=True)
+            elif sc.view == 'GRAPH':
                 row = layout.row(align=True)
 
                 if sc.show_filters:

Modified: branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c	2012-05-18 09:33:50 UTC (rev 46761)
@@ -7612,6 +7612,7 @@
 
 	{
 		MovieClip *clip;
+		bScreen *sc;
 
 		for (clip = main->movieclip.first; clip; clip = clip->id.next) {
 			MovieTrackingTrack *track;
@@ -7643,6 +7644,24 @@
 				track = track->next;
 			}
 		}
+
+		for (sc = main->screen.first; sc; sc = sc->id.next) {
+			ScrArea *sa;
+
+			for (sa = sc->areabase.first; sa; sa = sa->next) {
+				SpaceLink *sl;
+
+				for (sl = sa->spacedata.first; sl; sl = sl->next) {
+					if (sl->spacetype == SPACE_CLIP) {
+						SpaceClip *sclip = (SpaceClip *)sl;
+
+						if (sclip->around == 0) {
+							sclip->around = V3D_CENTROID;
+						}
+					}
+				}
+			}
+		}
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: branches/soc-2011-tomato/source/blender/editors/include/ED_clip.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/include/ED_clip.h	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/source/blender/editors/include/ED_clip.h	2012-05-18 09:33:50 UTC (rev 46761)
@@ -58,6 +58,7 @@
 void ED_space_clip_size(struct SpaceClip *sc, int *width, int *height);
 void ED_space_clip_zoom(struct SpaceClip *sc, ARegion *ar, float *zoomx, float *zoomy);
 void ED_space_clip_aspect(struct SpaceClip *sc, float *aspx, float *aspy);
+void ED_space_clip_aspect_dimension_aware(struct SpaceClip *sc, float *aspx, float *aspy);
 
 void ED_space_clip_mask_size(struct SpaceClip *sc, int *width, int *height);
 void ED_space_clip_mask_aspect(struct SpaceClip *sc, float *aspx, float *aspy);

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c	2012-05-18 09:33:50 UTC (rev 46761)
@@ -249,9 +249,15 @@
 
 void ED_space_clip_mask_size(SpaceClip *sc, int *width, int *height)
 {
-	if(!sc->mask) {
-		*width= 0;
-		*height= 0;
+	/* quite the same as ED_space_clip_size, but it also runs aspect correction on output resolution
+	 * this is needed because mask should be rasterized with exactly the same resolution as
+	 * currently displaying frame and it doesn't have access to aspect correction currently
+	 * used for display. (sergey)
+	 */
+
+	if (!sc->mask) {
+		*width = 0;
+		*height = 0;
 	} else {
 		float aspx, aspy;
 
@@ -306,6 +312,33 @@
 		*aspx = *aspy = 1.0f;
 }
 
+void ED_space_clip_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *aspy)
+{
+	int w, h;
+
+	/* most of tools does not require aspect to be returned with dimensions correction
+	 * due to they're invariant to this stuff, but some transformation tools like rotation
+	 * should be aware of aspect correction caused by different resolution in different
+	 * directions.
+	 * mainly this is sued for transformation stuff
+	 */
+
+	ED_space_clip_aspect(sc, aspx, aspy);
+	ED_space_clip_size(sc, &w, &h);
+
+	*aspx *= (float)w;
+	*aspy *= (float)h;
+
+	if(*aspx < *aspy) {
+		*aspy= *aspy / *aspx;
+		*aspx= 1.0f;
+	}
+	else {
+		*aspx= *aspx / *aspy;
+		*aspy= 1.0f;
+	}
+}
+
 void ED_clip_update_frame(const Main *mainp, int cfra)
 {
 	wmWindowManager *wm;

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c	2012-05-18 09:33:50 UTC (rev 46761)
@@ -35,6 +35,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_mask_types.h"
 #include "DNA_movieclip_types.h"
+#include "DNA_view3d_types.h"	/* for pivot point */
 
 #include "MEM_guardedalloc.h"
 
@@ -239,6 +240,7 @@
 	sc->zoom = 1.0f;
 	sc->path_length = 20;
 	sc->scopes.track_preview_height = 120;
+	sc->around = V3D_LOCAL;
 
 	/* header */
 	ar = MEM_callocN(sizeof(ARegion), "header for clip");

Modified: branches/soc-2011-tomato/source/blender/editors/transform/transform.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/transform/transform.c	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/source/blender/editors/transform/transform.c	2012-05-18 09:33:50 UTC (rev 46761)
@@ -244,22 +244,18 @@
 	}
 	else if (t->spacetype==SPACE_CLIP) {
 		float v[2];
+		float aspx = 1.0f, aspy = 1.0f;
 
 		copy_v2_v2(v, vec);
 
-		if (t->options & CTX_MOVIECLIP) {
-			float aspx, aspy;
-			ED_space_clip_aspect(t->sa->spacedata.first, &aspx, &aspy);
-			v[0] /= aspx;
-			v[1] /= aspy;
-		}
-		else if (t->options & CTX_MASK) {
-			float aspx, aspy;
+		if (t->options & CTX_MOVIECLIP)
+			ED_space_clip_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);
+		else if (t->options & CTX_MASK)
 			ED_space_clip_mask_aspect(t->sa->spacedata.first, &aspx, &aspy);
-			v[0] /= aspx;
-			v[1] /= aspy;
-		}
 
+		v[0] /= aspx;
+		v[1] /= aspy;
+
 		UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
 	}
 }
@@ -316,12 +312,10 @@
 
 
 			if (t->options & CTX_MOVIECLIP) {
-				int width, height;
-				ED_space_clip_size(sc, &width, &height);
-				ED_space_clip_aspect(sc, &aspx, &aspy);
+				ED_space_clip_aspect_dimension_aware(sc, &aspx, &aspy);
 
-				vec[0] *= width / aspx;
-				vec[1] *= height / aspy;
+				vec[0] /= aspx;
+				vec[1] /= aspy;
 			}
 			else if (t->options & CTX_MASK) {
 				ED_space_clip_mask_aspect(sc, &aspx, &aspy);
@@ -357,12 +351,10 @@
 			float aspx, aspy;
 
 			if (t->options & CTX_MOVIECLIP) {
-				int width, height;
-				ED_space_clip_size(sc, &width, &height);
-				ED_space_clip_aspect(sc, &aspx, &aspy);
+				ED_space_clip_aspect_dimension_aware(sc, &aspx, &aspy);
 
-				vec[0] *= aspx / width;
-				vec[1] *= aspy / height;
+				vec[0] *= aspx;
+				vec[1] *= aspy;
 			}
 			else if (t->options & CTX_MASK) {
 				ED_space_clip_aspect(sc, &aspx, &aspy);
@@ -711,7 +703,7 @@
 					t->redraw |= TREDRAW_HARD;
 				}
 				else if (t->mode == TFM_TRANSLATION) {
-					if(t->options & (CTX_MOVIECLIP | CTX_MASK)) {
+					if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
 						restoreTransObjects(t);
 
 						t->flag ^= T_ALT_TRANSFORM;
@@ -721,7 +713,7 @@
 				break;
 			case TFM_MODAL_ROTATE:
 				/* only switch when... */
-				if (!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
+				if (!(t->options & CTX_TEXTURE) && !(t->options & (CTX_MOVIECLIP | CTX_MASK))) {
 					if ( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
 						
 						resetTransRestrictions(t);
@@ -748,6 +740,14 @@
 					initSnapping(t, NULL); // need to reinit after mode change
 					t->redraw |= TREDRAW_HARD;
 				}
+				else if (t->mode == TFM_RESIZE) {
+					if (t->options & CTX_MOVIECLIP) {
+						restoreTransObjects(t);
+
+						t->flag ^= T_ALT_TRANSFORM;
+						t->redraw |= TREDRAW_HARD;
+					}
+				}
 				break;
 				
 			case TFM_MODAL_SNAP_INV_ON:
@@ -976,7 +976,7 @@
 			break;
 		case RKEY:
 			/* only switch when... */
-			if (!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
+			if (!(t->options & CTX_TEXTURE)) {
 				if ( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
 
 					resetTransRestrictions(t);
@@ -2737,6 +2737,9 @@
 	{
 		copy_v3_v3(center, td->center);
 	}
+	else if (t->options & CTX_MOVIECLIP) {
+		copy_v3_v3(center, td->center);
+	}
 	else {
 		copy_v3_v3(center, t->center);
 	}
@@ -3020,6 +3023,10 @@
 		{
 			center = td->center;
 		}
+
+		if (t->options & CTX_MOVIECLIP) {
+			center = td->center;
+		}
 	}
 
 	if (t->flag & T_POINTS) {

Modified: branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c	2012-05-18 09:26:55 UTC (rev 46760)
+++ branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c	2012-05-18 09:33:50 UTC (rev 46761)
@@ -5388,23 +5388,24 @@
 	short coord;
 } TransDataTracking;
 
-static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt, MovieTrackingTrack *track,
-                                  int area, float *loc, float *rel, float *off)
+static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
+                                  MovieTrackingTrack *track, MovieTrackingMarker *marker,
+                                  int area, float *loc, float *rel, float *off, float aspx, float aspy)
 {
 	int anchor = area == TRACK_AREA_POINT && off;
 
 	tdt->mode = transDataTracking_ModeTracks;
 
 	if (anchor) {
-		td2d->loc[0] = rel[0]; /* hold original location */
-		td2d->loc[1] = rel[1];
+		td2d->loc[0] = rel[0] * aspx; /* hold original location */
+		td2d->loc[1] = rel[1] * aspy;
 
 		tdt->loc= loc;
 		td2d->loc2d = loc; /* current location */
 	}
 	else {
-		td2d->loc[0] = loc[0]; /* hold original location */
-		td2d->loc[1] = loc[1];
+		td2d->loc[0] = loc[0] * aspx; /* hold original location */
+		td2d->loc[1] = loc[1] * aspy;
 
 		td2d->loc2d = loc; /* current location */
 	}
@@ -5418,8 +5419,8 @@
 
 	if (rel) {
 		if (!anchor) {
-			td2d->loc[0] += rel[0];
-			td2d->loc[1] += rel[1];

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list