[Bf-committers] Re: A little Editface Question

Martin Poirier theeth at yahoo.com
Thu Jun 9 15:23:47 CEST 2005



--- Ton Roosendaal <ton at blender.org> wrote:

> Hi,
> 
> I would sugest a new method. The set_wuv() is a
> horrible construction  
> at the moment. Afaik, Johnny already solved copying
> pinning flags, seam  
> flags, smooth flags, and so on.
> 
> What is needed now is a parametric solution for
> finding new UVs and  
> vertexcolors based on an existing face and a 3d
> coordinate that lies  
> within the plane of that face. That's basically just
> an interpolation  
> function.

I have such code in python, but the generic concept is
very easily portable.

> Code below was copied from render module, I didn't
> compile it! But it  
> has the ingredients :)
> 
> 
> /* input efa and co (vector */
> /* output in TFace: uv (2 values) and vcol (4 char
> values) */
> void set_uv_vcol(EditFace *efa, float *co, float
> *uv, char *col)
> {
> 	
> 	/* define best projection of face XY, XZ or YZ */
> 		xn= fabs(efa->n[0]);
> 		yn= fabs(efa->n[1]);
> 		zn= fabs(efa->n[2]);
> 		if(zn>=xn && zn>=yn) {i= 0; j= 1;}
> 		else if(yn>=xn && yn>=zn) {i= 0; j= 2;}
> 		else {i= 1; j= 2;}
> 
> 	/* calculate u and v */
> 		v1= efa->v1;
> 		v2= efa->v2;
>   		v3= efa->v3;
> 
> 		t00= v3->co[i]-v1->co[i]; t01=
> v3->co[j]-v1->co[j];
> 		t10= v3->co[i]-v2->co[i]; t11=
> v3->co[j]-v2->co[j];
> 			
> 		detsh= 1.0/(t00*t11-t10*t01);	/* potential danger
> */
> 		t00*= detsh; t01*=detsh;
> 		t10*=detsh; t11*=detsh;
> 		
> 		u= (co[i]-v3->co[i])*t11-(co[j]-v3->co[j])*t10;
> 		v= (co[j]-v3->co[j])*t00-(co[i]-v3->co[i])*t01;
> 	
> 	/* btw; u and v range from -1 to 0 */
> 
> 	/* interpolate */
> 		l= 1.0+u+v;
> 		
> 		/* pseudocode!!! */
> 		/* just fill in colors or UV texture values here
> */
> 
> 		new = l*vertex3_val - u*vertex1_val -
> v*vertex2_val;
> 
> }
> 
> OK... this now doesn't work yet, since we need to
> get it working for  
> Quads.
> 
> That's a simple case as well;
> 
> 	/* in other triangle */
> 	if(efa->v4 && l < 0.0) {
> 		/* do it all over, but now with vertex 2 replaced
> with 4 */
> 
> 	}
> 
> 
> So, would this work?

The method I have doesn't approximate with a
projection and is very precise, but probably a bit
slower (has to inverse a matrix).

Martin

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Bf-committers mailing list