PDA

View Full Version : Texture Mapping(Planar mapping)


figgy
25th October 2003, 08:58 PM
Please help me, this is doing my head in!!
Below is an extract from an Unreal T3D file i am trying to convert to AC3D.
The geometry looks fine, but i am having touble with calculating the Texture coords for each poly.

Begin Polygon Item=Cap Texture=Terminal_A01
Origin +00212.077362,+00512.000000,-00128.000000
Normal +00000.000000,+00000.000000,-00001.000000
TextureU -00000.707107,-00000.707107,+00000.000000
TextureV -00000.707107,+00000.707107,+00000.000000
Vertex +00212.077362,+00512.000000,-00128.000000
Vertex +00512.000000,+00212.077347,-00128.000000
Vertex +00512.000000,-00212.077393,-00128.000000
Vertex +00212.077255,-00512.000061,-00128.000000
Vertex -00212.077347,-00512.000000,-00128.000000
Vertex -00512.000061,-00212.077179,-00128.000000
Vertex -00511.999969,+00212.077438,-00128.000000
Vertex -00212.077347,+00512.000000,-00128.000000
End Polygon

Origin is the first vertex in the poly.
TextureU and V are the Vectors describing the cordinate system(Normalized)

Here's my code(it doesn't work)

//temp is the vertex - the origin
temp.x = (vertex.x - origin.x);
temp.y = (vertex.y - origin.y);
temp.z = (vertex.z - origin.z);
U = Dot(temp,textureU)/128;//128 is the Bitmap Width
V = Dot(temp,textureV)/128;//128 is the Bitmap Height

Any ideas? The internet is hopeless!

Thanx Mark

Dennis
25th October 2003, 11:10 PM
What kind of results are you getting (visually)?

Your code looks solid - I plugged the verts/coords into a spreadsheet using your same values, put that into AC3D, and the results look normal. Sounds like it may just be an implementation problem in your code?

Here are the texture coordinates I got for points 1 through 8 using your formula:

0 0
8.28641E-08 -3.313709408
2.343146846 -5.656856171
5.656856928 -5.656855746
8.000002592 -3.313709408
8.000002001 1.34792E-06
5.656855409 2.343146924
2.343146592 2.343146592


If the code's not that large, maybe you could post the function(s) that generates the coordinates?

Dennis

figgy
27th October 2003, 04:39 PM
:D Thanks Dennis, I thought the problem was with my formula.
When i ran it with a textured rectangle it looked fine. When i ran it with anything else, everthing went screwy.

What i'd done was to ovewrite every V index in my UV array with my U value.

BrushUV[index] = U;
BrushUV[index+1] = V;

index++; should have been index+=2; duh!!!

Thanks for putting on the right track.

regards

Mark