• 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
Paul C Skertich

Imported OBJ Looks Funky... :(

9 posts in this topic

Below is a screen shot of my imported OBJ inside my editor. I've been looking at several tutorials and for now - I just want to get a simple OBJ cube loaded with a color shader file. I am think I'm confused on the whole Index section, because I think this is where it's going haywire. I'll try to chainge the topology to trianglelist because now I have it set to trianglestrip.

Inside the debug console it writes the OBJ structure. 8 vertices and 12 faces. the OBJ import reverse the Index backwards also. It has to be the part where it loads the vertex and the index. Whenever ever someone has time - could they at least if I'm doing something wrong in codewise.

[code]

// Read in the vertices, texture coordinates, and normals into the data structures.
// Important: Also convert to left hand coordinate system since Maya uses right hand coordinate system.
fin.get(input);
while(!fin.eof())
{
if(input == 'v')
{
fin.get(input);

// Read in the vertices.
if(input == ' ')
{
fin >> vertices[vertexIndex].x >> vertices[vertexIndex].y >> vertices[vertexIndex].z;

// Invert the Z vertex to change to left hand system.
vertices[vertexIndex].z = vertices[vertexIndex].z * -1.0f;
vertexIndex++;
}



// Read in the texture uv coordinates.
if(input == 't')
{
fin >> texcoords[texcoordIndex].x >> texcoords[texcoordIndex].y;

// Invert the V texture coordinates to left hand system.
texcoords[texcoordIndex].y = 1.0f - texcoords[texcoordIndex].y;
texcoordIndex++;
}

// Read in the normals.
if(input == 'n')
{
fin >> normals[normalIndex].x >> normals[normalIndex].y >> normals[normalIndex].z;

// Invert the Z normal to change to left hand system.
normals[normalIndex].z = normals[normalIndex].z * -1.0f;
normalIndex++;
}
}

// Read in the faces.
if(input == 'f')
{
fin.get(input);
if(input == ' ')
{
// Read the face data in backwards to convert it to a left hand system from right hand system.
fin >> faces[faceIndex].vIndex3 >> input2 >> faces[faceIndex].tIndex3 >> input2 >> faces[faceIndex].nIndex3
>> faces[faceIndex].vIndex2 >> input2 >> faces[faceIndex].tIndex2 >> input2 >> faces[faceIndex].nIndex2
>> faces[faceIndex].vIndex1 >> input2 >> faces[faceIndex].tIndex1 >> input2 >> faces[faceIndex].nIndex1;
faceIndex++;
}
}

// Read in the remainder of the line.
while(input != '\n')
{
fin.get(input);
}

// Start reading the beginning of the next line.
fin.get(input);
}

// Close the file.
fin.close();
[/code]

this part gathers the stored index count and literates the the file again - grabbing vertex data and such.

[code]
D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );

vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(VertexType) * vCount;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
///////////////**************new**************////////////////////

D3D11_SUBRESOURCE_DATA vertexBufferData;

ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = &vertices[0];
HR( dev->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &objVertexBuffer));

//Set the vertex buffer
UINT stride = sizeof(VertexType);
UINT offset = 0;
devcon->IASetVertexBuffers( 0, 1, &objVertexBuffer, &stride, &offset );

Debug::WriteLine("OBJ Vertex Data Loaded Successfully!");

D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) );

indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(FaceType) * 3 * 12;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;

D3D11_SUBRESOURCE_DATA iinitData;

iinitData.pSysMem = &faces[0];
HR(dev->CreateBuffer(&indexBufferDesc, &iinitData, &objIndexBuffer));

devcon->IASetIndexBuffer( objIndexBuffer, DXGI_FORMAT_R32_UINT, 0);

Debug::WriteLine("Index Buffer from OBJ loaded Successfully!");


[/code]

then when it's drawn - it looks like what's below. Additional, here's a wireframe shot within the editor.
[attachment=10401:OBJGoneWrong.PNG]
[attachment=10402:BadOBJWireFrame.PNG]

Thanks for the help guys! Much appreciated!
0

Share this post


Link to post
Share on other sites
would you suggest I create my own format or look into another format like FBX? Since FBX is popular but I read on google there's some problems - so I wasn't sure if I should go ahead with importing FBX files. Thanks for the response BitMaster.
0

Share this post


Link to post
Share on other sites
The huge advantage of .obj files is that they are human readable (a real blessing for anything you need to debug) and relatively simple (usually, they can contain some weird stuff but you usually never encounter those bits in 'normal' files).
Unless you would rather use a library (like Assimp) I would strongly advise sticking with .obj files until loading and display works as intended. When that is working, consider a different format.

That said, I would advise against writing your own loaders (unless that is the point of the exercise). It is a rather lengthy and not very interesting work that has already been solved a lot of times.
2

Share this post


Link to post
Share on other sites
In addition to what has been said about the indexing base, you code makes several assumptions about the content of obj file, in particular:[list]
[*]Triangles only (i.e. always 3 sets of indices for faces, no more, no less)
[*]Texture AND normal data is always present (i.e. face indices are always of the form: #/#/# )
[/list]
I would check the file by hand to make sure these assumptions are not violated.

Also, I'm not sure what you mean by changing the topology to triangle list, given your above assumptions the trivial way of rendering the parsed obj data is as a triangle list. Edited by scniton
1

Share this post


Link to post
Share on other sites
Alright, I'm gotta study more about setting up Index Buffers a bit more. If I look back now, it doesn't really make sense in Index Buffer's mind because it's like, "You want me to draw what again? Okay cool, I'll draw this but you'll not like it!" So, this reminds me to do more studing before tackling the fun stuff.
0

Share this post


Link to post
Share on other sites
OH YEAH BABY! A successful Obj Import without texture just pretty hot red! Okay, so the code now just picks out the vertices and the indices! Check it out - wireframe and solid.

[attachment=10409:SuccessfulOBJImport-SOLID.PNG][attachment=10410:SuccessfulOBJImport-WIRE.PNG]

You guy's da BEST!
0

Share this post


Link to post
Share on other sites
Okay, a cube - so what right? Well, I did some revisions to the code to automatically calculate the vertices and indices. In the drawIndex section I did the same calculation again and this is the final result of a imported obj sphere. Looks like a egg but eggs are good too!

[attachment=10411:Successful_OBJ_Sphere_Import-SOLID.PNG][attachment=10412:Successful_OBJ_Sphere_Import-Wire.PNG]
0

Share this post


Link to post
Share on other sites
BitMaster was right that I had to substract fromt he Index Collection in order to draw this on screen. Scniton was correct at the code's assumption. With this in mind - I came to the conclusion...if it's reading the index and collecting the Index Verteices and the normal Indexes and the Texture Indexes. I better filter the one's I just need for now then improve upon. I justed wanted to challenge myself to get a simple obj file imported. The sphere looks squashed so I'm working on this and addiotnally I'm working on the importing side. I got so excited I forgot to thank everyone.
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