Today we are going to learn Direct3D use of model import, Direct3D support. x model file import use,. The x file is a Microsoft-defined 3D model file format that contains some information such as meshes, animations, textures, and so on. Currently 3DS Max and Maya do not natively support the export of the X model, only a plugin called "3DS Max Panda" can be used on 3DS Max to convert the model to an X file.
Model: |
Http://yunpan.cn/cLXcxGKjwmqgk Access Password ec5c |
X Model Viewer: |
http://yunpan.cn/cLXcnArcQ7h5y Access Password 8605 |
Direct3D using the model requires the following steps
- Load the network model for X Files
- Loading materials and textures
- Draw Grid
1. Load the network model to the X file
D3dxloadmeshfromx (L"Miki. X",//name of the modelD3dxmesh_managed,//additional options when creating meshes, D3dmesh enumeration values one or more valuesg_pd3ddevice,//D3D Equipment&padjbuffer,//buffer memory address for polygon information around each polygon&pmtrlbuffer,//save a subset of all meshes material that holds the buffer address of the model's material and texture filesNull//special effects of the storage mesh model, direct null&g_dwnummtrls,//the number of all materials&g_pmesh);//model Grid
2. Loading materials and textures
D3dxmaterial *pmtrls = (d3dxmaterial*) pmtrlbuffer->getbufferpointer ();//Create a d3dxmaterial structure to read material and texture informationG_pmaterials =NewD3dmaterial9[g_dwnummtrls];//creating an array of materialsG_ptextures =NewLpdirect3dtexture9[g_dwnummtrls];//creating an array of maps for(DWORD i=0; i<g_dwnummtrls; i++) {G_pmaterials[i]= Pmtrls[i]. MATD3D;//get the material,G_pmaterials[i]. Ambient = G_pmaterials[i]. Diffuse;//and set the color value of the ambient light//create a Texture object and create a map from inside the materialG_ptextures[i] =NULL; D3DXCreateTextureFromFileA (g_pd3ddevice, Pmtrls[i].ptexturefilename,&G_ptextures[i]); }
3. Draw the Grid
// to draw the various parts of the grid for 0; i < G_dwnummtrls; i++) { g_pd3ddevice->setmaterial (&g_pmaterials[i]); // Set Material G_pd3ddevice->settexture (0, g_ptextures[i]); // set up a picture G_pmesh->drawsubset (i); // Draw model Grid }
Direct3D for X model loading