• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
gchris6810

Duplicating vertices so the count is equal to UV Coordinates

11 posts in this topic

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.

0

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..... 

0

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
2

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
0

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
0

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

0

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
0

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
-1

Share this post


Link to post
Share on other sites

The source data indexes multiple streams/pools of vmaps (position, uv) for each individual vertex element. Your mesh may also store discontinuous uv-map data meaning a vertex may have different uv-values associated with it for different triangles connected to the vertex. You can only set a single index buffer, so you'll have to combine position- and uv-data into a single indexable stream.

 

So, you need to unweld/duplicate vertices. The most intuitive way is to construct both the vertex- and the index stream in a single pass:

 

- Set up an "unweld-buffer" of vertex-count number of elements, each element in this buffer stores a linked-list of possible position-uv-normal etc. sets for a specific vertex combined with an index into the vertex buffer.

- Loop over all vertices in all triangles. (foreach(mesh->triangles as triangle) foreach(triangle->vertices as vertex))

- Grab for each vertex the set of position, uv, etc. data (relative to the current triangle for discontinuous maps)

- Look for a compatible existing element in the unweld-buffer, if it exists place the existing index associated with this element into the index buffer, if it does not, create a new element, assign it the index "vertex-buffer count + 1" and add it to both the linked list and the vertex buffer.

Edited by eppo
0

Share this post


Link to post
Share on other sites

so yep, it absolutely does have to do with the format specifics

I guess what I meant was that every format requires you build up a vertex buffer and then deconstruct it, and that they all keep things in pools, though COLLADA’s pools seem to be 1-for-1 with the other pools. Rare, but still fully applicable.

But those details should be covered in the documentation.
Not only those details but everything else you need except to understand that those formats are not how they are represented in games and that you need to reconstruct the data for games (as described in detail by eppo).

It was my hope that any problems related to any specific API could be resolved by the poster on his or her own by checking the documentation for said API…on his or her own. The thing that caught me so many years ago was being in a mind-trap where I thought the original file format was something like what games use, and it was only when I escaped from that that I realized how to do it right, and I was hoping he’d be able to look at his API and take my words in combination and figure that out for himself.


L. Spiro Edited by L. Spiro
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0