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

天行健 君子當自強而不息

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在线免费| 亚洲精品一区二区三区福利| 午夜天堂精品久久久久 | 国内精品视频在线播放| 性欧美激情精品| 新67194成人永久网站| 国精品一区二区三区| 模特精品裸拍一区| 欧美日韩不卡| 欧美一区二区在线视频| 久久精品一级爱片| 99精品视频免费| 亚洲欧美视频一区二区三区| 黄色亚洲免费| 亚洲人成免费| 国产精品一区久久久| 欧美va天堂在线| 欧美调教vk| 欧美bbbxxxxx| 国产精品久久久久久久第一福利| 久久婷婷综合激情| 欧美日韩精品久久久| 久久视频在线视频| 欧美日韩精品中文字幕| 久久激情中文| 欧美日韩激情网| 蜜桃精品一区二区三区 | 久久爱www| 在线亚洲免费| 久久综合久久综合九色| 午夜精品国产精品大乳美女| 牛牛精品成人免费视频| 翔田千里一区二区| 欧美精品一区二| 免费在线日韩av| 国产日本欧洲亚洲| aa国产精品| 99riav久久精品riav| 久久精品国产一区二区三区| 亚洲自拍偷拍视频| 欧美日韩视频在线观看一区二区三区 | 欧美激情在线播放| 久久综合久久综合久久综合| 国产精品美腿一区在线看 | 欧美国产日产韩国视频| 国模一区二区三区| 亚洲欧美日韩天堂| 亚洲欧美在线高清| 欧美日韩一区免费| 亚洲精品自在在线观看| 亚洲精选久久| 欧美风情在线| 亚洲黄色av| 亚洲精品欧美精品| 欧美成人精品h版在线观看| 久久综合国产精品| 激情久久久久久久| 欧美一区二视频在线免费观看| 亚洲欧美日韩另类精品一区二区三区| 欧美精品亚洲一区二区在线播放| 亚洲国产精品悠悠久久琪琪| 亚洲人成免费| 欧美大片在线观看| 亚洲国产欧美日韩| 亚洲蜜桃精久久久久久久| 欧美成人一区二免费视频软件| 欧美高清在线一区| 亚洲青涩在线| 欧美日韩国产综合新一区| 亚洲另类在线一区| 亚洲欧美在线x视频| 国产日韩精品一区二区| 久久精品国产精品亚洲综合| 久久综合影音| 亚洲人成在线观看网站高清| 欧美激情综合在线| 国产精品99久久久久久久久| 午夜精品在线视频| 黄色成人av在线| 男男成人高潮片免费网站| 亚洲破处大片| 午夜在线精品偷拍| 1024日韩| 欧美三级网页| 欧美制服丝袜第一页| 亚洲国产成人tv| 亚洲欧美日韩精品久久| 国产字幕视频一区二区| 欧美高清在线观看| 国产精品99久久99久久久二8| 久久精品国产亚洲5555| 亚洲国产小视频| 欧美日韩在线一区二区三区| 午夜精品美女久久久久av福利| 免费观看30秒视频久久| 一本色道久久加勒比精品| 国产一区二区三区在线观看免费| 美女网站久久| 午夜精彩国产免费不卡不顿大片| 欧美成人高清| 亚洲欧美激情一区二区| 欲色影视综合吧| 国产精品爽爽ⅴa在线观看| 久久综合亚州| 亚洲欧美在线aaa| 亚洲国产精品第一区二区三区| 性欧美xxxx大乳国产app| 亚洲福利专区| 国产日韩一区二区三区在线播放 | 久久一区视频| 亚洲一区二区视频在线| 亚洲高清不卡在线| 亚洲免费在线观看| 日韩视频不卡| 一区在线视频| 国产日韩精品一区二区三区| 欧美激情中文字幕一区二区| 久久精品国产免费观看| 亚洲一区在线播放| 亚洲精品免费电影| 欧美国产日韩在线| 另类尿喷潮videofree| 欧美一区二区三区四区夜夜大片| 99re热这里只有精品视频| 亚洲国产美女精品久久久久∴| 国产一区二区三区高清播放| 国产精品入口福利| 国产精品vvv| 国产精品v欧美精品v日本精品动漫| 欧美激情成人在线| 蜜臀av国产精品久久久久| 久久精品二区三区| 欧美亚洲一区| 欧美一级淫片aaaaaaa视频| 亚洲午夜激情网页| 国产精品99久久久久久www| 99精品国产热久久91蜜凸| 亚洲精品午夜| 亚洲伦理精品| 一区二区高清在线观看| 在线天堂一区av电影| 在线视频欧美日韩| 亚洲在线网站| 欧美一级理论性理论a| 午夜精品视频| 久久精品国产第一区二区三区最新章节| 午夜精品国产更新| 久久成年人视频| 久久婷婷国产综合尤物精品| 毛片基地黄久久久久久天堂| 欧美大片91| 欧美天堂亚洲电影院在线播放| 国产精品美女久久久久久免费| 国产欧美日本| 一区二区视频免费完整版观看| 在线免费日韩片| 亚洲乱码视频| 亚洲欧美综合国产精品一区| 久久久久网站| 亚洲国产免费看| 一本色道久久综合狠狠躁篇怎么玩| 亚洲小少妇裸体bbw| 欧美在线三级| 欧美激情欧美激情在线五月| 欧美系列电影免费观看| 国产一区二区中文字幕免费看| 激情综合网激情| 夜夜爽av福利精品导航| 欧美一区二区三区另类| 欧美刺激性大交免费视频| 亚洲日本欧美| 欧美一区二区女人| 欧美激情一区二区三区不卡| 国产精品日韩一区| 亚洲电影在线观看| 亚洲欧美成人一区二区三区| 美国成人毛片| 亚洲深夜福利在线| 噜噜噜久久亚洲精品国产品小说| 欧美日韩一区二区三区四区在线观看 | 日韩天堂在线观看| 欧美一站二站| 欧美日韩亚洲精品内裤| 国模大胆一区二区三区| 一区二区三区视频在线| 久久亚洲精品视频| 一本色道久久综合亚洲91 | 99视频精品全部免费在线| 欧美影院成人| 国产精品久久久久影院亚瑟 | 亚洲激情社区| 久久精品国产2020观看福利| 亚洲日本欧美天堂| 久久视频这里只有精品| 国产伦精品一区二区三区照片91| 日韩午夜电影av| 欧美成人一区二区| 久久成人精品无人区| 国产精品毛片高清在线完整版| 亚洲免费不卡|