Sign in to follow this  

modifying colors of a Mesh

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello everyone, i created a Mesh by D3DXCreateBox() function and now i want to change it's colors. as far as i learn, i need to access the object's vertex buffer by IBaseMesh::LockVertexBuffer() or IBaseMesh::GetVertexBuffer(). but i think the container address that i have to provide to those functions should be in the same FVF struct as the defaults of the box. so my questions are: *how can i access/modify the color/vertex info of an object which was created by D3DXCreateBox/Sphere/Somethin ? *how can i change/set the texture information of that object? *will there be any difference in the answers of those 2 questions if i create the object by LoadMeshFromFile instead of D3DXCreate... ? *anyone can suggest a plugin to export 3dsmax2008's 3ds format into .x files? thanks

Share this post


Link to post
Share on other sites
thanks for the link. it's really helpful. but now i'm confused about VERTEX structure.



in the article VERTEX structure was defined like:

struct _VERTEX
{
D3DXVECTOR3 pos; // vertex position
D3DXVECTOR3 norm; // vertex normal
float tu; // texture coordinates
float tv;
} VERTEX,*LPVERTEX;

and was used like this:

LPVERTEX pVerts;
Mesh::LockVertexBuffer(0,(BYTE **) &pVerts);
int vertexCount = Mesh::GetNumVertices();
for(int i=0; i<vertexCount; i++)
{
pVerts->tu = ....
}

now does that mean that LockVertexBuffer function automatically fills the VERTEX structure's member variables correctly? i think it requires the definition of VERTEX structure's member variables to be in a special byte order.
if so, how can i know if i can remove the norms and texture coordinates from the struct and add a variable for color i.e?


thanks

Share this post


Link to post
Share on other sites
Quote:
does that mean that LockVertexBuffer function automatically fills the VERTEX structure's member variables correctly?


When the mesh is cloned, the existing data (in the code example it's the position and normal data) is copied over, so you only need to take care of filling the new members you've added. This copying is done in the Clone() function, however, not in LockVertexBuffer() (although that doesn't really matter).

Quote:
i think it requires the definition of VERTEX structure's member variables to be in a special byte order.


Sure, like any D3D vertex structure, but you just declare the vertex structure you need and Clone() takes care of the rest (also see below). Of course, your structure must follow the format requirements D3D imposes on all vertex structures (i.e., position comes first, normals go before tex-coords, etc. The DirectX SDK should list the exact requirements).

Quote:
if so, how can i know if i can remove the norms and texture coordinates from the struct and add a variable for color i.e?


You don't have to worry about it. When you clone a mesh, you specify the vertex format you want the mesh to be converted to. If you request a piece of data that the mesh doesn't currently have, Clone() will create room for that data. If the original mesh has some data that you did not specify in your requested vertex format, it is removed.

So for example, if the mesh's vertices are made of position, normal and texture data and you Clone() the mesh and specify that you want position and color data, Clone() will copy over the position, allocate memory for the color data, and discard the normal and texture data. Note that the newly created data is not initialized with meaningful values, so that's up to you.

Share this post


Link to post
Share on other sites

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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