== Sculpt Mode ==
* Replaced get_tex_angle() with tex_angle() and set_tex_angle(). This removes the need to do a bunch of error-prone NULL checking everywhere the texture angle is used.
This commit is contained in:
@@ -121,7 +121,7 @@ void sculptmode_draw_mesh(int);
|
|||||||
void sculpt_paint_brush(char clear);
|
void sculpt_paint_brush(char clear);
|
||||||
|
|
||||||
struct BrushData *sculptmode_brush(void);
|
struct BrushData *sculptmode_brush(void);
|
||||||
float *get_tex_angle(void);
|
float tex_angle(void);
|
||||||
|
|
||||||
void sculptmode_update_tex(void);
|
void sculptmode_update_tex(void);
|
||||||
char sculpt_modifiers_active(struct Object *ob);
|
char sculpt_modifiers_active(struct Object *ob);
|
||||||
|
|||||||
@@ -2815,7 +2815,6 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
|||||||
PropsetData *pd= sculpt_session()->propset;
|
PropsetData *pd= sculpt_session()->propset;
|
||||||
short r1=100, r2=100, r3=100;
|
short r1=100, r2=100, r3=100;
|
||||||
short mouse[2];
|
short mouse[2];
|
||||||
float *ang= get_tex_angle();
|
|
||||||
if(pd) {
|
if(pd) {
|
||||||
if(pd->mode == PropsetSize) {
|
if(pd->mode == PropsetSize) {
|
||||||
r1= sculptmode_brush()->size;
|
r1= sculptmode_brush()->size;
|
||||||
@@ -2842,7 +2841,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
|||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(pd->origloc[0], pd->origloc[1], 0);
|
glTranslatef(pd->origloc[0], pd->origloc[1], 0);
|
||||||
if(ang) glRotatef(*ang, 0, 0, 1);
|
glRotatef(tex_angle(), 0, 0, 1);
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|||||||
@@ -1005,13 +1005,20 @@ unsigned *get_ri_pixel(const RenderInfo *ri, int px, int py)
|
|||||||
return ri->rect + py * ri->pr_rectx + px;
|
return ri->rect + py * ri->pr_rectx + px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use the warpfac field in MTex to store a rotation value for sculpt textures. */
|
/* Use the warpfac field in MTex to store a rotation value for sculpt textures. Value is in degrees */
|
||||||
float *get_tex_angle(void)
|
float tex_angle(void)
|
||||||
{
|
{
|
||||||
SculptData *sd= sculpt_data();
|
SculptData *sd= sculpt_data();
|
||||||
if(sd->texact!=-1 && sd->mtex[sd->texact])
|
if(sd->texact!=-1 && sd->mtex[sd->texact])
|
||||||
return &sd->mtex[sd->texact]->warpfac;
|
return sd->mtex[sd->texact]->warpfac;
|
||||||
return NULL;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_tex_angle(const float f)
|
||||||
|
{
|
||||||
|
SculptData *sd = sculpt_data();
|
||||||
|
if(sd->texact != -1 && sd->mtex[sd->texact])
|
||||||
|
sd->mtex[sd->texact]->warpfac = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float to_rad(const float deg)
|
float to_rad(const float deg)
|
||||||
@@ -1054,8 +1061,7 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
|
|||||||
else if(ss->texrndr) {
|
else if(ss->texrndr) {
|
||||||
const short bsize= sculptmode_brush()->size * 2;
|
const short bsize= sculptmode_brush()->size * 2;
|
||||||
const short half= sculptmode_brush()->size;
|
const short half= sculptmode_brush()->size;
|
||||||
const float *ang= get_tex_angle();
|
const float rot= to_rad(tex_angle());
|
||||||
const float rot= ang?to_rad(*ang):0.0f;
|
|
||||||
int px, py;
|
int px, py;
|
||||||
unsigned i, *p;
|
unsigned i, *p;
|
||||||
RenderInfo *ri= ss->texrndr;
|
RenderInfo *ri= ss->texrndr;
|
||||||
@@ -1099,7 +1105,7 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
|
|||||||
float fx= (pv.co[0] - e->mouse[0] + half) * (ri->pr_rectx*1.0f/bsize) - ri->pr_rectx/2;
|
float fx= (pv.co[0] - e->mouse[0] + half) * (ri->pr_rectx*1.0f/bsize) - ri->pr_rectx/2;
|
||||||
float fy= (pv.co[1] - e->mouse[1] + half) * (ri->pr_recty*1.0f/bsize) - ri->pr_recty/2;
|
float fy= (pv.co[1] - e->mouse[1] + half) * (ri->pr_recty*1.0f/bsize) - ri->pr_recty/2;
|
||||||
|
|
||||||
float angle= atan2(fy, fx) + rot;
|
float angle= atan2(fy, fx) - rot;
|
||||||
float len= sqrtf(fx*fx + fy*fy);
|
float len= sqrtf(fx*fx + fy*fy);
|
||||||
|
|
||||||
px= ri->pr_rectx/2 + len * cos(angle);
|
px= ri->pr_rectx/2 + len * cos(angle);
|
||||||
@@ -1515,9 +1521,8 @@ void sculptmode_propset_header()
|
|||||||
val= sculptmode_brush()->strength;
|
val= sculptmode_brush()->strength;
|
||||||
}
|
}
|
||||||
else if(pd->mode == PropsetTexRot) {
|
else if(pd->mode == PropsetTexRot) {
|
||||||
float *ang= get_tex_angle();
|
|
||||||
name= "Texture Angle";
|
name= "Texture Angle";
|
||||||
val= ang?*get_tex_angle():0.0f;
|
val= tex_angle();
|
||||||
}
|
}
|
||||||
sprintf(str, "Brush %s: %d", name, val);
|
sprintf(str, "Brush %s: %d", name, val);
|
||||||
headerprint(str);
|
headerprint(str);
|
||||||
@@ -1528,19 +1533,18 @@ void sculptmode_propset_end(int cancel)
|
|||||||
{
|
{
|
||||||
SculptSession *ss= sculpt_session();
|
SculptSession *ss= sculpt_session();
|
||||||
PropsetData *pd= ss ? ss->propset : NULL;
|
PropsetData *pd= ss ? ss->propset : NULL;
|
||||||
float *ang= get_tex_angle();
|
|
||||||
if(pd) {
|
if(pd) {
|
||||||
if(cancel) {
|
if(cancel) {
|
||||||
sculptmode_brush()->size= pd->origsize;
|
sculptmode_brush()->size= pd->origsize;
|
||||||
sculptmode_brush()->strength= pd->origstrength;
|
sculptmode_brush()->strength= pd->origstrength;
|
||||||
if(ang) *ang= pd->origtexrot;
|
set_tex_angle(pd->origtexrot);
|
||||||
} else {
|
} else {
|
||||||
if(pd->mode != PropsetSize)
|
if(pd->mode != PropsetSize)
|
||||||
sculptmode_brush()->size= pd->origsize;
|
sculptmode_brush()->size= pd->origsize;
|
||||||
if(pd->mode != PropsetStrength)
|
if(pd->mode != PropsetStrength)
|
||||||
sculptmode_brush()->strength= pd->origstrength;
|
sculptmode_brush()->strength= pd->origstrength;
|
||||||
if(pd->mode != PropsetTexRot)
|
if(pd->mode != PropsetTexRot)
|
||||||
if(ang) *ang= pd->origtexrot;
|
set_tex_angle(pd->origtexrot);
|
||||||
}
|
}
|
||||||
glDeleteTextures(1, &pd->tex);
|
glDeleteTextures(1, &pd->tex);
|
||||||
MEM_freeN(pd->texdata);
|
MEM_freeN(pd->texdata);
|
||||||
@@ -1555,13 +1559,11 @@ void sculptmode_propset_init(PropsetMode mode)
|
|||||||
{
|
{
|
||||||
SculptSession *ss= sculpt_session();
|
SculptSession *ss= sculpt_session();
|
||||||
PropsetData *pd= ss->propset;
|
PropsetData *pd= ss->propset;
|
||||||
float *ang= get_tex_angle();
|
const float ang= tex_angle();
|
||||||
|
|
||||||
if(!pd) {
|
if(!pd) {
|
||||||
short mouse[2];
|
short mouse[2];
|
||||||
|
|
||||||
if(mode == PropsetTexRot && !ang) return;
|
|
||||||
|
|
||||||
pd= MEM_callocN(sizeof(PropsetData),"PropsetSize");
|
pd= MEM_callocN(sizeof(PropsetData),"PropsetSize");
|
||||||
ss->propset= pd;
|
ss->propset= pd;
|
||||||
|
|
||||||
@@ -1574,14 +1576,13 @@ void sculptmode_propset_init(PropsetMode mode)
|
|||||||
else if(mode == PropsetStrength)
|
else if(mode == PropsetStrength)
|
||||||
pd->origloc[0]-= 200 - 2*sculptmode_brush()->strength;
|
pd->origloc[0]-= 200 - 2*sculptmode_brush()->strength;
|
||||||
else if(mode == PropsetTexRot) {
|
else if(mode == PropsetTexRot) {
|
||||||
pd->origloc[0]-= 200 * cos(to_rad(*ang));
|
pd->origloc[0]-= 200 * cos(to_rad(ang));
|
||||||
pd->origloc[1]-= 200 * sin(to_rad(*ang));
|
pd->origloc[1]-= 200 * sin(to_rad(ang));
|
||||||
}
|
}
|
||||||
|
|
||||||
pd->origsize= sculptmode_brush()->size;
|
pd->origsize= sculptmode_brush()->size;
|
||||||
pd->origstrength= sculptmode_brush()->strength;
|
pd->origstrength= sculptmode_brush()->strength;
|
||||||
if(ang)
|
pd->origtexrot= ang;
|
||||||
pd->origtexrot= *ang;
|
|
||||||
|
|
||||||
sculptmode_propset_calctex();
|
sculptmode_propset_calctex();
|
||||||
|
|
||||||
@@ -1622,7 +1623,6 @@ void sculptmode_propset(unsigned short event)
|
|||||||
float dist;
|
float dist;
|
||||||
BrushData *brush= sculptmode_brush();
|
BrushData *brush= sculptmode_brush();
|
||||||
char valset= 0;
|
char valset= 0;
|
||||||
float *ang= get_tex_angle();
|
|
||||||
|
|
||||||
handleNumInput(&pd->num, event);
|
handleNumInput(&pd->num, event);
|
||||||
|
|
||||||
@@ -1634,7 +1634,7 @@ void sculptmode_propset(unsigned short event)
|
|||||||
else if(pd->mode==PropsetStrength)
|
else if(pd->mode==PropsetStrength)
|
||||||
brush->strength= val;
|
brush->strength= val;
|
||||||
else if(pd->mode==PropsetTexRot)
|
else if(pd->mode==PropsetTexRot)
|
||||||
*ang= val;
|
set_tex_angle(val);
|
||||||
valset= 1;
|
valset= 1;
|
||||||
allqueue(REDRAWVIEW3D, 0);
|
allqueue(REDRAWVIEW3D, 0);
|
||||||
}
|
}
|
||||||
@@ -1656,8 +1656,9 @@ void sculptmode_propset(unsigned short event)
|
|||||||
brush->strength= fin>=0 ? fin : 0;
|
brush->strength= fin>=0 ? fin : 0;
|
||||||
if(ctrl) brush->strength= (brush->strength+5)/10*10;
|
if(ctrl) brush->strength= (brush->strength+5)/10*10;
|
||||||
} else if(pd->mode == PropsetTexRot) {
|
} else if(pd->mode == PropsetTexRot) {
|
||||||
*ang= (int)to_deg(atan2(tmp[1], tmp[0])) + 180;
|
set_tex_angle((int)to_deg(atan2(tmp[1], tmp[0])) + 180);
|
||||||
if(ctrl) *ang= ((int)(*ang)+5)/10*10;
|
if(ctrl)
|
||||||
|
set_tex_angle(((int)(tex_angle())+5)/10*10);
|
||||||
}
|
}
|
||||||
valset= 1;
|
valset= 1;
|
||||||
allqueue(REDRAWVIEW3D, 0);
|
allqueue(REDRAWVIEW3D, 0);
|
||||||
@@ -1667,7 +1668,7 @@ void sculptmode_propset(unsigned short event)
|
|||||||
case RIGHTMOUSE:
|
case RIGHTMOUSE:
|
||||||
brush->size= pd->origsize;
|
brush->size= pd->origsize;
|
||||||
brush->strength= pd->origstrength;
|
brush->strength= pd->origstrength;
|
||||||
if(ang) *ang= pd->origtexrot;
|
set_tex_angle(pd->origtexrot);
|
||||||
case LEFTMOUSE:
|
case LEFTMOUSE:
|
||||||
while(get_mbut()==L_MOUSE);
|
while(get_mbut()==L_MOUSE);
|
||||||
case RETKEY:
|
case RETKEY:
|
||||||
@@ -1688,8 +1689,10 @@ void sculptmode_propset(unsigned short event)
|
|||||||
sculptmode_propset_calctex();
|
sculptmode_propset_calctex();
|
||||||
}
|
}
|
||||||
else if(pd->mode == PropsetTexRot) {
|
else if(pd->mode == PropsetTexRot) {
|
||||||
if(*ang<0) *ang= 0;
|
if(tex_angle() < 0)
|
||||||
if(*ang>360) *ang= 360;
|
set_tex_angle(0);
|
||||||
|
else if(tex_angle() > 360)
|
||||||
|
set_tex_angle(360);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user