Posted: Wed Dec 05, 2012 9:59 pm
Joined: 02 Nov 2012
Posts: 6
I am writing an exporter and hit a brick wall attempting to export UV coordinates. My UV export code is:
| Code: |
def WriteMeshUVCoordinates(Config, Mesh):
if Config.Verbose:
print(' Writing UV Coordinates')
# start UV list
Config.File.write('{}"uvList" : [ '.format(' ' * Config.WhiteSpace))
if len(Mesh.tessface_uv_textures) > 0:
Faces = Mesh.tessface_uv_textures.active.data
for index, f in enumerate(Faces):
if index != 0:
Config.File.write(', ')
if len(f.uv) == 4:
# quads
Config.File.write('{}, {}, {}, {}, {}, {}, '.format(f.uv1.x, 1.0 - f.uv1.y, f.uv2.x, 1.0 - f.uv2.y, f.uv3.x, 1.0 - f.uv3.y))
Config.File.write('{}, {}, {}, {}, {}, {}'.format(f.uv1.x, 1.0 - f.uv1.y, f.uv3.x, 1.0 - f.uv3.y, f.uv4.x, 1.0 - f.uv4.y))
elif len(f.uv) == 3:
# triangles
Config.File.write('{}, {}, {}, {}, {}, {}, '.format(f.uv1.x, 1.0 - f.uv1.y, f.uv2.x, 1.0 - f.uv2.y, f.uv3.x, 1.0 - f.uv3.y))
# end UV list
Config.File.write(']')
if Config.Verbose:
print(' Done')
|
I am unsure if it is related to how I export my indices or not, so here is the index export code too:
| Code: |
def WriteMeshTriList(Config, Mesh):
if Config.Verbose:
print(' Writing Mesh Triangle List.')
# start triangle list
Config.File.write('{}"triList" : [ '.format(' ' * Config.WhiteSpace))
for index, face in enumerate(Mesh.tessfaces):
# if not the first element in the list
if index != 0:
Config.File.write(', ')
if len(face.vertices) == 4:
# quad
# should sort by face.center
Config.File.write('{}, {}, {}, '.format(face.vertices[0], face.vertices[1], face.vertices[2]))
Config.File.write('{}, {}, {}'.format(face.vertices[0], face.vertices[2], face.vertices[3]))
if len(face.vertices) == 3:
# triangles :D!
# should sort by face.center
Config.File.write('{}, {}, {}'.format(face.vertices[0], face.vertices[1], face.vertices[2]))
# end triangle list
Config.File.write(' ]')
if Config.Verbose:
print(' Done')
|
An image showing the problem is available here:
https://www.dropbox.com/s/6qtjjrvvf8qyjm5/zomb_uvmishap.png
Obviously the right is what it should look like.
It's pretty clear my UV are messed up
I'd really appreciate any help, as this project has already taken much longer than anticipated. Thanks!
_________________
<3
Posted: Thu Dec 06, 2012 5:36 am
Joined: 02 Nov 2012
Posts: 6
I think I'm on the right track... I think it has to do with the coordinate spaces. I'm not entirely sure how to deal with different coordinate spaces. I'll do some more googling but any input so I know I'm on the right track would be super helpful.
_________________
<3
Posted: Thu Dec 06, 2012 2:02 pm
Joined: 05 Apr 2009
Posts: 696
you flip the Y coordinate, which is usually required, but could it be that your target format expects this like it is originally in blender? or maybe X flipped or something like this?
note that 3d view may differ from the actual texture mapping, e.g. you need to change coordinates from Generated to UV if you use GLSL shading to see the actual uv mapping, but in multitexture mode it doesn't seem to be required...
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Posted: Thu Dec 06, 2012 5:53 pm
Joined: 02 Nov 2012
Posts: 6
I'm pretty confident I need to flip the V coordinate, because it wasn't showing anything before I did that. And I'm using GLSL in Blender shading so that shouldn't be the problem. That is good to know though, so thank you. If everything looks correct maybe I messed up my rendering code, but I haven't been able to find any problems yet... I'm super confused.
_________________
<3
Posted: Thu Dec 06, 2012 10:07 pm
Joined: 02 Nov 2012
Posts: 6
Just found the problem I think. I'm exporting the UV coordinates for each index, but it should be per vertex right?? I just removed my index array and changed my vertex array to not use the index buffer and it worked. It's been a very long time since I did any rendering code. Hope my ignorance helped someone out there. And thanks again CoDEmanX for your input.
_________________
<3
Posted: Thu Dec 06, 2012 10:28 pm
Joined: 05 Apr 2009
Posts: 696
UVs are actually stored per loop (not vertex), but if you use tessface_uv_texture, then it's the old style (uv1-uv4) and a little different.
good to hear you got it sorted!
_________________
I'm sitting, waiting, wishing, building Blender in superstition...