Kalisme
Kalisme

Reputation: 518

can blender export per vertex UV coordinates?

Is it possible to write an exporter for Blender that exports the meshes UV texture coordinates on a per vertex level aposed to the standard UVs from faces?

I'm not really a python person and have only been using it for two days, but I've managed to write a simple mesh exporter for Android... I'm able to export the Vertices and indices to arrays, but I can't get the UVs to export in the same fashion... I can only get them in relation to face vertices which isn't overly helpful....

I'm not really sure how to post the python code because of the formatting, but here is the part where I grab all the information and place it into arrays:

    obverts = bpy.context.active_object.data.vertices
    obfaces = bpy.context.active_object.data.faces
    verts = []
    indices = []
    tex = []

    for vertex in obverts:
        verts.append(vertex.co.x)
        verts.append(vertex.co.y)
        verts.append(vertex.co.z)

    for face in obfaces:
        indices.append(face.vertices[0])
        indices.append(face.vertices[1])
        indices.append(face.vertices[2])
        face_index = face.index
        for u,v in bpy.context.active_object.data.uv_textures.active.data[ face_index ].uv:
            tex.append(u)
            tex.append(v)

Now that all works fine, except the last four lines that get the UV coordinates... This is where it gets the UVs from the faces... but how can I get the UVs in relation to the data.vertices? I read something about "sticky uv coordinates" but I can't find the option on my version of Blender. I'm using Blender 2.57 and have spent all day trying to find the answer, so if anyone could help; I'd be very thankful.

Upvotes: 2

Views: 5310

Answers (2)

Daniol Dan
Daniol Dan

Reputation: 101

you can export UV per vertex, if you separate all faces of the object.

(yes this will duplicate vertices used by two or more faces)


goto edit mode

mark all edges as sharp


goto object mode

assign and apply the "edge split" modifier


now all faces use unique verts and edges,

thus each vertex has its own single UV coord

Upvotes: 0

Paul S
Paul S

Reputation: 7755

I'm able to export the Vertices and indices to arrays, but I can't get the UVs to export in the same fashion... I can only get them in relation to face vertices which isn't overly helpful....

UVs will have to be in relation to faces because each vertex might have a different uv for each polygon it's part of.

For example think of a cube that has a different texture on each face. A vertex will be the top left on one face, and the top right of the face next to it.

Upvotes: 2

Related Questions