RiotGODD

04-08-2001, 08:10 AM

Ive just read abobt loading .t3d files, but I cant understand how to convert U and V vectors into "usual" UV values. Can anyone explane it?

View Full Version : Unreal .t3d texture coordinats

RiotGODD

04-08-2001, 08:10 AM

Ive just read abobt loading .t3d files, but I cant understand how to convert U and V vectors into "usual" UV values. Can anyone explane it?

Tim Stirling

04-08-2001, 08:37 AM

Something to note that the uv coordiantes are based on world coords. This means that something twice as large will have twice the texture uv value if the same size texture was used. The vertices are all usually powers of 2 and are like the textures (i.e 128, 256, 512). If the texture being used is 256 pixcels wide/tall then if one vertex was at 0 the u/v would be = 0 and if the other was at 512 then the u/v would be 2 (i.e vertex / texture size) if the texture was only 128 big then the coord would be 4 - get it. The uv coords given show the plane that the texturing is on - this is kind of hard to explain but it tells you what axis the u or v are proportional to: if U is ampped along the x axis and v along the y axis etc. for vertical planes. You should see what happens for a horizonatal planes- do you map u to x or z - this is what the uv coords given are for. They also give the scaling of the texture. I did lots of testing to work out a lot of the stuff but have not time to explain it to you. I might/will add more later. got ot go .....

Tim

Tim

DFrey

04-08-2001, 08:54 AM

Don't you just take the dot product of the U vector with the vertex to get the u texture coordinate, likewise for the V vector? Then add in the pan values if any. The resulting texture coordinates would then need to be divided by the texture dimensions to get them into GL's floating point format of course. Did I miss a step? (I haven't actually done this yet, but do plan too.)

RiotGODD

04-09-2001, 02:35 AM

So, the formula is:

V = DotProduct(vector, Vvector) / TextureHeight;

U = DotProduct(vector, Uvector) / TextureWidth;

Am I right?

[This message has been edited by RiotGODD (edited 04-09-2001).]

V = DotProduct(vector, Vvector) / TextureHeight;

U = DotProduct(vector, Uvector) / TextureWidth;

Am I right?

[This message has been edited by RiotGODD (edited 04-09-2001).]

Tim Stirling

04-09-2001, 09:52 AM

DFrey: you may well be correct, I have never tried any method as of yet. I have been looking at the process of calculating these UV coords and although I know the basics but I am a little confused when calculating the coords when I don't know how the plane is situated, in my level editor when I add a cube I can work it out but not for every situation ( a slope). Any hints, links ?? scaling and offsets/panning are fine but i also don't know about rotations of the texture?

RiotGODD: if DFrey is correct (which I think he is) then your formulae are correct (if you change vector to vertex, only minor) and then you add the panning.

I would be very interested in finding out how you get on as such a loading facility is much needed and my c programming isn't that good (I would only use any code for reference!).

Tim http://www.opengl.org/discussion_boards/ubb/smile.gif

RiotGODD: if DFrey is correct (which I think he is) then your formulae are correct (if you change vector to vertex, only minor) and then you add the panning.

I would be very interested in finding out how you get on as such a loading facility is much needed and my c programming isn't that good (I would only use any code for reference!).

Tim http://www.opengl.org/discussion_boards/ubb/smile.gif

RiotGODD

04-10-2001, 10:09 AM

Tim Stirling:You asked for code? Here it is:

//it doesnt seem to be the optimal way, but it works!

int count(FILE *f,char* end, char* lookfor)

{

char data[255];

int Found = 0;

do

{

fscanf(f,"%s",&data);

if(strcmp(data,lookfor)==0)

{

Found += 1;

}

}while(!(strcmp(data,end)==0));

return Found;

}

void readstr(FILE *f,char word[])

{

static char data[255];

do

{

fscanf(f,"%s",&data);

}while(!(strcmp(data,word)==0));

}

void LoadWORLD(char *OpenFile,WORLD *w)

{

FILE* f;

VECTOR U, V, temp;

int NumPoly, NumVertex;

f = fopen(OpenFile, "r");

fscanf(f,"Begin PolyList");

NumPoly = count(f,"PolyList", "Begin");

w->NumPoly = NumPoly;

w->polies = new POLYGON[NumPoly];

std::cout<<"Number of polies: "<<NumPoly<<'\n';

fclose (f);

f = fopen(OpenFile, "r");

fscanf(f,"Begin PolyList");

for(int i = 0; i<NumPoly; i++)

{

NumVertex = count(f,"End", "Vertex");

w->polies[i].NumVectors = NumVertex;

w->polies[i].vector = new TVECTOR[NumVertex];

std::cout<<"Polygon "<<i<<" has "<<NumVertex<<" vectors"<<'\n';

}

fclose (f);

f = fopen(OpenFile, "r");

fscanf(f,"Begin PolyList");

for(i = 0; i<NumPoly; i++)

{

readstr(f, "TextureU");

fscanf(f,"%f,%f,%f",&U.x, &U.z, &U.y);

U.z = -U.z;

readstr(f, "TextureV");

fscanf(f,"%f,%f,%f",&V.x, &V.z, &V.y);

V.z = -V.z;

for(int n = 0; n<w->polies[i].NumVectors; n++)

{

readstr(f, "Vertex");

fscanf(f,"%f,%f,%f",&w->polies[i].vector[n].x, &w->polies[i].vector[n].z, &w->polies[i].vector[n].y);

w->polies[i].vector[n].z = -w->polies[i].vector[n].z;

temp.x = w->polies[i].vector[n].x;

temp.y = w->polies[i].vector[n].y;

temp.z = w->polies[i].vector[n].z;

w->polies[i].vector[n].u = DotProduct(U, temp) / 256;

w->polies[i].vector[n].v = DotProduct(V, temp) / 256;

}

}

fclose (f);

}

Feel free to ask every thing that is unclear.

//it doesnt seem to be the optimal way, but it works!

int count(FILE *f,char* end, char* lookfor)

{

char data[255];

int Found = 0;

do

{

fscanf(f,"%s",&data);

if(strcmp(data,lookfor)==0)

{

Found += 1;

}

}while(!(strcmp(data,end)==0));

return Found;

}

void readstr(FILE *f,char word[])

{

static char data[255];

do

{

fscanf(f,"%s",&data);

}while(!(strcmp(data,word)==0));

}

void LoadWORLD(char *OpenFile,WORLD *w)

{

FILE* f;

VECTOR U, V, temp;

int NumPoly, NumVertex;

f = fopen(OpenFile, "r");

fscanf(f,"Begin PolyList");

NumPoly = count(f,"PolyList", "Begin");

w->NumPoly = NumPoly;

w->polies = new POLYGON[NumPoly];

std::cout<<"Number of polies: "<<NumPoly<<'\n';

fclose (f);

f = fopen(OpenFile, "r");

fscanf(f,"Begin PolyList");

for(int i = 0; i<NumPoly; i++)

{

NumVertex = count(f,"End", "Vertex");

w->polies[i].NumVectors = NumVertex;

w->polies[i].vector = new TVECTOR[NumVertex];

std::cout<<"Polygon "<<i<<" has "<<NumVertex<<" vectors"<<'\n';

}

fclose (f);

f = fopen(OpenFile, "r");

fscanf(f,"Begin PolyList");

for(i = 0; i<NumPoly; i++)

{

readstr(f, "TextureU");

fscanf(f,"%f,%f,%f",&U.x, &U.z, &U.y);

U.z = -U.z;

readstr(f, "TextureV");

fscanf(f,"%f,%f,%f",&V.x, &V.z, &V.y);

V.z = -V.z;

for(int n = 0; n<w->polies[i].NumVectors; n++)

{

readstr(f, "Vertex");

fscanf(f,"%f,%f,%f",&w->polies[i].vector[n].x, &w->polies[i].vector[n].z, &w->polies[i].vector[n].y);

w->polies[i].vector[n].z = -w->polies[i].vector[n].z;

temp.x = w->polies[i].vector[n].x;

temp.y = w->polies[i].vector[n].y;

temp.z = w->polies[i].vector[n].z;

w->polies[i].vector[n].u = DotProduct(U, temp) / 256;

w->polies[i].vector[n].v = DotProduct(V, temp) / 256;

}

}

fclose (f);

}

Feel free to ask every thing that is unclear.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.