* Replaced the three X/Y/Z sliders that controlled the texture size in sculpt

mode with a single slider. (Doesn't seem likely the user is going to want to
  scale in one axis differently from another.) Additionally, the new slider
  works correctly in Tile mode in addition to 3D mode. In Tile mode, the slider
  value is considered pixel units.

In the process, found and fixed a few sculptmode bugs
* When loading a file that is already in sculptmode, initialize sculptdata
  as soon as the first sculpt/partial-visibility operation occurs
* Bug in the undo_push code; reading from free'd memory
This commit is contained in:
2006-11-19 09:25:17 +00:00
parent 0e682ce194
commit 204f6066a9
3 changed files with 34 additions and 14 deletions

View File

@@ -414,13 +414,14 @@ typedef struct SculptData
short symm_x, symm_y, symm_z; short symm_x, symm_y, symm_z;
/* For the Brush Shape */ /* For the Brush Shape */
float texsize[3]; short texscale;
short texact, texnr; short texact, texnr;
short spacing; short spacing;
char pad[2];
char texrept; char texrept;
char texfade; char texfade;
char averaging, pad[3]; char averaging, pad2[3];
} SculptData; } SculptData;
#define SCULPTREPT_DRAG 1 #define SCULPTREPT_DRAG 1

View File

@@ -4140,9 +4140,7 @@ void sculptmode_draw_interface_textures(uiBlock *block, unsigned short cx, unsig
uiDefButC(block,ROW,B_NOP, "3D", cx+78,cy,37,19, &sd->texrept, 18,SCULPTREPT_3D, 0,0,"Use vertex coords as texture coordinates"); uiDefButC(block,ROW,B_NOP, "3D", cx+78,cy,37,19, &sd->texrept, 18,SCULPTREPT_3D, 0,0,"Use vertex coords as texture coordinates");
cy-= 20; cy-= 20;
uiDefButF(block,NUM,B_NOP, "X", cx, cy,39,19, &sd->texsize[0],-20,20,10,0,"Scaling factor for texture's X axis"); uiDefButS(block,NUM,B_NOP, "Scale", cx,cy,115,19, &sd->texscale,1,1000,0,0,"Scaling factor for texture axis");
uiDefButF(block,NUM,B_NOP, "Y", cx+39,cy,38,19, &sd->texsize[1],-20,20,10,0,"Scaling factor for texture's Y axis");
uiDefButF(block,NUM,B_NOP, "Z", cx+78,cy,38,19, &sd->texsize[2],-20,20,10,0,"Scaling factor for texture's Z axis");
cy-= 20; cy-= 20;
uiDefButC(block,TOG,B_NOP, "Fade", cx,cy,50,19, &sd->texfade, 0,0,0,0,"Smooth the edges of the texture"); uiDefButC(block,TOG,B_NOP, "Fade", cx,cy,50,19, &sd->texfade, 0,0,0,0,"Smooth the edges of the texture");

View File

@@ -172,7 +172,7 @@ void sculptmode_init(Scene *sce)
sd->texact= -1; sd->texact= -1;
sd->texfade= 1; sd->texfade= 1;
sd->averaging= 1; sd->averaging= 1;
sd->texsize[0]= sd->texsize[1]= sd->texsize[2]= 1; sd->texscale= 100;
sd->texrept= SCULPTREPT_DRAG; sd->texrept= SCULPTREPT_DRAG;
} }
@@ -276,11 +276,12 @@ void sculptmode_undo_push(char *str, int verts, int fe, int pv)
{ {
int cnt= 7; int cnt= 7;
SculptUndo *su= G.scene->sculptdata.undo; SculptUndo *su= G.scene->sculptdata.undo;
SculptUndoStep *n= MEM_callocN(sizeof(SculptUndoStep), "SculptUndo"), *sus, *chop; SculptUndoStep *n= MEM_callocN(sizeof(SculptUndoStep), "SculptUndo"), *sus, *chop, *path;
Mesh *me= get_mesh(G.scene->sculptdata.active_ob); Mesh *me= get_mesh(G.scene->sculptdata.active_ob);
/* Chop off undo data after cur */ /* Chop off undo data after cur */
for(sus= su->steps.last; sus && sus != su->cur; sus= sus->prev) { for(sus= su->steps.last; sus && sus != su->cur; sus= path) {
path= sus->prev;
sculptmode_undo_free_link(sus); sculptmode_undo_free_link(sus);
BLI_freelinkN(&su->steps, sus); BLI_freelinkN(&su->steps, sus);
} }
@@ -311,7 +312,8 @@ void sculptmode_undo_push(char *str, int verts, int fe, int pv)
/* Make sure that non-vert data isn't lost */ /* Make sure that non-vert data isn't lost */
sculptmode_undo_pull_chopped(chop); sculptmode_undo_pull_chopped(chop);
for(sus= su->steps.first; sus && sus != chop; sus= sus->next) { for(sus= su->steps.first; sus && sus != chop; sus= path) {
path= sus->next;
sculptmode_undo_free_link(sus); sculptmode_undo_free_link(sus);
BLI_freelinkN(&su->steps, sus); BLI_freelinkN(&su->steps, sus);
} }
@@ -394,6 +396,7 @@ void sculptmode_undo_update(SculptUndoStep *newcur)
if(modifiers_getVirtualModifierList(ob)) if(modifiers_getVirtualModifierList(ob))
DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA); DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
if(G.vd->depths) G.vd->depths->damaged= 1;
allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWVIEW3D, 0);
} }
@@ -810,15 +813,16 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
avg= 1; avg= 1;
else if(G.scene->sculptdata.texrept==SCULPTREPT_3D) { else if(G.scene->sculptdata.texrept==SCULPTREPT_3D) {
float jnk; float jnk;
const float factor= 0.01;
MTex mtex; MTex mtex;
memset(&mtex,0,sizeof(MTex)); memset(&mtex,0,sizeof(MTex));
mtex.tex= G.scene->sculptdata.mtex[G.scene->sculptdata.texact]->tex; mtex.tex= G.scene->sculptdata.mtex[G.scene->sculptdata.texact]->tex;
mtex.projx= 1; mtex.projx= 1;
mtex.projy= 2; mtex.projy= 2;
mtex.projz= 3; mtex.projz= 3;
mtex.size[0]= G.scene->sculptdata.texsize[0]; mtex.size[0]= G.scene->sculptdata.texscale * factor;
mtex.size[1]= G.scene->sculptdata.texsize[1]; mtex.size[1]= G.scene->sculptdata.texscale * factor;
mtex.size[2]= G.scene->sculptdata.texsize[2]; mtex.size[2]= G.scene->sculptdata.texscale * factor;
externtex(&mtex,point,&avg,&jnk,&jnk,&jnk,&jnk); externtex(&mtex,point,&avg,&jnk,&jnk,&jnk,&jnk);
} else { } else {
@@ -871,10 +875,12 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
py= magn * sin(theta) + cx; py= magn * sin(theta) + cx;
if(G.scene->sculptdata.texrept==SCULPTREPT_TILE) { if(G.scene->sculptdata.texrept==SCULPTREPT_TILE) {
const float scale= G.scene->sculptdata.texscale;
px+= e->mouse[0]; px+= e->mouse[0];
py+= e->mouse[1]; py+= e->mouse[1];
p= ri->rect + (py%ri->pr_recty) * ri->pr_rectx + (px%ri->pr_rectx); px%= (int)scale;
p= ri->rect + (projverts[vindex].co[1]%ri->pr_recty) * ri->pr_rectx + (projverts[vindex].co[0]%ri->pr_rectx); py%= (int)scale;
p= ri->rect + (int)(ri->pr_recty*py/scale) * ri->pr_rectx + (int)(ri->pr_rectx*px/scale);
} }
else p= ri->rect + py * ri->pr_rectx + px; else p= ri->rect + py * ri->pr_rectx + px;
@@ -1436,6 +1442,18 @@ void sculptmode_draw_mesh(ListBase *damaged_rects) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }
void sculptmode_correct_state()
{
if(get_mesh(G.scene->sculptdata.active_ob) != get_mesh(OBACT))
set_sculpt_object(OBACT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
if(!G.scene->sculptdata.vertex_users) calc_vertex_users();
if(!G.scene->sculptdata.undo) sculptmode_undo_init();
}
void sculpt() void sculpt()
{ {
Object *ob= 0; Object *ob= 0;
@@ -1473,6 +1491,7 @@ void sculpt()
/* Make sure sculptdata has been init'd properly */ /* Make sure sculptdata has been init'd properly */
if(!G.scene->sculptdata.vertex_users) calc_vertex_users(); if(!G.scene->sculptdata.vertex_users) calc_vertex_users();
if(!G.scene->sculptdata.undo) sculptmode_undo_init();
/* Init texture /* Init texture
FIXME: Shouldn't be doing this every time! */ FIXME: Shouldn't be doing this every time! */
@@ -1928,6 +1947,8 @@ void sculptmode_pmv(int mode)
{ {
Object *ob= OBACT; Object *ob= OBACT;
rcti hb_2d= sculptmode_pmv_box(); /* Get 2D hide box */ rcti hb_2d= sculptmode_pmv_box(); /* Get 2D hide box */
sculptmode_correct_state();
waitcursor(1); waitcursor(1);