[tuhopuu-devel] sorry line breaks again

BjornMose tuhopuu-devel@blender.org
Wed, 21 Jan 2004 21:51:34 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0027_01C3E068.BD02BE00
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: 8bit

gnarf !"§$%&/

i try to attach it
bjornmose

------=_NextPart_000_0027_01C3E068.BD02BE00
Content-Type: text/plain;
	name="uvpatch.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="uvpatch.txt"

hi all, hi theeth

Here comes the patch with the panel in edit_buttons for UV calculation
as shown here: http://www.freewebs.com/bjornmose/

Some portions of the code did not work when
called with the mouse on the buttons panel.
So i decided to do a redesign, which also replaces some
reoccuring sequences of code by function calls.=20

There is a #ifdef switch, so you can compare the results.
When activated UKEY calls old code, buttons the new.

To find the spots i touched "grep" for /*+++ BM=20

bjornmose

proposal for featurelist.txt:
*** bjornmose:
	Added a buttons panel to edit_buttons for UV calculation.
	This also extends the users choice,
	how the spherical and cylindrical mapping is oriented
	in relation to the 3D view.
	Further more it makes the nasty popups for the numerical values
	"cubemapsize" and "radius" obsolete.
	There was a problem calling the UV calculation function from another =
window,
	which was also the reason the UV entry was taken out of the header =
menu.
	Since the new code has fixed that, the menue entry was enabled too.
=09
THE PATCH:
=09
Index: blender/include/BDR_editface.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: =
/cvsroot/tuhopuu/tuhopuu2/source/blender/include/BDR_editface.h,v
retrieving revision 1.1.1.2
diff -r1.1.1.2 BDR_editface.h
55a56,57
> void calculate_uv_map(unsigned short mapmode);
> =20
Index: blender/include/butspace.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/tuhopuu/tuhopuu2/source/blender/include/butspace.h,v
retrieving revision 1.3
diff -r1.3 butspace.h
99a100,102
> /* uvautocalculation */
> void do_uvautocalculationbuts(unsigned short event);
> void get_uvautocalculationsettings(float *radius,float *cubesize, int =
*mapdir, int *mapalign);
515a519,546
>=20
> /*+++ BM */
> /* *********************** */
> #define B_UVAUTOCALCBUTS	3400
> enum {
> 	B_UVAUTO_REDRAW =3D 3301,
> 		B_UVAUTO_SPHERE,
> 		B_UVAUTO_CYLINDER,
> 		B_UVAUTO_CYLRADIUS,
> 		B_UVAUTO_WINDOW,
> 		B_UVAUTO_CUBE,
> 		B_UVAUTO_CUBESIZE,
> 		B_UVAUTO_STD1,
> 		B_UVAUTO_STD2,
> 		B_UVAUTO_STD4,
> 		B_UVAUTO_STD8,
> 		B_UVAUTO_BOUNDS1,
> 		B_UVAUTO_BOUNDS2,
> 		B_UVAUTO_BOUNDS4,
> 		B_UVAUTO_BOUNDS8,
> 		B_UVAUTO_TOP,
> 		B_UVAUTO_FACE,
> 		B_UVAUTO_OBJECT,
> 		B_UVAUTO_ALIGNX,
> 		B_UVAUTO_ALIGNY	=09
> };
> /* *********************** */
> /*--- BM */
Index: blender/src/butspace.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/tuhopuu/tuhopuu2/source/blender/src/butspace.c,v
retrieving revision 1.1.1.2
diff -r1.1.1.2 butspace.c
317a318,322
> /*+++ BM*/
> 	else if(event<=3DB_UVAUTOCALCBUTS) {
> 		do_uvautocalculationbuts(event);
> 	}
> /*--- BM*/
Index: blender/src/buttons_editing.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: =
/cvsroot/tuhopuu/tuhopuu2/source/blender/src/buttons_editing.c,v
retrieving revision 1.8
diff -r1.8 buttons_editing.c
155a156,162
> /*+++ BM*/
> /* don't like storing data here but where else ? */
> float   uv_radius   =3D 1.0;
> float   uv_cubesize =3D 1.0;
> int     uv_mapdir   =3D 1;
> int     uv_mapalign =3D 1;
> /*--- BM*/
2014a2022,2051
> /*+++ BM*/
> void get_uvautocalculationsettings(float *radius,float *cubesize, int =
*mapdir, int *mapalign)
> {
> /* don't like storing data here but where else ? */
> 	*radius   =3D uv_radius;
> 	*cubesize =3D uv_cubesize;
> 	*mapdir   =3D uv_mapdir;
> 	*mapalign =3D uv_mapalign;
> }
>=20
> void do_uvautocalculationbuts(unsigned short event)
> {  =20
> 	switch(event) {=20
> 	case B_UVAUTO_STD1:
> 	case B_UVAUTO_STD2:
> 	case B_UVAUTO_STD4:
> 	case B_UVAUTO_STD8:
> 	case B_UVAUTO_BOUNDS1:
> 	case B_UVAUTO_BOUNDS2:
> 	case B_UVAUTO_BOUNDS4:
> 	case B_UVAUTO_BOUNDS8:
> 	case B_UVAUTO_SPHERE:
> 	case B_UVAUTO_CYLINDER:
> 	case B_UVAUTO_WINDOW:
> 	case B_UVAUTO_CUBE:
> 		if( select_area(SPACE_VIEW3D)) calculate_uv_map(event);
> 	}
> }
>=20
>=20
2059a2097,2143
> /*+++ BM */
> static void editing_panel_mesh_uvautocalculation(void)
> {
> 	uiBlock *block;
> 	int butH =3D 20,butHS =3D 22, row =3D 7;
> =09
> 	block=3D uiNewBlock(&curarea->uiblocks, =
"editing_panel_mesh_uvautocalculation", UI_EMBOSS, UI_HELV, =
curarea->win);
> 	if(uiNewPanel(curarea, block, "UV Calculation", "Editing", 1280, 0, =
318, 204)=3D=3D0) return;
> =09
> 	uiBlockBeginAlign(block);
> 	uiDefBut(block, LABEL, B_UVAUTO_BOUNDS1,"Standard 1/", =
100,row*butHS,150,butH, 0, 0, 0, 0, 0, "Standard UV mapping");
> 	uiDefBut(block, BUT, B_UVAUTO_STD1,"1", 300,row*butHS,50,butH, 0, 0, =
0, 0, 0, "Apply standard UV mapping 1/1");
> 	uiDefBut(block, BUT, B_UVAUTO_STD2,"2", 350,row*butHS,50,butH, 0, 0, =
0, 0, 0, "Apply standard UV mapping 1/2");
> 	uiDefBut(block, BUT, B_UVAUTO_STD4,"4", 400,row*butHS,50,butH, 0, 0, =
0, 0, 0, "Apply standard UV mapping 1/4");
> 	uiDefBut(block, BUT, B_UVAUTO_STD8,"8", 450,row*butHS,50,butH, 0, 0, =
0, 0, 0, "Apply standard UV mapping 1/8");
>=20
> 	uiBlockBeginAlign(block); row--;
> 	uiDefBut(block, LABEL, B_UVAUTO_BOUNDS1,"Bounds 1/", =
100,row*butHS,150,butH, 0, 0, 0, 0, 0, "Bounding box UV mapping");
> 	uiDefBut(block, BUT, B_UVAUTO_BOUNDS1,"1", 300,row*butHS,50,butH, 0, =
0, 0, 0, 0, "Apply bounds 1/1");
> 	uiDefBut(block, BUT, B_UVAUTO_BOUNDS2,"2", 350,row*butHS,50,butH, 0, =
0, 0, 0, 0, "Apply bounds 1/2");
> 	uiDefBut(block, BUT, B_UVAUTO_BOUNDS4,"4", 400,row*butHS,50,butH, 0, =
0, 0, 0, 0, "Apply bounds 1/4");
> 	uiDefBut(block, BUT, B_UVAUTO_BOUNDS8,"8", 450,row*butHS,50,butH, 0, =
0, 0, 0, 0, "Apply bounds 1/8");
> =09
> 	row -=3D 1; /* some extra room */
> 	uiBlockBeginAlign(block);row--;
> 	uiDefBut(block, BUT, B_UVAUTO_WINDOW,  "From Window", 	=
100,row*butHS,200,butH, 0, 0, 0, 0, 0, "Apply from window mappin");
> 	row--;
> 	uiDefBut(block, BUT, B_UVAUTO_CUBE,"Cube",  100,row*butHS,200,butH, =
0, 0, 0, 0, 0, "Apply cube mappin");
> 	uiDefButF(block, NUM,B_UVAUTO_CUBESIZE ,"Size:", =
400,row*butHS,200,butH, &uv_cubesize, 0.0001, 100.0, 10, 0, "Change the =
cubemap size");	=09
> 	row--;
> 	uiDefBut(block, BUT, B_UVAUTO_SPHERE,  "Sphere", 	=
100,row*butHS,200,butH, 0, 0, 0, 0, 0, "Apply sphere mappin");
> 	row--;
> 	uiDefBut(block, BUT, B_UVAUTO_CYLINDER,"Cylinder",  =
100,row*butHS,200,butH, 0, 0, 0, 0, 0, "Apply cylinder mappin");
> 	uiDefButF(block, NUM,B_UVAUTO_CYLRADIUS ,"Radius:", =
400,row*butHS,200,butH, &uv_radius, 0.1, 100.0, 10, 0, "Change the =
radius of mapping cylinder");	=09
> =09
> 	uiBlockBeginAlign(block);	row--;
> 	uiDefButI(block, ROW,B_UVAUTO_TOP , "VATop"  ,100,row*butHS,100,butH, =
&uv_mapdir,2.0, 0.0, 0.0,0.0, "View aligns poles");
> 	uiDefButI(block, ROW,B_UVAUTO_FACE , "VAFace",200,row*butHS,100,butH, =
&uv_mapdir,2.0, 1.0, 0.0,0.0, "View is on aequator");
> 	uiDefButI(block, ROW,B_UVAUTO_OBJECT ,"AlObj",300,row*butHS,100,butH, =
&uv_mapdir,2.0, 2.0, 0.0,0.0, "Align to object(OLD SPHERE/CYLINDER)");
> 	uiBlockBeginAlign(block);
> 	uiDefButI(block, ROW,B_UVAUTO_ALIGNX , "PZX",400,row*butHS,100,butH, =
&uv_mapalign,2.0, 0.0, 0.0,0.0, "Polar 0 is X");
> 	uiDefButI(block, ROW,B_UVAUTO_ALIGNY , "PZY",500,row*butHS,100,butH,  =
  &uv_mapalign,2.0, 1.0, 0.0,0.0, "Polar 0 is Y");
> }
>=20
> /*--- BM*/
>=20
>=20
2085c2169
< 			if(G.f & G_FACESELECT)
---
> 			if(G.f & G_FACESELECT){
2087c2171,2174
< 		=09
---
> 				/*+++ BM*/
> 				editing_panel_mesh_uvautocalculation();
> 				/*--- BM*/
> 			}
Index: blender/src/editface.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/tuhopuu/tuhopuu2/source/blender/src/editface.c,v
retrieving revision 1.4
diff -r1.4 editface.c
88a89
> #include "butspace.h"
97a99,535
> /*+++ BM */
> /* functions to make code 'buttons save' and have code for one task =
once */
> /* don't know if underscore for internal functions is OK ? */
> /* andILoveThooseLongCamelBacks */  =20
> int _getCenterVectorFromAround(float *result,Object *ob,Mesh *me) =
/*1=3Dwe can 0=3Dwe can not*/
> {
> 	float min[3], max[3];
> 	int a;
> 	TFace *tface;
> 	MFace *mface;
> 	switch (G.vd->around)=20
> 	{
> 	case  V3D_CENTRE : /*bounding box center*/
> 		/* INIT_MINMAX(min,max); but floats otherways complier warnings */
> 		min[0]=3Dmin[1]=3Dmin[2] =3D1e20f; max[0]=3Dmax[1]=3Dmax[2] =
=3D-1e20f;=20
> 		tface=3D me->tface;
> 		mface=3D me->mface;
> 		for(a=3D0; a<me->totface; a++, mface++, tface++) {
> 			if(tface->flag & TF_SELECT) {
> 				if(mface->v3=3D=3D0) continue; /* this is not really a face */
> 				DO_MINMAX( (me->mvert+mface->v1)->co, min, max);
> 				DO_MINMAX( (me->mvert+mface->v2)->co, min, max);
> 				DO_MINMAX( (me->mvert+mface->v3)->co, min, max);
> 				if(mface->v4) DO_MINMAX( (me->mvert+mface->v4)->co, min, max);
> 			}
> 		}
> 		VecMidf(result, min, max);
> 		return (1);
> 	case  V3D_CURSOR : /*cursor center*/=20
> 		{
> 			float *cursx;
> 			cursx=3D give_cursor();
> 			/* shift to objects world */
> 			result[0]=3D cursx[0]-ob->obmat[3][0];
> 			result[1]=3D cursx[1]-ob->obmat[3][1];
> 			result[2]=3D cursx[2]-ob->obmat[3][2];
> 		}
> 		return(1);
> 	case  V3D_LOCAL : /*object center*/
> 	case  V3D_CENTROID : /*median refers to multiple objects centers. =
only one object here*/
> 		result[0]=3D result[1]=3D result[2]=3D 0.0;
> 		return(1);
> 	default : /* covered all known modes, but if there was a new one */
> 		/* say something to the user if we can't*/
> 		okee("this operation center does not work here!");
> 		return(0);=20
> 	}
> =09
> }
> void _calulateUvMapMatix(float result[][4] ,Object *ob,float =
upangledeg,float sideangledeg, float radius)
> {
> 		float rotup[4][4],rotside[4][4], viewmatrix[4][4], rotobj[4][4];
> 		int k;
> 		float upangle =3D 0.0, sideangle =3D 0.0;
> 		/* get rotation of the current view matrix */
> 		Mat4CpyMat4(viewmatrix,G.vd->viewmat);
> 		/* but shifting */
> 		for( k=3D 0; k< 4; k++) {
> 			viewmatrix[3][k] =3D0.0;
> 		}
>=20
> 		/* get rotation of the current object matrix */
> 		Mat4CpyMat4(rotobj,ob->obmat);
> 		/* but shifting */
> 		for( k=3D 0; k< 4; k++){
> 			rotobj[3][k] =3D0.0;
> 		}
>=20
>    		/* never assume local variables to be zeroed */
> 		Mat4Clr(*rotup);
> 		Mat4Clr(*rotside);
>=20
> 		/* need this to compensate front/side.. against opengl x,y,z world =
definition */
> 		/* this is "kanonen gegen spatzen" i know, a few plus minus 1 will =
do here */
> 		/* i wanted to keep the reason here, so we're rotating*/
> 		/* debug helper if (fbutton(&sideangledeg, -180.0, 180, "Side =
angle") =3D=3D0) return; */
> 		sideangle =3DM_PI * (sideangledeg + 180.0) /180.0;
> 		rotside[0][0] =3D (float)cos(sideangle);  rotside[0][1] =3D =
-(float)sin(sideangle);
> 		rotside[1][0] =3D (float)sin(sideangle);  rotside[1][1] =3D =
(float)cos(sideangle);
> 		rotside[2][2] =3D 1.0f;
>      =20
> 		/* debug helper if (fbutton(&upangledeg, -90.0, 90.0, "Up angle") =
=3D=3D0) return; */
> 		upangle =3DM_PI * upangledeg /180.0;
> 		rotup[1][1] =3D (float)cos(upangle)/radius;  rotup[1][2] =3D =
-(float)sin(upangle)/radius;
> 		rotup[2][1] =3D (float)sin(upangle)/radius;  rotup[2][2] =3D =
(float)cos(upangle)/radius;
> 		rotup[0][0] =3D (float)1.0/radius;
> 		/* calculate transforms*/
> 		=
Mat4MulSerie(result,rotup,rotside,viewmatrix,rotobj,NULL,NULL,NULL,NULL);=

> }
>=20
> void _uv_shift_project(float *target,float *shift,float rotmat[][4], =
int projectionmode,float *source,float *min,float *max)
> {
> 	/*
> 	half save=20
> 	paranoia checking all pointers =20
> 	if (!target) return; and so on ...
> 	*/
> 	float pv[3];
> 	VecSubf(pv, source, shift);
> 	Mat4MulVecfl(rotmat,pv);
> 	switch (projectionmode) {
> 	case B_UVAUTO_CYLINDER:=20
> 		tubemap(pv[0], pv[1], pv[2], &target[0],&target[1]);
> 		if (target[0] >=3D 1.0f) target[0] -=3D 1.0f; /* split line is =
always zero */=20
> 		break;
> 	case B_UVAUTO_SPHERE:=20
> 		spheremap(pv[0], pv[1], pv[2], &target[0],&target[1]);
> 		if (target[0] >=3D 1.0f) target[0] -=3D 1.0f; /* split line is =
always zero */
> 		break;
> 	case 3: /* ortho special case for BOUNDS */
> 		target[0] =3D -pv[0];
> 		target[1] =3D pv[2];
> 		break;
> 	case 4: /* very special case for FROM WINDOWS */
> 		{
> 		/* simulate the original code */
> 		/* that muliplies the object matrix to the view live to use =
project_short() */
> 		/* and restores the matrix before display */
> 		/* quote
> 		mymultmatrix(ob->obmat);
> 		MTC_Mat4SwapMat4(G.vd->persmat, mat);
> 		mygetsingmatrix(G.vd->persmat);
> 		....
> 		myloadmatrix(G.vd->viewmat);
> 		MTC_Mat4SwapMat4(G.vd->persmat, mat);
> 		*/
> 		/* now the function can be called from buttons/header view so the =
obove 'trick' won't work */
>=20
> 		float pv4[4];
> 		float dx =3D G.vd->area->winx , dy=3D G.vd->area->winy;
>         pv4[0] =3D source[0]; pv4[1] =3D source[1]; pv4[2] =3D =
source[2];
>         pv4[3] =3D 1.0;
>         Mat4MulVec4fl(rotmat,pv4); /* rotmat is the object matrix in =
this case */
> 		/* almost project_short */
> 	    Mat4MulVec4fl(G.vd->persmat,pv4);
> 		if (fabs(pv[3]) > 0.00001) { /* to be sure avoid div by zero */
> 		target[0] =3D dx/2.0 + (dx/2.0)*pv4[0]/pv4[3];
> 		target[1] =3D dy/2.0 + (dy/2.0)*pv4[1]/pv4[3];
> 		}
> 		else{
> 		/* scaling is lost but give a valid result */
> 		target[0] =3D dx/2.0 + (dx/2.0)*pv4[0];
> 		target[1] =3D dy/2.0 + (dy/2.0)*pv4[1];
> 		}
>=20
>         /* G.vd->persmat seems to do this funky scaling */=20
> 		if (dx > dy) dy =3D dx;
> 		else         dx =3D dy;
> 		target[0] /=3D dx;
> 		target[1] /=3D dy;
> 		}
> 		break;
>     default:
> 		target[0] =3D 0.0;
> 		target[1] =3D 1.0;
> 	}
> 	/* we know the values here and may need min_max later*/
> 	/* min max may be NULL */
> 	if (min){
> 		min[0] =3D MIN2(target[0], min[0]);
> 		min[1] =3D MIN2(target[1], min[1]);
> 	}
> 	/* this keeps max requests independand from min ; not fastest but =
savest*/=20
> 	if (max){
> 		max[0] =3D MAX2(target[0], max[0]);
> 		max[1] =3D MAX2(target[1], max[1]);
> 	}
> =09
> }
>=20
> void calculate_uv_map(unsigned short mapmode)
> {
> 	float uv_radius,uv_cubesize,dx,dy;
> 	int uv_mapdir,uv_mapalign;
> 	Mesh *me;
> 	TFace *tface;
> 	MFace *mface;
> 	Object *ob;
> 	float rotatematrix[4][4];
> 	float upangle =3D 0.0, sideangle =3D 0.0, radius =3D 1.0;
>=20
> 	float min[3], cent[3], max[3];
> 	float fac =3D 1.0;
>=20
> 	int i, n, mi;=20
> 	int a, b;
> 	float upangledeg =3D 0.0, sideangledeg =3D 90.0;=20
>=20
> 	/* read settings from the buttons window */=20
> 	=
get_uvautocalculationsettings(&uv_radius,&uv_cubesize,&uv_mapdir,&uv_mapa=
lign);
> 	if (uv_mapdir   =3D=3D 1)=20
> 	{
> 		upangledeg   =3D 90.0;
> 		sideangledeg =3D  0.0;
> 	}
> 	else=20
> 	{upangledeg   =3D  0.0;
> 	if (uv_mapalign =3D=3D1) sideangledeg =3D 0.0;
> 	else sideangledeg =3D 90.0;
> 	}
> =09
>=20
> 	me=3D get_mesh(ob=3DOBACT);
> 	if(me=3D=3D0 || me->tface=3D=3D0) return;
> 	if(me->totface=3D=3D0) return;
> =09
> 	switch(mapmode) {
> 	case B_UVAUTO_BOUNDS8:	=09
> 	case B_UVAUTO_BOUNDS4:	=09
> 	case B_UVAUTO_BOUNDS2:	=09
> 	case B_UVAUTO_BOUNDS1:	=09
> 		switch(mapmode) { /* i don't like gotos ! */
> 		case B_UVAUTO_BOUNDS8:	=09
> 			fac =3D 0.125; break;
> 		case B_UVAUTO_BOUNDS4:	=09
> 			fac =3D 0.25; break;
> 		case B_UVAUTO_BOUNDS2:	=09
> 			fac =3D 0.5; break;
> 		}
> 		min[0]=3D min[1]=3D 1.0;
> 		max[0]=3D max[1]=3D 0.0;
>=20
> 		{
> 		=09
> 			if (!_getCenterVectorFromAround(cent,ob,me)) return;
> 			_calulateUvMapMatix(rotatematrix,ob,upangledeg,sideangledeg,1.0f);
> 		=09
> 			tface=3D me->tface;
> 			mface=3D me->mface;
> 			for(a=3D0; a<me->totface; a++, mface++, tface++) {   /* go for all =
faces of the given mesh */
> 				if(tface->flag & TF_SELECT) { /* if this face is selected in UI */
> 					if(mface->v3=3D=3D0) continue; /* must be ploygon with more than =
2 vertices */
> 					=
_uv_shift_project(tface->uv[0],cent,rotatematrix,3,(me->mvert+mface->v1)-=
>co,min,max);
> 					=
_uv_shift_project(tface->uv[1],cent,rotatematrix,3,(me->mvert+mface->v2)-=
>co,min,max);
> 					=
_uv_shift_project(tface->uv[2],cent,rotatematrix,3,(me->mvert+mface->v3)-=
>co,min,max);
> 					if(mface->v4) {
> 						=
_uv_shift_project(tface->uv[3],cent,rotatematrix,3,(me->mvert+mface->v4)-=
>co,min,max);
> 					}
> 				}
> 			}
> 		}
> 	=09
> 		/* rescale UV to be in 0..1,1/2,1/4,1/8 */
> 		dx=3D (max[0]-min[0]);
> 		dy=3D (max[1]-min[1]);
>=20
> 		tface=3D me->tface;
> 		mface=3D me->mface;
> 		for(a=3D0; a<me->totface; a++, mface++, tface++) {
> 			if(tface->flag & TF_SELECT) {
> 				if(mface->v3=3D=3D0) continue;
> 			=09
> 				if(mface->v4) b=3D 3; else b=3D 2;
> 				for(; b>=3D0; b--) {
> 					tface->uv[b][0]=3D  ((tface->uv[b][0] - min[0])* fac) / dx;
> 					tface->uv[b][1]=3D  1.0 - fac + ((tface->uv[b][1] - min[1]) * =
fac) /dy;
> 				}
> 			}
> 		}
> 		break;
>=20
> 	case B_UVAUTO_WINDOW:	=09
> 		{
> 			/* prepare for this special case */
> 			cent[0] =3D cent[1] =3D cent[2] =3D 0.0;=20
> 		    Mat4CpyMat4(rotatematrix,ob->obmat);
>=20
> 			tface=3D me->tface;
> 			mface=3D me->mface;
> 			for(a=3D0; a<me->totface; a++, mface++, tface++) {   /* go for all =
faces of the given mesh */
> 				if(tface->flag & TF_SELECT) { /* if this face is selected in UI */
> 					if(mface->v3=3D=3D0) continue; /* must be ploygon with more than =
2 vertices */
> 					=
_uv_shift_project(tface->uv[0],cent,rotatematrix,4,(me->mvert+mface->v1)-=
>co,NULL,NULL);
> 					=
_uv_shift_project(tface->uv[1],cent,rotatematrix,4,(me->mvert+mface->v2)-=
>co,NULL,NULL);
> 					=
_uv_shift_project(tface->uv[2],cent,rotatematrix,4,(me->mvert+mface->v3)-=
>co,NULL,NULL);
> 					if(mface->v4) {
> 						=
_uv_shift_project(tface->uv[3],cent,rotatematrix,4,(me->mvert+mface->v4)-=
>co,NULL,NULL);
> 					}
> 				}
> 			}
> 		}
> 		break;
>=20
>=20
> 	case B_UVAUTO_STD8:
> 	case B_UVAUTO_STD4:
> 	case B_UVAUTO_STD2:
> 	case B_UVAUTO_STD1:
> 		switch(mapmode){ /* i don't like gotos ! */
> 		case B_UVAUTO_STD8:
> 			fac =3D 0.125; break;
> 		case B_UVAUTO_STD4:
> 			fac =3D 0.25; break;
> 		case B_UVAUTO_STD2:
> 			fac =3D 0.5; break;
> 		}
> 		tface=3D me->tface;
> 		for(a=3D0; a<me->totface; a++, tface++) {
> 			if(tface->flag & TF_SELECT) {
> 				default_uv(tface->uv, fac);
> 			}
> 		}
> 		break;
>=20
> 	case B_UVAUTO_CYLINDER:
> 	case B_UVAUTO_SPHERE:
> 		{
> 			if (!_getCenterVectorFromAround(cent,ob,me)) return;
> 		=09
> 			if(mapmode=3D=3DB_UVAUTO_CYLINDER) radius =3D uv_radius;
> 		=09
> 			if (uv_mapdir !=3D 2) {
> 				=
_calulateUvMapMatix(rotatematrix,ob,upangledeg,sideangledeg,radius);
> 			}
> 			else /* be compatible to the "old" sphere/cylinder mode */
> 			{Mat4One(rotatematrix);}
>=20
> 			tface=3D me->tface; mface=3D me->mface;
> 			for(a=3D0; a<me->totface; a++, mface++, tface++) {   /* go for all =
faces of the given mesh */
> 				if(tface->flag & TF_SELECT) { /* if this face is selected in UI */
> 					if(mface->v3=3D=3D0) continue; /* must be ploygon with more than =
2 vertices */
> 					=
_uv_shift_project(tface->uv[0],cent,rotatematrix,mapmode,(me->mvert+mface=
->v1)->co,NULL,NULL);
> 					=
_uv_shift_project(tface->uv[1],cent,rotatematrix,mapmode,(me->mvert+mface=
->v2)->co,NULL,NULL);
> 					=
_uv_shift_project(tface->uv[2],cent,rotatematrix,mapmode,(me->mvert+mface=
->v3)->co,NULL,NULL);
> 					n =3D 3;      =20
> 					if(mface->v4) {
> 						=
_uv_shift_project(tface->uv[3],cent,rotatematrix,mapmode,(me->mvert+mface=
->v4)->co,NULL,NULL);
> 						n=3D4;
> 					}
>=20
> 					mi =3D 0; 			=09
> 					for (i =3D 1; i < n; i++) {
> 						if (tface->uv[i][0] > tface->uv[mi][0]) mi =3D i;
> 					}
> 					for (i =3D 0; i < n; i++) {
> 						if (i !=3D mi) {
> 							dx =3D tface->uv[mi][0] - tface->uv[i][0];
> 							if (dx > 0.5) {
> 								tface->uv[i][0] +=3D 1.0;
> 							}=20
> 						}=20
> 					}=20
> 				}
> 			}
> 		}
> 		break;
>=20
> 	case B_UVAUTO_CUBE:
> 		{
>  		/* OLD code to be compatible */
> 		/* what i actually does is */
> 		/* choosing x,y,z axis for projetion depending on the largest normal =
component */
> 		/* but clusters all together around the center of map */
> 			float no[3];
> 			MVert *mv=3D me->mvert;
> 			short cox, coy;
> 			float *loc=3D ob->obmat[3];
>=20
> 			tface=3D me->tface;
> 			mface=3D me->mface;
> 			for(a=3D0; a<me->totface; a++, mface++, tface++) {
> 				if(tface->flag & TF_SELECT) {
> 					if(mface->v3=3D=3D0) continue;
> 				=09
> 					CalcNormFloat((mv+mface->v1)->co, (mv+mface->v2)->co, =
(mv+mface->v3)->co, no);
> 				=09
> 					no[0]=3D fabs(no[0]);
> 					no[1]=3D fabs(no[1]);
> 					no[2]=3D fabs(no[2]);
> 				=09
> 					cox=3D0; coy=3D 1;
> 					if(no[2]>=3Dno[0] && no[2]>=3Dno[1]);
> 					else if(no[1]>=3Dno[0] && no[1]>=3Dno[2]) coy=3D 2;
> 					else { cox=3D 1; coy=3D 2;}
> 				=09
> 					tface->uv[0][0]=3D 0.5+0.5*uv_cubesize*(loc[cox] + =
(mv+mface->v1)->co[cox]);
> 					tface->uv[0][1]=3D 0.5+0.5*uv_cubesize*(loc[coy] + =
(mv+mface->v1)->co[coy]);
> 					dx =3D floor(tface->uv[0][0]);
> 					dy =3D floor(tface->uv[0][1]);
> 					tface->uv[0][0] -=3D dx;
> 					tface->uv[0][1] -=3D dy;
> 					tface->uv[1][0]=3D 0.5+0.5*uv_cubesize*(loc[cox] + =
(mv+mface->v2)->co[cox]);
> 					tface->uv[1][1]=3D 0.5+0.5*uv_cubesize*(loc[coy] + =
(mv+mface->v2)->co[coy]);
> 					tface->uv[1][0] -=3D dx;
> 					tface->uv[1][1] -=3D dy;
> 					tface->uv[2][0]=3D 0.5+0.5*uv_cubesize*(loc[cox] + =
(mv+mface->v3)->co[cox]);
> 					tface->uv[2][1]=3D 0.5+0.5*uv_cubesize*(loc[coy] + =
(mv+mface->v3)->co[coy]);
> 					tface->uv[2][0] -=3D dx;
> 					tface->uv[2][1] -=3D dy;
> 					if(mface->v4) {
> 						tface->uv[3][0]=3D 0.5+0.5*uv_cubesize*(loc[cox] + =
(mv+mface->v4)->co[cox]);
> 						tface->uv[3][1]=3D 0.5+0.5*uv_cubesize*(loc[coy] + =
(mv+mface->v4)->co[coy]);
> 						tface->uv[3][0] -=3D dx;
> 						tface->uv[3][1] -=3D dy;
> 					}
> 				=09
> 				}
> 			}
> 		}
> 		break;=20
> 	default:
> 		return; /* this is a mapmode i don't know */
> 	} /* end switch mapmode */
>=20
> 	/* clipping and wrapping */
> 	if(G.sima && G.sima->flag & SI_CLIP_UV) {
> 		tface=3D me->tface;
> 		mface=3D me->mface;
> 		for(a=3D0; a<me->totface; a++, mface++, tface++) {
> 			if(tface->flag & TF_SELECT) {
> 				if(mface->v3=3D=3D0) continue;
> 			=09
> 				dx=3D dy=3D 0;
> 				if(mface->v4) b=3D 3; else b=3D 2;
> 				for(; b>=3D0; b--) {
> 					while(tface->uv[b][0] + dx < 0.0) dx+=3D 0.5;
> 					while(tface->uv[b][0] + dx > 1.0) dx-=3D 0.5;
> 					while(tface->uv[b][1] + dy < 0.0) dy+=3D 0.5;
> 					while(tface->uv[b][1] + dy > 1.0) dy-=3D 0.5;
> 				}
> =09
> 				if(mface->v4) b=3D 3; else b=3D 2;
> 				for(; b>=3D0; b--) {
> 					tface->uv[b][0]+=3D dx;
> 					CLAMP(tface->uv[b][0], 0.0, 1.0);
> 				=09
> 					tface->uv[b][1]+=3D dy;
> 					CLAMP(tface->uv[b][1], 0.0, 1.0);
> 				}
> 			}
> 		}
> 	}
>     /* post redraw requests */
> 	allqueue(REDRAWVIEW3D, 0);
> 	allqueue(REDRAWIMAGE, 0);
> }
> /*--- BM */
625a1064,1119
> /*+++ BM this is the MASTER switch to check if the new code can do =
what the old could */
> /* uncomment to have the old stuff on the UKEY and the new in the =
buttons panel */
> /* #define BM_OLDCODECHECK */
> #ifndef BM_OLDCODECHECK
> /*+++ BM code needed to keep UKEY alive */
> void uv_autocalc_tface()
> {
> =09
> 	short mode;
> 	mode=3D pupmenu(MENUTITLE("UV Calculation")
> 		MENUSTRING("Cube",          UV_CUBE_MAPPING) "|"
> 		MENUSTRING("Cylinder",      UV_CYL_MAPPING) "|"
> 		MENUSTRING("Sphere",	  UV_SPHERE_MAPPING) "|"
> 		MENUSTRING("Bounds to 1/8", UV_BOUNDS8_MAPPING) "|"
> 		MENUSTRING("Bounds to 1/4", UV_BOUNDS4_MAPPING) "|"
> 		MENUSTRING("Bounds to 1/2", UV_BOUNDS2_MAPPING) "|"
> 		MENUSTRING("Bounds to 1/1", UV_BOUNDS1_MAPPING) "|"
> 		MENUSTRING("Standard 1/8",  UV_STD8_MAPPING) "|"
> 		MENUSTRING("Standard 1/4",  UV_STD4_MAPPING) "|"
> 		MENUSTRING("Standard 1/2",  UV_STD2_MAPPING) "|"
> 		MENUSTRING("Standard 1/1",  UV_STD1_MAPPING) "|"
> 		MENUSTRING("From Window",   UV_WINDOW_MAPPING) );
> =09
> =09
> 	switch(mode) {
> 	case UV_CUBE_MAPPING:
> 		calculate_uv_map(B_UVAUTO_CUBE); break;
> 	case UV_CYL_MAPPING:
> 		calculate_uv_map(B_UVAUTO_CYLINDER); break;
> 	case UV_SPHERE_MAPPING:
> 		calculate_uv_map(B_UVAUTO_SPHERE); break;
> 	case UV_BOUNDS8_MAPPING:
> 		calculate_uv_map(B_UVAUTO_BOUNDS8); break;
> 	case UV_BOUNDS4_MAPPING:
> 		calculate_uv_map(B_UVAUTO_BOUNDS4); break;
> 	case UV_BOUNDS2_MAPPING:
> 		calculate_uv_map(B_UVAUTO_BOUNDS2); break;
> 	case UV_BOUNDS1_MAPPING:
> 		calculate_uv_map(B_UVAUTO_BOUNDS1); break;
> 	case UV_STD8_MAPPING:
> 		calculate_uv_map(B_UVAUTO_STD8); break;
> 	case UV_STD4_MAPPING:
> 		calculate_uv_map(B_UVAUTO_STD4); break;
> 	case UV_STD2_MAPPING:
> 		calculate_uv_map(B_UVAUTO_STD2); break;
> 	case UV_STD1_MAPPING:
> 		calculate_uv_map(B_UVAUTO_STD1); break;
> 	case UV_WINDOW_MAPPING:
> 		calculate_uv_map(B_UVAUTO_WINDOW); break;
> 	}
> =09
> }
>=20
> #else /* #ifndef BM_OLDCODECHECK */
> /*+++ BM my plan is to remove all this */
> /* feel free to do it after approval */
706a1201,1207
> /*+++ BM should be at least */
> 		/* but does not make very much sense */
> 		/* what i actually does is */
> 		/* choosing x,y,z axis for projetion depending on the largest normal =
component */
> 		/* but clusters all together around the center of map */
> 		break;=20
> /*--- BM  */
730d1230
<=20
804a1305,1309
> 		/*+++ BM replace this when WIP is done
> 		by=20
> 		calculate_uv_map(B_UVAUTO_XXX);
>=20
> 		*/
888a1394
> 		/*+++ BM */
889a1396,1398
> 		calculate_uv_map(B_UVAUTO_CYLINDER); /* reads the buttons */
> 		break;
>=20
892,917c1401
< 		float rotup[4][4],rotside[4][4], viewmatrix[4][4], =
finalmatrix[4][4],rotobj[4][4];
< 		int k;
< 		float upangle =3D 0.0, sideangle =3D 0.0, radius =3D 1.0;
< 		static float upangledeg =3D 0.0, sideangledeg =3D 90.0;
< 		short centermode;
< =20
< 		centermode =3D G.vd->around;
< 		/* check if we can do this, do it, otherways tell the user we can't =
and quit */
< 		switch (centermode)
< 		{
< 		case  V3D_CENTRE : /*bounding box center*/
< 			INIT_MINMAX(min, max);
<=20
< 			tface=3D me->tface;
< 			mface=3D me->mface;
< 			for(a=3D0; a<me->totface; a++, mface++, tface++) {
< 				if(tface->flag & TF_SELECT) {
< 					if(mface->v3=3D=3D0) continue; /* this is not realy a face */
<=20
< 					DO_MINMAX( (me->mvert+mface->v1)->co, min, max);
< 					DO_MINMAX( (me->mvert+mface->v2)->co, min, max);
< 					DO_MINMAX( (me->mvert+mface->v3)->co, min, max);
< 					if(mface->v4) DO_MINMAX( (me->mvert+mface->v3)->co, min, max);
< 				}
< 			}
< 			VecMidf(cent, min, max);
---
> 		calculate_uv_map(B_UVAUTO_SPHERE); /* reads  the buttons */
919,1009d1402
< 		case  V3D_CURSOR : /*cursor center*/=20
< 		{
< 			float *cursx;
< 			cursx=3D give_cursor();
< 			/* shift to objects world */
< 			cent[0]=3D cursx[0]-ob->obmat[3][0];
< 			cent[1]=3D cursx[1]-ob->obmat[3][1];
< 			cent[2]=3D cursx[2]-ob->obmat[3][2];
< 		}
< 		break;
< 		case  V3D_LOCAL : /*object center*/
< 		case  V3D_CENTROID : /*median refers to multiple objects centers. =
only one object here*/
< 			cent[0]=3D cent[1]=3D cent[2]=3D 0.0;
< 		break;
< 		default : /* covered all known modes, but if there was a new one */
< 			/* say something to the user if we can't*/
< 			okee("this operation center does not work here!");
< 			return;=20
< 		}
<=20
< 		if(mode=3D=3DUV_CYL_EX){
< 			static float cylradius =3D 1.0; /* static to remeber last user =
response */
< 			if (fbutton(&cylradius, 0.1, 90.0, "radius") =3D=3D 0) return;
< 			radius =3D cylradius;
< 		}
<=20
< 		/* get rotation of the current view matrix */
< 		Mat4CpyMat4(viewmatrix,G.vd->viewmat);
< 		/* but shifting */
< 		for( k=3D 0; k< 4; k++) {
< 			viewmatrix[3][k] =3D0.0;
< 		}
<=20
< 		/* get rotation of the current object matrix */
< 		Mat4CpyMat4(rotobj,ob->obmat);
< 		/* but shifting */
< 		for( k=3D 0; k< 4; k++){
< 			rotobj[3][k] =3D0.0;
< 		}
<=20
<    		/* never assume local variables to be zeroed */
< 		Mat4Clr(*rotup);
< 		Mat4Clr(*rotside);
<=20
< 		/* need this to compensate front/side.. against opengl x,y,z world =
definition */
< 		/* this is "kanonen gegen spatzen" i know, a few plus minus 1 will =
do here */
< 		/* i wanted to keep the reason here, so we're rotating*/
< 		/* debug helper if (fbutton(&sideangledeg, -180.0, 180, "Side =
angle") =3D=3D0) return; */
< 		sideangle =3D M_PI * (sideangledeg + 180.0) /180.0;
< 		rotside[0][0] =3D cos(sideangle);  rotside[0][1] =3D =
-sin(sideangle);
< 		rotside[1][0] =3D sin(sideangle);       rotside[1][1] =3D =
cos(sideangle);
< 		rotside[2][2] =3D 1.0;
<      =20
< 		/* debug helper if (fbutton(&upangledeg, -90.0, 90.0, "Up angle") =
=3D=3D0) return; */
< 		upangle =3D M_PI * upangledeg /180.0;
< 		rotup[1][1] =3D cos(upangle)/radius;  rotup[1][2] =3D =
-sin(upangle)/radius;
< 		rotup[2][1] =3D sin(upangle)/radius;      rotup[2][2] =3D =
cos(upangle)/radius;
< 		rotup[0][0] =3D 1.0/radius;
< 		/* calculate transforms*/
< 		=
Mat4MulSerie(finalmatrix,rotup,rotside,viewmatrix,rotobj,NULL,NULL,NULL,N=
ULL);
< 		/* now finalmatrix holds what we want */
<=20
< 		tface=3D me->tface;
< 		mface=3D me->mface;
< 		for(a=3D0; a<me->totface; a++, mface++, tface++) {   /* go for all =
faces of the given mesh */
< 			if(tface->flag & TF_SELECT) { /* if this face is selected in UI */
< 				if(mface->v3=3D=3D0) continue; /* must be ploygon with more than 2 =
vertices */
< 				/* repeating this for all 3(4) vertices sucks. better make =
function*/
< 				VecSubf(no, (me->mvert+mface->v1)->co, cent); /* shift to make =
cent the origin */
< 				Mat4MulVecfl(finalmatrix, no);
< 				if(mode=3D=3DUV_CYL_EX) tubemap(no[0], no[1], no[2], tface->uv[0], =
&tface->uv[0][1]);
< 				else spheremap(no[0], no[1], no[2], tface->uv[0], =
&tface->uv[0][1]);
< =09
< 				VecSubf(no, (me->mvert+mface->v2)->co, cent);
< 				Mat4MulVecfl(finalmatrix, no);
< 				if(mode=3D=3DUV_CYL_EX) tubemap(no[0], no[1], no[2], tface->uv[1], =
&tface->uv[1][1]);
< 				else spheremap(no[0], no[1], no[2], tface->uv[1], =
&tface->uv[1][1]);
<        =20
< 				VecSubf(no, (me->mvert+mface->v3)->co, cent);
< 				Mat4MulVecfl(finalmatrix, no);
< 				if(mode=3D=3DUV_CYL_EX) tubemap(no[0], no[1], no[2], tface->uv[2], =
&tface->uv[2][1]);
< 				else spheremap(no[0], no[1], no[2], tface->uv[2], =
&tface->uv[2][1]);
< 				n =3D 3;
<       =20
< 				if(mface->v4) {
<        =20
< 					VecSubf(no, (me->mvert+mface->v4)->co, cent);
< 					Mat4MulVecfl(finalmatrix, no);
< 					if(mode=3D=3DUV_CYL_EX) tubemap(no[0], no[1], no[2], =
tface->uv[3], &tface->uv[3][1]);
< 					else spheremap(no[0], no[1], no[2], tface->uv[3], =
&tface->uv[3][1]);
< 				n =3D 4;
1011c1404
< 				mi =3D 0; /* maximum index */
---
> 		/*--- BM */
1013,1027d1405
< 				for (i =3D 1; i < n; i++) {
< 					if (tface->uv[i][0] > tface->uv[mi][0]) mi =3D i;
< 				}
< 				for (i =3D 0; i < n; i++) {
< 					if (i !=3D mi) {
< 						dx =3D tface->uv[mi][0] - tface->uv[i][0];
< 						if (dx > 0.5) {
< 							tface->uv[i][0] +=3D 1.0;
< 						}=20
< 					}=20
< 				}=20
< 			}
< 		}
< 	}
<     break;
1066a1445,1449
> /*--- BM my plan is to remove all this */
> #endif /* #ifndef BM_OLDCODECHECK */
>=20
>=20
>=20
Index: blender/src/header_view3d.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/tuhopuu/tuhopuu2/source/blender/src/header_view3d.c,v
retrieving revision 1.5
diff -r1.5 header_view3d.c
2510,2512c2510,2514
< 	// case 3: /* uv calculation */
< 	//	uv_autocalc_tface();
< 	//	break;
---
> 	/*+++ BM */
> 	 case 4: /* uv calculation */
> 		uv_autocalc_tface();
> 		break;
> 	/*--- BM */
2543,2545c2545,2549
< 		* UV calculation :(
< 		uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Calculate UVs",		0, =
yco-=3D20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
< 	*/
---
> 		* UV calculation :(  fixed BM */
> 	/*+++ BM */
> 		uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Calculate UVs",		0, =
yco-=3D20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
> 	/*--- BM */
> =09



------=_NextPart_000_0027_01C3E068.BD02BE00--