[Bf-committers] Recursive Noise Button Enhancement

Robert Tiess bf-committers@blender.org
Thu, 04 Mar 2004 10:34:36 -0500


This is a multi-part message in MIME format.
--------------020303020109040501050907
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

As with what I did for enhancing the Edit window Smooth button,
making it recursive, I have done something similar for the Noise
button (the vertexnoise() function in editmesh.c).

The enclosed code establishes a new popup slider menu for user
selectable noise level application.  The range goes from 1 to 100.

Often when we use the Noise button we have to click it numerous
times to get any kind of noticeable effect.  This also wastes valuable
Undo levels (just as it was true with smoothing before the recursive
version was recently adopted for a future commit).

Now you can perform numerous texture-based noise modifications
to a mesh while only consuming one Undo level and at the same
time achieving better results faster.

The code enclosed in the attached text file is a clean replacement
for the existing vertenoise function.  Due to multiple ongoing tests
and changes in editmesh.c at my end I didn't think it wise to
attempt to send a cvs diff patch given all the modifications.

I hope you find this enhancement as useful as the iterative smoothing.

Thank you for considering this code.

Robert
(RobertT on Elysiun.com)
rjtiess@warwick.net


--------------020303020109040501050907
Content-Type: text/plain;
 name="recursivevertexnoise.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="recursivevertexnoise.txt"

//The following function replaces the same named function in editmesh.c:

void vertexnoise(void)
{
	extern float Tin;
	Material *ma;
	Tex *tex;
	EditVert *eve;
	float b2, ofs, vec[3];
	int noiseLoop, teller=0;
	short noiseAmount = 1;

	if(G.obedit==0) return;

	if (button(&noiseAmount, 1, 100, "Recurs: ")==0) return;
	
	undo_push_mesh("Noise");
	
	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;
	
	for (noiseLoop=0; noiseLoop<noiseAmount; noiseLoop++) {
		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);
			
					eve->co[2]+= 0.05*Tin;
				}
			}
			eve= eve->next;
		}
	}

	allqueue(REDRAWVIEW3D, 0);
	makeDispList(G.obedit);
}

--------------020303020109040501050907--