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

天行健 君子當自強而不息

Using the .X File Format(9)

Loading Meshes from .X

Now that you've got a firm grip on how the .X file format works, consider how Microsoft first intended for you to use it−to contain 3D mesh information for your games. The D3DX library comes with a number of functions you can use to load mesh data from an .X file. With the addition of the .X parser developed in this chapter, you have even more options available to you. Check out just how easy it is to work with D3DX to load mesh data.

 

Loading Meshes Using D3DX

The D3DX library defines the handy ID3DXMesh object that contains and renders 3D meshes for you. Although you can use your own custom mesh storage containers, I find sticking to the ID3DXMesh object perfectly sensible. That's the object I'll use for the rest of this chapter (with the exception of the also−handy ID3DXSkinMesh object, which you'll see in a moment).

The fastest way to load mesh data using D3DX is to call on the D3DXLoadMeshFromX and D3DXLoadMeshFromXof functions. Both of these meshes will take the data contained within an .X file and convert it to an ID3DXMesh object. The D3DXLoadMeshFromX file loads an entire .X file at once (compressing all meshes into a single output mesh), whereas the D3DXLoadMeshFromXof function loads a single mesh pointed at by an IDirectXFileData object.

The D3DXLoadMeshFromX function provides a file name to load, some flags to control loading aspects, a 3D device pointer, pointers to buffers for containing material data, and some miscellaneous data pointers that you can ignore for now.

Loads a mesh from a DirectX .x file.

HRESULT D3DXLoadMeshFromX(
LPCTSTR pFilename,
DWORD Options,
LPDIRECT3DDEVICE9 pD3DDevice,
LPD3DXBUFFER * ppAdjacency,
LPD3DXBUFFER * ppMaterials,
LPD3DXBUFFER * ppEffectInstances,
DWORD * pNumMaterials,
LPD3DXMESH * ppMesh
);

Parameters

pFilename
[in] Pointer to a string that specifies the filename. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
Options
[in] Combination of one or more flags from the D3DXMESH enumeration, which specifies creation options for the mesh.
pD3DDevice
[in] Pointer to an IDirect3DDevice9 interface, the device object associated with the mesh.
ppAdjacency
[out] Pointer to a buffer that contains adjacency data. The adjacency data contains an array of three DWORDs per face that specify the three neighbors for each face in the mesh. For more information about accessing the buffer, see ID3DXBuffer.
ppMaterials
[out] Pointer to a buffer containing materials data. The buffer contains an array of D3DXMATERIAL structures, containing information from the DirectX file. For more information about accessing the buffer, see ID3DXBuffer.
ppEffectInstances
[out] Pointer to a buffer containing an array of effect instances, one per attribute group in the returned mesh. An effect instance is a particular instance of state information used to initialize an effect. See D3DXEFFECTINSTANCE. For more information about accessing the buffer, see ID3DXBuffer.
pNumMaterials
[out] Pointer to the number of D3DXMATERIAL structures in the ppMaterials array, when the method returns.
ppMesh
[out] Address of a pointer to an ID3DXMesh interface, representing the loaded mesh.

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following values: D3DERR_INVALIDCALL, E_OUTOFMEMORY.

Remarks

The compiler setting also determines the function version. If Unicode is defined, the function call resolves to D3DXLoadMeshFromXW. Otherwise, the function call resolves to D3DXLoadMeshFromXA because ANSI strings are being used.

All the meshes in the file will be collapsed into one output mesh. If the file contains a frame hierarchy, all the transformations will be applied to the mesh.

For mesh files that do not contain effect instance information, default effect instances will be generated from the material information in the .x file. A default effect instance will have default values that correspond to the members of the D3DMATERIAL9 structure.

The default texture name is also filled in, but is handled differently. The name will be Texture0@Name, which corresponds to an effect variable by the name of "Texture0" with an annotation called "Name." This will contain the string file name for the texture.

First, you need to instance an ID3DXMesh object.

ID3DXMesh *Mesh = NULL;

From there, suppose you want to load the .X file called test.x. Simple enough−you just need to specify the file name in the call to D3DXLoadMeshFromX but wait! What's with the Options parameter? You use it to tell D3DX how to load the mesh−into system memory or video memory, using write−only memory, and so on. A flag represents each option. Table 3.3 lists some of the most common macros.

From Table 3.3, you can see there are really not many options for loading meshes. In fact, I recommend using only D3DXMESH_SYSTEMMEM or D3DXMESH_WRITEONLY The first option, D3DXMESH_SYSTEMMEM, forces your mesh's data to be stored in system memory, making access to the mesh data faster for both read and write operations.

Specifying D3DXMESH_DYNAMIC means you are going to change the mesh data periodically. It's best to specify this flag if you plan to periodically change the mesh's data (such as vertices) in any way during run time.

If speed is your need, then I suggest using the D3DXMESH_WRITEONLY flag, which tells D3DX to use memory that will not allow read access. Most often that means you will use video memory because it is usually (but not always) write−only. If you're not going to read a mesh's vertex data, then I suggest using this flag.

Tip If you're not using system memory or write−only access, what's left to use? Just specify a value of 0 for Options in the call to D3DXLoadMeshFromX, and you'll be fine.

Getting back to the parameters of D3DXLoadMeshFromX, you'll see the pointer to a 3D device interface. No problem−you should have one of those hanging around in your project! Next is the ID3DXBUFFER pointer, ppAdjacency. Set that to NULL−you won't be using it here.

The next three parameters, ppMaterials, ppEffectInstance, and pNumMaterials, contain the mesh's material information, such as material color values and texture file names, as well as effects data. If you're using DirectX 8, you can safely exclude the ppEffectInstance reference−it doesn't exist in that version. If you're using DirectX 9, you can set ppEffectInstance to NULL because you don't require any effects information.

The ppMaterials pointer points to an ID3DXBuffer interface, which is merely a container for data. pNumMaterials is a pointer to a DWORD variable that will contain the number of materials in a mesh that was loaded. You'll see how to use material information in a moment.

Finishing up with D3DXLoadMeshFromX, you see the actual ID3DXMesh object pointer−ppMesh. This is the interface you supply to contain your newly loaded mesh data. And there you have it! Now put all of this stuff together into a working example of loading a mesh.

Load a mesh, again called test.x, using write−only memory. After you've instanced the mesh object pointer, you need to instance an ID3DXBuffer object to contain material data and a DWORD variable to contain the number of materials.

ID3DXBuffer *pMaterials = NULL;
DWORD NumMaterials;

From here, call D3DXLoadMeshFromX.

// pDevice = pointer to a valid IDirect3DDevice9 object
D3DXLoadMeshFromX("test.x", D3DXMESH_WRITEONLY, pDevice, NULL, &pMaterials, NULL, &NumMaterials, &Mesh);

Great! If everything went as expected, D3DXLoadMeshFromX will return a success code, and your mesh will have been loaded in the ID3DXMesh interface Mesh! Of course, every single mesh contained in the .X file was crunched into a single mesh object, so how about those times when you want access to each separately−defined mesh in the file?

This is where the D3DXLoadMeshFromXof file comes in. You use the D3DXLoadMeshFromXof function in conjunction with your .X parser to load mesh data from an enumerated Mesh object. Just take a look at the D3DXLoadMeshFromXof function prototype to see what this entails.

Loads a mesh from an ID3DXFileData object.

HRESULT D3DXLoadMeshFromXof(
LPD3DXFILEDATA pxofMesh,
DWORD Options,
LPDIRECT3DDEVICE9 pDevice,
LPD3DXBUFFER * ppAdjacency,
LPD3DXBUFFER * ppMaterials,
LPD3DXBUFFER * ppEffectInstances,
DWORD * pNumMaterials,
LPD3DXMESH * ppMesh
);

Parameters

pxofMesh
[in] Pointer to an ID3DXFileData interface, representing the file data object to load.
Options
[out] Combination of one or more flags from the D3DXMESH enumeration, specifying creation options for the mesh.
pDevice
[in] Pointer to an IDirect3DDevice9 interface, the device object associated with the mesh.
ppAdjacency
[out] Pointer to a buffer that contains adjacency data. The adjacency data contains an array of three DWORDs per face that specify the three neighbors for each face in the mesh. For more information about accessing the buffer, see ID3DXBuffer.
ppMaterials
[in, out] Address of a pointer to an ID3DXBuffer interface. When the method returns, this parameter is filled with an array of D3DXMATERIAL structures.
ppEffectInstances
[out] Pointer to a buffer containing an array of effect instances, one per attribute group in the returned mesh. An effect instance is a particular instance of state information used to initialize an effect. See D3DXEFFECTINSTANCE. For more information about accessing the buffer, see ID3DXBuffer.
pNumMaterials
[in, out] Pointer to the number of D3DXMATERIAL structures in the ppMaterials array, when the method returns.
ppMesh
[out, retval] Address of a pointer to an ID3DXMesh interface, representing the loaded mesh.

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL.

D3DXERR_INVALIDDATA E_OUTOFMEMORY

Remarks

For mesh files that do not contain effect instance information, default effect instances will be generated from the material information in the .x file. A default effect instance will have default values that correspond to the members of the D3DMATERIAL9 structure.

The default texture name is also filled in, but is handled differently. The name will be Texture0@Name, which corresponds to an effect variable by the name of "Texture0" with an annotation called "Name." This will contain the string file name for the texture.

Now wait a sec! D3DXLoadMeshFromXof looks almost exactly like D3DXLoadMeshFromX! The only difference is the first parameter; instead of a pointer to an .X file name to load, D3DXLoadMeshFromXof has a pointer to an ID3DXFileData object. By providing the pointer to a currently enumerated ID3DXFileData object, D3DX will take over and load all of the appropriate mesh data for you! And
since every other parameter is the same as in D3DXLoadMeshFromX, you'll have no trouble using D3DXLoadMeshFromXof in your .X parser class!

Regardless of which function you use to load the mesh data (D3DXLoadMeshFromX or D3DXLoadMeshFromXof), all you have left to do is process the material information once a mesh has been loaded into an ID3DXMesh object.

To process the material information, you need to retrieve a pointer to the material's ID3DXBuffer's data buffer (used in the call to D3DXLoadMeshFromX or D3DXLoadMeshFromXof) and cast it to a D3DXMATERIAL type. From there, iterate all materials, using the number of materials set in NumMaterials as your index. Then you need to instance an array of D3DMATERIAL9 structures and IDirect3DTexture9 interfaces to contain the mesh's material data. Use the following code to process the material information:

// Objects to hold material and texture data
D3DMATERIAL9 *Materials = NULL;
IDirect3DTexture9 *Textures = NULL;
// Get a pointer to the material data
D3DXMATERIAL *pMat;
pMat = (D3DXMATERIAL*)pMaterials−>GetBufferPointer();
// Allocate material storage space
if(NumMaterials)
{
Materials = new D3DMATERIAL9[NumMaterials];
Textures = new IDirect3DTexture9*[NumMaterials];
	// Iterate through all loaded materials
for(DWORD i=0;i<NumMaterials;i++)
{
// Copy over the material information
Materials[i] = pMat[i].MatD3D;
// Copy diffuse color over to ambient color
Materials[i].Ambient = Materials[i].Diffuse;
// Load a texture if one is specified
Textures[i] = NULL;
		if(pMat[i].pTextureFilename) 
D3DXCreateTextureFromFile(pDevice, pMat[i].pTextureFilename, &Textures[i]);
}
}
else
{
// Allocate a default material if none were loaded
Materials = new D3DMATERIAL9[1];
Textures = new IDirect3DTexture9*[1];
	// Set a default white material and no texture
Textures[0] = NULL;
ZeroMemory(&Materials[0], sizeof(D3DMATERIAL9));
	Materials[0].Diffuse.r = Materials[0].Ambient.r = 1.0f;
Materials[0].Diffuse.g = Materials[0].Ambient.g = 1.0f;
Materials[0].Diffuse.b = Materials[0].Ambient.b = 1.0f;
Materials[0].Diffuse.a = Materials[0].Ambient.a = 1.0f;
}
// Free material data buffer
pMaterials−>Release();

You can see in the preceding code that I added a case to check whether no materials were loaded, in which case you need to create a default material to use. Once those materials are loaded, you're ready to begin using the mesh interface to render.


posted on 2008-04-18 09:41 lovedday 閱讀(928) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(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视频精品在线| 这里只有精品视频| 国产在线日韩| 亚洲电影av| 国产精品久久久久一区二区三区| 亚洲欧美国产va在线影院| 性一交一乱一区二区洋洋av| 国产日韩欧美在线观看| 免费在线成人| 欧美日韩另类丝袜其他| 午夜影院日韩| 免费成人激情视频| 亚洲专区一二三| 久久人91精品久久久久久不卡| 亚洲福利一区| 亚洲一区二区三区高清| 欧美福利电影在线观看| 亚洲永久在线观看| 久久丁香综合五月国产三级网站| 91久久国产综合久久蜜月精品 | 夜夜嗨av一区二区三区四区| 99热这里只有成人精品国产| 国产在线国偷精品产拍免费yy| 欧美国产日本| 国产日韩欧美一二三区| 亚洲成人在线网| 国产日产欧美一区| 亚洲欧洲一区二区在线播放| 国产伦精品免费视频| 亚洲风情在线资源站| 国产一区二区精品| 亚洲精品资源| 在线观看日韩一区| 午夜精品影院| 亚洲一级黄色av| 免播放器亚洲一区| 久久久国产精彩视频美女艺术照福利| 欧美精品自拍偷拍动漫精品| 另类专区欧美制服同性| 国产精品二区三区四区| 亚洲国产欧美一区二区三区丁香婷| 国产精品日韩高清| 亚洲精品精选| 亚洲精品国精品久久99热一| 欧美伊人久久久久久久久影院| 亚洲一区二区在线播放| 欧美二区视频| 欧美寡妇偷汉性猛交| 在线成人免费观看| 欧美一区二区播放| 久久99在线观看| 国产精品乱人伦一区二区| 99国产精品久久| 一区二区三区黄色| 欧美精品一卡| 亚洲精品一区二区三区婷婷月| 在线日韩av片| 玖玖精品视频| 亚洲欧洲日本一区二区三区| 亚洲精品乱码久久久久| 欧美激情无毛| 亚洲人成艺术| 亚洲色在线视频| 国产精品久久久久一区二区| 一区二区三区国产在线| 亚洲在线1234| 国产日韩一区| 久久国产日本精品| 噜噜噜91成人网| 亚洲精品美女在线观看播放| 欧美精品1区| 亚洲天堂av综合网| 久久精品官网| 亚洲欧洲在线看| 欧美少妇一区二区| 亚洲午夜电影在线观看| 欧美一区二区黄色| 亚洲成色999久久网站| 欧美成人中文| 亚洲午夜羞羞片| 久久久久欧美| 日韩亚洲欧美中文三级| 国产精品九九| 久久久精品性| 一区二区三区波多野结衣在线观看| 亚洲欧美日韩中文播放| 国产一区二区三区奇米久涩| 欧美aa国产视频| 亚洲私人影院| 欧美激情小视频| 午夜国产精品视频| 精品999网站| 欧美特黄a级高清免费大片a级| 性色av香蕉一区二区| 亚洲黄色毛片| 久久久亚洲国产美女国产盗摄| 亚洲人成网站色ww在线| 国产精品自拍网站| 欧美成人精品1314www| 亚洲制服少妇| 亚洲区在线播放| 老司机免费视频一区二区三区| 亚洲乱码视频| 一区二区三区在线看| 国产精品xxx在线观看www| 久久女同精品一区二区| 在线视频中文亚洲| 亚洲国产精品视频一区| 久久久免费精品视频| 亚洲一区在线看| 亚洲精品美女久久7777777| 国产一区二区av| 国产精品久久久久久久久久妞妞 | 亚洲图片欧美一区| 欧美韩日视频| 久久久久久一区二区| 午夜视频在线观看一区二区三区| 亚洲人被黑人高潮完整版| 国产欧美一区二区精品仙草咪| 欧美精品首页| 欧美激情网站在线观看| 久久精品二区| 欧美一区二区视频在线观看2020| 一区二区高清在线观看| 亚洲黄色尤物视频| 免费高清在线一区| 久久久综合网站| 欧美在线观看一区二区三区| 亚洲性感美女99在线| 99re热精品| aa日韩免费精品视频一| 亚洲精品一级| 亚洲毛片在线免费观看| 亚洲激情网站| 亚洲精品女av网站| 亚洲精品欧美日韩| 日韩视频一区二区三区在线播放免费观看| 国产综合视频| 在线 亚洲欧美在线综合一区| 国产亚洲精品一区二区| 国产视频精品网| 国内在线观看一区二区三区| 国产专区综合网| 黄色小说综合网站| 亚洲东热激情| 亚洲伦理在线| 亚洲欧美国产精品专区久久| 亚洲欧美激情在线视频| 欧美一区观看| 另类av一区二区| 亚洲福利小视频| 一本色道久久综合| 亚洲一区在线观看免费观看电影高清 | 国产农村妇女精品一区二区| 国产日韩亚洲欧美综合| 一色屋精品视频在线观看网站| 一区二区三区在线视频观看| 亚洲日本aⅴ片在线观看香蕉| 亚洲理论电影网| 亚洲新中文字幕| 久久人人九九| 亚洲欧洲三级电影| 亚洲一线二线三线久久久| 久久精品国产亚洲精品| 欧美国产一区视频在线观看| 国产精品高潮久久| 激情文学综合丁香| 99这里只有久久精品视频| 欧美一区二区久久久| 欧美.com| 亚洲欧美99| 毛片一区二区三区| 国产精品二区影院| 亚洲国产精品久久久久秋霞影院 | 国产欧美日韩一区| 亚洲欧洲综合另类在线| 亚洲免费影院| 亚洲国产精品国自产拍av秋霞| 亚洲视频电影图片偷拍一区| 久久久久免费观看| 国产精品免费在线| 亚洲国产你懂的| 欧美影院视频| 亚洲伦理在线| 男女av一区三区二区色多| 国产精品永久在线| 一区二区不卡在线视频 午夜欧美不卡在| 欧美一区免费视频| 一本大道av伊人久久综合|