export uv coordinates data to XML issue

   1688   0   0
User Avatar
Member
101 posts
Joined: Feb. 2015
Offline
Hi, I am really banging my head against the wall with an issue here:
I am writing some python scripts to export geometry data to Cycles renderer, under a simple xml file.
As far as simple geometry is concern no problem about that.
But I have a really hard time figuring out how to export uvs.
There is not much infos on the XML api for Cycles standalone. But I have read some examples of exporters for other packages


for v in mesh.vertices:
P += “%f %f %f ” % (v.co, v.co, v.co)

verts_and_uvs = zip(mesh.tessfaces, mesh.tessface_uv_textures.active.data)

for f, uvf in verts_and_uvs:
vcount = len(f.vertices)
nverts += str(vcount) + “ ”

for v in f.vertices:
verts += str(v) + “ ”

uvs += str(uvf.uv1) + “ ” + str(uvf.uv1) + “ ”
uvs += str(uvf.uv2) + “ ” + str(uvf.uv2) + “ ”
uvs += str(uvf.uv3) + “ ” + str(uvf.uv3) + “ ”
if vcount==4:
uvs += “ ” + str(uvf.uv4) + “ ” + str(uvf.uv4) + “ ”


node = etree.Element('mesh', attrib={'nverts': nverts.strip(), ‘verts’: verts.strip(), ‘P’: P, ‘UV’ : uvs.strip()})



Below is my houdini version of that.
The script runs fine. But uvs not rendered correctly in Cycles.
I really can't figure out what I am doing wrong.
Does anybody have a clue ?


for v in geo.points():

P += “%s %s %s ” % (v.position(), v.position(), v.position())

uvsList =
for prim in geo.prims():
subList =
for vert in prim.vertices():
subList.append(vert.point().attribValue('uv'))
uvsList.append(subList)

print uvsList
prims_and_uvs = zip(geo.prims(), uvsList)



for prim, uvsList in prims_and_uvs:
vcount = len(prim.vertices())
nverts += str(vcount) + “ ”

for v in prim.vertices():
verts += str(v.point().number()) + “ ”

uvs += str(uvsList) + “ ” +str(uvsList) + “ ”
uvs += str(uvsList) + “ ” +str(uvsList) + “ ”
uvs += str(uvsList) + “ ” +str(uvsList) + “ ”

if vcount == 4:
uvs += str(uvsList) + “ ” +str(uvsList) + “ ”

node = etree.Element('mesh', attrib={'nverts': nverts.strip(), ‘verts’: verts.strip(), ‘P’: P, ‘UV’ : uvs.strip()})


https://vimeo.com/user43710534 [vimeo.com]
  • Quick Links