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

天行健 君子當自強而不息

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>
            国产精品亚洲一区| 国产乱码精品一区二区三区忘忧草 | 欧美高清在线一区| 麻豆av一区二区三区| 最新高清无码专区| 一区二区三区产品免费精品久久75| 欧美调教视频| 久久久国际精品| 欧美成人精品高清在线播放| 亚洲午夜女主播在线直播| 亚洲欧美日韩一区二区在线| 激情小说另类小说亚洲欧美| 亚洲欧洲在线视频| 国产伦一区二区三区色一情| 蜜桃av综合| 国产精品mm| 欧美成人免费全部| 国产精品国产精品| 免费成人高清视频| 欧美午夜精品久久久久久人妖| 久久精品最新地址| 欧美精品一区在线观看| 久久精品国产999大香线蕉| 欧美aⅴ99久久黑人专区| 小处雏高清一区二区三区| 久久伊伊香蕉| 欧美一区二区三区另类| 女人天堂亚洲aⅴ在线观看| 欧美一区二区三区免费观看| 欧美黄色视屏| 美女诱惑一区| 国产视频观看一区| 99视频有精品| 亚洲免费成人av| 久久久国产精品亚洲一区 | 男男成人高潮片免费网站| 欧美视频在线观看一区| 欧美激情影音先锋| 国产综合久久久久久鬼色| 在线视频欧美日韩| 日韩视频一区| 欧美国产日韩一二三区| 欧美~级网站不卡| 国产一区二区三区成人欧美日韩在线观看| 最近中文字幕日韩精品 | 亚洲影视在线| 欧美日韩八区| 91久久精品国产| 亚洲国产欧美一区二区三区久久| 久久丁香综合五月国产三级网站| 亚洲综合色网站| 欧美揉bbbbb揉bbbbb| 亚洲国内精品| 亚洲乱码久久| 欧美激情一区二区三区在线视频| 免费久久99精品国产自| 极品中文字幕一区| 久久久亚洲精品一区二区三区| 欧美专区日韩专区| 国产日韩欧美一区二区| 亚洲欧美日韩中文视频| 久久av最新网址| 国产日韩欧美一二三区| 久久国产精品一区二区| 久久综合九九| 最近中文字幕mv在线一区二区三区四区 | 久久精品国产久精国产思思| 国产精品日韩二区| 亚洲欧美一区二区三区在线| 久久精品国产99| 影音先锋成人资源站| 久热精品视频在线观看一区| 欧美激情综合| 亚洲视频在线看| 国产亚洲精品一区二区| 久久精品国产精品亚洲精品| 欧美不卡在线视频| 夜夜夜久久久| 国产精品制服诱惑| 久久漫画官网| 亚洲精品少妇30p| 先锋亚洲精品| 伊人天天综合| 欧美色精品在线视频| 香蕉成人伊视频在线观看| 久久综合伊人77777尤物| 亚洲精品乱码久久久久久蜜桃麻豆| 欧美精品一区二区三区视频| 亚洲夜间福利| 欧美成人综合一区| 亚洲一区二区视频在线| 国产一区久久久| 欧美久久精品午夜青青大伊人| 亚洲一区网站| 91久久国产自产拍夜夜嗨| 欧美亚洲一区在线| 亚洲国产精品久久久| 国产精品高潮呻吟久久av黑人| 久久久久久久成人| 亚洲四色影视在线观看| 欧美不卡视频一区发布| 亚洲欧美日韩成人| 亚洲国产第一| 国产女人aaa级久久久级| 欧美精品免费播放| 久久久噜噜噜久久久| 亚洲一区精品视频| 最近中文字幕日韩精品| 麻豆精品一区二区av白丝在线| 在线亚洲精品| 亚洲国产精品一区二区三区| 国产日韩精品一区二区| 欧美视频在线观看一区| 欧美成人亚洲成人日韩成人| 久久av资源网站| 亚洲性视频网站| 日韩一区二区精品视频| 欧美激情1区| 久久在线免费观看| 性8sex亚洲区入口| 亚洲一区二区三区欧美| 日韩视频一区二区三区| 亚洲大胆视频| 激情亚洲网站| 黄色成人av在线| 国产欧美综合在线| 国产精品视频一二| 国产精品第十页| 欧美视频在线观看一区二区| 欧美乱人伦中文字幕在线| 欧美va天堂在线| 欧美大香线蕉线伊人久久国产精品| 久久久成人精品| 久久―日本道色综合久久| 翔田千里一区二区| 校园激情久久| 久久电影一区| 久久综合给合久久狠狠狠97色69| 欧美一级黄色网| 欧美在线视频一区二区三区| 欧美一区二区三区在线| 久久黄色网页| 久久久久久亚洲精品杨幂换脸 | 欧美日本一区二区视频在线观看| 欧美成人午夜剧场免费观看| 欧美成人午夜77777| 欧美精品色综合| 国产精品大全| 国产一区二区三区最好精华液| 国产专区欧美专区| 亚洲第一区中文99精品| 亚洲级视频在线观看免费1级| 亚洲精品1区2区| 99re热这里只有精品视频| 一区二区欧美日韩视频| 翔田千里一区二区| 久久一区欧美| 亚洲第一黄网| 一区二区三区视频在线看| 校园激情久久| 欧美成人蜜桃| 国产精品毛片va一区二区三区 | 国产精品亚洲激情| 国外成人网址| 一区二区国产日产| 欧美中文字幕不卡| 欧美成人蜜桃| 亚洲无限乱码一二三四麻| 欧美一区二区免费视频| 欧美 日韩 国产在线| 国产精品久久久久久五月尺| 曰韩精品一区二区| 亚洲一区二区四区| 麻豆91精品91久久久的内涵| 亚洲精品久久久一区二区三区| 亚洲一区二区网站| 欧美大成色www永久网站婷| 国产精品羞羞答答| 亚洲日本va午夜在线影院| 午夜精品免费视频| 亚洲国产精品一区在线观看不卡| 亚洲伊人色欲综合网| 欧美成人黑人xx视频免费观看| 国产精品入口福利| 亚洲精品激情| 久久免费视频一区| 一区二区三区免费网站| 麻豆成人小视频| 国产一区二区精品久久| 亚洲无线视频| 亚洲日本va午夜在线电影| 久久精品二区| 国产欧美精品国产国产专区| 日韩视频精品| 欧美大片国产精品| 久久精品亚洲热| 国产一区二区三区精品欧美日韩一区二区三区 | 亚洲一二三区在线| 亚洲青涩在线| 免费久久99精品国产自在现线|