Isn't it any way to export uvcoords and texture names?


(madmage) #1

Hi everybody :smiley:

I’m developing a very simple game engine tutorial for italian games developers community 8) , i decided to use blender as the 3d modeler :stuck_out_tongue: , 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 :frowning: , do you think export scripts will ever support textures and uvcoords?


(Briggs) #2

You can get acess to the UV coordinate of the mesh via the 2.1 python API.

‘import Blender 210’


(Guinness) #3

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]))


(madmage) #4

in my version of Blender (2.23):

  1. there is no function hasFaceUV() in the object face
  2. there are no face.v, nor face.uv
  3. there are mesh.texcoords but are always [] and mesh.texture that is always None
  4. those things are in Blender210 module, NOT in Blender module

so, now… where can i download 2.25 version? is it possible that ONLY in 2.25 i can export textures and texture uv ?[/quote]


(madmage) #5

here is what i’ve done:

  1. i made a cube (SPACE, Add->Mesh->Cube),
  2. then i went to materials and create a new material,
  3. then i went to textures and create a new texture (all this with the mesh selected)
    4 )now, i set the texture to image and load a jpeg image
  4. if i add a lamp somewhere and render, my cube is textured
  5. i go to material and set the mapping of the texture to cube, so my image displays properly

now, the script:


import Blender210

mesh = Blender210.getMesh("Cube")

print "Vertices: %s" % mesh.vertices
print "Faces: %s" % mesh.faces
print "TexCoords (UVCoords): %s" % mesh.texcoords
print "Texture: %s" % mesh.texture

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


(theeth) #6

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.

Martin


(madmage) #7

ok, i found the functions… but they say i have NO uv coord… (hasFaceUV returns 0)… and, anyway, the texture filename?

may one of you send me a simple example with a simple textured cube and a very simple script that exports the texture filename and the uvcoords?

thanks a lot for the help


(wiseman303) #8

here is what i’ve done:

  1. i made a cube (SPACE, Add->Mesh->Cube),
  2. then i went to materials and create a new material,
  3. then i went to textures and create a new texture (all this with the mesh selected)
    4 )now, i set the texture to image and load a jpeg image
  4. if i add a lamp somewhere and render, my cube is textured
  5. i go to material and set the mapping of the texture to cube, so my image displays properly

That is your problem, You have to UV map the mesh. Using materials won’t work.

Search the forums for UV, and you should find more info.


(madmage) #9

ok… it’s strange to me all this… but THIS works, finally… the UV mapping is a bit confusing for me… but i’ll find information on the net (links?)

now, why in the other way the UV coords aren’t memorized?

and, moreover, how can i get the texture filename?


(madmage) #10

ok, i’ve answered myself… using Blender210 I can print it with:

mesh = Blender210.getMesh("Cube")

print mesh.texture

and anyway in this case (with uvmapping) the uv coords could be displayed with:

print mesh.texcoords

as i expected…

only for completeness sake, where is the texture filename using Blender (and not Blender210) module?

two more little questions, a little ot, and i go to continue my tutorial:

  1. how can i make [] brackets in the text window in blender (and also the #)?

  2. i make uvmapping pressing UKey when in faceselect mode… but where is the button or menu item that the UKey activates?


(Ben) #11
  1. alt+93 for ] ,alt+91 for [ ,alt+35 for #
    2)There’s no button for it

(theeth) #12

I suggest you change your keyboard language to International English. That way, # is Shift-3 and [ ] are the last two on the second row from the top.

Martin


(eeshlo) #13

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.