• 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
Volgogradetzzz

Parsing obj models

6 posts in this topic

Hello. I need an obj parser. And althought specification is simple I met some problems. For example this teapot (found in google):
[url="http://isg.cs.tcd.ie/spheretree/models/teapot.obj"]http://isg.cs.tcd.ie/spheretree/models/teapot.obj[/url]
Number of vertices - 599. Number of texture coordinates - 553. Number of normals - 694. Why their counts are different??? How it's possible?
Now lets invectigate index data. For example take 1-st vertex - and we can see that this vertex can share data 1/1/1 and also 1/1/496!!!
So having all this I can't load model properly. I'm searching the web and I can't find correct model with uvs and normals. Or maybe they are correct and it's only my misunderstanding?
0

Share this post


Link to post
Share on other sites
Check the documentation of the "f" (face) instruction.

The obj describes an indexed mesh, where each of the data arrays (positions, texture coordinates and normals) have different indices. D3D, on the other hand, expects only single index array to an interleaved data array (index buffer + 1 vertex buffer). I don't remember whether OpenGL supports different index streams for different vertex elements.

To load the obj to a d3d-compatible format, you need to interleave the data based on the f instructions in order to get a single vertex buffer. The new indices should then be set to point to the resulting interleaved vertex array.

To see an example, see the DX SDK sample "MeshFromObj".
1

Share this post


Link to post
Share on other sites
[quote name='Nik02' timestamp='1333875622' post='4929263']
The obj describes an indexed mesh, where each of the data arrays (positions, texture coordinates and normals) have different indices. D3D, on the other hand, expects only single index array to an interleaved data array (index buffer + 1 vertex buffer). I don't remember whether OpenGL supports different index streams for different vertex elements.
[/quote]
OpenGL also can handle at most one index stream.

[quote name='Nik02' timestamp='1333875622' post='4929263']
To load the obj to a d3d-compatible format, you need to interleave the data based on the f instructions in order to get a single vertex buffer. The new indices should then be set to point to the resulting interleaved vertex array.
[/quote]
Interleaving is not a strict neccessity (AFAIK also not for the most modern D3D / OpenGL versions). You can have more than a single data stream.

[quote name='Volgogradetzzz' timestamp='1333873759' post='4929257']
...
So having all this I can't load model properly. I'm searching the web and I can't find correct model with uvs and normals. Or maybe they are correct and it's only my misunderstanding?
[/quote]
As Nik02 has stated, every vertex in D3D / OpenGL must provide data for each declared vertex attribute. Addressing a vertex can be done only in its entirety due to the single index. This means usually that for each index combination found in the OBJ's f section one needs to assemble a vertex for D3D / OpenGL (i.e. copying the indexed attribute data in a consistent order) and to generate a new index (a counter is just sufficient). If you want a smaller memory footprint, you can investigate whether the OBJ's index combination was already used earlier; if so, you can re-use the formerly made vertex by just push the belonging D3D / OpenGL index into the index buffer (instead of assembling a copy of the same vertex).
1

Share this post


Link to post
Share on other sites
I'm flash programmer and new stage3D API require me to pass vertex buffer (can be several) and index buffer. And each index corresponds to single vertex. So I'm very confused about this phrase (I repeate it again):
[quote]For example take 1-st vertex - and we can see that this vertex can share data 1//1 and also 1//496!!![/quote]
How I understand this: take first vertex and take first normal for this face index. And take first vertex and take 496-th normal for this face index (second case).
But it's impossible in actionScript to tell GPU to use 1-st normal for 1-st vertex as wel as 496-th normal for the same 1-st vertex. Please correct me if I wrong.

Upd.: I rephrase my question. In the link to obj model array in face instructions points to the same vertex, but different normals. Is it ok that vertext have 2 normals?
0

Share this post


Link to post
Share on other sites
First we should clear up some confusion. To begin with, a vertex is a collection of attributes that defines a point on a model. A vertex can have different attributes, such as position, normal, texture coordinate, color, and so on; whatever attribute you have to describe your vertex. A vertex is not only the position.

The model you linked contains three different attributes: position (the v-tag), texture coordinate (the vt-tag) and normal (the vn-tag). These tags list all individual position attributes, all texture coordinate attributes and all normal attributes that will be used by your list of vertices.

Then you have the face descriptors (the f-tag). Let's take two typical lines from the file. First, "f 1/1/1 2/2/2 3/3/3". The list of triplets references each individual attribute that makes the vertex, and the tree triplets makes the three vertices in the face (the triangle in this case, since there are three vertices).

So, first, 1/1/1 means that the first vertex of the triangle is made up of the first position in the position list, the first texture coordinate in the texture coordinate list, and the first normal in the normal list. Likewise, 2/2/2 and 3/3/3 makes up two more vertices, of the second and third attribute of each corresponding list.

Then look at an example of what I think is confusing you: "f 4/4/5 3/3/6 5/5/7". It follows the very same pattern as previous example. The face is made up of three vertices, and the first vertex is made up from the fourth position, fourth texture coordinate, and the fifth normal. Likewise, the second vertex is made up of the third position, third texture coordinate, and the sixth normal.

So no vertex has two normals, but you may have two [i]different[/i] vertices that have the same position but different normals. That is what 1/1/1 and 1/1/496 means; two vertices with the same position but different normals.

If your API does not support individual attribute indices, then you need to split and duplicate vertices. You cannot base your vertex arrays on the position attribute and attach texture coordinate and normal to each position. You have to base it on the face list, and build the vertices from there. Merging and duplicating vertices from one indexed format to another is not very difficult, but definitely a challenge if you're a beginner.

I would drop the index completely and build a flat vertex array instead. That is, load all attributes into separate arrays, load the face list, and construct a vertex array by passing over the face list and copying the attributes into the vertex array in the order determined by the face indices. When you have passed over the whole face list, you have a flat vertex array that stores the attributes in the order specified by the face list.
2

Share this post


Link to post
Share on other sites
[quote name='haegarr' timestamp='1333877115' post='4929266']
Interleaving is not a strict neccessity (AFAIK also not for the most modern D3D / OpenGL versions). You can have more than a single data stream.

[/quote]

Yea, but in this particular case I didn't see the point of causing even more confusion by saying that [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

The point was that only one index buffer could be used at a time.
0

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