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

Modeling and coding

4 posts in this topic

So my question is when you make some 3D model or some 3D animation on let`s say 3D studio max and after that when you export it or something how do you actually connect it the source code of the game ?
0

Share this post


Link to post
Share on other sites
In essence, a 3D file is nothing more than a bunch of vertex data, related with each other via polygons (for example triangle 3 is made of vertex 5,6 and 800). More advanced file formats may also contain info about the textures and materials being used, or a scene setup. Telling where the camera is, what lights, rotations/movements of objects, et cetera. But let's keep it simple and focus on the 3D geometry data only, thus the polygons.

"Connecting 3D files with the source code" is a bit of a strange term. What really happens is that a program, engine, editor, or whatever application, reads the 3D file. Then converts it to its own internal format, which is, again, a bunch of triangles. The conversion is often needed to optimize performance and memory usage. And possibly to discard unneeded data or to add extra data that was not present in the 3D file. For example, if I import a OBJ file, it may contain secundary UV coordinates I don't need in my game, or lacks tangents. This conversion step may takes some time, so it's not uncommon that engines save the converted object to its own fileformat first. That makes loading them faster the next time.

Once the vertexdata has been read from a file, it will be stored in the computer RAM and/or videocard memory for usage. Typically you'll send an array of vertices or triangles to a videocard in a certain way(order / format) so the videocard knows how to brew a real 3D model of it. Additional stuff like lighting it, or texturing the model is done with shaders or renderAPI (DirectX, OpenGL) commands. The vertexdata usually helps telling how the texture should be wrapped on it, by telling its UV coordinates.


Really, it's not much else than reading a bitmap image. You draw it, save it. Then a program reads the file, converts it to an internal format optimal for drawing it quickly on the screen, and stores it in the memory. Then drawing calls will fetch the data from the memory and put it on the screen.

Rick
1

Share this post


Link to post
Share on other sites
thank you for shedding some light on mu incompetence :) can you suggest me some more reading about it or give a some very simple example e.g. some chunk of code
0

Share this post


Link to post
Share on other sites
That's not incompetence, it's just a matter of doing and all will become clear one day ;)

What kind of model formats do you plan to use? You could start with OBJ, a widely supported, simple format. It does not support animations as far as I know though. You could also look for Collada files, which are based on XML and also pretty common nowadays. Quite a lot harder to read, although once you have a proper XML reader... MS3D (Milkshape) files are also pretty simple to read, and do support animations. Anyway, first determine your needs and the programs you use for modelling, then pick a file format. Then just check the internet for a description that tells how those files are constructed.

OBJ files are text based. I don't know the exact format from the top of my head, but if you open one in Notepad you'll see (many) lines of coordinates. For example, a cube model could have
v -1 -1 -1 left bottom rear corner
v -1 -1 +1 left bottom front corner
...
The "v lines" are Vertices, made of an X Y and Z value. In the cube case, you probably will see 8 vertices. Asides vertices, you probably also run into normals and texcoords. Normals are also XYZ values, but normalized which means they are inside the -1..+1 range. Texcoords(UV) are usually made of 2 values (S and T), the horizontal and vertical coordinate. So, just store all those coordintes into arrays. One array with vertex coordinates, another array with normals, and so on.


Next step is to combine the coordinates. Models often use "indices", those are lookup index numbers. A cube can be made of 6 polygon quads. Or 6x2 = 12 triangles. I suggest you triangulate the data for ease, as OpenGL or DirectX likes to work with triangles in the end. Now each triangle refers to 3 vertices, 3 normals, 3 texcoords, et cetera. If you didn't triangulate the model, polygons may refer to 4 vertices instead in the case of a cube.
[code]
// Read 3 vertex indices from the file
int vindex0, vindex1, vindex2;
vindex0 = ...
// Read 3 texcoord indices from the file
int tindex0, tindex1, tindex2;
...

// Add a triangle
++triCount;
triangle[ triCount ].vertex[0] = vertexArray[ index0 ];
triangle[ triCount ].vertex[1] = vertexArray[ index1 ];
triangle[ triCount ].vertex[2] = vertexArray[ index2 ];
triangle[ triCount ].texcoord[0] = texcoordArray[ tindex0 ];
... and so on...
[/code]

Other (binary) formats may pack the data a bit different. For example, the program could decide the following structs are stored in the file
[code]
struct Vertex
{
float vertexPos[3];
float normal[3];
float texCoord[2];
};

struct Triangle
{
Vector vert[2]; // triangle made of 3 vertices
};

struct Model
{
int triangleCount;
Triangle tris[];
}
------------------------------
file.read( &model.triangleCount, 4 );
setArrayLength( model.tris. model.triangleCount );
// Read the entire triangle buffer in a single call
file.read( &model.tris, model.triangleCount * sizeOf(Triangle) );
[/code]
Although the principles are mostly the same, the format can differ for each format. That's why it's important to read about the file you chose first.


Now that you have all the data loaded, you may want to convert it to your own format. This depends on what/how you want to render it. Let's say we use OpenGL and we want to use triangles, indices, normals, and texcoords. In that case you could make 4 arrays. One with the vertexcoords, one with the normals, one with the texcoords and another one with the indices. Make sure the vertices, normals and texcoords are all ordered in the same way. Thus that element X in the texcoord/normal Array belong to vertex[x] as well. Then you can draw the model like this:
[code]

// Send the normalArray to OpenGL
glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer( GL_FLOAT, 0, model.normalArray );

// Send the texcoordArray to OpenGL
glClientActiveTextureARB( GL_TEXTURE0_ARB );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 4, GL_FLOAT, 0, model.texcoordArray );

// Send vertex coordinates to OpenGL
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, model.vertexArray );

// Use indices to render the model (array with 16 bit uints)
glDrawElements( GL_TRIANGLES , model.triangleCount ,
GL_UNSIGNED_SHORT , model.indicesArray );

// And don't forget to disable when done
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
glClientActiveTextureARB( GL_TEXTURE0_ARB );
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
[/code]
Not sure if that works with modern OpenGL anymore though, as it prefers to use VBO's instead. It's a bit more work to set that up, but more flexible and powerful at the same time. There are more ways to Rome, this is just one of them. But try to start simple to get a feeling with vertexData, indices and formatting.

Probably there are tutorials on sites like Nehe that show you how to read a file, and how to render it.

Good luck!
0

Share this post


Link to post
Share on other sites
Wow, these are some great descriptions. Very useful information on what goes on when implementing 3D files, glad I came across this. Thanks for sharing some insight.
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