青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

D3D Animation Basis(5)

Loading Meshes

The first of the mesh−related helper functions is load_mesh. Actually there are three versions of the load_mesh function. The first version is used to load a mesh from an .X file using the D3DXLoadMeshFromX function. That means all meshes contained within the .X file are compressed into a single mesh object, which is subsequently stored in a D3DXMESHCONTAINER_EX object.

All iterations of the load_mesh function contain pointers to a valid 3D device object, the directory path to where your meshes' textures are stored, and the mesh loading flags and optional flexible vertex format that the load_mesh functions use to clone the meshes after loading. That means you can force your loaded meshes to use specific vertex formats!

Here's the prototype of the first load_mesh function:

HRESULT load_mesh(D3DXMESHCONTAINER_EX** ret_mesh_container,
  IDirect3DDevice9* device,
  const char* filename,
  const char* texture_path,
  DWORD new_fvf,
  DWORD load_flags);

The first load_mesh function takes a pointer to a D3DXMESHCONTAINER_EX object pointer that you want to use for storing the loaded mesh data. Notice I said pointer to a pointer. The load_mesh function will allocate the appropriate objects for you and store the pointers in the pointer you pass to load_mesh. This is similar to the way the InitD3D function stores the Direct3D and 3D device object pointers.

Also, you must pass a valid 3D device object to the load_mesh function (as the device pointer)−you use this device object to create the mesh container and texture buffers. The mesh that you want to load is specified as filename, and the directory in which your textures are located is specified in texture_path. This texture directory path is prefixed to any texture file names as they are loaded.

Finally, there are new_fvf and load_flags. You use the new_fvf parameter to force the mesh being loaded to use a specific FVF. For instance, if you only wanted to use 3D coordinates and normals, then you would set new_fvf to (D3DFVF_XYZ|D3DFVF_NORMAL). The load_mesh function will use CloneMeshFVF to clone the mesh using the specific FVF you specified.

The load_flags parameter is used to set the mesh loading flags as specified by the D3DXLoadMeshFromX function in the DX SDK documents. The default value for this parameter is D3DXMESH_SYSTEMMEM, meaning that the mesh is loaded into system memory (as opposed to hardware memory).

Here is implement of load_mesh function:

HRESULT load_mesh(D3DXMESHCONTAINER_EX** ret_mesh_container,
                  IDirect3DDevice9
* device,
                  
const char* filename,
                  
const char* texture_path,
                  DWORD new_fvf,
                  DWORD load_flags)
{
    
// error checking
    if(ret_mesh_container == NULL || device == NULL || filename == NULL || texture_path == NULL)
        
return E_FAIL;

    
// use system memory if converting FVF
    if(new_fvf)
        load_flags 
= D3DXMESH_SYSTEMMEM;

    
// load the mesh using D3DX routines

    ID3DXBuffer
*    material_buffer;
    ID3DXBuffer
*    adj_buffer;
    DWORD            num_materials;
    ID3DXMesh
*        mesh;

    HRESULT hr 
= D3DXLoadMeshFromX(filename, load_flags, device, &adj_buffer, &material_buffer, NULL,
                                   
&num_materials, &mesh);

    
if(FAILED(hr))
        
return hr;

    
// convert to new FVF first as needed
    if(new_fvf)
    {
        ID3DXMesh
* clone_mesh;
        hr 
= mesh->CloneMeshFVF(load_flags, new_fvf, device, &clone_mesh);

        
if(FAILED(hr))
        {
            release_com(adj_buffer);
            release_com(material_buffer);
            release_com(mesh);

            
return hr;
        }

        
// free prior mesh and store new pointer
        release_com(mesh);
        mesh 
= clone_mesh; clone_mesh = NULL;
    }

    D3DXMESHCONTAINER_EX
* mesh_container = new D3DXMESHCONTAINER_EX;
    
*ret_mesh_container = mesh_container;

    
// store mesh name (filename), type, and mesh pointer.
    mesh_container->Name           = strdup(filename);
    mesh_container
->MeshData.Type  = D3DXMESHTYPE_MESH;
    mesh_container
->MeshData.pMesh = mesh;

    mesh 
= NULL;

    
// store adjacency information

    DWORD adj_buffer_size 
= adj_buffer->GetBufferSize();

    
if(adj_buffer_size)
    {
        mesh_container
->pAdjacency = new DWORD[adj_buffer_size];
        memcpy(mesh_container
->pAdjacency, adj_buffer->GetBufferPointer(), adj_buffer_size);
    }

    release_com(adj_buffer);

    
// build material list

    mesh_container
->NumMaterials = num_materials;

    
if(num_materials == 0)
    {
        
// create a default material
        mesh_container->NumMaterials = 1;
        mesh_container
->pMaterials     = new D3DXMATERIAL[1];
        mesh_container
->textures     = new IDirect3DTexture9*[1];

        ZeroMemory(mesh_container
->pMaterials, sizeof(D3DXMATERIAL));

        mesh_container
->pMaterials[0].MatD3D.Diffuse.r = 1.0f;
        mesh_container
->pMaterials[0].MatD3D.Diffuse.g = 1.0f;
        mesh_container
->pMaterials[0].MatD3D.Diffuse.b = 1.0f;
        mesh_container
->pMaterials[0].MatD3D.Diffuse.a = 1.0f;
        mesh_container
->pMaterials[0].MatD3D.Ambient   = mesh_container->pMaterials[0].MatD3D.Diffuse;
        mesh_container
->pMaterials[0].MatD3D.Specular  = mesh_container->pMaterials[0].MatD3D.Diffuse;
        mesh_container
->pMaterials[0].pTextureFilename = NULL;
        mesh_container
->textures[0]                       = NULL;
    }
    
else
    {
        
// load the materials
        D3DXMATERIAL* xmaterials   = (D3DXMATERIAL*) material_buffer->GetBufferPointer();
        mesh_container
->pMaterials = new D3DXMATERIAL[mesh_container->NumMaterials];
        mesh_container
->textures   = new IDirect3DTexture9*[mesh_container->NumMaterials];

        
for(DWORD i = 0; i < mesh_container->NumMaterials; i++)
        {
            mesh_container
->pMaterials[i].MatD3D = xmaterials[i].MatD3D;
            mesh_container
->pMaterials[i].MatD3D.Ambient = mesh_container->pMaterials[i].MatD3D.Diffuse;

            mesh_container
->textures[i] = NULL;

            
// load the texture if one exists
            if(xmaterials[i].pTextureFilename)
            {
                
char texture_file[MAX_PATH];
                sprintf(texture_file, 
"%s%s", texture_path, xmaterials[i].pTextureFilename);
                D3DXCreateTextureFromFile(device, texture_file, 
&mesh_container->textures[i]);
            }
        }
    }

    release_com(material_buffer);

    mesh_container
->MeshData.pMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL);
    mesh_container 
= NULL;

    
return S_OK;
}

 

And that's it for the first load_mesh function! Let's check out how to use it. Suppose you want to load a mesh (from a file called Mesh.x) using the load_mesh function just shown. To demonstrate the ability to specify a new FVF, specify that you want to use XYZ components, normals, and texture coordinates for your mesh. Also, suppose your textures are in a subdirectory called \textures. As for the mesh loading flags, leave those alone to allow the mesh to load into system memory (as per the default flag shown in the prototype). Here's the code:

// Instance the mesh object
D3DXMESHCONTAINER_EX *Mesh = NULL;

// Load a mesh − notice the pointer to the mesh object
load_mesh(&Mesh, pD3DDevice, "Mesh.x", "..\\Textures\\", (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1));

Once the mesh has been loaded, you can access the mesh object via the Mesh−>MeshData.pMesh object pointer. Also, material data is stored in Mesh−>pMaterials, and texture data is stored in Mesh−>textures. The number of materials a mesh uses is stored in Mesh−>>NumMaterials. To render a loaded mesh, you can use the following code:

// pMesh = pointer to D3DXMESHCONTAINER_EX object

// Go through all material subsets
for(DWORD i=0;i<pMesh−>NumMaterials;i++) {
  // Set material and texture
  pD3DDevice−>SetMaterial(&pMesh−>pMaterials[i].MatD3D);
  pD3DDevice−>SetTexture(0, pMesh−>pTextures[i]);

 // Draw the mesh subset
 pDrawMesh−>DrawSubset(i);
}


posted on 2008-04-14 15:52 lovedday 閱讀(354) 評論(0)  編輯 收藏 引用

公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲黄色av| 国产自产高清不卡| 99精品福利视频| 亚洲精品在线看| 国产精品亚洲产品| 久久亚洲一区二区三区四区| 久久免费视频在线| 一区二区三区.www| 香蕉久久夜色精品| 亚洲国产日韩在线| 亚洲永久在线| 亚洲国产专区| 亚洲一区二区三区在线观看视频| 海角社区69精品视频| 亚洲日本欧美日韩高观看| 欧美午夜电影完整版| 久久三级视频| 欧美日韩一区二区三区四区在线观看| 午夜精品久久久久久久久久久久久| 欧美在线一区二区| 亚洲五月六月| 久久综合久久久久88| 亚洲一区二区三区午夜| 久久综合色播五月| 亚洲在线视频网站| 美女诱惑一区| 欧美专区亚洲专区| 欧美日韩国产三级| 欧美不卡在线视频| 国产日韩亚洲欧美综合| 亚洲精品小视频| 悠悠资源网亚洲青| 亚洲在线电影| 亚洲天堂av在线免费| 久久亚洲国产成人| 久久精品中文| 国产精品视频yy9099| 日韩网站在线观看| 亚洲精品乱码久久久久| 欧美一区免费视频| 欧美一区2区三区4区公司二百| 欧美精品一区二| 亚洲第一久久影院| 亚洲二区视频在线| 久久视频一区二区| 久久久久五月天| 国产麻豆午夜三级精品| 一本一本a久久| 99精品视频一区| 欧美xxx成人| 欧美国产极速在线| 亚洲国产天堂久久综合| 久久久欧美精品| 老**午夜毛片一区二区三区| 国产一区二区毛片| 亚洲欧美日韩一区二区三区在线观看 | 国产精品www色诱视频| 欧美激情一区二区三区不卡| **性色生活片久久毛片| 久久精品亚洲一区二区三区浴池| 久久精品99| 国产专区欧美精品| 久久精品视频免费播放| 久久亚洲综合网| 亚洲国产成人精品久久久国产成人一区| 香港久久久电影| 麻豆精品在线播放| 亚洲国产综合视频在线观看| 乱码第一页成人| 亚洲人被黑人高潮完整版| 一区二区三区精品在线 | 欧美一级淫片播放口| 久久精品二区亚洲w码| 国内精品久久久久久影视8| 久久久999精品| 欧美激情一区二区三级高清视频| 亚洲美女电影在线| 欧美性猛交xxxx免费看久久久| 国产精品99久久久久久久vr | 亚洲在线第一页| 国产日韩一区二区三区在线播放 | 久久精品亚洲精品| 欧美激情网友自拍| 亚洲一二区在线| 国产一区二区三区高清| 另类亚洲自拍| 在线视频欧美日韩| 另类av一区二区| 日韩视频久久| 国产性天天综合网| 欧美精品久久久久久| 亚洲综合色在线| 亚洲成人自拍视频| 午夜国产不卡在线观看视频| 黄色日韩精品| 欧美日韩午夜在线| 久久精品视频播放| 一区二区三区久久久| 免费国产一区二区| 午夜视频久久久久久| 亚洲电影免费观看高清| 欧美性色综合| 免费不卡在线观看av| 亚洲在线中文字幕| 亚洲国产裸拍裸体视频在线观看乱了中文 | 欧美mv日韩mv国产网站app| 亚洲视频一区二区| 亚洲第一色在线| 久久精品免费看| 亚洲一区二区精品视频| 亚洲电影免费观看高清完整版在线| 欧美少妇一区| 蘑菇福利视频一区播放| 久久成人免费电影| 亚洲自拍高清| 99精品国产在热久久下载| 免费成人网www| 欧美在线亚洲一区| 亚洲自拍偷拍福利| 夜夜精品视频| 亚洲日韩视频| 一区在线观看| 黑人巨大精品欧美一区二区小视频| 欧美性一二三区| 欧美久久婷婷综合色| 美女诱惑黄网站一区| 久久男人资源视频| 久久精品五月| 久久久精品日韩欧美| 欧美在线免费播放| 欧美一级大片在线免费观看| 亚洲主播在线观看| 亚洲欧美日韩国产中文在线| 亚洲午夜av电影| 亚洲无线一线二线三线区别av| 日韩一级大片| 一区二区三区四区国产| 亚洲深爱激情| 亚洲一级二级| 亚洲欧美国产高清va在线播| 亚洲综合999| 欧美在线视频免费播放| 欧美中在线观看| 久久久久久夜精品精品免费| 久久久国产一区二区| 久久久久久久国产| 美女诱惑一区| 欧美区日韩区| 欧美体内she精视频| 国产伦理一区| 一区二区三区在线视频播放| 亚洲国产精品久久久久久女王| 亚洲国产成人在线播放| 亚洲精品资源| 国产精品99久久久久久宅男 | 精品av久久707| 亚洲国产成人精品久久久国产成人一区 | 午夜精品视频在线| 久久久国产精彩视频美女艺术照福利| 久久久久www| 欧美精品一区二区蜜臀亚洲| 欧美三级韩国三级日本三斤| 国产精品视频yy9299一区| 黄色小说综合网站| 亚洲欧洲在线一区| 午夜精品www| 免费看精品久久片| 日韩一本二本av| 欧美一区综合| 欧美精品国产精品日韩精品| 国产精品一区二区a| 一色屋精品视频在线观看网站| 亚洲精品免费在线播放| 香蕉久久精品日日躁夜夜躁| 欧美电影资源| 亚洲一区成人| 欧美成人一区二免费视频软件| 国产精品老牛| 亚洲人成7777| 久久蜜桃av一区精品变态类天堂| 欧美成人国产| 亚洲——在线| 欧美日韩不卡| 一区二区三区在线视频观看| 亚洲一线二线三线久久久| 欧美成人日本| 欧美永久精品| 欧美特黄一区| 日韩亚洲一区在线播放| 久久免费国产| 亚洲欧美日韩国产中文| 欧美日韩一区二区三区免费| 亚洲国产精品999| 久久精品亚洲精品| 制服诱惑一区二区| 欧美精品99| 亚洲精品自在久久| 欧美.com| 久久综合伊人77777麻豆| 国产亚洲精品久久久久久|