Obtain vertices in the specified format from the mesh (. X file) and output them to the file.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.