forked from bartvdbraak/blender
Added Ctrl+FKey shortcut for rotating the brush texture. Also improved the drawing of rotated brushes in propset mode.
This commit is contained in:
parent
e9bdfa4a3a
commit
0909fa71ea
@ -48,7 +48,8 @@ struct SculptUndo;
|
||||
typedef enum PropsetMode {
|
||||
PropsetNone = 0,
|
||||
PropsetSize,
|
||||
PropsetStrength
|
||||
PropsetStrength,
|
||||
PropsetTexRot
|
||||
} PropsetMode;
|
||||
typedef struct PropsetData {
|
||||
PropsetMode mode;
|
||||
@ -58,6 +59,7 @@ typedef struct PropsetData {
|
||||
|
||||
short origsize;
|
||||
char origstrength;
|
||||
float origtexrot;
|
||||
|
||||
NumInput num;
|
||||
} PropsetData;
|
||||
@ -122,6 +124,7 @@ void sculptmode_draw_mesh(int);
|
||||
void sculpt_paint_brush(char clear);
|
||||
|
||||
struct BrushData *sculptmode_brush();
|
||||
float *get_tex_angle();
|
||||
|
||||
void sculptmode_update_tex();
|
||||
void sculpt();
|
||||
|
@ -4348,7 +4348,7 @@ void sculptmode_draw_interface_textures(uiBlock *block, unsigned short cx, unsig
|
||||
|
||||
if(sd->texrept != SCULPTREPT_3D) {
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButF(block,NUM,0, "Rot", cx,cy,115,19, &mtex->warpfac, 0,360,100,0, "Rotate texture clockwise");
|
||||
uiDefButF(block,NUM,0, "Angle", cx,cy,115,19, &mtex->warpfac, 0,360,100,0, "Rotate texture counterclockwise");
|
||||
}
|
||||
cy-= 20;
|
||||
|
||||
|
@ -2748,6 +2748,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
||||
if(!G.obedit && (G.f & G_SCULPTMODE) && area_is_active_area(v3d->area) && sculpt_session()) {
|
||||
PropsetData *pd= sculpt_session()->propset;
|
||||
short r1=100, r2=100, r3=100;
|
||||
short mouse[2];
|
||||
if(pd) {
|
||||
if(pd->mode == PropsetSize) {
|
||||
r1= sculptmode_brush()->size;
|
||||
@ -2757,6 +2758,9 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
||||
r1= 200 - sculptmode_brush()->strength * 2;
|
||||
r2= 200;
|
||||
r3= 200;
|
||||
} else if(pd->mode == PropsetTexRot) {
|
||||
r1= r2= 200;
|
||||
r3= 200;
|
||||
}
|
||||
|
||||
/* Draw brush with texture */
|
||||
@ -2768,24 +2772,38 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(pd->origloc[0], pd->origloc[1], 0);
|
||||
glRotatef(*get_tex_angle(), 0, 0, 1);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(0,0,0,1);
|
||||
glTexCoord2f(0,0);
|
||||
glVertex2f(pd->origloc[0]-r3, pd->origloc[1]-r3);
|
||||
glVertex2f(-r3, -r3);
|
||||
glTexCoord2f(1,0);
|
||||
glVertex2f(pd->origloc[0]+r3, pd->origloc[1]-r3);
|
||||
glVertex2f(r3, -r3);
|
||||
glTexCoord2f(1,1);
|
||||
glVertex2f(pd->origloc[0]+r3, pd->origloc[1]+r3);
|
||||
glVertex2f(r3, r3);
|
||||
glTexCoord2f(0,1);
|
||||
glVertex2f(pd->origloc[0]-r3, pd->origloc[1]+r3);
|
||||
glVertex2f(-r3, r3);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
if(r1 != r2)
|
||||
fdrawXORcirc(pd->origloc[0], pd->origloc[1], r1);
|
||||
fdrawXORcirc(pd->origloc[0], pd->origloc[1], r2);
|
||||
|
||||
if(pd->mode == PropsetTexRot) {
|
||||
const float ang= pd->origtexrot * (M_PI/180.0f);
|
||||
getmouseco_areawin(mouse);
|
||||
sdrawXORline(pd->origloc[0], pd->origloc[1],
|
||||
pd->origloc[0]+200*cos(ang), pd->origloc[1]+200*sin(ang));
|
||||
sdrawXORline(pd->origloc[0], pd->origloc[1], mouse[0], mouse[1]);
|
||||
}
|
||||
} else {
|
||||
sculpt_paint_brush(1);
|
||||
}
|
||||
|
@ -1018,6 +1018,24 @@ unsigned *get_ri_pixel(const RenderInfo *ri, int px, int py)
|
||||
return ri->rect + py * ri->pr_rectx + px;
|
||||
}
|
||||
|
||||
float *get_tex_angle()
|
||||
{
|
||||
SculptData *sd= sculpt_data();
|
||||
if(sd->texact!=-1 && sd->mtex[sd->texact])
|
||||
return &sd->mtex[sd->texact]->warpfac;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
float to_rad(const float deg)
|
||||
{
|
||||
return deg * (M_PI/180.0f);
|
||||
}
|
||||
|
||||
float to_deg(const float rad)
|
||||
{
|
||||
return rad * (180.0f/M_PI);
|
||||
}
|
||||
|
||||
float tex_strength(EditData *e, float *point, const float len,const unsigned vindex)
|
||||
{
|
||||
SculptData *sd= sculpt_data();
|
||||
@ -1045,7 +1063,7 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
|
||||
else if(ss->texrndr) {
|
||||
const short bsize= sculptmode_brush()->size * 2;
|
||||
const short half= sculptmode_brush()->size;
|
||||
const float rot= sd->mtex[sd->texact]->warpfac * (M_PI/180.0f);
|
||||
const float rot= to_rad(*get_tex_angle());
|
||||
int px, py;
|
||||
unsigned i, *p;
|
||||
RenderInfo *ri= ss->texrndr;
|
||||
@ -1067,7 +1085,7 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
|
||||
float fx= pv.co[0];
|
||||
float fy= pv.co[1];
|
||||
|
||||
float angle= atan2(fy, fx) + rot;
|
||||
float angle= atan2(fy, fx) - rot;
|
||||
float len= sqrtf(fx*fx + fy*fy);
|
||||
|
||||
if(rot<0.001 && rot>-0.001) {
|
||||
@ -1425,7 +1443,6 @@ void sculptmode_propset_calctex()
|
||||
if(pd) {
|
||||
int i, j;
|
||||
const int tsz = 128;
|
||||
const int hsz = 64;
|
||||
float *d;
|
||||
if(!pd->texdata) {
|
||||
pd->texdata= MEM_mallocN(sizeof(float)*tsz*tsz, "Brush preview");
|
||||
@ -1440,21 +1457,9 @@ void sculptmode_propset_calctex()
|
||||
pd->texdata[i*tsz+j]= magn < tsz/2 ? 1 : 0;
|
||||
}
|
||||
if(sd->texact != -1 && ss->texrndr) {
|
||||
const float rot= sd->mtex[sd->texact]->warpfac * (M_PI/180.0f);
|
||||
|
||||
for(i=0; i<tsz; ++i)
|
||||
for(j=0; j<tsz; ++j) {
|
||||
const float fx= j-hsz;
|
||||
const float fy= i-hsz;
|
||||
const float angle= atan2(fy, fx) + rot;
|
||||
const float dist= sqrt(fx*fx + fy*fy);
|
||||
int px= dist * cos(angle) + hsz;
|
||||
int py= dist * sin(angle) + hsz;
|
||||
if(px<0) px= 0;
|
||||
if(py<0) py= 0;
|
||||
if(px>tsz) px= tsz;
|
||||
if(py>tsz) py= tsz;
|
||||
const int col= ss->texrndr->rect[py*tsz+px];
|
||||
const int col= ss->texrndr->rect[i*tsz+j];
|
||||
pd->texdata[i*tsz+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f;
|
||||
}
|
||||
}
|
||||
@ -1492,6 +1497,10 @@ void sculptmode_propset_header()
|
||||
name= "Strength";
|
||||
val= sculptmode_brush()->strength;
|
||||
}
|
||||
else if(pd->mode == PropsetTexRot) {
|
||||
name= "Texture Angle";
|
||||
val= *get_tex_angle();
|
||||
}
|
||||
sprintf(str, "Brush %s: %d", name, val);
|
||||
headerprint(str);
|
||||
}
|
||||
@ -1505,11 +1514,14 @@ void sculptmode_propset_end(int cancel)
|
||||
if(cancel) {
|
||||
sculptmode_brush()->size= pd->origsize;
|
||||
sculptmode_brush()->strength= pd->origstrength;
|
||||
*get_tex_angle()= pd->origtexrot;
|
||||
} else {
|
||||
if(pd->mode != PropsetSize)
|
||||
sculptmode_brush()->size= pd->origsize;
|
||||
if(pd->mode != PropsetStrength)
|
||||
sculptmode_brush()->strength= pd->origstrength;
|
||||
if(pd->mode != PropsetTexRot)
|
||||
*get_tex_angle()= pd->origtexrot;
|
||||
}
|
||||
glDeleteTextures(1, &pd->tex);
|
||||
MEM_freeN(pd->texdata);
|
||||
@ -1539,9 +1551,14 @@ void sculptmode_propset_init(PropsetMode mode)
|
||||
pd->origloc[0]-= sculptmode_brush()->size;
|
||||
else if(mode == PropsetStrength)
|
||||
pd->origloc[0]-= 200 - 2*sculptmode_brush()->strength;
|
||||
else if(mode == PropsetTexRot) {
|
||||
pd->origloc[0]-= 200 * cos(to_rad(*get_tex_angle()));
|
||||
pd->origloc[1]-= 200 * sin(to_rad(*get_tex_angle()));
|
||||
}
|
||||
|
||||
pd->origsize= sculptmode_brush()->size;
|
||||
pd->origstrength= sculptmode_brush()->strength;
|
||||
pd->origtexrot= *get_tex_angle();
|
||||
|
||||
sculptmode_propset_calctex();
|
||||
|
||||
@ -1590,6 +1607,8 @@ void sculptmode_propset(unsigned short event)
|
||||
brush->size= val;
|
||||
else if(pd->mode==PropsetStrength)
|
||||
brush->strength= val;
|
||||
else if(pd->mode==PropsetTexRot)
|
||||
*get_tex_angle()= val;
|
||||
valset= 1;
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
@ -1610,7 +1629,10 @@ void sculptmode_propset(unsigned short event)
|
||||
float fin= (200.0f - dist) * 0.5f;
|
||||
brush->strength= fin>=0 ? fin : 0;
|
||||
if(ctrl) brush->strength= (brush->strength+5)/10*10;
|
||||
|
||||
} else if(pd->mode == PropsetTexRot) {
|
||||
float *ang= get_tex_angle();
|
||||
*ang= (int)to_deg(atan2(tmp[1], tmp[0])) + 180;
|
||||
if(ctrl) *ang= ((int)(*ang)+5)/10*10;
|
||||
}
|
||||
valset= 1;
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
@ -1620,6 +1642,7 @@ void sculptmode_propset(unsigned short event)
|
||||
case RIGHTMOUSE:
|
||||
brush->size= pd->origsize;
|
||||
brush->strength= pd->origstrength;
|
||||
*get_tex_angle()= pd->origtexrot;
|
||||
case LEFTMOUSE:
|
||||
while(get_mbut()==L_MOUSE);
|
||||
case RETKEY:
|
||||
@ -1639,6 +1662,11 @@ void sculptmode_propset(unsigned short event)
|
||||
if(brush->strength > 100) brush->strength= 100;
|
||||
sculptmode_propset_calctex();
|
||||
}
|
||||
else if(pd->mode == PropsetTexRot) {
|
||||
float *angle= get_tex_angle();
|
||||
if(*angle<0) *angle= 0;
|
||||
if(*angle>360) *angle= 360;
|
||||
}
|
||||
}
|
||||
|
||||
sculptmode_propset_header();
|
||||
|
@ -1264,7 +1264,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
||||
if(G.qual==0)
|
||||
sculptmode_propset_init(PropsetSize);
|
||||
if(G.qual==LR_SHIFTKEY)
|
||||
sculptmode_propset_init(PropsetStrength);
|
||||
sculptmode_propset_init(PropsetStrength);
|
||||
if(G.qual==LR_CTRLKEY)
|
||||
sculptmode_propset_init(PropsetTexRot);
|
||||
break;
|
||||
case VKEY:
|
||||
br->dir= br->dir==1 ? 2 : 1;
|
||||
|
Loading…
Reference in New Issue
Block a user