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

天行健 君子當(dāng)自強(qiáng)而不息

網(wǎng)格模型高級(jí)技術(shù)(12)

為了方便加載.x文件中的框架和網(wǎng)格模型數(shù)據(jù),Direct3D提供了一個(gè)ID3DXAllocateHierarchy接口,該接口中有4個(gè)純虛函數(shù):用來創(chuàng)建框架的CreateFrame(),創(chuàng)建網(wǎng)格容器的CreateMeshContainer(),銷毀框架的DestroyFrame(),銷毀網(wǎng)格容器的DestroyMeshContainer()。應(yīng)用程序會(huì)在相應(yīng)的時(shí)機(jī)自動(dòng)調(diào)用這些對(duì)應(yīng)的函數(shù),以構(gòu)建或者銷毀對(duì)應(yīng)的框架或網(wǎng)格模型。

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個(gè)純虛函數(shù)以實(shí)現(xiàn)動(dòng)畫網(wǎng)格模型數(shù)據(jù)的加載和釋放。

該類的定義如下:

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);
};
 

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

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;
}

 

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

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;
}

 

在一個(gè)框架創(chuàng)建好后,需要?jiǎng)?chuàng)建該框架的網(wǎng)格容器,這通過函數(shù)CreateMeshContainer()來實(shí)現(xiàn):

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;
}

在此實(shí)現(xiàn)的骨骼動(dòng)畫網(wǎng)格模型中沒有涉及到蒙皮信息,所以在CreateMeshContainer()函數(shù)中沒有處理參數(shù)skin_info指向的蒙皮信息。

 

函數(shù)DestroyFrame()只有一個(gè)參數(shù)指向準(zhǔn)備釋放的框架對(duì)象:

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

 

函數(shù)DestroyMeshContainer()也只有一個(gè)參數(shù)指向?qū)⒁尫诺木W(wǎng)格容器對(duì)象:

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 閱讀(2197) 評(píng)論(3)  編輯 收藏 引用

評(píng)論

# re: 網(wǎng)格模型高級(jí)技術(shù)(12) 2010-04-04 11:58 chuckey

誰寫的這種文章,也太無聊了,全就抄了一下.  回復(fù)  更多評(píng)論   

# re: 網(wǎng)格模型高級(jí)技術(shù)(12) 2010-07-14 14:52 騾子寶

博主能出來解釋一下嗎?看得云里霧里的。
FRAME是每個(gè)骨骼創(chuàng)建一個(gè)FRAME嗎?每個(gè)FRMAE都創(chuàng)建一個(gè)CONTAINER嗎?  回復(fù)  更多評(píng)論   

# re: 網(wǎng)格模型高級(jí)技術(shù)(12) 2011-05-22 13:04

看看  回復(fù)  更多評(píng)論   


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久九九热免费视频| 亚洲欧美一区二区三区在线| 国产精品一区二区a| 亚洲大片av| 韩国av一区二区| 久久亚洲欧美| 欧美在线免费看| 欧美三级电影精品| 亚洲福利视频二区| 9国产精品视频| 亚洲大片免费看| 欧美在线播放| 欧美在线视频免费观看| 欧美日韩视频一区二区| 亚洲欧洲精品成人久久奇米网| 激情一区二区三区| 欧美一级理论性理论a| 亚洲欧美春色| 欧美视频第二页| 夜久久久久久| 亚洲综合色婷婷| 欧美午夜视频| 亚洲午夜激情| 亚洲欧美国产视频| 国产精品爽黄69| 亚洲欧美日韩在线观看a三区| 亚洲一级片在线观看| 欧美日韩在线视频首页| 日韩一二三在线视频播| 亚洲欧美www| 国产精品丝袜xxxxxxx| 亚洲欧美国产日韩中文字幕 | 欧美日韩一区二区三区在线 | 国产亚洲精品久久飘花| 午夜国产一区| 久久精选视频| 在线成人小视频| 老鸭窝毛片一区二区三区| 欧美电影免费观看大全| 日韩图片一区| 国产精品久久久久毛片软件| 午夜精品久久久久久久99樱桃| 久久狠狠一本精品综合网| 国产一区自拍视频| 欧美福利一区二区| 中文久久乱码一区二区| 久久精品导航| 亚洲国产欧美一区二区三区丁香婷| 欧美黑人一区二区三区| 一本久久综合| 久久亚洲图片| 一本大道久久a久久精品综合| 国产精品久久久久一区二区三区共| 欧美淫片网站| 91久久在线播放| 久久精品国内一区二区三区| 亚洲一区在线免费观看| 久久九九有精品国产23| 亚洲精品一区二区三区樱花| 欧美午夜精品久久久久久孕妇 | 欧美国产免费| 亚洲一区二区三区免费视频| 久久一二三国产| 夜夜狂射影院欧美极品| 国产在线精品一区二区中文| 欧美高清一区二区| 欧美一区网站| 亚洲精品国产精品国自产在线| 午夜伦欧美伦电影理论片| 亚洲二区在线| 国产日韩欧美电影在线观看| 欧美成年人网站| 久久精品观看| 亚洲午夜激情| 亚洲欧洲三级| 美国成人毛片| 性色av一区二区三区| 亚洲毛片av在线| 亚洲大黄网站| 国内精品久久久久久久影视麻豆 | 欧美视频在线观看视频极品| 久久精品一本| 亚洲欧美成人网| 99国产精品国产精品久久| 欧美成人蜜桃| 久久视频这里只有精品| 亚洲欧美网站| 亚洲欧美一区二区原创| 亚洲精品在线免费观看视频| 一区二区在线观看视频| 国产午夜精品久久久久久免费视| 欧美日韩中文精品| 欧美日韩国产二区| 欧美.www| 久久综合伊人77777| 久久国产福利国产秒拍| 午夜精品久久99蜜桃的功能介绍| 99精品免费网| 日韩视频在线观看免费| 亚洲黄色毛片| 亚洲国产日韩精品| 亚洲黄色片网站| 亚洲激情影院| 亚洲黄色在线观看| 亚洲激情黄色| 日韩一级精品| 9色porny自拍视频一区二区| 亚洲另类黄色| 一区二区三区国产盗摄| 在线亚洲高清视频| 亚洲精品中文在线| 亚洲精品日韩欧美| 亚洲美女福利视频网站| 99re成人精品视频| 亚洲视频www| 午夜天堂精品久久久久| 先锋影音国产精品| 欧美一区激情| 浪潮色综合久久天堂| 欧美风情在线观看| 亚洲精品在线一区二区| 一本色道久久综合亚洲精品小说| 一本久道久久综合狠狠爱| 国产精品99久久99久久久二8 | 国产精品久久久久久久午夜片 | 欧美亚洲综合在线| 久久久另类综合| 免费成年人欧美视频| 亚洲国产精品成人精品| 99精品久久久| 欧美专区日韩视频| 欧美高清在线精品一区| 欧美性色综合| 一区二区在线视频观看| 日韩一二三区视频| 午夜精品999| 免费成人激情视频| 亚洲肉体裸体xxxx137| 亚洲欧美另类中文字幕| 久久久久久电影| 欧美三级小说| 一区二区在线视频| 亚洲一区高清| 欧美大片一区二区| 中文亚洲字幕| 蜜桃久久精品乱码一区二区| 国产精品高清免费在线观看| 国产曰批免费观看久久久| 99国内精品久久| 久久久亚洲影院你懂的| 亚洲区一区二| 久久国产一区二区三区| 欧美日韩久久| 一区二区视频欧美| 亚洲欧美综合一区| 亚洲欧洲日本专区| 久久成人综合视频| 国产精品久久久久久久久久尿| 亚洲成人影音| 欧美在线在线| 99精品久久免费看蜜臀剧情介绍| 久久久久久婷| 国产精品人成在线观看免费 | 在线播放中文一区| 午夜激情一区| 日韩视频一区二区在线观看 | 国产免费成人| 日韩一级裸体免费视频| 免费一区二区三区| 小嫩嫩精品导航| 欧美视频一区二区三区四区| 亚洲日韩视频| 免费一区二区三区| 久久精品国产精品亚洲综合 | 欧美亚洲一区| 欧美精品电影| 亚洲国产精品久久久久久女王| 久久九九免费视频| 欧美一级二区| 国产性天天综合网| 午夜精品久久久久久久| 国产精品99久久久久久www| 欧美激情一区二区三区蜜桃视频| 在线精品观看| 免费在线日韩av| 久久久久久综合| 伊人影院久久| 老司机午夜精品视频| 久久精品视频在线看| 国产亚洲精品aa午夜观看| 午夜亚洲福利在线老司机| 99这里只有久久精品视频| 欧美精品一区二区三区蜜桃 | 欧美精品一区二区三区很污很色的| 亚洲国产成人精品久久| 欧美激情91| 欧美精品免费在线观看| 一区二区黄色| 一区二区三区福利| 国产精品视频第一区|