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’s rotation part (its rot memember is now in radians).
This commit is contained in:
Bastien Montagne 2011-11-13 18:03:27 +00:00
parent c491b8bf45
commit fea58943ec
12 changed files with 112 additions and 41 deletions

View File

@ -42,7 +42,7 @@ extern "C" {
* 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

View File

@ -229,7 +229,7 @@ void default_tex_mapping(TexMapping *texmap)
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 @@ void init_tex_mapping(TexMapping *texmap)
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);

View File

@ -7301,6 +7301,52 @@ static void do_version_ntree_tex_mapping_260(void *UNUSED(data), ID *UNUSED(id),
}
}
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 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
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 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
/* 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! */

View File

@ -376,9 +376,10 @@ typedef struct NodeVertexCol {
/* 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 @@ typedef struct NodeScriptDict {
/* 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 */

View File

@ -278,7 +278,7 @@ typedef struct Tex {
} 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];

View File

@ -1928,17 +1928,17 @@ static void def_cmp_chroma_matte(StructRNA *srna)
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 @@ static void def_cmp_defocus(StructRNA *srna)
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 @@ static void def_cmp_dblur(StructRNA *srna)
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 @@ static void def_cmp_glare(StructRNA *srna)
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);

View File

@ -472,7 +472,7 @@ static void rna_def_texmapping(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Location", "");
RNA_def_property_update(prop, 0, "rna_Texture_mapping_update");
prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_XYZ); /* Not PROP_EUL, this is already in degrees, not radians */
prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER); /* Not PROP_XYZ, this is now in radians, no more degrees */
RNA_def_property_float_sdna(prop, NULL, "rot");
RNA_def_property_ui_text(prop, "Rotation", "");
RNA_def_property_update(prop, 0, "rna_Texture_mapping_update");

View File

@ -102,7 +102,7 @@ static void do_chroma_key(bNode *node, float *out, float *in)
z=in[2]*cosf(theta)-in[1]*sinf(theta);
/*if within the acceptance angle */
angle=c->t1*(float)M_PI/180.0f; /* convert to radians */
angle=c->t1; /* t1 is radians. */
/* if kfg is <0 then the pixel is outside of the key color */
kfg= x-(fabsf(z)/tanf(angle/2.0f));
@ -115,7 +115,7 @@ static void do_chroma_key(bNode *node, float *out, float *in)
alpha=(1.0f-kfg)*(c->fstrength);
beta=atan2(z,x);
angle2=c->t2*(float)(M_PI/180.0);
angle2=c->t2; /* t2 is radians. */
/* if beta is within the cutoff angle */
if(fabsf(beta) < (angle2/2.0f)) {
@ -180,8 +180,8 @@ static void node_composit_init_chroma_matte(bNodeTree *UNUSED(ntree), bNode* nod
{
NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node chroma");
node->storage= c;
c->t1= 30.0f;
c->t2= 10.0f;
c->t1= DEG2RADF(30.0f);
c->t2= DEG2RADF(10.0f);
c->t3= 0.0f;
c->fsize= 0.0f;
c->fstrength= 1.0f;

View File

@ -58,8 +58,9 @@ typedef struct BokehCoeffs {
static void makeBokeh(char bktype, char ro, int* len_bkh, float* inradsq, BokehCoeffs BKH[8], float bkh_b[4])
{
float x0, x1, y0, y1, dx, dy, iDxy;
float w = MAX2(1e-5f, ro)*(float)(M_PI/180); // never reported stangely enough, but a zero offset causes missing center line...
float wi = (360.f/bktype)*(float)(M_PI/180);
/* ro now is in radians. */
float w = MAX2(1e-6f, ro); // never reported stangely enough, but a zero offset causes missing center line...
float wi = DEG2RADF(360.f/bktype);
int i, ov, nv;
// bktype must be at least 3 & <= 8
@ -862,7 +863,7 @@ static void node_composit_init_defocus(bNodeTree *UNUSED(ntree), bNode* node, bN
/* qdn: defocus node */
NodeDefocus *nbd = MEM_callocN(sizeof(NodeDefocus), "node defocus data");
nbd->bktype = 0;
nbd->rotation = 0.f;
nbd->rotation = 0.0f;
nbd->preview = 1;
nbd->gamco = 0;
nbd->samples = 16;

View File

@ -47,7 +47,7 @@ static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap,
{
if ((dist != 0.f) || (spin != 0.f) || (zoom != 0.f)) {
void (*getpix)(CompBuf*, float, float, float*) = wrap ? qd_getPixelLerpWrap : qd_getPixelLerp;
const float a= angle * (float)M_PI / 180.f;
const float a= angle;
const float itsc= 1.f / powf(2.f, (float)iterations);
float D;
float center_x_pix, center_y_pix;
@ -65,7 +65,7 @@ static CompBuf *dblur(bNode *node, CompBuf *img, int iterations, int wrap,
tx= itsc * D * cosf(a);
ty= -itsc * D * sinf(a);
sc= itsc * zoom;
rot= itsc * spin * (float)M_PI / 180.f;
rot= itsc * spin;
/* blur the image */
for(i= 0; i < iterations; ++i) {

View File

@ -238,7 +238,7 @@ static void streaks(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
int x, y, n;
unsigned int nump=0;
fRGB c1, c2, c3, c4;
float a, ang = 360.f/(float)ndg->angle;
float a, ang = DEG2RADF(360.0f)/(float)ndg->angle;
bsrc = BTP(src, ndg->threshold, 1 << ndg->quality);
tsrc = dupalloc_compbuf(bsrc); // sample from buffer
@ -246,8 +246,8 @@ static void streaks(NodeGlare* ndg, CompBuf* dst, CompBuf* src)
sbuf = alloc_compbuf(tsrc->x, tsrc->y, tsrc->type, 1); // streak sum buffer
for (a=0.f; a<360.f; a+=ang) {
const float an = (a + (float)ndg->angle_ofs)*(float)M_PI/180.f;
for (a=0.f; a<DEG2RADF(360.0f); a+=ang) {
const float an = a + ndg->angle_ofs;
const float vx = cos((double)an), vy = sin((double)an);
for (n=0; n<ndg->iter; ++n) {
const float p4 = pow(4.0, (double)n);
@ -483,7 +483,7 @@ static void node_composit_init_glare(bNodeTree *UNUSED(ntree), bNode* node, bNod
ndg->mix = 0;
ndg->threshold = 1;
ndg->angle = 4;
ndg->angle_ofs = 0;
ndg->angle_ofs = 0.0f;
ndg->fade = 0.9;
ndg->size = 8;
node->storage = ndg;

View File

@ -58,7 +58,7 @@ static void node_composit_exec_rotate(void *UNUSED(data), bNode *node, bNodeStac
int x, y, yo, xo;
ImBuf *ibuf, *obuf;
rad= ((float)M_PI*in[1]->vec[0])/180.0f;
rad= in[1]->vec[0];
s= sin(rad);