I’m developing a very simple game engine tutorial for italian games developers community 8) , i decided to use blender as the 3d modeler , exporting the world created with it and then load in my game engine.
But it seems to me there’s no way to export uv coords and texture names (filenames), since the variables (mesh).texture and (mesh).uvcoords are always None.
Anyway in a lot of export scripts I have downloaded (RenderMan, for example, but also others simpler) things appear like I CAN export textures and uvcoords.
Are these scripts developed in a way that WHEN (if) Blender’s scripting API will support textures and uvcoords, they work, or I didn’t understand something?
Finally, since Blender is waiting to know what it will be , do you think export scripts will ever support textures and uvcoords?
In 2.25 (maybe 2.23 as well) do something like this:
import Blender
iterate through your mesh faces and export the uv property
for yourMeshFace in yourMesh.faces:
for i in range(len(yourMeshFace.v)):
if yourMesh.hasFaceUV():
yourExportFile.write(“UV=%s,%s” % (yourMeshFace.uv[i][0],
yourMeshFace.uv[i][1]))
this script displays all the vertices (8 vertices, 3 number each, 24 numbers), all the faces (all quads, but the faces are made up of 6 numbers, the last two are 0), but [] instead of texcoords and None instead of the name of the texture
If you use the NMesh module from the Blender module (NOT Blender210), the object returned by NMesh.GetRaw() will have a property called hasFaceUV, and the objects in the faces list will have a property called uv, which is a list of the uv coordinates of the face.
For the Blender module, you can find the texture name in the face datablock, every face can have another texture. A face has an image datablock where you can find it’s name, although unlike Blender210 mesh.texture, this is not the full path or even the full name of the image, but only the bit you can see in the image menu of the uv-editor for instance.
object = Blender.Object.Get(object_name)
mesh = object.data
used_textures = []
if mesh.hasFaceUV():
for face in mesh.faces:
if face.image:
name = face.image.name
if name not in used_textures: used_textures.append(name)
print used_textures
This will return a list of all textures used by the mesh.