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

天行健 君子當自強而不息

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 閱讀(919) 評論(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>
            国产毛片久久| 国产精品99久久久久久有的能看| 精品动漫3d一区二区三区免费| 国产精品丝袜白浆摸在线| 欧美午夜电影一区| 国产精品免费电影| 国产欧美另类| 国产日韩亚洲欧美综合| 狠狠干综合网| 亚洲精品视频二区| 亚洲一区美女视频在线观看免费| 午夜精品一区二区在线观看| 久久精品99无色码中文字幕| 久热精品在线视频| 亚洲丰满少妇videoshd| 亚洲国产日韩综合一区| av成人免费在线| 欧美一区二区精美| 美女主播精品视频一二三四| 欧美精品国产精品| 国产精品视区| 亚洲国产精品综合| 亚洲欧洲av一区二区| 久久亚洲综合色| 日韩视频精品在线观看| 欧美中文字幕在线视频| 欧美日韩国产一区| 国精品一区二区三区| 一区二区三区欧美日韩| 久热精品在线视频| 亚洲免费视频成人| 欧美精品乱码久久久久久按摩| 国产欧美综合一区二区三区| 久久精品一二三| 欧美巨乳波霸| 1204国产成人精品视频| 欧美一区二区三区电影在线观看| 欧美大香线蕉线伊人久久国产精品| 亚洲一区二区欧美日韩| 久久综合综合久久综合| 国产亚洲毛片在线| 亚洲在线观看| 亚洲日本久久| 欧美高清成人| 欧美激情成人在线| 久久免费视频在线观看| 国产精品久久久久久久久婷婷| 在线精品亚洲一区二区| 欧美一区影院| 中文国产成人精品| 亚洲校园激情| 欧美视频一区二区三区四区| 亚洲国产日韩在线| 麻豆精品在线视频| 久久久国产精品一区二区中文| 国产精品腿扒开做爽爽爽挤奶网站 | 国内精品美女av在线播放| 亚洲午夜视频在线观看| 亚洲日本中文字幕| 欧美高清在线视频观看不卡| 亚洲国内精品在线| 老司机67194精品线观看| 亚洲女女女同性video| 国产精品蜜臀在线观看| 亚洲免费一在线| 亚洲图片激情小说| 国产精品美女久久| 欧美在线免费看| 欧美一区二区三区男人的天堂 | 亚洲第一福利视频| 欧美成人在线网站| 欧美第一黄色网| 一区二区三区欧美成人| 一区二区三区久久| 国产欧美短视频| 另类激情亚洲| 欧美激情一区二区三区成人| 一区二区三区四区国产| 亚洲视频大全| 黄色一区二区三区四区| 欧美国产精品| 欧美视频中文一区二区三区在线观看| 亚洲欧美在线x视频| 久久精品一区二区三区四区| 亚洲激情国产| 亚洲一区一卡| 亚洲黄网站黄| 亚洲视频在线观看网站| 久久激情一区| 亚洲国产美女| 一区二区三区欧美在线观看| 国产老女人精品毛片久久| 久久免费精品日本久久中文字幕| 久久综合色88| 亚洲一区亚洲| 久久九九免费视频| 一区二区三区鲁丝不卡| 久久精品色图| 欧美国产日韩亚洲一区| 亚洲欧美视频| 免费观看国产成人| 午夜精品久久久久久久久久久久| 久久丁香综合五月国产三级网站| 在线观看成人网| 在线亚洲一区二区| 亚洲国产成人久久综合一区| 在线亚洲免费| 亚洲理伦在线| 久久xxxx精品视频| 亚洲一二三区视频在线观看| 久久国产天堂福利天堂| 亚洲小少妇裸体bbw| 老牛影视一区二区三区| 欧美一区在线视频| 欧美午夜不卡视频| 亚洲国产精品一区在线观看不卡| 老鸭窝91久久精品色噜噜导演| 亚洲欧美一区二区三区极速播放 | 久久视频精品在线| 香港久久久电影| 欧美日韩国产麻豆| 欧美激情一区二区三区成人| 国产嫩草一区二区三区在线观看 | 先锋资源久久| 欧美日韩在线看| 亚洲激情在线观看| 亚洲国产导航| 久久人体大胆视频| 久久人人精品| 国产偷自视频区视频一区二区| 日韩视频免费在线| av成人国产| 欧美激情bt| 亚洲日韩视频| 日韩亚洲精品视频| 欧美高清视频一二三区| 免费视频亚洲| 亚洲国产合集| 欧美二区在线播放| 亚洲高清在线播放| 亚洲九九爱视频| 欧美日韩久久| 99在线精品视频| 亚洲专区一区二区三区| 国产精品你懂得| 欧美亚洲视频在线看网址| 久久精品伊人| 91久久国产自产拍夜夜嗨| 欧美激情精品久久久久久久变态| 亚洲国产91色在线| 亚洲欧美中文字幕| 一区二区三区精品国产| 一区二区三区国产精品| 欧美日韩一区在线观看视频| 日韩一级黄色片| 亚洲免费婷婷| 国产欧美一区二区精品仙草咪| 亚洲一区二区三区国产| 欧美一区深夜视频| 亚洲第一精品夜夜躁人人爽| 欧美成va人片在线观看| av不卡在线看| 亚洲人成毛片在线播放| 欧美调教视频| 欧美3dxxxxhd| 一区二区三区精品久久久| 欧美国产先锋| 亚洲尤物视频在线| 老牛影视一区二区三区| 夜夜嗨av一区二区三区中文字幕| 国产精品第一页第二页第三页| 午夜精品视频一区| 亚洲成人在线网站| 亚洲男人天堂2024| 激情五月综合色婷婷一区二区| 免费一区二区三区| 亚洲一品av免费观看| 久久性色av| 亚洲专区一区二区三区| 亚洲电影激情视频网站| 国产精品爱久久久久久久| 久久国产精品亚洲77777| 亚洲人久久久| 麻豆精品传媒视频| 小黄鸭精品密入口导航| 亚洲人成网站在线播| 国产老肥熟一区二区三区| 欧美高清在线一区| 久久久天天操| 午夜国产精品视频| 亚洲精品女人| 久久精品国语| 亚洲一区二区三区久久| 亚洲国产一区二区a毛片| 国产女主播视频一区二区| 欧美黄色影院| 蘑菇福利视频一区播放| 一本在线高清不卡dvd | 欧美福利视频在线观看| 欧美在线视频网站|