Recently, I was answering a buddy's question in gameres: Getting vertices in the specified format from the mesh (. X file) and outputting them to the file.
The procedure is as follows:
Id3dxmesh * clonemesh;
Idirect3dvertexbuffer9 * PVB;
Vertexpnt * V = 0;
HR (mmesh-> clonemeshfvf (d3dusage_dynamic | d3dxmesh_vb_writeonly, d3dfvf_xyz | d3dfvf_normal | d3dfvf_tex0,
Gd3ddevice, & clonemesh ));
HR (clonemesh-> getvertexbuffer (& PVB ));
PVB-> lock (0, 0, (void **) & V, d3dlock_discard );
{
/* V = (vertexpnt *) (PVB );*/
}
D3dvertexbuffer_desc DESC;
PVB-> getdesc (& DESC );
STD: ofstream fout;
Fout. Open ("C: // mesh.txt ");
DWORD numvertex = clonemesh-> getnumvertices ();
For (uint I = 0; I <(numvertex/* DESC. Size/32 */); I ++)
{
If (fout. is_open ())
{
Fout <V [I]. POS. x <"" <V [I]. POS. Y <"" <V [I]. POS. z <STD: Endl;
Fout <V [I]. normal. x <"" <V [I]. normal. Y <"" <V [I]. normal. z <STD: Endl;
Fout <V [I]. tex0.x <"" <V [I]. tex0.y <STD: Endl;
Fout <"here" <STD: Endl;
}
Else
MessageBox (0, "No mesh.txt", "error", 1 );
}
Fout. Close ();
PVB-> unlock ();
There have been several small setbacks in writing this program:
1. In the for loop, I use DESC. Size/32 to get the number of vertices. The result program always has assert, which seems to be an access error such as out-of-bounds. Later, I asked a friend to know that the mesh has an interface for getting the number of vertices, namely, clonemesh> getnumvertices () in the program ();
2. During file creation, I used "C:/mesh.txt" during fout initialization, but I didn't use it to the translation function. No error was reported during the final program operation. However, when I opened mesh.txt on the C drive, I had no content, so I was depressed for a while. Later, I posted the question and got a reminder to add the escape character. If you do not need to escape characters, you can write "C:/mesh.txt" to avoid escape characters.