Skip to main content
gamedev.net
🔒 Locked

UV Coordinates in MaxScript

Started by rjwr10 1 reply 1.6k views
Original Post
rjwr10
rjwr10
Hey all, I''m writing a maxscript file to export Max files to the format I want them in, it''s going to be pretty standard, but when exporting the texture coordinates for every face''s vertices, I used something like this: ... in somefunction ExportMesh format "uvcoords %\n" m.numtverts to: outstream for i=1 to m.numtverts do ( local v = gettvert m i format " % % 0 \n" v.x v.y to: outstream ) .. so this is done for every face in the current mesh being exported... I''m only doing UV coordinates, so no W, which is why i dont use the v.z, so... my problem is, the coordinates that are being output to file aren''t in the range of 0.0f to 1.0f.. they''re actually arn''t anywhere near that range. So i figure MAX does things a little differently... (btw this is 3d studio max 4).. does anyone know how I can convert these texture coordinates to the DirectX 0..1 range? To simplify things, faces are only allowed 3 vertices in my engine, so basically triangles only... my structure goes something like this: struct sface { int m_iInds[3]; //indices to vertex list held one level up float m_fU[3], m_fV[3]; // *snip* everything else like diffuse, normals, etc.. }; Everything else in my script works perfectly, my engine loads the geometry correctly and can render it w/ the diffuse/specular colors... just w/o texture info, and if I feed it texture coords or use directx autogenerate UV coords, the textures are mapped, they just don''t display the way I want them to... (w/ the coordinates from MAX).... so any help would be much appreciated thanks, rj
dabx11
dabx11
Been awhile since I wrote a max script..but here is part of an exporter I made...

Max has like a buffer of UV values..and each triangle has 3 indexes to the buffer....Kind of like Vertex and Index buffers..



try (
print "<TEXCOORDS>" to:file
print o[i].NumTVerts to:file
for v = 1 to o[i].NumTVerts do (
u = gettvert o[i] v
print u to:file
)
)
catch (print "Error...Texcoords")

try (
if o[i].NumTVerts != 0 then (
print "<TEXFACES>" to:file

for f = 1 to o[i].NumFaces do (
ti = gettvface o[i] f
print ti to:file
)
)
)
catch (print "Error...TexFaces")





Here is the output for a simple box from my exporter...



"<MESH>"
"Box01"
[184.0,228.0,153.0]
"<VERTS>"
8
[-10.8372,-12.1117,0]
[9.1817,-12.1117,0]
[-10.8372,9.46492,0]
[9.1817,9.46492,0]
[-10.8372,-12.1117,23.5746]
[9.1817,-12.1117,23.5746]
[-10.8372,9.46492,23.5746]
[9.1817,9.46492,23.5746]
"<FACES>"
12
[1.0,3.0,4.0,0.0,0.0,-1.0,2]
[4.0,2.0,1.0,0.0,0.0,-1.0,2]
[5.0,6.0,8.0,0.0,0.0,1.0,4]
[8.0,7.0,5.0,0.0,0.0,1.0,4]
[1.0,2.0,6.0,0.0,-1.0,0.0,8]
[6.0,5.0,1.0,0.0,-1.0,0.0,8]
[2.0,4.0,8.0,1.0,0.0,0.0,16]
[8.0,6.0,2.0,1.0,0.0,0.0,16]
[4.0,3.0,7.0,0.0,1.0,0.0,32]
[7.0,8.0,4.0,0.0,1.0,0.0,32]
[3.0,1.0,5.0,-1.0,0.0,0.0,64]
[5.0,7.0,3.0,-1.0,0.0,0.0,64]
"<TEXCOORDS>"
12
[0,0,0]
[1,0,0]
[0,1,0]
[1,1,0]
[0,0,0]
[1,0,0]
[0,1,0]
[1,1,0]
[0,0,0]
[1,0,0]
[0,1,0]
[1,1,0]
"<TEXFACES>"
[10,12,11]
[11,9,10]
[9,10,12]
[12,11,9]
[5,6,8]
[8,7,5]
[1,2,4]
[4,3,1]
[5,6,8]
[8,7,5]
[1,2,4]
[4,3,1]
"<\MESH>"
"<ENDGEO>"




rjwr10
rjwr10
Hey, thanks for the quick reply.

Yea I know about the indexed texture stuff, I forgot to put that part of my code in there, but I do get the texture indices for the faces and then once its all loaded, get the actual texture coordinate values for each face. Thanks again, but I think i''m having a different problem

-rj

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.