Jump to content
  • Advertisement
Sign in to follow this  
gchris6810

Duplicating vertices so the count is equal to UV Coordinates

This topic is 2083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I have a model which has a significantly larger UV count than vertex count and I need to know how I can know which vertices to duplicate so as the model displays correctly. I understand that this has something to do with the UV coordinate indices in the mesh but I don't really know this would work practically in code, so a short code example would be very helpful along with a short explanation of how it works.

 

Thanks in advance for the help.

Share this post


Link to post
Share on other sites
Advertisement

I am loading a COLLADA model. Although personally I didn't think it has that much to do with the format specifics. But I may be wrong..... 

Share this post


Link to post
Share on other sites
It doesn’t really matter which format, as far as the overall concept goes—they all work the same.

The vertices, normals, UV’s, etc., are all in what we call “pools”. There is some way in whatever API you are using to access indices into these pools. The total number of indices will be the same for each pool (or else there would be no logical way to recreate the mesh), but while the indices in the pool for vertices will have more repeats the indices into the pool of UV’s will have fewer (hence fewer total vertices than UV’s).

The only thing that is specific to the API is how you access the indices and the pools of vertices, normals, UV’s, etc. We leave that up to you.

The concept is that once you are able to access all of these things, you create a vertex buffer by simply accessing the indices in-order and creating each vertex as specified, repeats allowed.
You then create an index-buffer–vertex-buffer pair by checking your newly created vertex buffer for repeats, eliminating them, and creating an index buffer at the same time.

You need to keep in mind that whatever format serves as your source was not meant for games. It was meant to be an interchange format to exchange graphics data between Maya and 3DS Max (not strictly true, but 99% true). Its definition of an index buffer is not your game’s definition of an index buffer.
It must be deconstructed in this way and then reconstructed for your purposes.


L. Spiro

Share this post


Link to post
Share on other sites

Sorry, L. Spiro I don't really understand what you mean, are you saying that you use the indices to build the vertex array something like this:

 

EDIT: Don't worry I am only using COLLADA for interchange to my engine.

// This probably wouldn't work in practice but you get the idea
for( size_t i = 0; i < faces.size( ); i++ )
{
  newArray[i].x = initialArray[faces[i]].x;
  newArray[i].y = initialArray[faces[i]].y;
  newArray[i].z = initialArray[faces[i]].z;
}
Edited by gchris6810

Share this post


Link to post
Share on other sites

I think there are a few possible reasons for the problem you describe.

1. The easiest.. you have multiple sets of texture coordinates and this should be easy to figure out by checking the counts ;)

2. You misunderstood the concept of the index buffer. The number of elements in the position buffer has nothing to do with the vertex count. It possible that you need different vertices at the same position (in the worst case one per adjacent triangle). You should think about the relations of the different buffer sizes and counts. E.g. IndexCount = PrimitiveCount * 3 (for triangles). If your model consists of multiple meshes you need to consider the offsets too. You may post the different buffer sizes and counts here and I’m sure that we will find out what’s wrong.

3. your model is messed up ;)

Edited by derKai

Share this post


Link to post
Share on other sites

I am loading a COLLADA model. Although personally I didn't think it has that much to do with the format specifics. But I may be wrong..... 

Collada contains a list of indices into each of the vertex attributes, so yep, it absolutely does have to do with the format specifics biggrin.png

The index stream will say something like 1 2 3 4 5 6

That means build a vertex using position #1 and UV #2, then build a vertex using position #3 and UV #4, etc... (assuming the mesh only has positions and UV, and that positions are the first attribute and UV's are the second attribute).

 

Check out the spec.

 

What particular kind of COLLADA tag are you trying to parse?

Edited by Hodgman

Share this post


Link to post
Share on other sites

I am not trying to parse the tags. I am using OpenCOLLADA to load the model so therefore the information is passed to my application as separate UV index and position index lists. Perhaps I should have been clearer about how I obtained the data.

 

EDIT: Could we please try and cut through the generality so as I can have something more specific to work on. Thanks.

Edited by gchris6810

Share this post


Link to post
Share on other sites

OK, here is the counts for a single mesh:

 

number of positions: 342

number of uv coords: 1884

number of faces: 628

 

okay.. here you see the number of uv coords is 3 times the number of faces.. this is very typical for textured models..

i've never seen separete index lists per semantic. i guess all your index lists are of the same size (3 * 628)

if thats so you may allocate your vertexbuffer (or buffers if you don't want interleaved vertexbuffers), iterate over the index lists and fill your buffer with the data at the given indices:

positionBuffer[faceCount*3]
tecCoordsBuffer[faceCount*3]

for(int i=0; i<faceCount*3; i++)
{
    positionBuffer[i] = positionData[positionIndices[i]];
    texCoordBuffer[i] = texCoordData[texCoordIndices[i]];
}

this will flatten you buffers (you don't need the indexbuffer for drawing)

for a interleaved buffer you will create a struct containing fields for position and texcoords and an array of these structs in a similar way

Edited by derKai

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!