Jump to content
  • Advertisement
Sign in to follow this  
xujiezhige

Can CloneMesh() convert one vertex format to another?

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

I load a teapot mesh from .X file. Then I want to add normal data member to vertex format. So I clone a new mesh with new vertex format.
See the following code:

[color=#ff0000]if( FAILED( D3DXLoadMeshFromX( pszFileName, D3DXMESH_SYSTEMMEM, m_pd3dDevice, NULL,
NULL, NULL, NULL, &pMeshTemp ) ) )
return E_FAIL;

[color=#ff0000] D3DVERTEXELEMENT9 decl[]=
{
0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0,
0, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0,
D3DDECL_END()
};

[color=#ff0000] if( FAILED( pMeshTemp->CloneMesh( D3DXMESH_MANAGED, decl, m_pd3dDevice, ppMesh ) ) )
return E_FAIL;

[color=#ff0000]if( FAILED( D3DXComputeNormals( *ppMesh, NULL ) ) )
return E_FAIL;

[color=#000000]The codes provided are problemtic, the program crashes when running.

[color=#000000]But it works when I change [color="#ff0000"]D3DDECLTYPE_FLOAT4 to [color="#ff0000"]D3DDECLTYPE_FLOAT3 [color=#000000]and [color=#ff0000]16 [color=#000000]to [color=#ff0000]12[color=#000000].

[color=#000000]Is the problem related to the x file?

Share this post


Link to post
Share on other sites
Advertisement
Normals only have 3 floats. So try changing second D3DDECLTYPE_FLOAT4 to FLOAT3 and it should also work. Thats not a problem, because you made a mistake for making Normals float4 in the first place.

Share this post


Link to post
Share on other sites

Positions also typically have 3 positions, not 4.


Normals only have 3 floats. So try changing second D3DDECLTYPE_FLOAT4 to FLOAT3 and it should also work. Thats not a problem, because you made a mistake for making Normals float4 in the first place.


Thank you!

But we often use 4 float to represent position, just making the last element to 1. So I could use 4 float to contain position ( or normal ).
Can you tell why?

Share this post


Link to post
Share on other sites
I all depens on your Vertex-Struct and/or FVF. If you use 4 floats there, you can use 4 floats here. Internally DirectX does nothing else than float4(pos.x,pos.y,pos.z,1.0f); so thats why you can theoretically do this. Obivously you defined Position and/or Normal to float3 somewhere else in your code.

Share this post


Link to post
Share on other sites
Thank you, The king2.

Through my several test, I find CloneMesh() can convert any vertex format to what you want. The reason of program crashing after my first modification is that D3DXComputeNormal() will fail if the normal is float4.

I find some information in Doc.gallery_193491_378_4021.jpg

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!