[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41437] branches/soc-2011-tomato/source/ blender: Camera tracking integration

Sergey Sharybin g.ulairi at gmail.com
Tue Nov 1 10:52:09 CET 2011


Revision: 41437
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41437
Author:   nazgul
Date:     2011-11-01 09:52:08 +0000 (Tue, 01 Nov 2011)
Log Message:
-----------
Camera tracking integration
===========================

Automated image sequence offset calculation for image input node and image editor.

Calculate offset or sequence when loading image in node or editor and also
re-calculate offset when switching currently displaying image in editor or
source image in input node. This kind of recalculation is needed because offset
is stored in ImageUser structure so when you're switching from one sequence to
another it can be really confusing because offset from previous sequence would
be used for new sequence.

NOTE: Not sure this commit is fine to be included in tomato merge commit,
      prefer to test it further and commit as separate change after merge.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h	2011-11-01 09:48:20 UTC (rev 41436)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_image.h	2011-11-01 09:52:08 UTC (rev 41437)
@@ -169,6 +169,9 @@
 /* check if texture has alpha (depth=32) */
 int BKE_image_has_alpha(struct Image *image);
 
+int BKE_image_sequence_first_num(const char *full_name);
+void BKE_image_guess_offset(struct Scene *scene, struct Image *ima, struct ImageUser *iuser);
+
 /* image_gen.c */
 void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4]);
 void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2011-11-01 09:48:20 UTC (rev 41436)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/image.c	2011-11-01 09:52:08 UTC (rev 41437)
@@ -2295,3 +2295,29 @@
 		return 0;
 }
 
+int BKE_image_sequence_first_num(const char *full_name)
+{
+	unsigned short numlen;
+	char head[FILE_MAX], tail[FILE_MAX], name[FILE_MAX];
+	int offset;
+	char num[FILE_MAX]= {0};
+
+	BLI_strncpy(name, full_name, sizeof(name));
+	BLI_stringdec(name, head, tail, &numlen);
+
+	BLI_strncpy(num, full_name+strlen(head), numlen+1);
+
+	return atoi(num);
+}
+
+void BKE_image_guess_offset(Scene *scene, Image *ima, ImageUser *iuser)
+{
+	int cfra= iuser->framenr-iuser->offset+iuser->sfra;
+
+	iuser->offset= BKE_image_sequence_first_num(ima->name)-1;
+
+	if(scene)
+		cfra= scene->r.cfra;
+
+	BKE_image_user_calc_frame(iuser, cfra, 0);
+}

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-11-01 09:48:20 UTC (rev 41436)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-11-01 09:52:08 UTC (rev 41437)
@@ -154,7 +154,7 @@
 
 	/* movieclips always points to first image from sequence,
 	   autoguess offset for now. could be something smarter in the future */
-	offset= sequence_guess_offset(clip->name, strlen(head), numlen);
+	offset= BKE_image_sequence_first_num(clip->name);
 
 	if(numlen) BLI_stringenc(name, head, tail, numlen, offset+framenr-1);
 	else strncpy(name, clip->name, sizeof(name));

Modified: branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c	2011-11-01 09:48:20 UTC (rev 41436)
+++ branches/soc-2011-tomato/source/blender/editors/space_image/image_ops.c	2011-11-01 09:52:08 UTC (rev 41437)
@@ -808,8 +808,9 @@
 	/* initialize because of new image */
 	if(iuser) {
 		iuser->sfra= 1;
-		iuser->offset= 0;
 		iuser->fie_ima= 2;
+
+		BKE_image_guess_offset(NULL, ima, iuser);
 	}
 
 	/* XXX unpackImage frees image buffers */

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c	2011-11-01 09:48:20 UTC (rev 41436)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c	2011-11-01 09:52:08 UTC (rev 41437)
@@ -463,6 +463,17 @@
 	return item;
 }
 
+static void rna_Node_image_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	bNode *node= (bNode*)ptr->data;
+	Image *ima= (Image *)node->id;
+	ImageUser *iuser= node->storage;
+
+	BKE_image_guess_offset(scene, ima, iuser);
+
+	rna_Node_update(bmain, scene, ptr);
+}
+
 static EnumPropertyItem *rna_Node_image_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
 {
 	bNode *node= (bNode*)ptr->data;
@@ -1394,7 +1405,7 @@
 	RNA_def_property_struct_type(prop, "Image");
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Image", "");
-	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_image_update");
 	
 	RNA_def_struct_sdna_from(srna, "ImageUser", "storage");
 	

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c	2011-11-01 09:48:20 UTC (rev 41436)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c	2011-11-01 09:52:08 UTC (rev 41437)
@@ -120,6 +120,7 @@
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
+#include "BKE_image.h"
 #include "BKE_paint.h"
 
 #include "ED_image.h"
@@ -473,8 +474,11 @@
 {
 	SpaceImage *sima= (SpaceImage*)(ptr->data);
 	bScreen *sc= (bScreen*)ptr->id.data;
+	Scene *scene= sc->scene;
+	Image *ima= (Image*)value.data;
 
-	ED_space_image_set(NULL, sima, sc->scene, sc->scene->obedit, (Image*)value.data);
+	ED_space_image_set(NULL, sima, scene, scene->obedit, ima);
+	BKE_image_guess_offset(scene, ima, &sima->iuser);
 }
 
 static EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *UNUSED(C), PointerRNA *ptr,




More information about the Bf-blender-cvs mailing list