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

How many vertices in a teapot?

17 posts in this topic

Is there any way to access the vertices using the ID3DXMesh interface of a teapot (after using D3DXCreateTeapot)? Is there any way to add a color of type D3DCOLOR to each vertex?
0

Share this post


Link to post
Share on other sites
Is this a trick question? LOL. You can access the vertex buffer through the mesh interface. To add a color type you may need to create a new vertexformat.

[url="http://www.mvps.org/directx/articles/d3dxmesh.htm"]http://www.mvps.org/directx/articles/d3dxmesh.htm[/url]
0

Share this post


Link to post
Share on other sites
How do I know if I've reached the end of the buffer? i.e. how many verts are in the teapot?
0

Share this post


Link to post
Share on other sites
Did you try the [url=http://msdn.microsoft.com/en-us/library/windows/desktop/bb205745(v=vs.85).aspx]ID3DXBaseMesh::GetNumVertices()[/url] member function?
0

Share this post


Link to post
Share on other sites
I guess it depends on the teapot. Some have more vertices than others (of course, more is not always better, especially when it comes to teapots).

[size=1]Ok, I'll leave now![/size]
0

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1337994647' post='4943387']
Is this a trick question? LOL. You can access the vertex buffer through the mesh interface. To add a color type you may need to create a new vertexformat.

[url="http://www.mvps.org/directx/articles/d3dxmesh.htm"]http://www.mvps.org/...es/d3dxmesh.htm[/url]
[/quote]

I can create a new vertex, like so...
[CODE]
struct VertexCol
{
VertexCol():pos(0.0f, 0.0f, 0.0f),col(0x00000000){}
VertexCol(float x, float y, float z, D3DCOLOR c):pos(x,y,z), col(c){}
VertexCol(const D3DXVECTOR3& v, D3DCOLOR c):pos(v),col(c){}
D3DXVECTOR3 pos;
D3DCOLOR col;
static IDirect3DVertexDeclaration9* Decl;
};
[/CODE]

[CODE]
D3DVERTEXELEMENT9 VertexColElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexColElements, &VertexCol::Decl));
[/CODE]

The question is how do I implement this new format into the teapot? Edited by Hseptic
0

Share this post


Link to post
Share on other sites
use the ID3DXMesh::CloneMesh function, then lock the vertex buffer and write in all the colors. Make sure not to lock with the overwrite flag otherwise all the positions will be lost
1

Share this post


Link to post
Share on other sites
[quote name='hupsilardee' timestamp='1338057365' post='4943527']
use the ID3DXMesh::CloneMesh function, then lock the vertex buffer and write in all the colors. Make sure not to lock with the overwrite flag otherwise all the positions will be lost
[/quote]

I'm having trouble with the CloneMesh function. What exactly do I put for the second parameter? Right now I have:
[CODE]
mTeapot->CloneMesh(0, VertexColElements, gd3dDevice, &mTeapotClone);
[/CODE]
However it says that "VertexColElements" is undefined.
0

Share this post


Link to post
Share on other sites
You pass in a zero for options, vertex Elements, pointer to your device, and then (out) the new mesh. If it's telling you the VertexColElement is undefined then you need to define (initiate) it. If you've already defined it, debug (step through code) to see what happened to it.

Cloning allows you to create a structure (format) for the vertex buffer to hold the data YOU define.

It might be a good idea to convey what you're trying to accomplish. I think the standard format of a mesh already contains a vertex color section.
0

Share this post


Link to post
Share on other sites
I'm trying to add a color to each vertex in the teapot, though I'm still confused about the steps necessary to do so. I [i]have[/i] defined VertexColElements as shown in one of my above posts. It is not a compile or run time error. The coding environment merely shows a squiggly like under "VertexColElements" stating that it is an undefined idenitfier. This leads me to believe that I've missed something. I just don't know what.
0

Share this post


Link to post
Share on other sites
So you have vertex struct and declaration, then:
[code]
//afer CloneMesh
D3DVERTEXELEMENT9 decl[MAX_FVF_DECL_SIZE];
hr = teapotMesh->GetDeclaration(decl);
if(FAILED(hr))
{
...// on failed
}
WORD offsetToPosition = 0;
bool havePos = false;
for(UINT i = 0; i < MAX_FVF_DECL_SIZE; ++i)
{
if(decl[i].Stream == 0xFF || decl[i].Stream != 0)
{
break;
}

if((decl[i].Usage == D3DDECLUSAGE_POSITION) && (decl[i].Type == D3DDECLTYPE_FLOAT3))
{
offsetToPosition = decl[i].Offset;
havePos = true;
continue;
}
}

if(!havePos)
{
...// on failed
}
DWORD numVertices = teapotMesh->GetNumVertices();
DWORD numTri = teapotMesh->GetNumFaces();
DWORD numIndices = teapotMesh->GetNumFaces() * 3;
DWORD bytesPerVertex = teapotMesh->GetNumBytesPerVertex();

USHORT* pNewIndices = nullptr;
USHORT* pTeapotIndices = nullptr;
newMesh->LockIndexBuffer(0, 0, (void**)&pNewIndices, 0);
terrMesh->LockIndexBuffer(0, (void**)&pTeapotIndices);
memcpy(pNewIndices, pTeapotIndices, numIndices);
newMesh->UnlockIndexBuffer();
teapotMesh->UnlockIndexBuffer();

VERTEX* pNewVertices = nullptr;
BYTE* pTeapotVertices = nullptr;
newMesh->LockVertexBuffer(0, 0, (void**)&pNewVertices, 0);
teapotMesh->LockVertexBuffer(0, (void**)&pTeapotVertices);

for(DWORD i = 0; i < numVertices; ++i)
{
pNewVertices[i].position.x = *reinterpret_cast<float*>((i * bytesPerVertex) + pVertices + offsetToPosition);
pNewVertices[i].position.y = *reinterpret_cast<float*>((i * bytesPerVertex) + pVertices + offsetToPosition + sizeof(float));
pNewVertices[i].position.z = *reinterpret_cast<float*>((i * bytesPerVertex) + pVertices + offsetToPosition + sizeof(float) * 2);

pNewVertices[i].color = yourColor;
}

newMesh->UnlockVertexBuffer();
teapotMesh->UnlockVertexBuffer();
[/code] Edited by belfegor
0

Share this post


Link to post
Share on other sites
You have not actually [i]declared[/i] the static declarator member, you have only [i]defined[/i] it. In the header fileyou have something like this

[code]
// VertexCol.h
struct VertexCol
{
float x, y, z;
DWORD color;

static IDirect3DVertexDeclaration9* Decl;
};
[/code]

Then in one of your CPP files you need to type this

[code]
// VertexCol.cpp
IDirect3DVertexDeclaration9* VertexCol::Decl = NULL;
[/code]

Unfortunately, static members can be fiddly like this.
Then when this is in place you need to pass in the vertex elements to the CloneMesh function. Making sure that you have initialised VertexCol::Decl:

[code]
ID3DXMesh* oldMesh;
ID3DXMesh* newMesh;
D3DVERTEXELEMENT9 elements[MAX_FVF_DECL_SIZE]; // MAX_FVF_DECL_SIZE is the largest number of elements that any vertex declaration can have
VertexCol::Decl->GetDeclaration(elements, NULL);
oldMesh->CloneMesh(0, elements, device, &newMesh); // Instead of 0 consider using D3DXMESH_MANAGED as teh first arg
// now you have the new mesh with the vertex colors you can release the old one if you no longer need it
[/code]
1

Share this post


Link to post
Share on other sites
I have defined VertexColElements like so...
[CODE]
D3DVERTEXELEMENT9 VertexColElements[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
D3DDECL_END()
};
HR(gd3dDevice->CreateVertexDeclaration(VertexColElements, &VertexCol::Decl));
[/CODE]

I still don't know why the environment won't recognize VertexColElements when I insert it into the CloneMesh function like this...
[CODE]
mTeapot->CloneMesh(0, VertexColElements, gd3dDevice, &mTeapotClone);
[/CODE]

What's wrong?
0

Share this post


Link to post
Share on other sites
Is VertexColElements defined before the function call? It looks like mTeapot is a member, so can the class with the mTeapot member access it? As a quick workaround you could try copy-pasting that array directly above the call to mTeapot->CloneMesh(), that would work but is not great as a long term solution
0

Share this post


Link to post
Share on other sites
You have defined a structure but you have not declared a var to hold the struc in memory.
0

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1338391021' post='4944697']
You have defined a structure but you have not declared a var to hold the struc in memory.
[/quote]
Not quite correct, since VertexCol::Decl is a static variable. Refer to this: [quote name='hupsilardee' timestamp='1338119523' post='4943677']
Making sure that you have initialised VertexCol::Decl
[/quote]

I would go with hupsilardee's advice of copy-pasting the VertexColElements definition directly above the call to CloneMesh().
0

Share this post


Link to post
Share on other sites
[quote name='KymikoLoco' timestamp='1338394625' post='4944716']
[quote name='DJTN' timestamp='1338391021' post='4944697']
You have defined a structure but you have not declared a var to hold the struc in memory.
[/quote]
Not quite correct, since VertexCol::Decl is a static variable. Refer to this: [quote name='hupsilardee' timestamp='1338119523' post='4943677']
Making sure that you have initialised VertexCol::Decl
[/quote]

I would go with hupsilardee's advice of copy-pasting the VertexColElements definition directly above the call to CloneMesh().
[/quote]

But like I said, not as a long-term solution.
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