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

天行健 君子當自強而不息

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>
            欧美精品v国产精品v日韩精品| 久久综合国产精品| 亚洲人体一区| 亚洲精品综合久久中文字幕| 亚洲综合成人在线| 欧美精品国产精品| 欧美精品一区二区精品网| 老司机精品福利视频| 欧美性理论片在线观看片免费| 欧美黄色免费网站| 欧美伦理在线观看| 一区二区自拍| 久久精品人人做人人综合| 99re热这里只有精品免费视频| 一区二区三区视频免费在线观看| av成人毛片| 欧美精品色综合| 日韩视频免费看| 亚洲欧洲综合另类在线| 欧美高清不卡| 99re6这里只有精品视频在线观看 99re6这里只有精品 | 在线视频成人| 午夜精品偷拍| 欧美激情精品| 在线欧美日韩国产| 麻豆久久精品| 久久综合色88| 亚洲理伦在线| 一区二区三区.www| 国产精品专区第二| 久久婷婷久久| 欧美激情一区二区三区在线| 久久av一区二区| 亚洲第一精品久久忘忧草社区| 亚洲视频第一页| 亚洲午夜一区| 国产亚洲一区二区在线观看 | 久久精品色图| 亚洲自拍都市欧美小说| 欧美亚洲成人精品| 久久高清一区| 老司机67194精品线观看| 亚洲三级免费电影| 久久九九精品99国产精品| 久久国产精品毛片| 国产精品久久久久久久第一福利 | 亚洲精品视频啊美女在线直播| 欧美一级视频一区二区| 欧美在线视频播放| 亚洲人成7777| 欧美va亚洲va日韩∨a综合色| 日韩亚洲欧美精品| 国产三级精品在线不卡| 欧美国产一区二区在线观看| 欧美中文字幕第一页| 亚洲第一在线| 亚洲一区二区3| 亚洲激情第一区| 91久久精品www人人做人人爽 | 亚洲盗摄视频| 欧美xx视频| 亚洲第一福利在线观看| 日韩视频在线观看免费| 欧美激情一区二区三区四区| 狠狠噜噜久久| 亚洲美洲欧洲综合国产一区| 欧美精品97| 久久国产精品久久久久久久久久| 亚洲一区成人| 日韩视频―中文字幕| 久久本道综合色狠狠五月| 一区电影在线观看| 毛片一区二区| 久久久久久网址| 国产美女精品人人做人人爽| 亚洲精品女人| 一区二区三区|亚洲午夜| 欧美日韩色一区| 欧美激情中文不卡| 永久久久久久| 中日韩美女免费视频网址在线观看 | 亚洲成色精品| 国产日韩欧美一区二区| 欧美成人免费观看| 久久久久久久尹人综合网亚洲| 妖精成人www高清在线观看| 国产亚洲欧洲一区高清在线观看| 欧美一级二级三级蜜桃| 欧美精品日韩综合在线| 欧美成人三级在线| 在线观看中文字幕不卡| 久久精品国产免费看久久精品| 精品av久久久久电影| 亚洲免费一区二区| 性8sex亚洲区入口| 国产精品久久久久久久久久久久久| 亚洲网站在线播放| 亚洲伊人一本大道中文字幕| 亚洲欧洲日韩女同| 久久这里只精品最新地址| 久久综合九色| 在线激情影院一区| 蜜臀99久久精品久久久久久软件| 亚洲啪啪91| 蜜臀a∨国产成人精品| 亚洲精品中文字幕在线观看| 久久久久成人网| 牛牛影视久久网| 欧美日韩国产成人精品| 日韩一区二区电影网| 亚洲三级视频| 亚洲精品国久久99热| 日韩视频久久| 亚洲美女视频在线免费观看| 美女脱光内衣内裤视频久久影院 | 91久久夜色精品国产九色| 久久久久看片| 亚洲国产精品va在线看黑人| 亚洲人成人77777线观看| 一区二区三区久久网| 亚洲淫性视频| 国产一区二区三区的电影| 91久久中文字幕| 亚洲图片激情小说| 国产视频一区三区| 日韩一本二本av| 香蕉乱码成人久久天堂爱免费| 久久久噜噜噜久久久| 欧美激情精品久久久久久| 亚洲午夜电影网| 久久青青草原一区二区| 91久久亚洲| 欧美在线视频不卡| 欧美日精品一区视频| 久久另类ts人妖一区二区| 欧美精品在线网站| 亚洲综合激情| 亚洲成色www久久网站| 亚洲欧美日韩国产精品| 欧美成年人网| 国产精品一区二区你懂得| 久久精品盗摄| 一本大道av伊人久久综合| 久久综合九色| 午夜一区在线| 亚洲精品免费电影| 国产精品一二一区| 欧美区一区二区三区| 久久久久综合一区二区三区| 一区二区高清视频在线观看| 久久米奇亚洲| 亚洲欧美精品一区| 日韩视频免费观看| 亚洲黑丝在线| 老牛嫩草一区二区三区日本| 99国产精品99久久久久久| 免费视频一区二区三区在线观看| 狠狠久久亚洲欧美| 欧美日本网站| 免费视频一区| 欧美在线啊v一区| 正在播放亚洲| 亚洲激情国产| 欧美 日韩 国产一区二区在线视频 | 亚洲影院色无极综合| 奶水喷射视频一区| 女同一区二区| 久久美女性网| 久久久精品日韩欧美| 亚洲欧美www| 国产精品区一区二区三| 欧美国产成人在线| 久久综合影音| 久久久久国产成人精品亚洲午夜| 久久蜜桃精品| 久久久久成人精品免费播放动漫| 国产精品影视天天线| 欧美精品1区| 欧美精品自拍| 欧美日韩一区二区三区四区在线观看| 日韩亚洲视频| 夜夜嗨av一区二区三区四区 | 先锋亚洲精品| 亚洲综合日韩中文字幕v在线| 亚洲一区二区三区免费观看| 欧美日精品一区视频| 欧美日韩蜜桃| 欧美私人啪啪vps| 国产精品久久久久久久久婷婷| 午夜精品视频一区| 亚洲欧美另类国产| 亚洲欧洲另类国产综合| 亚洲午夜激情网站| 中文国产成人精品久久一| 日韩午夜av在线| 亚洲图片你懂的| 午夜亚洲视频| 久久久久久成人| 欧美成人综合一区| 亚洲精品午夜|