I am writing an exporter to export data so I can import models into my engine.
All is going well, but now I am working on texturing.
First, what I have done:
I have exported all the vertices, and then all the face points using their index. This works great, because no vertex is in the export data twice. For example, if I just export all the face vertexes, each vertex would be exported multiple times depending on how many faces share the vertex.
I am very happy with this. However, now I need to export UV coordinates. Now, once I get a teture UV mapped onto a mesh, some of these vertices will have different UV coords depending on which face you come at the vertex from.
So, for each vertex, if it has multiple uv coords, I need to export the vertex once for each. How would I go about doing this?
A vertex according to the docs has a ‘sticky’ uv coord, which I think has something to do with what I’m trying to do.
If anyone can shed any light on this or sticky UV coords, I would be greatful.
You shouldn’t think in the way that each vertex can have multiple UV coordinates, but instead that each face can have only one set of UVs. It’s really a face property in the same way that vertex colors are actually face properties.
It’s nmesh.face.uvco I believe.
I understand what you are saying, however DirectX, OpenGL, etc do not operate that way. UV coordinates are a property of the vertex, not of the face. Some face vertices can and should be shared, other face vertices should not.
For every vertex, I need to know every face that uses it, and determine if the vertex can be shared (because it has the same uv coord for each face), or if it needs to be instanced (one for each unique uv coord).
Programming is much different than modeling. This sort of distinction is very strict.
I don’t believe there is a list that shows what verts belong to which faces. The only way I’ve found is to compare their coordinates. This is fairly accurate unless there are doubles. You’re always free to look at the source for the various exporters that come with Blender. You might try looking at the directX exporter.