Jump to content
  • Advertisement
Sign in to follow this  
galapogos22

[D3DX 9] Mesh manipulation

This topic is 3895 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

Hey all! Quick question:- Is there a D3DX function to scale and normalize a mesh? I have looked in ID3DXBaseMesh and ID3XMESH in the SDK help but i cant see any functions that would do it. Do i have to do it myself? ie. clone the mesh -> find extreme vertex values -> change vertex info so extremes = 1 and rest is relative to this? Just point me in the right direction. Another question:- Also i want to make sure my mesh's are in a format i like so want them all to use FVF (fixed function) types i specify. After importing my mesh's (.x file from 3ds max) how would i go about converting them (if needed) to a format i want. It will involve ID3DXBaseMesh::GetFVFbut that is as far as i can figure. Again just point me to a helpful function or document and i will try to figure it out. Regards galapogos

Share this post


Link to post
Share on other sites
Advertisement
Normalizing a mesh? This is intresting. I don't think there would be a method for that in D3DX9 but I can be wrong.
When you clone a mesh, you can supply a new vertex format so the result mesh will take the new format as its vertex layout. You can use one of the vertex formats defined by D3DX9 or you can define one by yourself. I use C#, so things might be differnt in C++.

Share this post


Link to post
Share on other sites
Cool. Thats the second question answered. Normalising the mesh was due to the fact when i import them they are often incorrect in size. I need to scale and resize mesh's to suit my needs but i dont have the foggiest how to do so. Well i could go through i vertex at a time and chnge it i suppose but i thought (well hoped) microsft would have a special function to do it for me.

Share this post


Link to post
Share on other sites
Well there IS a function that will generate a bounding sphere for your mesh so that you don't need to go through it yourself (D3DXComputeBoundingSphere). With that it should be very easy to scale your vertices one at a time.



BYTE* vbPointer = NULL;
D3DXVECTOR3 boundingCenter;
FLOAT boundingRadius;

mesh->LockVertexBuffer(0, (VOID**)&vbPointer);

D3DXComputeBoundingSphere((D3DXVECTOR3*)vbPointer, numVertices, mesh->GetNumBytesPerVertex(), &boundingCenter, &boundingRadius);

FLOAT scaleValue = 1.0f / (D3DXVec3Length(&boundingCenter) + boundingRadius);

for (UINT i = 0; i < mesh->GetNumVertices(); i++)
{
*(D3DXVECTOR3*)vbPointer = *(D3DXVECTOR3*)vbPointer * scaleValue;
vbPointer += mesh->GetNumBytesPerVertex();
}

mesh->UnlockVertexBuffer();



That should do the trick, I think. At least, it seems to work for me.

Share this post


Link to post
Share on other sites
Oh and I forgot to mention...that code assumes that the vertex position is located in the first 3 FLOAT's of each vertex. If that's not the case, you'll need to make a slight modification.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!