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

天行健 君子當自強而不息

網格模型高級技術(12)

為了方便加載.x文件中的框架和網格模型數據,Direct3D提供了一個ID3DXAllocateHierarchy接口,該接口中有4個純虛函數:用來創建框架的CreateFrame(),創建網格容器的CreateMeshContainer(),銷毀框架的DestroyFrame(),銷毀網格容器的DestroyMeshContainer()。應用程序會在相應的時機自動調用這些對應的函數,以構建或者銷毀對應的框架或網格模型。

This interface is implemented by the application to allocate or free frame and mesh container objects. Methods on this are called during loading and destroying frame hierarchies.

Method Description
ID3DXAllocateHierarchy::CreateFrame Requests allocation of a frame object.
ID3DXAllocateHierarchy::CreateMeshContainer Requests allocation of a mesh container object.
ID3DXAllocateHierarchy::DestroyFrame Requests deallocation of a frame object.
ID3DXAllocateHierarchy::DestroyMeshContainer Requests deallocation of a mesh container object.

 

ID3DXAllocateHierarchy::CreateFrame

Requests allocation of a frame object.

HRESULT CreateFrame(
LPCSTR Name,
LPD3DXFRAME * ppNewFrame
);

Parameters

Name
[in] Name of the frame to be created.
ppNewFrame
[out, retval] Returns the created frame object.

Return Values

The return values of this method are implemented by an application programmer. In general, if no error occurs, program the method to return D3D_OK. Otherwise, program the method to return an appropriate error message from D3DERR or D3DXERR, as this will cause D3DXLoadMeshHierarchyFromX to fail also, and return the error.

 

ID3DXAllocateHierarchy::CreateMeshContainer

Requests allocation of a mesh container object.

HRESULT CreateMeshContainer(
LPCSTR Name,
CONST D3DXMESHDATA * pMeshData,
CONST D3DXMATERIAL * pMaterials,
CONST D3DXEFFECTINSTANCE * pEffectInstances,
DWORD NumMaterials,
CONST DWORD * pAdjacency,
LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER * ppNewMeshContainer
);

Parameters

Name
[in] Name of the mesh.
pMeshData
[in] Pointer to the mesh data structure.
pMaterials
[in] Array of materials used in the mesh.
pEffectInstances
[in] Array of effect instances used in the mesh. 
NumMaterials
[in] Number of materials in the materials array.
pAdjacency
[in] Adjacency array for the mesh.
pSkinInfo
[in] Pointer to the skin mesh object if skin data is found.
ppNewMeshContainer
[out, retval] Returns the created mesh container.

Return Values

The return values of this method are implemented by an application programmer. In general, if no error occurs, program the method to return D3D_OK. Otherwise, program the method to return an appropriate error message from D3DERR or D3DXERR, as this will cause D3DXLoadMeshHierarchyFromX to fail also, and return the error.

 

ID3DXAllocateHierarchy::DestroyFrame

Requests deallocation of a frame object.

HRESULT DestroyFrame(
LPD3DXFRAME pFrameToFree
);

Parameters

pFrameToFree
[in] Pointer to the frame to be deallocated.

Return Values

The return values of this method are implemented by an application programmer. In general, if no error occurs, program the method to return D3D_OK. Otherwise, program the method to return an appropriate error message from D3DERR or D3DXERR, as this will cause D3DXLoadMeshHierarchyFromX to fail also, and return the error.

 

ID3DXAllocateHierarchy::DestroyMeshContainer

Requests deallocation of a mesh container object.

HRESULT DestroyMeshContainer(
LPD3DXMESHCONTAINER pMeshContainerToFree
);

Parameters

pMeshContainerToFree
[in] Pointer to the mesh container object to be deallocated.

Return Values

The return values of this method are implemented by an application programmer. In general, if no error occurs, program the method to return D3D_OK. Otherwise, program the method to return an appropriate error message from D3DERR or D3DXERR, as this will cause D3DXLoadMeshHierarchyFromX to fail also, and return the error.

 

cAllocateHierarchy類繼承自ID3DXAllocateHierarchy接口,在cAllocateHierarchy類需要重載這4個純虛函數以實現動畫網格模型數據的加載和釋放。

該類的定義如下:

class cAllocateHierarchy : public ID3DXAllocateHierarchy
{
private:
HRESULT AllocateName(LPCSTR name, LPSTR* ret_name);
public:
STDMETHOD(CreateFrame)(LPCSTR name, LPD3DXFRAME* ret_frame);
	STDMETHOD(CreateMeshContainer)(LPCSTR name, 
CONST D3DXMESHDATA* mesh_data,
CONST D3DXMATERIAL* xmaterials,
CONST D3DXEFFECTINSTANCE* effect_instances,
DWORD num_materials,
CONST DWORD* adjacency,
LPD3DXSKININFO skin_info,
LPD3DXMESHCONTAINER* ret_mesh_container);
    STDMETHOD(DestroyFrame)(THIS_ LPD3DXFRAME frame_to_free);
STDMETHOD(DestroyMeshContainer)(THIS_ LPD3DXMESHCONTAINER base_mesh_container);
};
 

函數AllocateFrame()用來為框架生成一個名稱:

HRESULT cAllocateHierarchy::AllocateName(LPCSTR name, LPSTR* ret_name)
{
if(name != NULL)
{
UINT length = (UINT)strlen(name) + 1;
		*ret_name = new CHAR[length];
		if(*ret_name == NULL)
return E_OUTOFMEMORY;
		memcpy(*ret_name, name, length * sizeof(CHAR));
}
else
{
*ret_name = NULL;
}
	return S_OK;
}

 

函數CreateFrame()的作用在于生成一個新的擴展框架,并按照指定的參數為該框架命名:

HRESULT cAllocateHierarchy::CreateFrame(LPCSTR name, LPD3DXFRAME* ret_frame)
{
*ret_frame = NULL;
	D3DXFRAME_DERIVED* new_frame = new D3DXFRAME_DERIVED;
	if(new_frame == NULL)
return E_OUTOFMEMORY;
	HRESULT hr = AllocateName(name, &new_frame->Name);
	if(FAILED(hr))
{
delete new_frame;
return hr;
}
	D3DXMatrixIdentity(&new_frame->TransformationMatrix);
D3DXMatrixIdentity(&new_frame->CombinedTransformMatrix);
	new_frame->pMeshContainer   = NULL;
new_frame->pFrameSibling = NULL;
new_frame->pFrameFirstChild = NULL;
	*ret_frame = new_frame;
	return S_OK;
}

 

在一個框架創建好后,需要創建該框架的網格容器,這通過函數CreateMeshContainer()來實現:

HRESULT cAllocateHierarchy::CreateMeshContainer(LPCSTR name, 
CONST D3DXMESHDATA* mesh_data,
CONST D3DXMATERIAL* xmaterials,
CONST D3DXEFFECTINSTANCE* effect_instances,
DWORD num_materials,
CONST DWORD* adjacency,
LPD3DXSKININFO skin_info,
LPD3DXMESHCONTAINER* ret_mesh_container)
{
*ret_mesh_container = NULL;
	if(mesh_data->Type != D3DXMESHTYPE_MESH)
return E_FAIL;
	ID3DXMesh* mesh_ptr = mesh_data->pMesh;
DWORD fvf = mesh_ptr->GetFVF();
	if(fvf == 0)
return E_FAIL;
	// create a mesh container and zero it
	D3DXMESHCONTAINER_DERIVED* new_mesh_container = new D3DXMESHCONTAINER_DERIVED;
	if(new_mesh_container == NULL)
return E_OUTOFMEMORY;
	memset(new_mesh_container, 0, sizeof(D3DXMESHCONTAINER_DERIVED));
	// copy mesh name
	HRESULT hr = AllocateName(name, &new_mesh_container->Name);
	if(FAILED(hr))
{
DestroyMeshContainer(new_mesh_container);
return hr;
}
	IDirect3DDevice9* device;
mesh_ptr->GetDevice(&device);
	new_mesh_container->MeshData.Type = D3DXMESHTYPE_MESH;
	// be sure mesh contain normal
if(!(fvf & D3DFVF_NORMAL))
{
hr = mesh_ptr->CloneMeshFVF(mesh_ptr->GetOptions(), fvf | D3DFVF_NORMAL, device,
&new_mesh_container->MeshData.pMesh);
		if(FAILED(hr))
{
release_com(device);
DestroyMeshContainer(new_mesh_container);
return hr;
}
		mesh_ptr = new_mesh_container->MeshData.pMesh;
D3DXComputeNormals(mesh_ptr, NULL);
}
else
{
new_mesh_container->MeshData.pMesh = mesh_ptr;
mesh_ptr->AddRef(); // !! important, so DestroyMeshContainer() will not crash.
}
	// load materials and textures
	UINT num_faces = mesh_ptr->GetNumFaces();
	new_mesh_container->NumMaterials = max(1, num_materials);
new_mesh_container->pMaterials = new D3DXMATERIAL[new_mesh_container->NumMaterials];
new_mesh_container->ppTextures = new LPDIRECT3DTEXTURE9[new_mesh_container->NumMaterials];
new_mesh_container->pAdjacency = new DWORD[num_faces * 3];
	if((new_mesh_container->pAdjacency == NULL) || (new_mesh_container->pMaterials == NULL) ||
(new_mesh_container->ppTextures == NULL))
{
release_com(device);
DestroyMeshContainer(new_mesh_container);
return E_OUTOFMEMORY;
}
	memcpy(new_mesh_container->pAdjacency, adjacency, sizeof(DWORD) * num_faces * 3);
memset(new_mesh_container->ppTextures, 0, sizeof(LPDIRECT3DTEXTURE9) * new_mesh_container->NumMaterials);
	D3DXMATERIAL* xmaterials_ptr = new_mesh_container->pMaterials;
	if(num_materials > 0)
{
memcpy(xmaterials_ptr, xmaterials, sizeof(D3DXMATERIAL) * num_materials);
xmaterials_ptr->MatD3D.Ambient = xmaterials_ptr->MatD3D.Diffuse;
		for(UINT i = 0; i < num_materials; i++)
{
if(xmaterials_ptr[i].pTextureFilename != NULL)
{
WCHAR w_texture_path[MAX_PATH];
WCHAR w_filename[MAX_PATH];
				RemovePathFromFileName(xmaterials_ptr[i].pTextureFilename, w_filename);
DXUTFindDXSDKMediaFileCch(w_texture_path, MAX_PATH, w_filename);
				if(FAILED( D3DXCreateTextureFromFileW(device, w_texture_path, &new_mesh_container->ppTextures[i]) ))
new_mesh_container->ppTextures[i] = NULL;
}
}
}
else
{
xmaterials_ptr[0].pTextureFilename = NULL;
memset(&xmaterials_ptr[0].MatD3D, 0, sizeof(D3DMATERIAL9));
		xmaterials_ptr[0].MatD3D.Diffuse.r = 0.5f;
xmaterials_ptr[0].MatD3D.Diffuse.r = 0.5f;
xmaterials_ptr[0].MatD3D.Diffuse.b = 0.5f;
xmaterials_ptr[0].MatD3D.Specular = xmaterials_ptr[0].MatD3D.Diffuse;
xmaterials_ptr[0].MatD3D.Ambient = xmaterials_ptr[0].MatD3D.Diffuse;
}
	release_com(device);
	*ret_mesh_container = new_mesh_container;
	return S_OK;
}

在此實現的骨骼動畫網格模型中沒有涉及到蒙皮信息,所以在CreateMeshContainer()函數中沒有處理參數skin_info指向的蒙皮信息。

 

函數DestroyFrame()只有一個參數指向準備釋放的框架對象:

HRESULT cAllocateHierarchy::DestroyFrame(LPD3DXFRAME frame_to_free) 
{
SAFE_DELETE_ARRAY(frame_to_free->Name);
SAFE_DELETE(frame_to_free);
	return S_OK;
}

 

函數DestroyMeshContainer()也只有一個參數指向將要釋放的網格容器對象:

HRESULT cAllocateHierarchy::DestroyMeshContainer(LPD3DXMESHCONTAINER base_mesh_container)
{
if(base_mesh_container == NULL)
return S_OK;
	D3DXMESHCONTAINER_DERIVED* mesh_container = (D3DXMESHCONTAINER_DERIVED*) base_mesh_container;
	SAFE_DELETE_ARRAY(mesh_container->Name);
SAFE_DELETE_ARRAY(mesh_container->pAdjacency);
SAFE_DELETE_ARRAY(mesh_container->pMaterials);
	if(mesh_container->ppTextures != NULL)
{
for(UINT i = 0; i < mesh_container->NumMaterials; i++)
release_com(mesh_container->ppTextures[i]);
}
	SAFE_DELETE_ARRAY(mesh_container->ppTextures);
	SAFE_RELEASE(mesh_container->MeshData.pMesh);
SAFE_RELEASE(mesh_container->pSkinInfo);
	SAFE_DELETE(mesh_container);
	return S_OK;
}

posted on 2008-06-11 14:56 lovedday 閱讀(2184) 評論(3)  編輯 收藏 引用

評論

# re: 網格模型高級技術(12) 2010-04-04 11:58 chuckey

誰寫的這種文章,也太無聊了,全就抄了一下.  回復  更多評論   

# re: 網格模型高級技術(12) 2010-07-14 14:52 騾子寶

博主能出來解釋一下嗎?看得云里霧里的。
FRAME是每個骨骼創建一個FRAME嗎?每個FRMAE都創建一個CONTAINER嗎?  回復  更多評論   

# re: 網格模型高級技術(12) 2011-05-22 13:04

看看  回復  更多評論   

公告

導航

統計

常用鏈接

隨筆分類(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>
            开元免费观看欧美电视剧网站| 欧美va亚洲va日韩∨a综合色| 久久一区二区三区av| 亚洲一区日韩在线| 欧美高清视频一区二区三区在线观看 | 欧美成人一区二区三区| 久久久久久精| 国产婷婷色一区二区三区| 一区二区欧美国产| 亚洲网站视频福利| 欧美日韩国内自拍| 亚洲精品一区二区三区99| 亚洲精品在线看| 欧美成人tv| 亚洲欧洲日韩综合二区| 亚洲国产综合91精品麻豆| 亚洲精华国产欧美| 女生裸体视频一区二区三区| 欧美www视频在线观看| 影音先锋久久精品| 久久免费视频观看| 欧美成人自拍| 亚洲另类一区二区| 欧美人成在线| 一本色道久久88综合日韩精品| 一区二区三区免费网站| 欧美日韩性生活视频| 99精品欧美| 欧美在线3区| 国语自产精品视频在线看8查询8| 欧美一区二区三区免费看| 久久久久成人精品| 亚洲电影天堂av| 免费在线播放第一区高清av| 91久久精品国产| 亚洲一区二区高清视频| 国产精品爽黄69| 久久久久久电影| 亚洲国产欧美在线人成| 亚洲视频欧美在线| 国产视频亚洲精品| 美女视频黄 久久| 亚洲伦理在线观看| 久久精品女人| 99国产精品99久久久久久粉嫩| 欧美日韩一区二区三区免费看| 亚洲永久字幕| 欧美风情在线| 亚洲女同精品视频| 在线欧美日韩| 欧美性事免费在线观看| 久久精品国产99精品国产亚洲性色 | 在线观看欧美亚洲| 欧美日韩国产欧美日美国产精品| 亚洲无限av看| 欧美韩日一区二区| 欧美亚洲免费电影| 亚洲欧洲日产国产综合网| 国产精品盗摄久久久| 久久精品亚洲一区二区| 99在线热播精品免费| 狂野欧美性猛交xxxx巴西| avtt综合网| 一区二区三区在线免费观看| 欧美视频在线播放| 久久综合色88| 欧美一区二区三区啪啪| 亚洲日本中文字幕免费在线不卡| 久久精品视频网| 亚洲视频成人| 亚洲日韩视频| 黄色国产精品一区二区三区| 欧美性猛交99久久久久99按摩 | 一区二区三区在线观看国产| 欧美日韩在线电影| 欧美成人伊人久久综合网| 99热在这里有精品免费| 国产麻豆精品在线观看| 欧美人妖在线观看| 女同性一区二区三区人了人一 | 好吊妞**欧美| 国产欧美精品| 国产精品久久久久久久久久久久| 免费观看欧美在线视频的网站| 午夜国产精品视频| 亚洲午夜精品久久久久久app| 亚洲黄色片网站| 亚洲第一色中文字幕| 美国三级日本三级久久99| 欧美伊人久久大香线蕉综合69| 亚洲一区二区三| 一区二区三区黄色| 日韩视频一区二区三区| 亚洲国产精品女人久久久| 国内成人精品一区| 国产亚洲欧洲一区高清在线观看| 国产精品毛片大码女人| 欧美日韩国产精品专区| 欧美精品一区二区三区久久久竹菊| 玖玖在线精品| 欧美成年人在线观看| 欧美91福利在线观看| 免费欧美日韩| 欧美国产日韩一区二区三区| 欧美+日本+国产+在线a∨观看| 免费成人在线观看视频| 久久久天天操| 免费成人网www| 欧美久久成人| 国产精品久久97| 国产麻豆精品久久一二三| 国产亚洲成av人在线观看导航| 国产欧美日韩激情| 黄色在线一区| 亚洲精品乱码久久久久久日本蜜臀 | 牛牛影视久久网| 欧美电影免费观看大全| 亚洲精品国产精品国产自| 99视频+国产日韩欧美| 亚洲一区二区三区精品在线| 亚洲欧美乱综合| 久久一日本道色综合久久| 欧美aⅴ99久久黑人专区| 欧美色精品在线视频| 国产女主播一区| 亚洲国产一区视频| 亚洲视频在线二区| 久久久久久久成人| 亚洲高清二区| 亚洲一区免费| 久久中文字幕一区| 欧美涩涩网站| 伊人久久大香线| 一级成人国产| 久久婷婷久久一区二区三区| 欧美激情中文不卡| 亚洲自拍电影| 欧美成人中文字幕| 国产精品一区二区在线观看| 亚洲电影天堂av| 亚洲欧美日韩久久精品 | 黄色亚洲在线| 在线视频日韩| 免费观看成人www动漫视频| 日韩视频专区| 久久久久久综合| 国产精品女主播一区二区三区| 黄色一区二区三区| 亚洲你懂的在线视频| 欧美高清视频一区二区| 亚洲一级电影| 欧美精品久久天天躁| 国产一区二区三区四区hd| 一区二区三区视频在线看| 巨乳诱惑日韩免费av| 亚洲色图综合久久| 欧美国内亚洲| 在线精品视频一区二区三四| 亚洲一区影音先锋| 亚洲激情精品| 久久综合网络一区二区| 国产欧美一区二区三区国产幕精品| 亚洲精品影院在线观看| 免费不卡在线视频| 欧美一区2区三区4区公司二百| 欧美另类99xxxxx| 最新国产拍偷乱拍精品| 久热国产精品视频| 午夜亚洲性色视频| 国产精品卡一卡二卡三| 一本在线高清不卡dvd| 欧美国产日韩一区二区三区| 久久国产精品久久久久久| 国产精品乱人伦中文| 亚洲图色在线| 艳妇臀荡乳欲伦亚洲一区| 欧美精品福利| 99精品国产热久久91蜜凸| 欧美激情网友自拍| 欧美77777| 亚洲精品免费在线| 亚洲黄色在线| 欧美日韩999| 日韩五码在线| 日韩亚洲欧美精品| 欧美日韩中文在线| 亚洲色无码播放| 一区二区三区精密机械公司| 欧美日韩另类字幕中文| 亚洲午夜极品| 亚洲一级一区| 国产视频亚洲精品| 久久九九国产精品怡红院| 久久精品亚洲乱码伦伦中文 | 欧美一区二区三区另类| 性欧美办公室18xxxxhd| 国产一区三区三区| 欧美顶级少妇做爰| 欧美精品在线网站| 午夜精品久久久久久久99水蜜桃|