[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41807] trunk/blender/source/blender: Moving all node angle-type values to radians.

Bastien Montagne montagne29 at wanadoo.fr
Sun Nov 13 19:03:27 CET 2011


Revision: 41807
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41807
Author:   mont29
Date:     2011-11-13 18:03:27 +0000 (Sun, 13 Nov 2011)
Log Message:
-----------
Moving all node angle-type values to radians. This also fixes [#29151] rotate node wrong input (mixing up radians and degrees).

Warning!

Angles in nodes have just been moved to consistant Radians values (ANGLE subtype of RNA Float property). You will still see them as degrees in the GUI, though, unless you chose otherwise in Scene properties, Units panel.

Conversion from degrees to radians for old files is obviously done at loading time, but if you use a mixed pipeline of trunk and releases, be carefull!

Loading a 2.60.4 file (or higher) into any previous version of Blender, your angles in nodes will have odd values (well, radians interpreted as degrees)!

And if you save such file in a pre-2.60.4 version, the angle node values will be converted again when loaded in Blender 2.60.4 or higher...

This affects following nodes:
* Compo: Rotate, Defocus, ChromaMatte, Glare and DirectionalBlur
* Shader: Mapping
And all future code using the TexMapping struct?\226?\128?\153s rotation part (its rot memember is now in radians).

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/intern/texture.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesdna/DNA_texture_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_texture.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_chromaMatte.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_defocus.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_directionalblur.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_glare.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_rotate.c

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2011-11-13 17:45:42 UTC (rev 41806)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2011-11-13 18:03:27 UTC (rev 41807)
@@ -42,7 +42,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION			260
-#define BLENDER_SUBVERSION		3
+#define BLENDER_SUBVERSION		4
 
 #define BLENDER_MINVERSION		250
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/intern/texture.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/texture.c	2011-11-13 17:45:42 UTC (rev 41806)
+++ trunk/blender/source/blender/blenkernel/intern/texture.c	2011-11-13 18:03:27 UTC (rev 41807)
@@ -229,7 +229,7 @@
 
 void init_tex_mapping(TexMapping *texmap)
 {
-	float eul[3], smat[3][3], rmat[3][3], mat[3][3], proj[3][3];
+	float smat[3][3], rmat[3][3], mat[3][3], proj[3][3];
 
 	if(texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z &&
 	   is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) {
@@ -252,10 +252,8 @@
 		size_to_mat3(smat, texmap->size);
 		
 		/* rotation */
-		eul[0]= DEG2RADF(texmap->rot[0]);
-		eul[1]= DEG2RADF(texmap->rot[1]);
-		eul[2]= DEG2RADF(texmap->rot[2]);
-		eul_to_mat3( rmat,eul);
+		/* XXX TexMapping rotation are now in radians. */
+		eul_to_mat3(rmat, texmap->rot);
 		
 		/* compose it all */
 		mul_m3_m3m3(mat, rmat, smat);

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2011-11-13 17:45:42 UTC (rev 41806)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2011-11-13 18:03:27 UTC (rev 41807)
@@ -7301,6 +7301,52 @@
 	}
 }
 
+static void do_versions_nodetree_convert_angle(bNodeTree *ntree)
+{
+	bNode *node;
+	for (node=ntree->nodes.first; node; node=node->next) {
+		if (node->type == CMP_NODE_ROTATE) {
+			/* Convert degrees to radians. */
+			bNodeSocket *sock = ((bNodeSocket*)node->inputs.first)->next;
+			((bNodeSocketValueFloat*)sock->default_value)->value = DEG2RADF(((bNodeSocketValueFloat*)sock->default_value)->value);
+		}
+		else if (node->type == CMP_NODE_DBLUR) {
+			/* Convert degrees to radians. */
+			NodeDBlurData *ndbd= node->storage;
+			ndbd->angle = DEG2RADF(ndbd->angle);
+			ndbd->spin = DEG2RADF(ndbd->spin);
+		}
+		else if (node->type == CMP_NODE_DEFOCUS) {
+			/* Convert degrees to radians. */
+			NodeDefocus *nqd = node->storage;
+			/* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
+			nqd->rotation = DEG2RADF(nqd->rotation*255.0f);
+		}
+		else if (node->type == CMP_NODE_CHROMA_MATTE) {
+			/* Convert degrees to radians. */
+			NodeChroma *ndc = node->storage;
+			ndc->t1 = DEG2RADF(ndc->t1);
+			ndc->t2 = DEG2RADF(ndc->t2);
+		}
+		else if (node->type == CMP_NODE_GLARE) {
+			/* Convert degrees to radians. */
+			NodeGlare* ndg = node->storage;
+			/* XXX DNA char to float conversion seems to map the char value into the [0.0f, 1.0f] range... */
+			ndg->angle_ofs = DEG2RADF(ndg->angle_ofs*255.0f);
+		}
+		/* XXX TexMapping struct is used by other nodes too (at least node_composite_mapValue),
+		 *     but not the rot part...
+		 */
+		else if (node->type == SH_NODE_MAPPING) {
+			/* Convert degrees to radians. */
+			TexMapping* tmap = node->storage;
+			tmap->rot[0] = DEG2RADF(tmap->rot[0]);
+			tmap->rot[1] = DEG2RADF(tmap->rot[1]);
+			tmap->rot[2] = DEG2RADF(tmap->rot[2]);
+		}
+	}
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
 	/* WATCH IT!!!: pointers from libdata have not been converted */
@@ -12412,9 +12458,29 @@
 			ntreetype->foreach_nodetree(main, NULL, do_version_ntree_tex_mapping_260);
 	}
 
-	/* put compatibility code here until next subversion bump */
-	{
+	if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 4)){
 		{
+			/* Convert node angles to radians! */
+			Scene *sce;
+			Material *mat;
+			bNodeTree *ntree;
+
+			for (sce=main->scene.first; sce; sce=sce->id.next) {
+				if (sce->nodetree)
+					do_versions_nodetree_convert_angle(sce->nodetree);
+			}
+
+			for (mat=main->mat.first; mat; mat=mat->id.next) {
+				if (mat->nodetree)
+					do_versions_nodetree_convert_angle(mat->nodetree);
+			}
+
+			for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+				do_versions_nodetree_convert_angle(ntree);
+		}
+
+		{
+			/* Tomato compatibility code. */
 			bScreen *sc;
 			MovieClip *clip;
 
@@ -12475,6 +12541,10 @@
 		}
 	}
 
+	/* put compatibility code here until next subversion bump */
+	{
+	}
+
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 

Modified: trunk/blender/source/blender/makesdna/DNA_node_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_node_types.h	2011-11-13 17:45:42 UTC (rev 41806)
+++ trunk/blender/source/blender/makesdna/DNA_node_types.h	2011-11-13 18:03:27 UTC (rev 41807)
@@ -376,9 +376,10 @@
 
 /* qdn: Defocus blur node */
 typedef struct NodeDefocus {
-	char bktype, rotation, preview, gamco;
+	char bktype, pad_c1, preview, gamco;
 	short samples, no_zbuf;
 	float fstop, maxblur, bthresh, scale;
+	float rotation, pad_f1;
 } NodeDefocus;
 
 typedef struct NodeScriptDict {
@@ -389,8 +390,9 @@
 /* qdn: glare node */
 typedef struct NodeGlare {
 	char quality, type, iter;
-	char angle, angle_ofs, size, pad[2];
+	char angle, pad_c1, size, pad[2];
 	float colmod, mix, threshold, fade;
+	float angle_ofs, pad_f1;
 } NodeGlare;
 
 /* qdn: tonemap node */

Modified: trunk/blender/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_texture_types.h	2011-11-13 17:45:42 UTC (rev 41806)
+++ trunk/blender/source/blender/makesdna/DNA_texture_types.h	2011-11-13 18:03:27 UTC (rev 41807)
@@ -278,7 +278,7 @@
 	
 } Tex;
 
-/* used for mapping and texture nodes. note: rot is in degrees */
+/* used for mapping and texture nodes. note: rot is now in radians */
 
 typedef struct TexMapping {
 	float loc[3], rot[3], size[3];

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2011-11-13 17:45:42 UTC (rev 41806)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2011-11-13 18:03:27 UTC (rev 41807)
@@ -1928,17 +1928,17 @@
 	
 	RNA_def_struct_sdna_from(srna, "NodeChroma", "storage");
 	
-	prop = RNA_def_property(srna, "tolerance", PROP_FLOAT, PROP_NONE);
+	prop = RNA_def_property(srna, "tolerance", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "t1");
 	RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t1_set", NULL);
-	RNA_def_property_range(prop, 1.0f, 80.0f);
+	RNA_def_property_range(prop, DEG2RADF(1.0f), DEG2RADF(80.0f));
 	RNA_def_property_ui_text(prop, "Acceptance", "Tolerance for a color to be considered a keying color");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
-	prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE);
+	prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "t2");
 	RNA_def_property_float_funcs(prop, NULL, "rna_Matte_t2_set", NULL);
-	RNA_def_property_range(prop, 0.0f, 30.0f);
+	RNA_def_property_range(prop, 0.0f, DEG2RADF(30.0f));
 	RNA_def_property_ui_text(prop, "Cutoff", "Tolerance below which colors will be considered as exact matches");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 
@@ -2103,9 +2103,9 @@
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 
 	/* TODO: angle in degrees */		
-	prop = RNA_def_property(srna, "angle", PROP_INT, PROP_NONE);
-	RNA_def_property_int_sdna(prop, NULL, "rotation");
-	RNA_def_property_range(prop, 0, 90);
+	prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
+	RNA_def_property_float_sdna(prop, NULL, "rotation");
+	RNA_def_property_range(prop, 0.0f, DEG2RADF(90.0f));
 	RNA_def_property_ui_text(prop, "Angle", "Bokeh shape rotation offset in degrees");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
@@ -2271,15 +2271,15 @@
 	RNA_def_property_ui_text(prop, "Distance", "");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
-	prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_NONE);
+	prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "angle");
-	RNA_def_property_range(prop, 0.0f, 360.0f);
+	RNA_def_property_range(prop, 0.0f, DEG2RADF(360.0f));
 	RNA_def_property_ui_text(prop, "Angle", "");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
-	prop = RNA_def_property(srna, "spin", PROP_FLOAT, PROP_NONE);
+	prop = RNA_def_property(srna, "spin", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "spin");
-	RNA_def_property_range(prop, -360.0f, 360.0f);
+	RNA_def_property_range(prop, DEG2RADF(-360.0f), DEG2RADF(360.0f));
 	RNA_def_property_ui_text(prop, "Spin", "");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
@@ -2393,10 +2393,10 @@
 	RNA_def_property_ui_text(prop, "Streaks", "Total number of streaks");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
-	prop = RNA_def_property(srna, "angle_offset", PROP_INT, PROP_NONE);
-	RNA_def_property_int_sdna(prop, NULL, "angle_ofs");
-	RNA_def_property_range(prop, 0, 180);
-	RNA_def_property_ui_text(prop, "Angle Offset", "Streak angle offset in degrees");
+	prop = RNA_def_property(srna, "angle_offset", PROP_FLOAT, PROP_ANGLE);
+	RNA_def_property_float_sdna(prop, NULL, "angle_ofs");
+	RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
+	RNA_def_property_ui_text(prop, "Angle Offset", "Streak angle offset");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 	
 	prop = RNA_def_property(srna, "fade", PROP_FLOAT, PROP_NONE);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list