How to access real path to the textures?


(Charlls) #1

Hi,

ihmm, consider the following approach to get a texture filename using the 210 api:

OBJList = Blender210.getCurrentScene().objects
for obj in OBJList:
ob = Blender210.getMesh( obj.data )
print ob.texture

this gives a full path to A texture, but what if the mesh contains more than just one texture? how do i access the full paths of the rest of the textures in the mesh?

Help a Newbie


(jms) #2

You can’t do that with the Blender210 module.

jm


(Charlls) #3

Yeah youre right, thanks for the hint, here is the correct code:

for obj in Blender210.getCurrentScene().objects:
print obj
ob = Blender210.getObject(obj)
mesh = Blender210.getMesh(ob.data)
try:
imagename=mesh.texture
print imagename
except:
print mesh,“doesnt seem to have valid texture object”

Ok, but the question remains: you would guess that such a texture ‘object’ accessed thru a mesh object, which could naturally possess more than just one texture, should be an iterable object in the form:

for tex in mesh.texture:

but this is not the case. is just a plain string with no references/visible connections to the other textures on the mesh, what is going on here?


(rndrdbrian) #4

Try this:



if mesh.has_uvco:
			#print ("Has UV Texture")
			faces = mesh.faces
			imagename = faces[0].image
			print imagename.name



(theeth) #5

simply put, the Blender210 API is mostly incomplete and wasn’t developed since the Blender 2.1x series.

The Blender module is more complete and has more functionality (although the Blender210 has some that the other doesn’t, but very little).

Martin


(Charlls) #6

mdrdbrain, yes, that would be ideal, shame that that image.name only return the filename with no path reference :frowning:

…what i’ve come up with is use the os module and take advantage of gnu tools like locate, ugly , but is a workaround that actually works :slight_smile:


(stefu) #7

hi!

Why do I get face.image = ‘None’? I experiment with simple object and created material and added texture to it. Is this isuue that I have to do something in Blender to enable it?

I’m also writing custom ff exporter and just thought of simple solution If I just decide name materials with texture filenames. Then it is very simple to know which texture to load, it’s filename is same as material’s name (for example matname=texfilename=mesh.mats[0]). What do you think o this solution?

Thanks.


(theeth) #8

Why do I get face.image = ‘None’? I experiment with simple object and created material and added texture to it. Is this isuue that I have to do something in Blender to enable it?

I think that this property only applies to the image that is assigned with UV coordinates.

I’m also writing custom ff exporter and just thought of simple solution If I just decide name materials with texture filenames. Then it is very simple to know which texture to load, it’s filename is same as material’s name (for example matname=texfilename=mesh.mats[0]). What do you think o this solution?
that would work, but only in very specific cases (when, as you said, the material name would have a texture defined with it (in code)).

Martin


(eeshlo) #9

I did the same thing for the LF script but then using python itself, it won’t always work however, it might return multiple results, since only 21 characters are used for the image name, so very long names which only happen to differ in the characters beyond the 21st will match.

The same is true for stefu’s material naming method.

And yes, face.image is only for uv-textures, you can however get all used texturenames (material and uv) with the Image module. But not the associated material(s).


(stefu) #10

I used theeth’s Decaling tutorial to texture.
Is UV-texturing active when the little green ‘UV’ button is down (in the middle of Buttons view)? Somehow I tried everyting I could and face.image was always ‘None’. But that’s not problem. I can use my solution (in my earlier post) for game modelling.


(theeth) #11

I used theeth’s Decaling tutorial to texture.

The method used in my decal tut is not UV mapping, but object mapping.

Is UV-texturing active when the little green ‘UV’ button is down

No. That is UV mapping, not UV texturing.

If you want a tut on UV texturing, it is often associated with gamebleder. IamInnocent has a great beginner tutorial on UV texturing.

Martin


(Charlls) #12

and how do you access the image filenames with the method that stefu formerly used? i.e: adding the textures as ¿object mapping? instead of UV mapping… for those cases i also got a [none] result on the image names…ugh

in which part of the object hierarchy are supposed to be stored the image information in these cases?


(stefu) #13

Wow, Blender has so many ways to do things :smiley:
I Google-found UV-Texturing tutorial at www.ingiebee.com and it’s working now.

Charlls, I’v heard rumors that it is not possible to acces image filenames in ‘None’ cases. But I’m still learning, I hope there’s a way to get it.


(eeshlo) #14

To try to clear things up: It doesn’t matter what settings are used for the materials, no button will make the texturename for that material accessible.

Only names of textures assigned with the uv-editor can be accessed using face.image or mesh.texture from the Blender210 module

You can get a list of ALL texturenames used by using the Blender.Image module, but that doesn’t tell you anything about what material it is used with.


(Charlls) #15

Geee… what were they thinking those NaN developers when doing this area of the api?!

well, now we know what are the first items on the list of add-ons to Blender when it goes Open Source :smiley: