Generalized the sculptmode propset (DKEY) to work with strength as well as
brush size. Pressing the key once does brush size (same as before), then pressing it a second time switches to setting brush strength.
This commit is contained in:
@@ -37,11 +37,19 @@ struct Object;
|
||||
struct Scene;
|
||||
struct ScrArea;
|
||||
|
||||
typedef enum PropsetMode {
|
||||
PropsetNone = 0,
|
||||
PropsetSize,
|
||||
PropsetStrength
|
||||
} PropsetMode;
|
||||
typedef struct PropsetData {
|
||||
PropsetMode mode;
|
||||
unsigned int tex;
|
||||
short origloc[2];
|
||||
float *texdata;
|
||||
|
||||
short origsize;
|
||||
char origstrength;
|
||||
unsigned int tex;
|
||||
} PropsetData;
|
||||
|
||||
/* Memory */
|
||||
@@ -58,6 +66,7 @@ void sculptmode_undo_menu();
|
||||
void sculptmode_draw_interface_tools(struct uiBlock *block,unsigned short cx, unsigned short cy);
|
||||
void sculptmode_draw_interface_textures(struct uiBlock *block,unsigned short cx, unsigned short cy);
|
||||
void sculptmode_rem_tex(void*,void*);
|
||||
void sculptmode_propset_init(unsigned short key);
|
||||
void sculptmode_propset(const unsigned short event);
|
||||
void sculptmode_selectbrush_menu();
|
||||
void sculptmode_draw_mesh();
|
||||
|
||||
@@ -49,7 +49,6 @@ struct Scene;
|
||||
struct Image;
|
||||
struct Group;
|
||||
struct bNodeTree;
|
||||
struct PropsetData;
|
||||
|
||||
typedef struct Base {
|
||||
struct Base *next, *prev;
|
||||
@@ -370,7 +369,8 @@ typedef struct BrushData
|
||||
char airbrush;
|
||||
char pad[7];
|
||||
} BrushData;
|
||||
|
||||
|
||||
struct PropsetData;
|
||||
struct RenderInfo;
|
||||
struct SculptUndo;
|
||||
typedef struct SculptData
|
||||
@@ -394,7 +394,7 @@ typedef struct SculptData
|
||||
/* Used to cache the render of the active texture */
|
||||
struct RenderInfo *texrndr;
|
||||
|
||||
struct PropsetData *propset_data;
|
||||
struct PropsetData *propset;
|
||||
|
||||
struct SculptUndo *undo;
|
||||
|
||||
@@ -420,7 +420,7 @@ typedef struct SculptData
|
||||
char texrept;
|
||||
char texfade;
|
||||
|
||||
char averaging, propset, pad[2];
|
||||
char averaging, pad[3];
|
||||
} SculptData;
|
||||
|
||||
#define SCULPTREPT_DRAG 1
|
||||
|
||||
@@ -2876,9 +2876,19 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
||||
|
||||
/* Draw Sculpt Mode brush */
|
||||
if(!G.obedit && (G.f & G_SCULPTMODE)) {
|
||||
PropsetData *pd = G.scene->sculptdata.propset_data;
|
||||
const short r= sculptmode_brush()->size;
|
||||
PropsetData *pd = G.scene->sculptdata.propset;
|
||||
short r1, r2, r3;
|
||||
if(pd) {
|
||||
if(pd->mode == PropsetSize) {
|
||||
r1= sculptmode_brush()->size;
|
||||
r2= pd->origsize;
|
||||
r3= r1;
|
||||
} else if(pd->mode == PropsetStrength) {
|
||||
r1= 200 - sculptmode_brush()->strength * 2;
|
||||
r2= 200;
|
||||
r3= 200;
|
||||
}
|
||||
|
||||
/* Draw brush with texture */
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -2893,23 +2903,23 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(0,0,0,1);
|
||||
glTexCoord2f(0,0);
|
||||
glVertex2f(pd->origloc[0]-r, pd->origloc[1]-r);
|
||||
glVertex2f(pd->origloc[0]-r3, pd->origloc[1]-r3);
|
||||
glTexCoord2f(1,0);
|
||||
glVertex2f(pd->origloc[0]+r, pd->origloc[1]-r);
|
||||
glVertex2f(pd->origloc[0]+r3, pd->origloc[1]-r3);
|
||||
glTexCoord2f(1,1);
|
||||
glVertex2f(pd->origloc[0]+r, pd->origloc[1]+r);
|
||||
glVertex2f(pd->origloc[0]+r3, pd->origloc[1]+r3);
|
||||
glTexCoord2f(0,1);
|
||||
glVertex2f(pd->origloc[0]-r, pd->origloc[1]+r);
|
||||
glVertex2f(pd->origloc[0]-r3, pd->origloc[1]+r3);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if(pd->origsize != r)
|
||||
fdrawXORcirc(pd->origloc[0], pd->origloc[1], pd->origsize);
|
||||
fdrawXORcirc(pd->origloc[0], pd->origloc[1], r);
|
||||
if(r1 != r2)
|
||||
fdrawXORcirc(pd->origloc[0], pd->origloc[1], r1);
|
||||
fdrawXORcirc(pd->origloc[0], pd->origloc[1], r2);
|
||||
} else {
|
||||
short c[2];
|
||||
getmouseco_areawin(c);
|
||||
fdrawXORcirc((float)c[0], (float)c[1], r);
|
||||
fdrawXORcirc((float)c[0], (float)c[1], sculptmode_brush()->size);
|
||||
}
|
||||
}
|
||||
retopo_draw_paint_lines();
|
||||
|
||||
@@ -1190,71 +1190,134 @@ void sculptmode_set_strength(const int delta)
|
||||
sculptmode_brush()->strength= val;
|
||||
}
|
||||
|
||||
void sculptmode_propset(unsigned short event)
|
||||
void sculptmode_propset_calctex()
|
||||
{
|
||||
PropsetData *pd= NULL;
|
||||
short mouse[2];
|
||||
short tmp[2];
|
||||
const int tsz = 128;
|
||||
|
||||
/* Initialize */
|
||||
if(!G.scene->sculptdata.propset_data) {
|
||||
if(G.scene->sculptdata.propset==1) {
|
||||
float *d= MEM_mallocN(sizeof(float)*tsz*tsz, "Brush preview");
|
||||
int i,j;
|
||||
|
||||
|
||||
G.scene->sculptdata.propset_data= MEM_callocN(sizeof(PropsetData),"PropsetSize");
|
||||
pd= G.scene->sculptdata.propset_data;
|
||||
getmouseco_areawin(mouse);
|
||||
pd->origloc[0]= mouse[0];
|
||||
pd->origloc[1]= mouse[1];
|
||||
pd->origsize= sculptmode_brush()->size;
|
||||
pd->origstrength= sculptmode_brush()->strength;
|
||||
|
||||
/* Prepare texture */
|
||||
glGenTextures(1, (GLint *)&pd->tex);
|
||||
glBindTexture(GL_TEXTURE_2D, pd->tex);
|
||||
|
||||
PropsetData *pd= G.scene->sculptdata.propset;
|
||||
if(pd) {
|
||||
int i, j;
|
||||
const int tsz = 128;
|
||||
float *d;
|
||||
if(!pd->texdata) {
|
||||
pd->texdata= MEM_mallocN(sizeof(float)*tsz*tsz, "Brush preview");
|
||||
if(G.scene->sculptdata.texrept!=SCULPTREPT_3D)
|
||||
sculptmode_update_tex();
|
||||
|
||||
for(i=0; i<tsz; ++i)
|
||||
for(j=0; j<tsz; ++j)
|
||||
d[i*tsz+j]= simple_strength(sqrt(pow(i-tsz/2,2)+pow(j-tsz/2,2)),tsz/2);
|
||||
pd->texdata[i*tsz+j]= simple_strength(sqrt(pow(i-tsz/2,2)+pow(j-tsz/2,2)),tsz/2);
|
||||
if(G.scene->sculptdata.texact != -1 && G.scene->sculptdata.texrndr) {
|
||||
for(i=0; i<tsz; ++i)
|
||||
for(j=0; j<tsz; ++j) {
|
||||
const int col= G.scene->sculptdata.texrndr->rect[i*tsz+j];
|
||||
d[i*tsz+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f;
|
||||
pd->texdata[i*tsz+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f;
|
||||
}
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, tsz, tsz, 0, GL_ALPHA, GL_FLOAT, d);
|
||||
MEM_freeN(d);
|
||||
}
|
||||
|
||||
/* Adjust alpha with brush strength */
|
||||
d= MEM_dupallocN(pd->texdata);
|
||||
for(i=0; i<tsz; ++i)
|
||||
for(j=0; j<tsz; ++j)
|
||||
d[i*tsz+j]*= sculptmode_brush()->strength/200.0f+0.5f;
|
||||
|
||||
|
||||
if(!pd->tex)
|
||||
glGenTextures(1, (GLint *)&pd->tex);
|
||||
glBindTexture(GL_TEXTURE_2D, pd->tex);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, tsz, tsz, 0, GL_ALPHA, GL_FLOAT, d);
|
||||
MEM_freeN(d);
|
||||
}
|
||||
}
|
||||
|
||||
void sculptmode_propset_end(int cancel)
|
||||
{
|
||||
PropsetData *pd= G.scene->sculptdata.propset;
|
||||
if(pd) {
|
||||
if(cancel) {
|
||||
sculptmode_brush()->size= pd->origsize;
|
||||
sculptmode_brush()->strength= pd->origstrength;
|
||||
} else {
|
||||
if(pd->mode != PropsetSize)
|
||||
sculptmode_brush()->size= pd->origsize;
|
||||
if(pd->mode != PropsetStrength)
|
||||
sculptmode_brush()->strength= pd->origstrength;
|
||||
}
|
||||
glDeleteTextures(1, &pd->tex);
|
||||
MEM_freeN(pd->texdata);
|
||||
MEM_freeN(pd);
|
||||
G.scene->sculptdata.propset= NULL;
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
allqueue(REDRAWBUTSEDIT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void sculptmode_propset_init(unsigned short key)
|
||||
{
|
||||
PropsetData *pd= G.scene->sculptdata.propset;
|
||||
|
||||
if(!pd) {
|
||||
short mouse[2];
|
||||
|
||||
pd= MEM_callocN(sizeof(PropsetData),"PropsetSize");
|
||||
G.scene->sculptdata.propset= pd;
|
||||
|
||||
getmouseco_areawin(mouse);
|
||||
pd->origloc[0]= mouse[0];
|
||||
pd->origloc[1]= mouse[1];
|
||||
|
||||
pd->origsize= sculptmode_brush()->size;
|
||||
pd->origstrength= sculptmode_brush()->strength;
|
||||
|
||||
sculptmode_propset_calctex();
|
||||
}
|
||||
|
||||
pd= G.scene->sculptdata.propset_data;
|
||||
switch(key) {
|
||||
case DKEY:
|
||||
if(pd->mode == PropsetNone)
|
||||
pd->mode= PropsetSize;
|
||||
else if(pd->mode == PropsetSize)
|
||||
pd->mode= PropsetStrength;
|
||||
else
|
||||
sculptmode_propset_end(1);
|
||||
}
|
||||
}
|
||||
|
||||
void sculptmode_propset(unsigned short event)
|
||||
{
|
||||
PropsetData *pd= G.scene->sculptdata.propset;
|
||||
short mouse[2];
|
||||
short tmp[2];
|
||||
float dist;
|
||||
|
||||
switch(event) {
|
||||
case DKEY:
|
||||
sculptmode_propset_init(DKEY);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
break;
|
||||
case MOUSEX:
|
||||
case MOUSEY:
|
||||
getmouseco_areawin(mouse);
|
||||
tmp[0]= pd->origloc[0]-mouse[0];
|
||||
tmp[1]= pd->origloc[1]-mouse[1];
|
||||
sculptmode_brush()->size= sqrt(tmp[0]*tmp[0]+tmp[1]*tmp[1]);
|
||||
if(sculptmode_brush()->size>200) sculptmode_brush()->size= 200;
|
||||
dist= sqrt(tmp[0]*tmp[0]+tmp[1]*tmp[1]);
|
||||
if(pd->mode == PropsetSize) {
|
||||
sculptmode_brush()->size= dist;
|
||||
if(sculptmode_brush()->size>200) sculptmode_brush()->size= 200;
|
||||
} else if(pd->mode == PropsetStrength) {
|
||||
float fin= (200.0f - dist) * 0.5f;
|
||||
sculptmode_brush()->strength= fin>=0 ? fin : 0;
|
||||
sculptmode_propset_calctex();
|
||||
}
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
break;
|
||||
case WHEELUPMOUSE:
|
||||
/*case WHEELUPMOUSE:
|
||||
sculptmode_set_strength(5);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
break;
|
||||
case WHEELDOWNMOUSE:
|
||||
sculptmode_set_strength(-5);
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
break;
|
||||
break;*/
|
||||
case ESCKEY:
|
||||
case RIGHTMOUSE:
|
||||
sculptmode_brush()->size= pd->origsize;
|
||||
@@ -1263,12 +1326,7 @@ void sculptmode_propset(unsigned short event)
|
||||
while(get_mbut()==L_MOUSE);
|
||||
case RETKEY:
|
||||
case PADENTER:
|
||||
//glDeleteTextures(1, &pd->tex);
|
||||
G.scene->sculptdata.propset= 0;
|
||||
MEM_freeN(pd);
|
||||
G.scene->sculptdata.propset_data= NULL;
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
allqueue(REDRAWBUTSEDIT, 0);
|
||||
sculptmode_propset_end(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -906,7 +906,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
||||
}
|
||||
|
||||
if(!G.obedit && (G.f & G_SCULPTMODE)) {
|
||||
if(G.scene->sculptdata.propset==1) {
|
||||
if(G.scene->sculptdata.propset) {
|
||||
sculptmode_propset(event);
|
||||
return;
|
||||
}
|
||||
@@ -1386,7 +1386,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
|
||||
}
|
||||
else if((G.qual==0)){
|
||||
if(G.f & G_SCULPTMODE)
|
||||
G.scene->sculptdata.propset= 1;
|
||||
sculptmode_propset_init(DKEY);
|
||||
else {
|
||||
pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5");
|
||||
if(pupval>0) {
|
||||
|
||||
Reference in New Issue
Block a user