本文整理汇总了C++中LPD3DXMESH::LockVertexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH::LockVertexBuffer方法的具体用法?C++ LPD3DXMESH::LockVertexBuffer怎么用?C++ LPD3DXMESH::LockVertexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPD3DXMESH
的用法示例。
在下文中一共展示了LPD3DXMESH::LockVertexBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: D3DXMeshTransformation
HRESULT D3DXMeshTransformation( LPD3DXMESH pMesh, const D3DXMATRIX* pMatrix
, VisitorForD3DXVECTOR3* pPointFilter)
{
KG_PROCESS_ERROR(NULL != pMesh && NULL != pMatrix);
{
DWORD fvf = pMesh->GetFVF();
KG_PROCESS_ERROR(fvf | D3DFVF_XYZ);
DWORD dwNumBytePerVertex = pMesh->GetNumBytesPerVertex();
_ASSERTE(dwNumBytePerVertex >= sizeof(D3DXVECTOR3));
DWORD dwNumVertex = pMesh->GetNumVertices();
BYTE* pBufferStart = NULL;
_ASSERTE(sizeof(BYTE) == 1);
if(NULL == pPointFilter)
{
HRESULT hr = pMesh->LockVertexBuffer(0, (LPVOID*)&pBufferStart);
KG_COM_PROCESS_ERROR(hr);
D3DXVec3TransformCoordArray((D3DXVECTOR3*)(pBufferStart), dwNumBytePerVertex
, (D3DXVECTOR3*)pBufferStart, dwNumBytePerVertex, pMatrix, dwNumVertex);
pMesh->UnlockVertexBuffer();
}
else
{
//加了Filter之后性能下降是当然的,但是这不是给实时用的,所以没有关系,控制
//调用次数和调用时机就好了
D3DXMeshVertexEnumer vertexEnumer;
HRESULT hr = D3DXMeshCreateVertexEnumer(pMesh, vertexEnumer);
KG_COM_PROCESS_ERROR(hr);
_ASSERTE(vertexEnumer.IsValid());
HRESULT hrForVisitor = E_FAIL;
for (UINT i = 0; i < vertexEnumer.GetVertexCount(); ++i)
{
const D3DXVECTOR3& vTemp = vertexEnumer.GetPos(i);
hrForVisitor = pPointFilter->Accept(vTemp);
if (FAILED(hr))
{
continue;
}
D3DXVECTOR3 vTransformed;
D3DXVec3TransformCoord(&vTransformed, &vTemp, pMatrix);
vertexEnumer.SetPos(i, vTransformed);
}
}
}
return S_OK;
Exit0:
return E_FAIL;
}
示例2: CreateMappedSphere
LPD3DXMESH SkyBox::CreateMappedSphere(float fRad, UINT slices, UINT stacks)
{
// create the sphere
LPD3DXMESH mesh;
if (FAILED(D3DXCreateSphere(GameManager::GetDevice( ), fRad, slices, stacks, &mesh, NULL)))
return NULL;
// create a copy of the mesh with texture coordinates,
// since the D3DX function doesn't include them
LPD3DXMESH texMesh;
if (FAILED(mesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, FVF_PositionNormalTexture::FVF, GameManager::GetDevice( ), &texMesh)))
return mesh; // failed, return un-textured mesh
mesh->Release( ); // finished with the original mesh, release it
// lock the vertex buffer
FVF_PositionNormalTexture* pVerts;
//if (SUCCEEDED(texMesh->LockVertexBuffer(0, (BYTE **)&pVerts)))
if (SUCCEEDED(texMesh->LockVertexBuffer(0, (LPVOID*)&pVerts)))
{
int numVerts = texMesh->GetNumVertices( ); // get vertex count
// loop through the vertices
for (int i = 0; i < numVerts; i++)
{
// calculate texture coordinates
pVerts->tex.x = asinf(pVerts->normal.x) / D3DX_PI + 0.5f;
pVerts->tex.y = asinf(pVerts->normal.y) / D3DX_PI + 0.5f;
//pVerts->tex.x = 0.5f - (atan2f(pVerts->normal.z, pVerts->normal.x) / (2 * D3DX_PI));
//pVerts->tex.y = 0.5f - asinf(pVerts->normal.y) / (D3DX_PI);
//pVerts->tex.y = pVerts->normal.y * 0.5 + 0.5;
//if (pVerts->tex.x <(FLOAT)0.9) pVerts->tex.x = (FLOAT)0.0;
//pVerts->tex.x = pVerts->pos.x / sqrtf((pVerts->pos.x * pVerts->pos.x) + (pVerts->pos.y * pVerts->pos.x) + (pVerts->pos.z * pVerts->pos.z));
//pVerts->tex.y = pVerts->pos.y / sqrtf((pVerts->pos.x * pVerts->pos.x) + (pVerts->pos.y * pVerts->pos.x) + (pVerts->pos.z * pVerts->pos.z));
//float theta = asinf(pVerts->normal.z);
//float phi = atan2(pVerts->normal.y, pVerts->normal.x);
//
//pVerts->tex = D3DXVECTOR2(phi / 2 / 3.14159265, theta / 3.14159265);
// go to next vertex
pVerts++;
}
texMesh->UnlockVertexBuffer( ); // unlock the vertex buffer
}
// return pointer to caller
return texMesh;
}
示例3: convertMesh
LPD3DXMESH CWall::convertMesh(IDirect3DDevice9* pDevice, LPD3DXMESH& mesh){
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, sizeof(D3DXVECTOR3), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, sizeof(D3DXVECTOR3) * 2, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()//will be declared on
};
LPD3DXMESH newMesh = nullptr;
VERTEX* pVerts;
HRESULT result = mesh->CloneMesh(D3DXMESH_SYSTEMMEM, decl, pDevice, &newMesh);
if (FAILED(result)) return nullptr;
float u = 0;
float v = 0;
bool reverse = false;
if (SUCCEEDED(newMesh->LockVertexBuffer(0, (LPVOID*)&pVerts))){
int numVerts = newMesh->GetNumVertices();
for (int i = 0; i < numVerts; i++){
pVerts->tu = u;
pVerts->tv = v;
if (u == 0 && v==0){
if (reverse)
u++;
else
v++;
}
else if (v == 1 && u == 0){
u++;
}
else if (v == 0 && u == 1){
v++;
}
else{
if (reverse)
reverse = false;
else reverse = true;
u = 0;
v = 0;
}
pVerts++;
}
newMesh->UnlockVertexBuffer();
//temporary uv generator
return newMesh;
}
else{
return nullptr;
}
}
示例4: CreateCompatibleDC
LPD3DXMESH Renderer::CreateD3DXTextMesh( const char* pString, bool bCentered )
{
HRESULT hr;
LPD3DXMESH pMeshNew = NULL;
HDC hdc = CreateCompatibleDC( NULL );
if( hdc == NULL )
return NULL;
HFONT newfont=CreateFont(10, //Height
0, //Width
0, //Escapement
0, //Orientation
FW_NORMAL, //Weight
false, //Italic
false, //Underline
false, //Strikeout
DEFAULT_CHARSET,//Charset
OUT_DEFAULT_PRECIS, //Output Precision
CLIP_DEFAULT_PRECIS, //Clipping Precision
DEFAULT_QUALITY, //Quality
DEFAULT_PITCH|FF_DONTCARE, //Pitch and Family
"Arial");
HFONT hFontOld;
hFontOld = ( HFONT )SelectObject( hdc, newfont );
hr = D3DXCreateText( m_pD3DDevice, hdc, pString, 0.001f, 0.2f, &pMeshNew, NULL, NULL );
SelectObject( hdc, hFontOld );
DeleteDC( hdc );
if( SUCCEEDED( hr ) )
{
if( bCentered )
{
// Center text
D3DXVECTOR3 vMin, vMax;
PosNormalVertex* pVertices;
pMeshNew->LockVertexBuffer( 0, reinterpret_cast<VOID**>(&pVertices));
D3DXComputeBoundingBox( (D3DXVECTOR3*)pVertices, pMeshNew->GetNumVertices(), sizeof ( PosNormalVertex ), &vMin, &vMax );
D3DXVECTOR3 vOffset;
D3DXVec3Subtract( &vOffset, &vMax, &vMin );
D3DXVec3Scale( &vOffset, &vOffset, 0.5f );
for ( unsigned int i = 0; i < pMeshNew->GetNumVertices(); i++)
{
D3DXVec3Subtract( &pVertices[i].Coord, &pVertices[i].Coord, &vOffset );
}
pMeshNew->UnlockVertexBuffer();
}
}
return pMeshNew;
}
示例5: ComputeBoundingBox
bool Floor::ComputeBoundingBox()
{
if( m_computedBoundingBox) return true;
BYTE* pVertices = NULL;
LPD3DXMESH mesh = m_mesh->GetD3DMesh();
HRESULT hr = mesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
if(FAILED(hr))
return false;
D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, mesh->GetNumVertices(), mesh->GetNumBytesPerVertex(), &m_bottomLeft, &m_topRight);
mesh->UnlockVertexBuffer();
m_computedBoundingBox = true;
return true;
}
示例6: sizeof
//------------------------------------------------------
// DirectXメッシュの作成
//------------------------------------------------------
LPD3DXMESH iex3DObj::CreateMesh( LPIEMFILE lpIem )
{
LPD3DXMESH lpMesh;
u8 *pVertex, *pFace;
u32 *pData;
if( lpIem->version < 4 )
{
u32 Declaration = D3DFVF_MESHVERTEX;
// メッシュ作成
D3DXCreateMeshFVF( lpIem->NumFace, lpIem->NumVertex, D3DXMESH_MANAGED, Declaration, tdnSystem::GetDevice(), &lpMesh );
// 頂点設定
lpMesh->LockVertexBuffer( 0, (void**)&pVertex );
CopyMemory( pVertex, lpIem->lpVertex, sizeof(MESHVERTEX)*lpIem->NumVertex );
} else {
u32 Declaration = D3DFVF_MESHVERTEX2;
// メッシュ作成
D3DXCreateMeshFVF( lpIem->NumFace, lpIem->NumVertex, D3DXMESH_MANAGED, Declaration, tdnSystem::GetDevice(), &lpMesh );
// 頂点設定
lpMesh->LockVertexBuffer( 0, (void**)&pVertex );
CopyMemory( pVertex, lpIem->lpVertex, sizeof(MESHVERTEX2)*lpIem->NumVertex );
}
lpMesh->UnlockVertexBuffer();
// 面設定
lpMesh->LockIndexBuffer( 0, (void**)&pFace );
CopyMemory( pFace, lpIem->lpFace, sizeof(u16)*lpIem->NumFace*3 );
lpMesh->UnlockIndexBuffer();
// 属性設定
lpMesh->LockAttributeBuffer( 0, &pData );
CopyMemory( pData, lpIem->lpAtr, sizeof(u32)*lpIem->NumFace );
lpMesh->UnlockAttributeBuffer();
return lpMesh;
}
示例7: LoadMesh
void cMyASELoader::LoadMesh(){
#ifdef _DEBUG
_ASSERT(m_bLoaded && "Data Not Loaded");
#endif
int check = 0;
for (size_t i = 0; i < m_vecASENode.size(); i++){
if (m_vecASENode[i].nRef != INT_MAX){
m_vecsubSet.push_back(m_vecASENode[i].nRef);
LPD3DXMESH pMesh = NULL;
HRESULT hr = D3DXCreateMeshFVF(m_vecASENode[i].vecVertex.size() / 3,
m_vecASENode[i].vecVertex.size(),
D3DXMESH_MANAGED,
ST_PNT_VERTEX::FVF,
g_pD3DDevice,
&pMesh);
ST_PNT_VERTEX* pV = NULL;
pMesh->LockVertexBuffer(0, (LPVOID*)&pV);
memcpy(pV, &m_vecASENode[i].vecVertex[0], m_vecASENode[i].vecVertex.size() * sizeof(ST_PNT_VERTEX));
pMesh->UnlockVertexBuffer();
WORD* pI = NULL;
pMesh->LockIndexBuffer(0, (LPVOID*)&pI);
for (size_t j = 0; j < pMesh->GetNumVertices(); ++j)
{
pI[j] = j;
}
pMesh->UnlockIndexBuffer();
DWORD* pA = NULL;
pMesh->LockAttributeBuffer(0, &pA);
for (size_t j = 0; j < pMesh->GetNumFaces(); j++){
pA[j] = m_vecASENode[i].nRef;
}
pMesh->UnlockAttributeBuffer();
std::vector<DWORD> vecAdjBuffer(m_vecASENode[i].vecVertex.size());
pMesh->GenerateAdjacency(0.0f, &vecAdjBuffer[0]);
pMesh->OptimizeInplace(
D3DXMESHOPT_ATTRSORT |
D3DXMESHOPT_COMPACT |
D3DXMESHOPT_VERTEXCACHE,
&vecAdjBuffer[0], 0, 0, 0);
m_vecMeshs.push_back(pMesh);
}
}
m_bMeshed = true;
}
示例8:
PRIVATE inline void _MDLCenterMesh(float trans[eMaxPt], LPD3DXMESH mesh)
{
gfxVtx *pVtx;
if(SUCCEEDED(mesh->LockVertexBuffer(0, (BYTE**)&pVtx)))
{
for(int i = 0; i < mesh->GetNumVertices(); i++)
{
pVtx[i].x -= trans[eX];
pVtx[i].y -= trans[eY];
pVtx[i].z -= trans[eZ];
}
mesh->UnlockVertexBuffer();
}
}
示例9: CreateMesh
HRESULT AiPathReader::CreateMesh(LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH &pMesh) {
//Todo: ID3DXMesh::SetAttributeTable (set materials how they are defined in the face struct)
DWORD dwFVF = (D3DFVF_XYZ | D3DFVF_NORMAL);
struct D3DVERTEX {
D3DXVECTOR3 p;
D3DXVECTOR3 n;
};
HRESULT r = D3DXCreateMeshFVF(3 * nodes.size(), 3 * nodes.size(), D3DXMESH_MANAGED, dwFVF, pD3DDevice, &pMesh);
if(FAILED(r)) {
return r;
}
D3DVERTEX *vertexBuffer;
WORD *indexBuffer = nullptr;
unsigned long *pAdjacency = new unsigned long[nodes.size() * 3];
pMesh->LockIndexBuffer(0, reinterpret_cast<void **>(&indexBuffer));
pMesh->LockVertexBuffer(0, reinterpret_cast<void **>(&vertexBuffer));
for(int i = 0; i < nodes.size(); i++) {
auto face = nodes[i];
for(int j = 0; j < 3; j++) {
D3DVERTEX &vert = vertexBuffer[3 * i + j];
vert.p.x = face.triangle[j].x;
vert.p.y = face.triangle[j].y;
vert.p.z = face.triangle[j].z;
indexBuffer[3 * i + j] = 3 * i + j;
pAdjacency[3 * i + j] = (face.adjacency[j] == 0xffff) ? 0xffffffffUL : face.adjacency[j];
}
}
//D3DXWeldVertices(pMesh, D3DXWELDEPSILONS_WELDALL, nullptr, pAdjacency, nullptr, nullptr, nullptr);
//pMesh->OptimizeInplace(D3DXMESHOPT_COMPACT | D3DXMESHOPT_IGNOREVERTS | D3DXMESHOPT_STRIPREORDER, newAdjacency, pAdjacency, nullptr, nullptr);
delete[] pAdjacency;
HRESULT hr = D3DXComputeNormals(pMesh, nullptr);
D3DXMATERIAL *m_pMaterials = nullptr;
DWORD m_dwNumMaterials = 0;
hr = D3DXSaveMeshToX("NavMesh.x", pMesh, nullptr, m_pMaterials, nullptr, m_dwNumMaterials, D3DXF_FILEFORMAT_BINARY);
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
return S_OK;
}
示例10: D3DXMeshCreateVertexEnumer
HRESULT D3DXMeshCreateVertexEnumer( LPD3DXMESH pMesh, D3DXMeshVertexEnumer& enumer )
{
_ASSERTE(! enumer.IsValid());
ZeroMemory(&enumer, sizeof(D3DXMeshVertexEnumer));//因为外部传入的enumer是可能重用的,这里绝对要重新清空一次
_ASSERTE(NULL != pMesh);
KG_PROCESS_ERROR(NULL != pMesh);
{
BOOL bIsAcceptableMesh = pMesh->GetFVF() & D3DFVF_XYZ;
KG_PROCESS_ERROR(bIsAcceptableMesh && _T("不支持没有XYZ标志的Mesh,那样不能保证每个节点开头是顶点"));
HRESULT hr = pMesh->LockVertexBuffer(0, reinterpret_cast<LPVOID*>(&enumer.m_pBuffer));
KG_COM_PROCESS_ERROR(hr);
_ASSERTE(1 == sizeof(BYTE));
enumer.m_pMesh = pMesh;
enumer.m_pMesh->AddRef();
enumer.m_dwNumBytePerVertex = pMesh->GetNumBytesPerVertex();
enumer.m_dwNumVertexCount = pMesh->GetNumVertices();
return S_OK;
}
Exit0:
return E_FAIL;
}
示例11:
//メッシュコンテナ描画
void Dx_Graphics3D::DrawMeshContainer(LPD3DXMESHCONTAINER pMeshContainer, LPD3DXFRAME pFrame)
{
DxMeshContainer *mesh_container = (DxMeshContainer*)pMeshContainer;
DxFrame *frame = (DxFrame*)pFrame;
//
D3DMATERIAL9 mat;
LPDIRECT3DTEXTURE9 pTex=NULL;
//D3DXMESHDATA内のメッシュデータを抽出
LPD3DXMESH lpMesh = mesh_container->MeshData.pMesh;
//スキニング情報がない場合
if(pMeshContainer->pSkinInfo==NULL)
{
//デバイスにフレームのワールド行列を設置
this->device->SetTransform( D3DTS_WORLD, &frame->CombinedTransformationMatrix);
//メッシュ描画
for (DWORD i=0;i<mesh_container->NumMaterials;i++)
{
//マテリアル情報の取得
mat = mesh_container->pMaterials[i].MatD3D;
//テクスチャ情報の取得
pTex = mesh_container->ppTextures[i];
//メッシュサブセットを描画
this->DrawSubset(lpMesh,i,&mat,pTex);
}
}
//スキニング情報がある場合
else
{
D3DXMATRIX matId;
PBYTE pVerticesSrc;
PBYTE pVerticesDest;
//ボーン数を取得
DWORD NumBones = pMeshContainer->pSkinInfo->GetNumBones();
for( DWORD i = 0; i < NumBones; i++ ){
D3DXMatrixMultiply(
&mesh_container->pBoneMatrices[i],
&mesh_container->pBoneOffsetMatrices[i],
mesh_container->ppBoneMatrixPtrs[i]
);
}
//ワールド行列をクリア
D3DXMatrixIdentity(&matId);
this->device->SetTransform(D3DTS_WORLD, &matId);
//頂点バッファをロック
mesh_container->lpMesh->LockVertexBuffer( D3DLOCK_READONLY, (LPVOID*)&pVerticesSrc);
lpMesh->LockVertexBuffer( 0, (LPVOID*)&pVerticesDest);
//スキンメッシュ作成
mesh_container->pSkinInfo->UpdateSkinnedMesh( mesh_container->pBoneMatrices, NULL, pVerticesSrc, pVerticesDest);
//頂点バッファのロックを解除
mesh_container->lpMesh->UnlockVertexBuffer();
lpMesh->UnlockVertexBuffer();
//メッシュ描画
for(UINT i = 0;i<mesh_container->NumAttributeGroups;i++)
{
//メッシュサブセットの属性IDを取得
unsigned AttribId = mesh_container->pAttributeTable[i].AttribId;
//マテリアル情報を取得
mat = mesh_container->pMaterials[AttribId].MatD3D;
//テクスチャ情報を取得
pTex = mesh_container->ppTextures[AttribId];
//メッシュのサブセットを描画
this->DrawSubset(lpMesh,AttribId,&mat,pTex);
}
}
}
示例12:
/**
*
* PRECONDITION: parameter EFacePosition _eSide must be either FACE_TOP, or FACE_BOTTOM.
*
* @author Rebeccah Cox
* @param EFacePosition _eSide - the side the flag is on, either top or bottom.
* @param int32 _iX - the position along the X axis.
* @param int32 _iY - the position along the Z axis (looks like the y axis when
* looking at the flag plate).
* @param ETeam _eTeam - team the flagplate belongs to.
* @param uint32 _uiTextureID
* @param uint32 _uiModelID
* @return bool - returns true if the initialisation was successful.
*/
bool
CFlagPlate::Initialise(EFacePosition _eSide, int32 _iX, int32 _iY, ETeam _eTeam, uint32 _uiModelID, uint32 _uiTextureID)
{
// Set the position and side member variables in CTile.
m_eFace = _eSide;
m_iX = _iX;
m_iY = _iY;
m_vec3Position = g_atUpRightDirectionVecs[_eSide].vec3Up * 22.5f;
m_vec3Position += g_atUpRightDirectionVecs[_eSide].vec3Right * ((_iX * 3.0f) - 21.0f);
m_vec3Position -= g_atUpRightDirectionVecs[_eSide].vec3Direction * ((_iY * 3.0f) - 21.0f);
// Set the world matrix using the vectors.
m_matWorld._11 = g_atUpRightDirectionVecs[_eSide].vec3Right.x;
m_matWorld._21 = g_atUpRightDirectionVecs[_eSide].vec3Up.x;
m_matWorld._31 = g_atUpRightDirectionVecs[_eSide].vec3Direction.x;
m_matWorld._12 = g_atUpRightDirectionVecs[_eSide].vec3Right.y;
m_matWorld._22 = g_atUpRightDirectionVecs[_eSide].vec3Up.y;
m_matWorld._32 = g_atUpRightDirectionVecs[_eSide].vec3Direction.y;
m_matWorld._13 = g_atUpRightDirectionVecs[_eSide].vec3Right.z;
m_matWorld._23 = g_atUpRightDirectionVecs[_eSide].vec3Up.z;
m_matWorld._33 = g_atUpRightDirectionVecs[_eSide].vec3Direction.z;
m_matWorld._41 = m_vec3Position.x;
m_matWorld._42 = m_vec3Position.y;
m_matWorld._43 = m_vec3Position.z;
m_bTraversable = true;
m_iModelID = _uiModelID;
m_iTextureID = _uiTextureID;
/*// Set the model ID
if(BAD_ID == _uiModelID)
{
m_iModelID = CModelManager::GetInstance().CreateModel("../../models/tile_flagplate.x");
}
// Set the texture ID
if(BAD_ID == _uiTextureID)
{
if(TEAM_GREEN == _eTeam)
{
m_iTextureID = CTextureManager::GetInstance().CreateTexture("../../textures/tile_flagTile_green.png");
}
else
{
m_iTextureID = CTextureManager::GetInstance().CreateTexture("../../textures/tile_flagTile_purple.png");
}
}*/
D3DXVECTOR3* pFirstVertex = 0;
LPD3DXMESH pMesh = CModelManager::GetInstance().GetModel(m_iModelID)->GetModel();
pMesh->LockVertexBuffer(0, (void**)&pFirstVertex);
D3DXComputeBoundingBox(pFirstVertex,
pMesh->GetNumVertices(),
pMesh->GetNumBytesPerVertex(),
&m_tOBB.m_vec3Min, &m_tOBB.m_vec3Max);
pMesh->UnlockVertexBuffer();
CEntity::Initialise();
return (true);
}
示例13: main
//.........这里部分代码省略.........
pMesh = pLoadMesh;
printf("Welding verts: ");
DWORD* pAdj = new DWORD[pAdjacency->GetBufferSize() / 4];
D3DXWELDEPSILONS Eps;
memset(&Eps, 0, sizeof(Eps));
hr = D3DXWeldVertices(pMesh, D3DXWELDEPSILONS_WELDPARTIALMATCHES, &Eps, (DWORD*)pAdjacency->GetBufferPointer(), pAdj, NULL, NULL);
if (FAILED(hr))
{
printf("ERROR: %08x\n", hr);
goto mesherror;
}
hr = pMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, pAdj, (DWORD*)pAdjacency->GetBufferPointer(), NULL, NULL);
if (FAILED(hr))
{
printf("ERROR: %08x\n", hr);
goto mesherror;
}
pAdjacency->Release();
delete [] pAdj;
printf("%d faces, %d verts\n", pMesh->GetNumFaces(), pMesh->GetNumVertices());
printf("Mending mesh: ");
DWORD NumVerts = pMesh->GetNumVertices();
DWORD NumFaces = pMesh->GetNumFaces();
MESHVERT* MeshVert;
pMesh->LockVertexBuffer(0, (LPVOID*)&MeshVert);
//fill up Mend vectors with your mesh's data
MendVerts.reserve(NumVerts);
for(DWORD i = 0; i < NumVerts; ++i)
{
MeshMender::Vertex v;
v.pos = MeshVert[i].pos;
v.s = MeshVert[i].s;
v.t = MeshVert[i].t;
v.normal = MeshVert[i].norm;
MendVerts.push_back(v);
}
pMesh->UnlockVertexBuffer();
WORD* MeshIdx;
pMesh->LockIndexBuffer(0, (LPVOID*)&MeshIdx);
MendIndices.reserve(NumFaces * 3);
for(DWORD i = 0; i < NumFaces * 3; ++i)
{
MendIndices.push_back(MeshIdx[i]);
}
pMesh->UnlockIndexBuffer();
pMesh->Release();
pMesh = 0;
//pass it in to Mend mender to do it's stuff
mender.Mend(MendVerts, MendIndices, mappingNewToOld, 0.9f, 0.9f, 0.9f, 1.0f, MeshMender::DONT_CALCULATE_NORMALS, MeshMender::RESPECT_SPLITS);
mappingNewToOld.clear();
示例14: Load
//.........这里部分代码省略.........
DWORD index = AddVertex(quadP[j], NewVertex);
mIndexs.push_back(index);
}
}
}
break;
}
#pragma endregion
}
fclose(fileHandle);
DWORD FVF = NULL;
D3DVERTEXELEMENT9* pMeshVDeclaration = NULL;
int code = 0;
IdentifieLoadedFormat(FVF, pMeshVDeclaration, code);
if( code == 0 )
return;
//Setup Mesh with VertexDeclaration corresponding to the loaded data
LPD3DXMESH pMesh = NULL;
HRESULT hr = NULL;
int FacesCount = mIndexs.size()/3;
switch( m_VertexMetaFormat )
{
case VertexMetaFormat::VertexDeclaration:
{
if( FacesCount > 65535 )// if huge mesh, 32 bits face index
hr = D3DXCreateMesh(FacesCount, mVertexs.size(), D3DXMESH_32BIT | D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
pMeshVDeclaration, pDevice, &pMesh);
else
hr = D3DXCreateMesh(FacesCount, mVertexs.size(), D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
pMeshVDeclaration, pDevice, &pMesh);
}
break;
case VertexMetaFormat::FVF:
{
if( FacesCount > 65535 )// if huge mesh, 32 bits face index
hr = D3DXCreateMeshFVF(FacesCount, Vertexs.size(), D3DXMESH_32BIT | D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
FVF, pDevice, &pMesh);
else
hr = D3DXCreateMeshFVF(FacesCount, Vertexs.size(), D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM | D3DXMESH_SYSTEMMEM ,
FVF, pDevice, &pMesh);
}
break;
default:
assert( false );
}
assert( !FAILED(hr) );
//Puts vertex data inside loadedData in the smallest format needed
//(not nesesarily VertexTextureNormal)
void* loadedData = NULL;
void* loadedIndex = NULL;
size_t size = 0;
//Pass to our vertex format
PutLoadedDataInVertexDeclarationFormat(loadedData,loadedIndex,size,code, FacesCount);
//Free Auxiliary Arrays
Vertexs.clear();
Textures.clear();
Normals.clear();
mVertexsHT.clear();
void* data = NULL;
//Loads the Vertex Buffer
if( FAILED(pMesh->LockVertexBuffer(NULL, &data)) )
return;
memcpy(data, loadedData, size*mVertexs.size());
pMesh->UnlockVertexBuffer();
//Loads the Index Buffer
if( FAILED(pMesh->LockIndexBuffer(NULL, &data)) )
return;
if( FacesCount > 65535 )
memcpy(data, loadedIndex, sizeof(DWORD)*mIndexs.size());
else
memcpy(data, loadedIndex, sizeof(WORD)*mIndexs.size());
pMesh->UnlockIndexBuffer();
//Free main Arrays
mVertexs.clear();
mIndexs.clear();
//Mesh data ready
m_RootMeshContainer = new D3DXMESHCONTAINER;
m_RootMeshContainer->MeshData.pMesh = pMesh;
return;
}
示例15: InitGeometry
HRESULT InitGeometry( )
{
if (FAILED(D3DXCreateBox(g_pD3DDevice, 1.f, 1.f, 1.f, &g_pMesh, NULL)))
{
return E_FAIL;
}
D3DXVECTOR3 *vertices;
g_pMesh->LockVertexBuffer( D3DLOCK_READONLY, (void**) &vertices );
D3DXComputeBoundingBox( vertices, g_pMesh->GetNumVertices(), g_pMesh->GetNumBytesPerVertex(), &g_MinPoint, &g_MaxPoint );
g_pMesh->UnlockVertexBuffer();
D3DXMATRIX matScale, matTrans, matRotateZ, matWorld;
g_Box[0].BoxScaling = 1.5f;
g_Box[0].CenterPos = D3DXVECTOR3( 0.f, 0.f, 0.f );
g_Box[0].BoxRotateZ = 0.f;
g_Box[0].AxisDir[0] = D3DXVECTOR3( 1, 0, 0 );
g_Box[0].AxisDir[1] = D3DXVECTOR3( 0, 1, 0 );
g_Box[0].AxisDir[2] = D3DXVECTOR3( 0, 0, 1 );
for ( int i = 0; i < 3; ++i )
{
g_Box[0].AxisLen[i] = 0.5f;
D3DXVec3TransformNormal( &(g_Box[0].AxisDir[i]), &(g_Box[0].AxisDir[i]), &matRotateZ );
D3DXVec3Normalize( &( g_Box[0].AxisDir[i] ), &( g_Box[0].AxisDir[i] ) );
g_Box[0].AxisLen[i] = g_Box[0].AxisLen[i] * g_Box[0].BoxScaling;
}
D3DXMatrixTranslation( &matTrans, g_Box[0].CenterPos.x, g_Box[0].CenterPos.y, g_Box[0].CenterPos.z );
D3DXMatrixScaling( &matScale, g_Box[0].BoxScaling, g_Box[0].BoxScaling, g_Box[0].BoxScaling );
D3DXMatrixRotationZ( &matRotateZ, g_Box[0].BoxRotateZ );
matWorld = matRotateZ* matScale * matTrans;
D3DXVec3TransformCoord( &g_Box[0].MinPoint, &g_MinPoint, &matWorld );
D3DXVec3TransformCoord( &g_Box[0].MaxPoint, &g_MaxPoint, &matWorld );
g_Box[1].BoxScaling = 2.f;
g_Box[1].CenterPos = D3DXVECTOR3( 3.f, 3.f, 0.f );
g_Box[1].BoxRotateZ = 0.f;
g_Box[1].AxisDir[0] = D3DXVECTOR3( 1, 0, 0 );
g_Box[1].AxisDir[1] = D3DXVECTOR3( 0, 1, 0 );
g_Box[1].AxisDir[2] = D3DXVECTOR3( 0, 0, 1 );
for ( int i = 0; i < 3; ++i )
{
g_Box[1].AxisLen[i] = 0.5f;
D3DXVec3TransformNormal( &( g_Box[0].AxisDir[i] ), &( g_Box[1].AxisDir[i] ), &matRotateZ );
D3DXVec3Normalize( &( g_Box[1].AxisDir[i] ), &( g_Box[1].AxisDir[i] ) );
g_Box[1].AxisLen[i] = g_Box[1].AxisLen[i] * g_Box[1].BoxScaling;
}
D3DXMatrixTranslation( &matTrans, g_Box[1].CenterPos.x, g_Box[1].CenterPos.y, g_Box[1].CenterPos.z );
D3DXMatrixScaling( &matScale, g_Box[1].BoxScaling, g_Box[1].BoxScaling, g_Box[1].BoxScaling );
D3DXMatrixRotationZ( &matRotateZ, g_Box[1].BoxRotateZ );
matWorld = matRotateZ* matScale * matTrans;
D3DXVec3TransformCoord( &g_Box[1].MinPoint, &g_MinPoint, &matWorld );
D3DXVec3TransformCoord( &g_Box[1].MaxPoint, &g_MaxPoint, &matWorld );
return S_OK;
}