Hey ho, I've been trying for ages to figure out how to get the following script to export UV's properly. Currently they all come out as 0.0. Someone elses post mentioned that it doesn't work with NMesh, or something, but it does with Mesh? I dont *really* know python, and it took me a while to make this script from looking at other peoples export scripts, and the VERY inadequate phython API docs. All comments appreciated (except "Wib Wab Woo").
---------------------------------
| Code: |
import Blender
Filename = "out.mot"
###################################
File = open(Filename, "w")
print "Opened %s\nExporting" % Filename
for Obj in Blender.Scene.getCurrent().getChildren():
if Obj.getType() == "Mesh":
Mesh = Obj.getData()
File.write("Mesh\n\n")
for Vertex in Mesh.vertices:
File.write( " Vertex %s %s %s\n" % (Vertex.co[0], Vertex.co[1], Vertex.co[2]) )
File.write( " Normal %s %s %s\n" % (Vertex.no[0], Vertex.no[1], Vertex.no[2]) )
File.write( " UV %s %s\n" % (Vertex.uvco[0], Vertex.uvco[1]) )
for Face in Mesh.faces:
if len(Face.v) == 3: # Triangle
File.write(" Triangle %s %s %s\n" % (Face.v[0].index, Face.v[1].index, Face.v[2].index))
elif len(Face.v) == 4: # Quad
File.write(" Quad %s %s %s %s\n" % (Face.v[0].index, Face.v[1].index, Face.v[2].index, Face.v[3].index))
print "Exported"
File.close()
|
Hi
Here is a little prog I made to show Object data.
It may not be 100% right as I am a Python newbie, but I reckon you need the face.uv part.
# Print object data
import Blender
objects = Blender.Object.GetSelected()
object = objects[0] # this better be a mesh
objectname=object.name
meshname = object.data.name #or = objects[0].data.name
data = object.data #or = objects[0].data
faces = data.faces #or = objects[0].data.faces
vertices = data.verts #or = objects[0].data.verts
m = Blender.Mesh.get(objectname)
v = m.verts[0]
print v
#v.loc[0](1.0,1.0,1.0)
print"\n"
print "-----OBJECT DATA------------"
print "Object " + str(object)
print "Object Name " + str(objectname)
print "Data " + str(data)
print "Meshname " + str(meshname)
print "Faces " + str(faces)
print "No. of faces " + str(len(faces))
print "No. of verts " + str(len(vertices))
for face in faces:
facenum = 1
vertnum = 1
print "Face " + str(facenum)
print " Texture co-ords " + str(face.uv)
for vertex in face:
print " Vert " + str(vertnum)
print " Vert co-ords " + " : " + str(vertex.co[0]) + ", " + str(vertex.co[1]) + ", " + str(vertex.co[2])
print " Normal co-ords " + ": " + str(vertex.no[0]) + ", " + str(vertex.no[1]) + ", " + str(vertex.no[2])
vertnum += 1
facenum +=1
Yeah I think part of my problem, is that blender stores UV coords for each vertex of each face, so adjacent faces dont have to use adjacent parts of the texture. I (well, OpenGL), want it so that each vertex has its own UV coords and that they are the same for all the faces it is part of.
Oh well, I guess I can just remove the duplicates (because for my particular mapping, the vertices only have one set of UV coords....) Stupid that the thing I wrote doesn't work though...
Hi
Just been reading up on texture coords and it seems .uvco is the coord for a 'sticky' texture, and so will always be 0.0, and .uv is for an 'orco' texture.
By the way in your Python prog what does the index in say (Face.v[0].index) do? Stupid newbie question I know.
Cheers
All the vertices of the mesh are store in an array.
Triangles are then constructed by specifying three offsets into the array to select 3 vertices.
This saves space ('cause the vertices are often duplicated at the edge of faces), and probably speeds up rendering a bit, (and is the format that OpenGL wants)...