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

天行健 君子當自強而不息

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| 欧美美女日韩| 欧美高清视频一区二区三区在线观看| 免费欧美在线| 欧美日韩色一区| 国产精品专区第二| 在线激情影院一区| 日韩一级黄色大片| 欧美一区二区三区在线| 老司机免费视频一区二区三区| 欧美黄色网络| 亚洲自拍另类| 老司机免费视频久久| 欧美日本乱大交xxxxx| 国产毛片精品视频| 亚洲日本中文字幕免费在线不卡| 亚洲欧美一区二区精品久久久| 久久综合九九| 日韩一级精品| 久久天堂成人| 国产精品视频精品视频| 亚洲精品美女| 久久久综合网站| 99精品免费网| 美女网站久久| 国内精品伊人久久久久av一坑| 9人人澡人人爽人人精品| 久久久av水蜜桃| 中国女人久久久| 久久综合九色综合久99| 国产免费亚洲高清| 亚洲深爱激情| 久久久国产一区二区| 亚洲激情婷婷| 亚洲欧美在线x视频| 欧美高清在线视频观看不卡| 亚洲小少妇裸体bbw| 欧美国产亚洲精品久久久8v| 国产一区二区三区久久久| 中文久久精品| 亚洲国产精品久久久久婷婷老年| 亚洲美女免费视频| 免费在线欧美黄色| 亚洲国产毛片完整版| 久久久久久综合| 亚洲综合日韩在线| 国产精品免费aⅴ片在线观看| 亚洲美女一区| 亚洲国产成人porn| 老妇喷水一区二区三区| 国语精品中文字幕| 久久久久久久一区二区| 欧美一级电影久久| 国产日韩欧美91| 久久精品国产第一区二区三区最新章节 | 亚洲综合不卡| 欧美日韩国产成人| 一区二区三区你懂的| 亚洲免费大片| 国产精品videossex久久发布| 在线视频一区二区| 亚洲一卡久久| 国产一区二区丝袜高跟鞋图片| 欧美一区二区三区免费视频| 亚洲欧美日韩一区在线| 国产精品亚洲片夜色在线| 欧美一区二区三区在线观看视频| 亚洲在线视频网站| 国产欧美日韩伦理| 久久躁日日躁aaaaxxxx| 毛片精品免费在线观看| 一本久道综合久久精品| 亚洲少妇诱惑| 韩国欧美国产1区| 欧美激情2020午夜免费观看| 欧美日韩黄色一区二区| 亚洲在线成人| 欧美在线首页| 日韩午夜免费| 亚洲中无吗在线| 亚洲电影在线| 日韩一级精品| 韩国三级在线一区| 亚洲人成在线观看网站高清| 国产精品一区二区女厕厕| 欧美插天视频在线播放| 欧美色另类天堂2015| 久久久久久网址| 欧美另类一区| 欧美大片18| 国产精品成人aaaaa网站| 欧美一区二区三区日韩| 久久久精品五月天| 一本大道久久a久久综合婷婷| 亚洲一区二区三区在线| 伊人伊人伊人久久| 一区二区三区三区在线| 亚洲成人在线视频播放| 中文日韩在线视频| 亚洲国产精品美女| 在线中文字幕一区| 亚洲激情电影在线| 性刺激综合网| 亚洲一区二区视频在线观看| 久久综合色88| 久久久久欧美精品| 国产精品久久久久久av下载红粉 | 黄色欧美成人| 亚洲天堂av综合网| 日韩一级黄色片| 久久最新视频| 久久人人超碰| 国产日韩欧美在线播放不卡| 亚洲免费观看高清在线观看| 亚洲国产精品成人va在线观看| 亚洲伊人网站| 亚洲高清三级视频| 亚洲欧美在线高清| 先锋a资源在线看亚洲| 欧美日韩系列| 日韩天堂av| 一本色道久久88综合亚洲精品ⅰ| 老司机免费视频一区二区| 久久野战av| 激情欧美一区二区三区| 欧美与黑人午夜性猛交久久久| 香蕉久久国产| 国产精自产拍久久久久久| 亚洲天堂av高清| 新67194成人永久网站| 欧美激情一区二区三区不卡| 亚洲福利视频专区| 亚洲精品美女在线| 久久亚洲私人国产精品va媚药| 久久综合亚州| 最新成人在线| 欧美激情无毛| 99成人在线| 午夜在线一区二区| 国产日韩亚洲| 久久免费的精品国产v∧| 欧美成在线观看| 日韩一区二区精品| 国产精品xnxxcom| 性色av一区二区三区在线观看| 久久久久成人精品免费播放动漫| 悠悠资源网亚洲青| 欧美国产一区二区| 亚洲网站视频福利| 久久久久久高潮国产精品视| 一区二区在线不卡| 欧美韩日视频| 亚洲一区二区三区在线播放| 久久亚洲私人国产精品va媚药| 怡红院精品视频| 久久综合久久综合这里只有精品| 午夜精品影院| 欧美福利视频在线| 一本一本大道香蕉久在线精品| 欧美亚洲第一页| 欧美亚洲三区| 亚洲国产精品999| 亚洲曰本av电影| 在线色欧美三级视频| 欧美日韩在线播放三区四区| 午夜精品一区二区在线观看 | 黄色成人av在线| 欧美v亚洲v综合ⅴ国产v| 艳女tv在线观看国产一区| 久久精视频免费在线久久完整在线看| 亚洲国产精品久久人人爱蜜臀| 欧美午夜一区二区福利视频| 欧美在线影院| 99国产精品久久久| 狂野欧美激情性xxxx| 亚洲色图综合久久| 亚洲国产精品高清久久久| 国产精品另类一区| 欧美国产三级| 久久久久久久一区| 亚洲欧美经典视频| 亚洲精品视频二区| 欧美成人午夜影院| 久久久久国产一区二区三区| 中文日韩在线| 亚洲人成啪啪网站| 激情av一区二区| 国产视频观看一区| 国产精品久久久久久久久| 欧美国产日本| 老司机午夜精品| 久久精品国产综合精品| 亚洲影院在线| 在线亚洲一区| av成人免费观看| 99re热精品| 亚洲麻豆av| 亚洲精品一区二区网址| 亚洲高清久久|