[D3DX 9] Mesh manipulation

Started by
4 comments, last by MJP 16 years, 4 months ago
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
'I is what I is. Eggegegegegeg' - The wisdom of Popeye
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++.
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.
'I is what I is. Eggegegegegeg' - The wisdom of Popeye
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.
Awsome. Thanks. I will give it a go.

galapogos
'I is what I is. Eggegegegegeg' - The wisdom of Popeye
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.

This topic is closed to new replies.

Advertisement