How many vertices in a teapot?

Started by
16 comments, last by hupsilardee 11 years, 10 months ago
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?
Advertisement
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.

http://www.mvps.org/directx/articles/d3dxmesh.htm
How do I know if I've reached the end of the buffer? i.e. how many verts are in the teapot?
Did you try the ID3DXBaseMesh::GetNumVertices() member function?
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!

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


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.

http://www.mvps.org/...es/d3dxmesh.htm


I can create a new vertex, like so...

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;
};



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));


The question is how do I implement this new format into the teapot?
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
After locking, how do I insert the colors into the buffer exactly?

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


I'm having trouble with the CloneMesh function. What exactly do I put for the second parameter? Right now I have:

mTeapot->CloneMesh(0, VertexColElements, gd3dDevice, &mTeapotClone);

However it says that "VertexColElements" is undefined.
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.

This topic is closed to new replies.

Advertisement