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

Manualy Filling A ID3DXMesh

3 posts in this topic

Hi All.
im having trouble wrapping my head around filling the ID3DXMesh manualy.

how would i manually set the vertexes / normals / textures and what ever else is required ?

ive read a bunch of different posts on a similer thing, but cant get my head around what to do.

so whats some psuedo code to do this ?( some links might be nice )

how do you normally handle models ?( IE: do you use your own model loader / manager etc )

Thanks In Advance.
0

Share this post


Link to post
Share on other sites
The D3DX mesh is little more than a wrapper for a vertex buffer, an index buffer, an attribute buffer (that stores the subset index for each face for DrawSubset method to use) and the vertex format specifier. It does include convenience methods to draw and manipulate the internal buffers, though.

In D3D, it is common that attributes (position, normal, uv...) of vertices are interleaved in one vertex buffer. Though it is possible to use multiple streams at the API core level, the D3DX mesh interface uses only one stream (at least in D3D9, I don't remember if this is required in later versions). Therefore, the vertex data of a mesh can be stored as an array of simple structure that contains the desired components.

The primitive type of the D3DX mesh is always an indexed triangle list. That is, there are exactly (3*facecount) indices in the index buffer.

In order to "manually" fill the buffers, you lock them for writing, copy your stuff to the pointer you get from the lock method, and unlock them to commit the changes and to allow the system to use them for rendering.

Check the tutorials in the SDK, they cover the raw buffer usage as well as the usage of the D3DXMesh.
0

Share this post


Link to post
Share on other sites
[quote name='ryan20fun' timestamp='1323865429' post='4893816']
how would i manually set the vertexes / normals / textures and what ever else is required ?
[/quote]

First, declare your own vertex structure that contains each data you need. Like this one:
[code]struct Vertex_POS_NOR_TEX
{
vector3 position;
vector3 normal;
vector2 texCoords;
};[/code]

Then create a vertex declaration:
[code]D3DVERTEXELEMENT9 vertElem[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
};[/code]
Note that the order of each element is the same as your vertex structure. The second parameter of each element is very important. It tells you how much bytes the distance (offset in bytes) between current element and the head is. In our example, the head is POSITION (because in our Vertex_POST_NOR_TEX structure, the first member is position), so the second parameter must be 0. You know, a float is 4-bytes long. So, NORMAL data must be 12 bytes distant from head, because POSITION has 3 floats (3 x 4bytes = 12 bytes). TEXCOORD data is 20 bytes distant to the head, because NORMAL has 3 floats and TEXCOORD has 2 floats. In total, 5 floats = 5 x 4 = 20 bytes.

After that, you can create your mesh:
[code]LPD3DXMESH pYourMesh = NULL;
D3DXCreateMesh (yourVertexCount, yourPolygonCount, D3DXMESH_MANAGED, vertElem /* take a look above */, yourD3DDevice, &pYourMesh);[/code]
Note that D3DXMESH_MANAGED flag can be different and depends on your need. For example, if you manipulate your mesh frequently, you can use D3DXMESH_DYNAMIC. For details, take a look at D3DXMESH flags in SDK docs.

Now the most important step comes: Filling the buffers. As nik02 said, ID3DXMesh interface lets you play with vertex and index buffers, also attribute buffers (for subset manipulating). You can think of ID3DXMesh interface like this:
[code]struct ID3DXMesh
{
LPDIRECT3DVERTEXBUFFER9 pVertBuf;
LPDIRECT3DINDEXBUFFER9 pIndexBuf;
DWORD polyCount;
DWORD vertCount;

// blah blah...
};[/code]
For vertices, lock the vertex buffer, copy your vertex data, and unlock it. And for indices, lock the index buffer, copy your index data, and unlock it. Don't forget to call optimization functions: ID3DXMesh::OptimizeInplace(), D3DXCleanMesh(), D3DXWeldVertices(), ....

That's it! You created your mesh and now you can draw it by calling ID3DXMesh::DrawSubset().

[quote name='ryan20fun' timestamp='1323865429' post='4893816']
how do you normally handle models ?( IE: do you use your own model loader / manager etc )
[/quote]

I'm using my own model loader. It reads the data from file and creates meshes per subsets:
[code]For each subset returned from file
{
Create a vertex buffer and an index buffer;
Create a texture;
Create an effect/shader
Fill the buffers;
Load the texture;
Load the effect;
Fill other members (i.e. vertex count, index count, vertex size etc.)
}[/code]

To draw the entire model, I call IDirect3DDevice9::SetIndices(), IDirect3DDevice9::SetStreamSource() and IDirect3DDevice9::DrawIndexedPrimitive().

PS: Some links and book excerpts might be useful for you:
- Introduction to 3D Game Programming with DirectX 9.0c : A Shader Approach (from F. Luna) - Chapter 14 [i]Available at Google Books[/i]
- [url="http://www.scribd.com/doc/49909319/136/Creating-a-Mesh"]http://www.scribd.co...Creating-a-Mesh[/url]
- MSDN, SDK docs and samples.

hth.
-R
1

Share this post


Link to post
Share on other sites
In addition to what [url="http://www.gamedev.net/user/151330-programci_84/"][color="#284b72"]programci_84[/color][/url] said, if you want using DrawSubset method of the mesh, you need to fill the attribute buffer of the mesh too.

The attribute buffer stores the subset index for each face, so that the system knows which triangle belongs to which subset. The optimize methods can convert this data to ranges and sort the actual faces to match those ranges, therefore making the DrawSubset method much more efficient. Subset data itself does not have any other intrinsic meaning to the D3D core.

Of course, it is possible to use the vertex and index buffers of the mesh manually and draw it using DrawPrimitive, if you want to.This is a good approach if the mesh generally represents one renderable object.
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