[Bf-committers] noise function : new patch
hans pachet
bf-committers@blender.org
Mon, 11 Aug 2003 20:39:11 +0200
This patch makes the noise function a little more complete. It lets you
choose in which direction to displace : x,y,z-direction, and the direction
of the normals.
PS : I'm sorry for the large heap of text, but I don't know how to make a
decent patch. But it should work like this.
******************************************************************
1) Add these defines in buttons.c
#define B_NOISE_X 2084
#define B_NOISE_Y 2085
#define B_NOISE_Z 2086
#define B_NOISE_NOR 2087
******************************************************************
2) In buttons.c (about line 1400-1500) in the function void
do_meshbuts(unsigned short event),
replace the following case :
case B_VERTEXNOISE:
vertexnoise();
break;
by these four cases :
case B_NOISE_X:
vertexnoise(0,nlength);
break;
case B_NOISE_Y:
vertexnoise(1,nlength);
break;
case B_NOISE_Z:
vertexnoise(2,nlength);
break;
case B_NOISE_NOR:
vertexnoise(3,nlength);
break;
******************************************************************
3) In buttons.c (about line 1520), add the following function :
uiBlock *noise_menu(void *arg_unused)
{
uiBlock *block;
block= uiNewBlock(&curarea->uiblocks,
"noise menu", UI_EMBOSSX, UI_HELV,
curarea->win);
/* use this for a fake extra empy space around the buttons */
uiDefBut(block, LABEL, 0, "",
285, -20, 220, 80, NULL,
0, 0, 0, 0, "");
uiBlockSetCol(block, BUTSALMON);
uiDefBut(block, BUT, B_NOISE_X,"X",
295,30,80,19,
0, 0, 0, 0, 0,
"displaces in X-direction");
uiDefBut(block, BUT, B_NOISE_Y,"Y",
415,30,80,19,
0, 0, 0, 0, 0,
"displaces in Y-direction");
uiDefBut(block, BUT, B_NOISE_Z,"Z",
295,10,80,19,
0, 0, 0, 0, 0,
"displaces in Z-direction");
uiDefBut(block, BUT, B_NOISE_NOR,"Nor",
415,10,80,19,
0, 0, 0, 0, 0,
"displaces in direction of normals");
uiBlockSetCol(block, BUTGREY);
uiDefButF(block, NUMSLI, 0, "length ",
295, -10, 200,19,
&nlength, 0.000, 5.000, 0, 0,
"Set the noise length");
uiBlockSetDirection(block, UI_RIGHT);
return block;
}
******************************************************************
4) In buttons.c (about line 2065), replace the following line :
uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",847,by-=19,94,18, 0, 0, 0, 0, 0,
"Use vertex coordinate as texture coordinate");
by the following code :
UiBlockSetCol(block, BUTGREY);
uiDefBlockBut(block, noise_menu, NULL,"Noise |>> ",847,by-=19,94,18, "");
uiBlockSetCol(block, BUTSALMON);
******************************************************************
5) In editmesh.c (about line 2050), replace the whole function void
vertexnoise(void)
by these lines of code :
void vertexnoise(int noisedirection, float noiselength)
{
extern float Tin;
Material *ma;
Tex *tex;
EditVert *eve;
float b2, ofs, vec[3];
if(G.obedit==0) return;
ma= give_current_material(G.obedit, G.obedit->actcol);
if(ma==0 || ma->mtex[0]==0 || ma->mtex[0]->tex==0) {
return;
}
tex= ma->mtex[0]->tex;
ofs= tex->turbul/200.0;
eve= (struct EditVert *)G.edve.first;
while(eve) {
if(eve->f & 1) {
if(tex->type==TEX_STUCCI) {
b2= BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]);
if(tex->stype) ofs*=(b2*b2);
vec[0]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0]+ofs, eve->co[1],
eve->co[2]));
vec[1]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs,
eve->co[2]));
vec[2]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1],
eve->co[2]+ofs));
VecAddf(eve->co, eve->co, vec);
}
else {
externtex(ma->mtex[0], eve->co);
switch (noisedirection)
{
case 0:
eve->co[0]+= noiselength*(Tin-0.5);
break;
case 1:
eve->co[1]+= noiselength*(Tin-0.5);
break;
case 2:
eve->co[2]+= noiselength*(Tin-0.5);
break;
case 3:
eve->co[0]+= noiselength*eve->no[0]*(Tin-0.5);
eve->co[1]+= noiselength*eve->no[1]*(Tin-0.5);
eve->co[2]+= noiselength*eve->no[2]*(Tin-0.5);
break;
}
}
}
eve= eve->next;
}
allqueue(REDRAWVIEW3D, 0);
makeDispList(G.obedit);
}
******************************************************************
6) In BIF_editmesh.h (line 46), replace the following line :
void vertexnoise(void);
by this line
void vertexnoise(int noisedirection, float noiselength);
_________________________________________________________________