Help with texture coordinates?

General talk about the map making process.
Post Reply
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Help with texture coordinates?

Post by LouMan »

I have been trying to utilize the UV texture functions of my modeler to apply materials evenly to tripled vertices, etc. and I have been stuck for a while due to my own ignorance :?

The following is a simple exported obj file of a cube with UV textures applied to it:

####
#
# OBJ File Generated by LightWave3D
# LightWave3D OBJ Export v2.2
#
####
# Object: Cube.lwo
#
# Vertices: 8
# Points: 0
# Lines: 0
# Faces: 6
# Materials: 6
#
####

o Cube.lwo

# Vertex list

v -2.5 -2.5 0
v -2.5 -2.5 -5
v -2.5 2.5 -5
v -2.5 2.5 0
v 2.5 -2.5 0
v 2.5 -2.5 -5
v 2.5 2.5 -5
v 2.5 2.5 0

# Face list

g
usemtl xminus
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
f 4/-1 3/-2 2/-3 1/-4
g
usemtl yminus
vt -2.000000 0.500000
vt 3.000000 0.500000
vt 3.000000 5.500000
vt -2.000000 5.500000
f 2/-1 6/-2 5/-3 1/-4
g
usemtl zplus
vt -2.000000 -2.000000
vt 3.000000 -2.000000
vt 3.000000 3.000000
vt -2.000000 3.000000
f 3/-1 7/-2 6/-3 2/-4
g
usemtl yplus
vt -2.000000 0.500000
vt -2.000000 5.500000
vt 3.000000 5.500000
vt 3.000000 0.500000
f 8/-1 7/-2 3/-3 4/-4
g
usemtl zminus
vt -2.000000 -2.000000
vt -2.000000 3.000000
vt 3.000000 3.000000
vt 3.000000 -2.000000
f 5/-1 8/-2 4/-3 1/-4
g
usemtl xplus
vt 0.500000 -2.000000
vt 0.500000 3.000000
vt 5.500000 3.000000
vt 5.500000 -2.000000
f 6/-1 7/-2 8/-3 5/-4

# End of file

When I run this through the model tool I get this:

mesh #
# vertices: 8
# normals: 0
# texcoords: 4
# faces: 6

vertex -2.500000 2.500000 5.000000
vertex -2.500000 2.500000 0.000000
vertex -2.500000 -2.500000 0.000000
vertex -2.500000 -2.500000 5.000000
vertex 2.500000 -2.500000 0.000000
vertex 2.500000 -2.500000 5.000000
vertex 2.500000 2.500000 0.000000
vertex 2.500000 2.500000 5.000000
texcoord 2.500000 5.000000
texcoord 0.000000 2.500000
texcoord 2.500000 2.500000
texcoord -2.500000 0.000000
face
vertices 0 1 2 3
texcoords 0 1 2 3
matref xminus
endface
face
vertices 2 4 5 3
texcoords 0 1 2 3
matref yminus
endface
face
vertices 1 6 4 2
texcoords 0 1 2 3
matref zplus
endface
face
vertices 7 6 1 0
texcoords 0 1 2 3
matref yplus
endface
face
vertices 5 7 0 3
texcoords 0 1 2 3
matref zminus
endface
face
vertices 4 6 7 5
texcoords 0 1 2 3
matref xplus
endface
end

Two things that I noticed right off the bat:

1) The "vt" components of my exported obj file only have 2 vertices (assuming that these are U and V coords). I haven't figured out how to get the modeler to remedy this. I plead third degree ignorance on UV mapping. :oops:

2) The converted bzw file uses the same texcoords for all faces. I assume this is due to my modeler's obj output structure?

If anyone could enlighten me on what the "vt" component of an obj file describes, it would help a great deal. I am capable of creating my own conversion program if I know the basics of how to translate the "vt" components into texture coordinates. I am sorry for my lack of knowledge with texture mapping :(

Thanks!
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Post by JeffM »

the VT is the actual UV coordinate. it represnts a point on the texture. Since textures are 2d images, they only have 2 values.

The go from 0 to 1, where 0 is one side of the texture and 1 is the other side. So a position of 0.5 would be in the middle of the texture ( regarless of the texture's size in pixels ). values over 1 or less then 0, represent a texture that repeats more then one time across a face.

The format lightwave is making seems a little wierd. I usualy see all the VTs for an object together just like the Normals and Vert data. It also looks like it asumes that the indexes reset on every "usemtl" line, and tha'ts not the case.the indexes you have are wierd, they are negitive in places, and that is NOT right for an index. I'm not sure if the model tool supports that type of format, or if it's even a valid one.

this is an example of the types of obj files I am used to ( the kinds that model tool was made around ).

# Wavefront OBJ exported by MilkShape 3D

mtllib box.mtl

v -1.011785 0.996000 1.007936
v -1.011785 -1.019873 1.007936
v 0.988215 0.996000 1.007936
v 0.988215 -1.019873 1.007936
v 0.988215 0.996000 -1.007936
v 0.988215 -1.019873 -1.007936
v -1.011785 0.996000 -1.007936
v -1.011785 -1.019873 -1.007936
# 8 vertices

vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
# 4 texture coordinates

vn 0.000000 0.000000 1.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 -1.000000 0.000000
# 6 normals

g Box01
usemtl Material01
s 1
f 1/1/1 2/2/1 3/3/1
f 2/2/1 4/4/1 3/3/1
s 2
f 3/1/2 4/2/2 5/3/2
f 4/2/2 6/4/2 5/3/2
s 1
f 5/1/3 6/2/3 7/3/3
f 6/2/3 8/4/3 7/3/3
s 2
f 7/1/4 8/2/4 1/3/4
f 8/2/4 2/4/4 1/3/4
s 3
f 7/1/5 1/2/5 5/3/5
f 1/2/5 3/4/5 5/3/5
f 2/1/6 8/2/6 4/3/6
f 8/2/6 6/4/6 4/3/6
# 12 triangles in group

# 12 triangles total

now there may be other ways to define it, maybe we need to change model tool to support it, but I'd like to know how lightwave thinks it's suposed to work, what do the negive indexes mean?
ImageJeffM
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post by LouMan »

Thank you for the information - what you have written makes sense. I'm not sure what's up with the LightWave exported .obj files - I'll play around with it a little more to see if I can come to understand it :roll:

The key question I have is this:

How are the .obj vt coordinates translated into .bzw texcoords in the existing model tool? If I can understand this, I can work it into my own obj-bzw tool for LightWave generated .obj files and play with it until it (hopefully) works.

Thank you again! :)
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post by LouMan »

btw - I looked some info of obj files and found this from a website (http://ftp.ora.com/gff/CDROM/GFF/TEXTON ... AVEOBJ.HTM):

"It is also possible to reference points using negative indices. This makes it easy to describe the points in a face, then the face, without the need to store a large list of points and their indexes. In this way, "v" commands and "f" commands can be interspersed.

v -0.500000 0.000000 0.400000
v -0.500000 0.000000 -0.800000
v -0.500000 1.000000 -0.800000
v -0.500000 1.000000 0.400000
f -4 -3 -2 -1"
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Post by JeffM »

well model tool dosn't support negitive indexes.

we just take thte VT lines and make them rigt into TextCoord lines in the bzw, it's prety much a 1 to 1 maping.

bzw format is somewhat similar to obj in how hit handles geomery and UV coords.

model tool would need to be changed to support obj formats like this. do you know if there is a place to get the specification of the obj format that describes all the wacky stuff like this?
ImageJeffM
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post by LouMan »

The website indicated in my previous post is decent as far as describing .obj specifications. I did a search on Yahoo for "Wavefront .obj specifications" and had a number of good hits.

By the way, I have altered my previous conversion tool and it now (so far) converts the texcoords properly for LightWave .obj files. I had some trouble for a while until I noticed that each face's texture coordinates were transposed in my bzw file - once I reversed them - voila! - it seems to work.

Thanks for all of your help!
User avatar
LouMan
Chief Sgt. of Cartography
Chief Sgt. of Cartography
Posts: 338
Joined: Mon Jan 31, 2005 3:05 am
Location: Michigan, USA

Post by LouMan »

Attached is a pdf file (zipped) that describes the .obj specification in great detail. I haven't looked through all of it, but it seems very complete.
Attachments
obj_spec.zip
obj specification
(101.76 KiB) Downloaded 148 times
Post Reply