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

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

D3D中的網(wǎng)格模型(2)

10.4 優(yōu)化

Mesh的頂點和索引能夠被重組以便能更有效的渲染mesh。當(dāng)我們這樣做時,我們說我們優(yōu)化了一個mesh。我們可以使用下面的方法來進行優(yōu)化:

HRESULT ID3DXMesh::OptimizeInplace(

       DWORD Flags,

       CONST DWORD* pAdjacencyIn,

       DWORD* pAdjacencyOut,

       DWORD* pFaceRemap,

       LPD3DXBUFFER* ppVertexRemap

);

Flags — 表示執(zhí)行什么類型的優(yōu)化方法。它可以是下面的一個或幾個的組合:

         D3DXMESHOPT_COMPACT — 從mesh中移除沒有用的頂點和索引項。

         D3DXMESHOPT_ATTRSORT — 根據(jù)屬性給三角形排序并調(diào)整屬性表,這將使DrawSubset執(zhí)行更有效。

         D3DXMESHOPT_VERTEXCACHE — 增加頂點緩存的命中率。

         D3DXMESHOPT_STRIPREORDER — 重組頂點索引使三角帶盡可能的長。

         D3DXMESHOPT_IGNOREVERTS — 只優(yōu)化索引信息,忽略頂點信息。

注意:D3DXMESHOPT_VERTEXCACHE和D3DXMESHOPT_STRIPREORDER不能同時使用。

pAdjacencyIn — 指向沒有優(yōu)化的mesh的鄰接數(shù)組。

pAdjacencyOut — 指向一個DWORD數(shù)組,它被用來填充優(yōu)化好了的mesh鄰接信息。該數(shù)組必須有ID3DXMesh::GetNumFaces() * 3個元素。如果不需要該信息,可以將其設(shè)置為0。

pFaceRemap —指向一個DWORD數(shù)組,它被用來填充面重影射信息。該數(shù)組必須不小于ID3DXMesh::GetNumFaces()。當(dāng)一個mesh被優(yōu)化時,由索引緩存定義的面可能被移動;也就是說,在pFaceRemap中的第i項表示第i個原始面被移動到的面索引值。如果不需要該信息,可以將其設(shè)置為0。

ppVertexRemap — 指向ID3DXBuffer指針的地址,它被用來填充頂點重影射信息。這個緩存應(yīng)該包含ID3DXMesh::GetNumVertices()個頂點。當(dāng)一個mesh被優(yōu)化后,頂點可能被移動。頂點重影射信息用來說明原來的頂點被移動到新位置;也就是說,在ppVertexRemap中的第i項表示原來的第i個頂點的新位置。如果不需要該信息,可以將其設(shè)置為0。

例子:

// Get the adjacency info of the non-optimized mesh.

DWORD adjacencyInfo[Mesh->GetNumFaces() * 3];

Mesh->GenerateAdjacency(0.0f, adjacencyInfo);

 

// Array to hold optimized adjacency info.

DWORD optimizedAdjacencyInfo[Mesh->GetNumFaces() * 3];

Mesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_COMPACT | D3DXMESHOPT_VERTEXCACHE,

       adjacencyInfo, optimizedAdjacencyInfo, 0, 0);

 

一個更簡單的方法是Optimize方法,它輸出一個優(yōu)化的mesh,而不是在原來mesh的基礎(chǔ)上進行優(yōu)化:

Generates a new mesh with reordered faces and vertices to optimize drawing performance.

HRESULT Optimize(
DWORD Flags,
CONST DWORD * pAdjacencyIn,
DWORD * pAdjacencyOut,
DWORD * pFaceRemap,
LPD3DXBUFFER * ppVertexRemap,
LPD3DXMESH * ppOptMesh
);

Parameters

Flags
[in] Specifies the type of optimization to perform. This parameter can be set to a combination of one or more flags from D3DXMESHOPT and D3DXMESH (except D3DXMESH_32BIT, D3DXMESH_IB_WRITEONLY, and D3DXMESH_WRITEONLY).
pAdjacencyIn
[in] Pointer to an array of three DWORDs per face that specifies the three neighbors for each face in the source mesh. If the edge has no adjacent faces, the value is 0xffffffff. See Remarks.
pAdjacencyOut
[in, out] Pointer to an array of three DWORDs per face that specifies the three neighbors for each face in the optimized mesh. If the edge has no adjacent faces, the value is 0xffffffff.
pFaceRemap
[in, out] An array of DWORDs, one per face, that identifies the original mesh face that corresponds to each face in the optimized mesh. If the value supplied for this argument is NULL, face remap data is not returned.
ppVertexRemap
[out] Address of a pointer to an ID3DXBuffer interface, which contains a DWORD for each vertex that specifies how the new vertices map to the old vertices. This remap is useful if you need to alter external data based on the new vertex mapping.
ppOptMesh
[out] Address of a pointer to an ID3DXMesh interface, representing the optimized mesh.

Return Values

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

Remarks

This method generates a new mesh. Before running Optimize, an application must generate an adjacency buffer by calling ID3DXBaseMesh::GenerateAdjacency. The adjacency buffer contains adjacency data, such as a list of edges and the faces that are adjacent to each other.

This method is very similar to the ID3DXBaseMesh::CloneMesh method, except that it can perform optimization while generating the new clone of the mesh. The output mesh inherits all of the creation parameters of the input mesh.

D3DXMESHOPT

Specifies the type of mesh optimization to be performed.

typedef enum D3DXMESHOPT
{
D3DXMESHOPT_COMPACT = 0x01000000,
D3DXMESHOPT_ATTRSORT = 0x02000000,
D3DXMESHOPT_VERTEXCACHE = 0x04000000,
D3DXMESHOPT_STRIPREORDER = 0x08000000,
D3DXMESHOPT_IGNOREVERTS = 0x10000000,
D3DXMESHOPT_DONOTSPLIT = 0x20000000,
D3DXMESHOPT_DEVICEINDEPENDENT = 0x40000000,
} D3DXMESHOPT, *LPD3DXMESHOPT;

Constants

D3DXMESHOPT_COMPACT
Reorders faces to remove unused vertices and faces.
D3DXMESHOPT_ATTRSORT
Reorders faces to optimize for fewer attribute bundle state changes and enhanced ID3DXBaseMesh::DrawSubset performance.
D3DXMESHOPT_VERTEXCACHE
Reorders faces to increase the cache hit rate of vertex caches.
D3DXMESHOPT_STRIPREORDER
Reorders faces to maximize length of adjacent triangles.
D3DXMESHOPT_IGNOREVERTS
Optimize the faces only; do not optimize the vertices.
D3DXMESHOPT_DONOTSPLIT
While attribute sorting, do not split vertices that are shared between attribute groups.
D3DXMESHOPT_DEVICEINDEPENDENT
Affects the vertex cache size. Using this flag specifies a default vertex cache size that works well on legacy hardware.

Remarks

The D3DXMESHOPT_STRIPREORDER and D3DXMESHOPT_VERTEXCACHE optimization flags are mutually exclusive.

The D3DXMESHOPT_SHAREVB flag has been removed from this enumeration. Use D3DXMESH_VB_SHARE instead, in D3DXMESH.


10.5 屬性表

當(dāng)一個mesh被使用D3DXMESHOPT_ATTRSORT參數(shù)來優(yōu)化后,mesh的幾何信息將按照屬性進行排序,這樣各個子集的頂點/索引將組成連續(xù)的塊(如圖10.3)。

除了進行幾何信息的排序外,D3DXMESHOPT_ATTRSORT優(yōu)化項還將創(chuàng)建一個屬性表。該表是D3DXATTRIBUTERANGE結(jié)構(gòu)的一個數(shù)組。在屬性表中的每一項對應(yīng)mesh的一個子集并指示頂點/索引緩存中的一個連續(xù)連續(xù)內(nèi)存塊,這個子集的幾何信息就包含在這個塊中。D3DXATTRIBUTERANGE結(jié)構(gòu)的定義如下:

typedef struct _D3DXATTRIBUTERANGE {

       DWORD AttribId;

       DWORD FaceStart;

       DWORD FaceCount;

       DWORD VertexStart;

       DWORD VertexCount;

} D3DXATTRIBUTERANGE;

AttribId — 子集的ID。

FaceStart — 該子集的面的起始值,F(xiàn)aceStart*3就是起始三角形在索引緩存中的序號。

FaceCount — 在子集中的面(三角形)數(shù)。

VertexStart — 該子集的起始頂點在頂點緩存中的序號。

VertexCount — 在子集中的頂點數(shù)。


建立了屬性表以后,渲染一個子集就很容易了。僅僅查一下屬性表就能找出自己的幾何信息。注意如果沒有屬性表,每渲染一個子集就需要對屬性緩存進行一次線性搜索來找出子集包含的幾何信息。

可以使用下面的方法來訪問mesh的屬性表:

Retrieves either an attribute table for a mesh, or the number of entries stored in an attribute table for a mesh.

HRESULT GetAttributeTable(
D3DXATTRIBUTERANGE * pAttribTable,
DWORD * pAttribTableSize
);

Parameters

pAttribTable
[in, out] Pointer to an array of D3DXATTRIBUTERANGE structures, representing the entries in the mesh's attribute table. Specify NULL to retrieve the value for pAttribTableSize.
pAttribTableSize
[in, out] Pointer to either the number of entries stored in pAttribTable or a value to be filled in with the number of entries stored in the attribute table for the mesh.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

An attribute table is created by ID3DXMesh::Optimize and passing D3DXMESHOPT_ATTRSORT for the Flags parameter.

An attribute table is used to identify areas of the mesh that need to be drawn with different textures, render states, materials, and so on. In addition, the application can use the attribute table to hide portions of a mesh by not drawing a given attribute identifier when drawing the frame.

這個方法能夠做兩件事情:它可以返回屬性表的屬性數(shù),也可以用屬性數(shù)據(jù)來填充一個D3DXATTRIBUTERANGE結(jié)構(gòu)數(shù)組。

要得到屬性表的元素個數(shù),可以就將第一個參數(shù)設(shè)置為0:

DWORD numSubsets = 0;

Mesh->GetAttributeTable(0, &numSubsets);

一旦我們知道了屬性表的元素個數(shù),我們就能夠通過寫屬性表來填充一個D3DXATTRIBUTERANGE結(jié)構(gòu)數(shù)組:

D3DXATTRIBUTERANGE table = new D3DXATTRIBUTERANGE [numSubsets];

Mesh->GetAttributeTable( table, &numSubsets );

 

我們能夠使用ID3DXMesh::SetAttributeTable方法來直接設(shè)置屬性表。

Sets the attribute table for a mesh and the number of entries stored in the table.

HRESULT SetAttributeTable(
CONST D3DXATTRIBUTERANGE * pAttribTable,
DWORD cAttribTableSize
);

Parameters

pAttribTable
[in] Pointer to an array of D3DXATTRIBUTERANGE structures, representing the entries in the mesh attribute table.
cAttribTableSize
[in] Number of attributes in the mesh attribute table.

Return Values

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

Remarks

If an application keeps track of the information in an attribute table, and rearranges the table as a result of changes to attributes or faces, this method allows the application to update the attribute tables instead of calling ID3DXMesh::Optimize again.

下面的代碼就是設(shè)置一個有12個子集的屬性表:

D3DXATTRIBUTERANGE attributeTable[12];

// ...fill attributeTable array with data

Mesh->SetAttributeTable( attributeTable, 12);


10.6 鄰接信息

對于mesh的某些操作,如優(yōu)化,有必要了解的是三角形之間的鄰接信息。Mesh的鄰接數(shù)組存儲了這些信息。

鄰接數(shù)組是一個DWORD數(shù)組,其中的每一項對應(yīng)了mesh中的一個三角形。例如,第i項對應(yīng)的三角形由以下三個索引值定義:

A = i x3

B = i x3 + 1

C = i x3 + 2

注意,使用ULONG_MAX = 4294967295表示該邊沒有鄰接三角形。我們也可以用-1來表示,因為-1轉(zhuǎn)換成DWORD就是ULONG_MAX?;叵胍幌?,DWORD就是一個unsigned32-bit整數(shù)。

因為每個三角形都有三條邊,所以它最多有三個鄰接三角形(如圖10.4)。

因此,鄰接數(shù)組必須有三項(ID3DXBaseMesh::GetNumFaces()*3)—— 在mesh中每個三角形都可能有三個鄰接三角形。

很多D3Dxmesh創(chuàng)造函數(shù)都能輸出鄰接信息,但我們也可以使用下面的方法:

HRESULT ID3DXMesh::GenerateAdjacency(

       FLOAT fEpsilon,

       DWORD* pAdjacency

);

fEpsilon — 指示當(dāng)兩個點距離有多近時,可以認(rèn)為是一個點。當(dāng)兩點間的距離小于epsilon時,可認(rèn)為它們是同一個點。

pAdjacency — 一個指向填充了鄰接信息的DWORD數(shù)組指針。

例子:

DWORD adjacencyInfo[Mesh->GetNumFaces() * 3];

Mesh->GenerateAdjacency(0.001f, adjacencyInfo);


posted on 2008-03-27 11:32 lovedday 閱讀(1498) 評論(1)  編輯 收藏 引用

評論

# re: D3D中的網(wǎng)格模型(2) 2008-10-09 23:21 leshy

關(guān)于pFaceRemap,pVertexMap說反了  回復(fù)  更多評論   


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


公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲精品1区2区| 亚洲伦理在线| 久久免费视频在线| 亚洲国产精品久久精品怡红院| 久久成人免费电影| 欧美一区二区三区免费看 | 亚洲综合色在线| 国产精品视频午夜| 久久国产成人| 老司机免费视频久久| 亚洲精品久久久久久久久久久久久 | 欧美无砖砖区免费| 性久久久久久久| 久久久久国产精品一区| 亚洲精品视频二区| 在线性视频日韩欧美| 国产婷婷成人久久av免费高清| 久久精品免视看| 欧美激情精品久久久久久久变态 | 黄色亚洲免费| 亚洲精品日韩欧美| 国产日韩欧美综合| 欧美国产日本| 国产精品专区h在线观看| 麻豆成人在线播放| 欧美日韩综合精品| 久久伊人精品天天| 欧美日韩中文精品| 毛片基地黄久久久久久天堂| 欧美日本中文| 老牛国产精品一区的观看方式| 欧美精品一区视频| 久久久夜夜夜| 欧美午夜宅男影院在线观看| 久久久久久久波多野高潮日日| 欧美激情一区二区久久久| 欧美在线播放高清精品| 欧美激情一二区| 美女精品在线| 国产欧美日韩一区二区三区| 亚洲国产日韩欧美综合久久| 国产亚洲精品久久飘花| 亚洲精品一区二区三区av| 国产在线不卡视频| 亚洲一二三区在线| 在线综合亚洲| 欧美激情视频一区二区三区免费 | 欧美黄色片免费观看| 国产精品视频免费在线观看| 亚洲激情一区二区三区| 尤物在线精品| 翔田千里一区二区| 亚洲欧美在线另类| 欧美视频免费在线| 亚洲美女色禁图| 亚洲精品国产精品乱码不99| 久久精品综合| 久久综合亚洲社区| 国产一区二区三区直播精品电影| 在线亚洲美日韩| 亚洲视频第一页| 欧美日韩精品免费| 99ri日韩精品视频| 在线一区二区三区做爰视频网站| 免费日韩精品中文字幕视频在线| 美女精品国产| 亚洲大片av| 你懂的成人av| 亚洲第一在线综合网站| 亚洲国产精品久久久| 榴莲视频成人在线观看| 蜜桃精品久久久久久久免费影院| 国产亚洲制服色| 久久久久久黄| 欧美国产一区二区| 99成人在线| 欧美日韩亚洲91| 亚洲欧美国产日韩天堂区| 欧美专区在线观看一区| 国产日韩欧美在线播放| 久久久久国产成人精品亚洲午夜| 老鸭窝亚洲一区二区三区| 亚洲国产成人av| 欧美精品成人91久久久久久久| 亚洲精品乱码久久久久久| 亚洲一区二区三区精品视频| 国产精品久久久久久影院8一贰佰| 亚洲在线免费观看| 久久色在线播放| 亚洲精选一区二区| 国产精品久久久一区二区| 欧美一区二区三区播放老司机| 美国成人毛片| 一区二区欧美日韩视频| 国产欧美一区二区三区在线看蜜臀 | 久久久噜久噜久久综合| 亚洲激情二区| 国产精品夫妻自拍| 久久久久免费视频| 日韩午夜精品| 葵司免费一区二区三区四区五区| 亚洲精品视频在线播放| 国产精品视频xxxx| 老鸭窝91久久精品色噜噜导演| 亚洲精品免费一二三区| 久久精品国产亚洲aⅴ| 亚洲激情国产精品| 国产精品一区二区三区久久久 | 亚洲欧美日韩在线高清直播| 欧美freesex交免费视频| 亚洲视频在线看| 亚洲成色最大综合在线| 国产精品久久久久久久7电影| 久久色在线观看| 亚洲一区二区欧美| 亚洲国产女人aaa毛片在线| 欧美在线一级视频| 在线一区二区日韩| 亚洲激情视频在线播放| 国产一区二区三区最好精华液| 免费在线亚洲| 欧美在线观看日本一区| 中文一区二区| 亚洲人成在线播放网站岛国| 久久躁日日躁aaaaxxxx| 午夜性色一区二区三区免费视频| 亚洲国产三级| 好男人免费精品视频| 国产精品成人免费精品自在线观看| 久久天天狠狠| 久久久久久久久岛国免费| 亚洲尤物视频网| 一本久久a久久精品亚洲| 亚洲第一福利在线观看| 鲁大师影院一区二区三区| 欧美在线影院| 欧美一区二区私人影院日本| 亚洲视频在线观看三级| 99精品99| 一本色道婷婷久久欧美| 99视频精品在线| 亚洲精选一区| 亚洲乱码国产乱码精品精98午夜| 亚洲激情在线激情| 最新国产乱人伦偷精品免费网站| 红桃视频国产一区| 在线成人小视频| 亚洲国产成人久久综合一区| 在线看欧美日韩| 亚洲国产成人av| 亚洲精品久久久久久久久久久 | 国内精品一区二区| 韩日精品视频一区| 激情成人亚洲| 亚洲第一久久影院| 亚洲精选视频免费看| 日韩午夜免费| 亚洲欧美日韩直播| 久久久精品五月天| 欧美1区免费| 最新成人av在线| 在线亚洲成人| 久久国产精品一区二区| 美女国产一区| 欧美午夜免费影院| 国产一区二区毛片| 亚洲欧洲综合| 亚洲欧美日韩国产一区二区| 久久精品盗摄| 亚洲成色www8888| 中文在线资源观看视频网站免费不卡| 中文有码久久| 久久噜噜亚洲综合| 欧美日韩在线视频一区二区| 国产精品羞羞答答| 亚洲国产精品久久久| 亚洲午夜国产成人av电影男同| 午夜一区二区三区不卡视频| 欧美成人69| 亚洲四色影视在线观看| 久久久成人网| 国产精品第十页| 亚洲高清一区二| 欧美一乱一性一交一视频| 欧美激情第8页| 亚洲免费中文字幕| 欧美麻豆久久久久久中文| 国产亚洲精品一区二555| 日韩一级黄色大片| 久久永久免费| 亚洲欧美日韩另类| 欧美精品在线观看| 加勒比av一区二区| 欧美一级在线亚洲天堂| 欧美激情欧美激情在线五月| 亚洲一区二区在线免费观看视频| 免费日韩成人| 在线观看亚洲一区| 欧美中文字幕| 亚洲图片欧美一区|