making uv coordinates available

(stefu) #1


I have problem knowing how to make uv coordinates exportable. I have textured the model with UV-texturing method.
I think that it’s the Sticky ‘Make’ button in Edit buttons. But the problem is that it is not working. It does nothing if I click it. On another model it works and the label changes to ‘Delete’. I don’t remember what all I havetried with that model.
I tried also adding material and texture to the object, but nothing helps.
There’s also another ‘Stick’ button in Material Buttons (little green button in mid section)? doesn’t help.
The model is uv-editor-textured but how to make uv-coords exportable (set mesh.has_uvco true)?

(eeshlo) #2

‘Sticky’ coordinate textures have nothing to do with uv-textures assigned with the uv-editor. To check if a mesh has uv-coordinates use mesh.hasFaceUV(), the coordinates themselves are in face.uv:

mesh = Blender.NMesh.GetRaw(meshname)
if mesh.hasFaceUV():
	for face in mesh.faces:
		for uv in face.uv:
			print uv

(stefu) #3

Thanks, it works.
This is going to make thing little more difficult because of face-based texturecoordinates. Maybe I’m going to use only uv-textures to keep thing simple.

Btw, where can I find reference doc for Blender python? I have found Blend_py.pdf but it did say nothing about mesh.hasFaceUv() for example.

(rndrdbrian) #4

Stefu, are you needing vertex based UV coordinates instead of face based?

If so, then I’m pretty sure this code converts between face based to vertex based uv coordinates. I wrote this for my Orbiter exporter, which uses vertex based uv coordinates.

tu = []
tv = []
for verts in mesh.verts:
			tv.append('c')   # fill the tu & tv arrays for later

for faces in mesh.faces:
			xi = faces.v[0].index    # x index
			yi = faces.v[1].index    # y index
			zi = faces.v[2].index    # z index
			#print xi
			#print len(tu)
			#print tu[xi]
			#print dir(faces)
			if mesh.has_uvco:
				faceUV = faces.uv
				#print ("processing UV Coordinates...")
				#print faceUV[0],faceUV[1],faceUV[2]
				U0 = round(faceUV[0][0],2)
				V0 = round(faceUV[0][1],2)
				U1 = round(faceUV[1][0],2)
				V1 = round(faceUV[1][1],2)
				U2 = round(faceUV[2][0],2)
				V2 = round(faceUV[2][1],2)
				#print U0
				tu[xi] = str(U0)
				tv[xi] = str(V0)
				tu[yi] = str(U1)
				tv[yi] = str(V1)
				tu[zi] = str(U2)
				tv[zi] = str(V2)
				tu[xi] = "0"
				tv[xi] = "0"
				tu[yi] = "0"
				tv[yi] = "0"
				tu[zi] = "0"
				tv[zi] = "0"

I’m afraid I didn’t document the code very well though… Suck it and see. I’m pretty sure this should do what you want.



(stefu) #5

Hi rndrdbrian,
Currently I’m using face based uv-coordinates (because of Blender says so). But I’v been thinking of moving to vertex based because that would suit better with my OpenGL based game. It would for example allow using vertex arrays and save memory too (in most cases).

If I understad right your converter, it just goes through all faces and takes uv coordinates from there and attaches them to tu and tv lists in correspongind vertex indices.
But it doesn’t take account that one vertex might be shared with many faces and each face have different uv values for that vertex? Am I right? In that case I would need to duplicate vertices and make things more complicated. But I think that your script will do fine if I just decide to use uv-texturer so that no problem occurs.

Maybe I’ll give it a try :slight_smile: