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

天行健 君子當自強而不息

D3D中的網格模型(2)

10.4 優化

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

HRESULT ID3DXMesh::OptimizeInplace(

       DWORD Flags,

       CONST DWORD* pAdjacencyIn,

       DWORD* pAdjacencyOut,

       DWORD* pFaceRemap,

       LPD3DXBUFFER* ppVertexRemap

);

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

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

         D3DXMESHOPT_ATTRSORT — 根據屬性給三角形排序并調整屬性表,這將使DrawSubset執行更有效。

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

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

         D3DXMESHOPT_IGNOREVERTS — 只優化索引信息,忽略頂點信息。

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

pAdjacencyIn — 指向沒有優化的mesh的鄰接數組。

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

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

ppVertexRemap — 指向ID3DXBuffer指針的地址,它被用來填充頂點重影射信息。這個緩存應該包含ID3DXMesh::GetNumVertices()個頂點。當一個mesh被優化后,頂點可能被移動。頂點重影射信息用來說明原來的頂點被移動到新位置;也就是說,在ppVertexRemap中的第i項表示原來的第i個頂點的新位置。如果不需要該信息,可以將其設置為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方法,它輸出一個優化的mesh,而不是在原來mesh的基礎上進行優化:

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 屬性表

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

除了進行幾何信息的排序外,D3DXMESHOPT_ATTRSORT優化項還將創建一個屬性表。該表是D3DXATTRIBUTERANGE結構的一個數組。在屬性表中的每一項對應mesh的一個子集并指示頂點/索引緩存中的一個連續連續內存塊,這個子集的幾何信息就包含在這個塊中。D3DXATTRIBUTERANGE結構的定義如下:

typedef struct _D3DXATTRIBUTERANGE {

       DWORD AttribId;

       DWORD FaceStart;

       DWORD FaceCount;

       DWORD VertexStart;

       DWORD VertexCount;

} D3DXATTRIBUTERANGE;

AttribId — 子集的ID。

FaceStart — 該子集的面的起始值,FaceStart*3就是起始三角形在索引緩存中的序號。

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

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

VertexCount — 在子集中的頂點數。


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

可以使用下面的方法來訪問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.

這個方法能夠做兩件事情:它可以返回屬性表的屬性數,也可以用屬性數據來填充一個D3DXATTRIBUTERANGE結構數組。

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

DWORD numSubsets = 0;

Mesh->GetAttributeTable(0, &numSubsets);

一旦我們知道了屬性表的元素個數,我們就能夠通過寫屬性表來填充一個D3DXATTRIBUTERANGE結構數組:

D3DXATTRIBUTERANGE table = new D3DXATTRIBUTERANGE [numSubsets];

Mesh->GetAttributeTable( table, &numSubsets );

 

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

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.

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

D3DXATTRIBUTERANGE attributeTable[12];

// ...fill attributeTable array with data

Mesh->SetAttributeTable( attributeTable, 12);


10.6 鄰接信息

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

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

A = i x3

B = i x3 + 1

C = i x3 + 2

注意,使用ULONG_MAX = 4294967295表示該邊沒有鄰接三角形。我們也可以用-1來表示,因為-1轉換成DWORD就是ULONG_MAX。回想一下,DWORD就是一個unsigned32-bit整數。

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

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

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

HRESULT ID3DXMesh::GenerateAdjacency(

       FLOAT fEpsilon,

       DWORD* pAdjacency

);

fEpsilon — 指示當兩個點距離有多近時,可以認為是一個點。當兩點間的距離小于epsilon時,可認為它們是同一個點。

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

例子:

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

Mesh->GenerateAdjacency(0.001f, adjacencyInfo);


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

評論

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

關于pFaceRemap,pVertexMap說反了  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(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>
            久久久久在线| 亚洲区在线播放| 午夜在线a亚洲v天堂网2018| 欧美日韩在线播放一区二区| 日韩一级黄色av| 日韩亚洲欧美高清| 欧美午夜在线视频| 午夜在线观看免费一区| 性久久久久久久久久久久| 国产私拍一区| 欧美xxx成人| 欧美日韩精品一区二区在线播放| 一区二区三区四区国产| 亚洲影院免费观看| 国产一区二区丝袜高跟鞋图片| 免费在线看成人av| 欧美日韩性视频在线| 午夜精品理论片| 久久久久久久一区| 一本色道88久久加勒比精品| 亚洲欧美日本日韩| 亚洲国产精品久久久久| 99精品视频一区| 精品88久久久久88久久久| 91久久亚洲| 国产午夜精品麻豆| 亚洲福利视频一区| 国产精品一区二区久激情瑜伽| 美女图片一区二区| 国产精品海角社区在线观看| 美女脱光内衣内裤视频久久影院 | 一区二区三区久久| 欧美一二三区精品| 99精品久久久| 久久久久久久精| 亚洲综合视频网| 麻豆乱码国产一区二区三区| 午夜欧美大尺度福利影院在线看| 老牛嫩草一区二区三区日本| 午夜亚洲福利| 欧美激情一区二区三区在线视频| 久久精品国产综合精品| 欧美日本在线观看| 欧美成人精品高清在线播放| 国产精品性做久久久久久| 亚洲国产精品一区二区第一页| 国产日韩精品电影| 一本色道88久久加勒比精品| 91久久夜色精品国产九色| 欧美在线观看一区| 午夜电影亚洲| 国产精品久久久久久久久免费桃花| 免费的成人av| 精品1区2区| 欧美一区二区三区视频在线观看| 亚洲一区日本| 欧美日韩在线三级| 亚洲欧洲一区二区天堂久久| 亚洲黄色免费网站| 久久综合福利| 免费中文字幕日韩欧美| 韩日成人在线| 久久久精品tv| 免费欧美日韩国产三级电影| 激情久久久久| 久久久久久夜精品精品免费| 久久先锋影音| 在线不卡免费欧美| 久久精品国产欧美激情| 久久亚洲欧洲| 尤物yw午夜国产精品视频| 久久精品视频va| 久久一区二区三区国产精品| 黑人巨大精品欧美黑白配亚洲| 欧美在线影院| 美女主播一区| 亚洲国产精品va| 欧美国产精品v| 日韩亚洲在线观看| 亚洲在线不卡| 国产日韩欧美视频| 久久精品av麻豆的观看方式| 欧美成人精品高清在线播放| 亚洲乱码久久| 欧美日韩一区在线| 亚洲欧美日韩另类精品一区二区三区 | 午夜精品在线看| 久久蜜桃资源一区二区老牛 | 欧美视频观看一区| 亚洲欧美日本国产专区一区| 久久久精品999| 亚洲国产导航| 欧美日韩精品伦理作品在线免费观看| 一区二区三区 在线观看视| 欧美亚洲一级| 亚洲高清一区二| 欧美午夜无遮挡| 久久精品99久久香蕉国产色戒| 亚洲电影第1页| 亚洲欧美成人网| 激情久久一区| 欧美日韩精品一区二区| 欧美在线免费视屏| 亚洲国产日韩一区| 欧美一区在线视频| 亚洲精品午夜| 国产一区二区三区视频在线观看| 模特精品在线| 欧美一区二粉嫩精品国产一线天| 欧美激情视频一区二区三区不卡| 亚洲欧美国产高清| 亚洲国产精品一区二区第四页av | 国产日韩在线亚洲字幕中文| 欧美成人精品三级在线观看| 亚洲在线免费视频| 亚洲精品五月天| 久久深夜福利免费观看| 亚洲一区在线直播| 亚洲黄网站黄| 国产在线精品一区二区中文| 欧美午夜精品久久久久久孕妇| 麻豆成人av| 欧美在线啊v| 亚洲在线观看视频网站| 亚洲美女在线看| 亚洲第一中文字幕| 免费观看一区| 久久亚洲精品网站| 欧美亚洲自偷自偷| 亚洲视频观看| 日韩一级免费| 亚洲精品一区二区在线| 影音先锋在线一区| 韩日精品在线| 国产一区二区三区久久| 国产乱子伦一区二区三区国色天香| 欧美精品乱人伦久久久久久| 美女尤物久久精品| 久久久久久网站| 久久久av毛片精品| 久久久久久91香蕉国产| 欧美中日韩免费视频| 午夜在线观看欧美| 亚洲欧美精品在线观看| 亚洲欧美日韩综合aⅴ视频| 国产精品99久久久久久久久久久久| 亚洲欧洲日本mm| 亚洲精品无人区| 夜夜嗨网站十八久久| 夜夜精品视频| 亚洲一区二区三区在线| 亚洲免费在线视频| 香港久久久电影| 欧美与欧洲交xxxx免费观看| 久久狠狠婷婷| 久久综合九色| 欧美成人亚洲成人日韩成人| 欧美高清在线播放| 欧美日韩一区二区在线观看| 国产精品成人一区二区网站软件 | 欧美激情片在线观看| 欧美激情1区2区3区| 欧美日韩精品免费观看| 国产精品久久久久久久久久ktv| 国产精品一区在线观看你懂的| 国产日韩欧美综合一区| 在线日韩av| 一区二区三区视频在线观看 | 国产一区激情| 亚洲国产一二三| 亚洲一区二区三区精品在线| 欧美一区二区三区免费观看视频| 久久久久久成人| 亚洲国产小视频| 亚洲淫性视频| 麻豆久久久9性大片| 欧美日韩国产另类不卡| 国产乱码精品一区二区三区五月婷| 激情五月***国产精品| 夜夜狂射影院欧美极品| 欧美一区日本一区韩国一区| 欧美国产免费| 亚洲午夜久久久| 免费国产一区二区| 国产精品青草久久久久福利99| 亚洲第一在线视频| 亚洲一区二区三区四区五区黄| 久久亚洲一区二区三区四区| 亚洲人成在线播放| 欧美专区在线观看一区| 欧美连裤袜在线视频| 国产一区二区三区在线观看网站| 最近看过的日韩成人| 久久精品国产免费看久久精品| 亚洲国产成人av在线| 亚洲欧美国产制服动漫| 欧美精品偷拍| 在线欧美小视频| 久久国产精品久久w女人spa| 亚洲毛片av|