本文整理汇总了C++中LPD3DXMESH::UnlockVertexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH::UnlockVertexBuffer方法的具体用法?C++ LPD3DXMESH::UnlockVertexBuffer怎么用?C++ LPD3DXMESH::UnlockVertexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPD3DXMESH
的用法示例。
在下文中一共展示了LPD3DXMESH::UnlockVertexBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例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: 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;
}
示例7:
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();
}
}
示例8: 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;
}
示例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:
//メッシュコンテナ描画
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);
}
}
}
示例11:
/**
*
* 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);
}
示例12: optimizePhysXMesh
void optimizePhysXMesh(int flag, IDirect3DDevice9* D3DDevice, float epsilon, std::vector<physx::PxVec3>& pxVertices, oiram::IndexBuffer& indexBuffer)
{
assert(D3DDevice);
D3DVERTEXELEMENT9 szDecl[] = {
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0xFF, 0, D3DDECLTYPE_UNUSED, 0, 0, 0}
};
// 创建D3D MESH
LPD3DXMESH pMesh = 0;
DWORD options = D3DXMESH_SYSTEMMEM | D3DXMESH_DYNAMIC;
if (indexBuffer.use32BitIndices)
options |= D3DXMESH_32BIT;
DWORD numVertices = static_cast<DWORD>(pxVertices.size()), numFaces = numVertices / 3;
HRESULT hr = D3DXCreateMesh(numFaces, numVertices, options, szDecl, D3DDevice, &pMesh);
if (SUCCEEDED(hr))
{
LPVOID pData = nullptr;
// 填充Index Buffer
if (SUCCEEDED(pMesh->LockIndexBuffer(D3DLOCK_DISCARD, &pData)))
{
if (indexBuffer.use32BitIndices)
memcpy(pData, indexBuffer.uiIndexBuffer.data(), indexBuffer.uiIndexBuffer.size() * sizeof(physx::PxU32));
else
memcpy(pData, indexBuffer.usIndexBuffer.data(), indexBuffer.usIndexBuffer.size() * sizeof(physx::PxU16));
pMesh->UnlockIndexBuffer();
}
// 填充Vertex Buffer
if (SUCCEEDED(pMesh->LockVertexBuffer(D3DLOCK_DISCARD, &pData)))
{
memcpy(pData, pxVertices.data(), pxVertices.size() * sizeof(physx::PxVec3));
pMesh->UnlockVertexBuffer();
}
// 进行Mesh优化
DWORD dwFaces = pMesh->GetNumFaces();
std::vector<DWORD> szAdjacencies(dwFaces * 3);
DWORD* pAdjacency = &szAdjacencies[0];
pMesh->GenerateAdjacency(epsilon, pAdjacency);
// 清理mesh
hr = D3DXCleanMesh(D3DXCLEAN_SIMPLIFICATION, pMesh, pAdjacency, &pMesh, pAdjacency, NULL);
if (SUCCEEDED(hr))
{
// 去除mesh中重复的顶点
hr = D3DXWeldVertices(pMesh, D3DXWELDEPSILONS_WELDALL, NULL, pAdjacency, pAdjacency, NULL, NULL);
if (SUCCEEDED(hr))
{
// 将优化后的数据写回mesh data
DWORD numIndices = pMesh->GetNumFaces() * 3;
indexBuffer.use32BitIndices = numIndices > 65535;
if (indexBuffer.use32BitIndices)
indexBuffer.uiIndexBuffer.resize(numIndices);
else
indexBuffer.usIndexBuffer.resize(numIndices);
// 取出Index Buffer
if (SUCCEEDED(pMesh->LockIndexBuffer(D3DLOCK_READONLY | D3DLOCK_DISCARD, &pData)))
{
if (indexBuffer.use32BitIndices)
memcpy(indexBuffer.uiIndexBuffer.data(), pData, indexBuffer.uiIndexBuffer.size() * sizeof(physx::PxU32));
else
memcpy(indexBuffer.usIndexBuffer.data(), pData, indexBuffer.usIndexBuffer.size() * sizeof(physx::PxU16));
pMesh->UnlockIndexBuffer();
}
// 取出Vertex Buffer
DWORD dwVertices = pMesh->GetNumVertices();
pxVertices.resize(dwVertices);
if (SUCCEEDED(pMesh->LockVertexBuffer(D3DLOCK_READONLY | D3DLOCK_DISCARD, &pData)))
{
memcpy(pxVertices.data(), pData, pxVertices.size() * sizeof(physx::PxVec3));
pMesh->UnlockVertexBuffer();
}
}
}
pMesh->Release();
}
}
示例13: InitMesh
HRESULT InitMesh()
{
// Create mesh
HRESULT hr = D3DXCreateMeshFVF(
NumTriangles,
NumVertex,
D3DXMESH_MANAGED | D3DXMESH_32BIT,
Vertex_FVF,
g_pd3dDevice,
&g_pMesh);
if (FAILED(hr))
{
return E_FAIL;
}
// Define the 8 vertex of the cube
D3DXVECTOR3 vertex[] =
{
D3DXVECTOR3(-0.5f, -0.5f, -0.5f),
D3DXVECTOR3( 0.5f, -0.5f, -0.5f),
D3DXVECTOR3( 0.5f, 0.5f, -0.5f),
D3DXVECTOR3(-0.5f, 0.5f, -0.5f),
D3DXVECTOR3(-0.5f, -0.5f, 0.5f),
D3DXVECTOR3( 0.5f, -0.5f, 0.5f),
D3DXVECTOR3( 0.5f, 0.5f, 0.5f),
D3DXVECTOR3(-0.5f, 0.5f, 0.5f),
};
// Lock vertex buffer and copy data
void* pVertices = NULL;
g_pMesh->LockVertexBuffer(0, &pVertices);
memcpy(pVertices, vertex, sizeof(vertex));
g_pMesh->UnlockVertexBuffer();
// Define 36 index of the cube
DWORD index[] =
{
// Front face
0, 3, 1,
3, 2, 1,
// Back face
5, 6, 2,
6, 7, 2,
// Left face
4, 7, 0,
7, 3, 0,
// Right face
1, 2, 5,
2, 6, 5,
// Top face
3, 7, 2,
7, 6, 2,
// Bottom face
4, 0, 5,
0, 1, 5,
};
// Lock index buffer and copy data
DWORD* pIndices = NULL;
g_pMesh->LockIndexBuffer(0, (void**)&pIndices);
memcpy(pIndices, index, sizeof(index));
g_pMesh->UnlockIndexBuffer();
// Compute normals
D3DXComputeNormals(g_pMesh, 0);
return D3D_OK;
}
示例14: ConstruirSombra
void Sombra::ConstruirSombra(LPD3DXMESH pMesh, D3DXVECTOR3 vLight)
{
// Note: the MeshVertex format depends on the FVF of the mesh
struct MeshVertex { D3DXVECTOR3 p, n;
DWORD diffuse;
float tu,tv; };
MeshVertex *pVertices;
WORD *pIndices;
// Lock the geometry buffers
pMesh->LockVertexBuffer( 0L, (LPVOID*)&pVertices );
pMesh->LockIndexBuffer( 0L, (LPVOID*)&pIndices );
DWORD dwNumFaces = pMesh->GetNumFaces();
// Allocate a temporary edge list
WORD *pEdges = new WORD[dwNumFaces*6];
if( pEdges == NULL )
{
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
return ;
}
DWORD dwNumEdges = 0;
// For each face
for( DWORD i = 0; i < dwNumFaces; ++i )
{
WORD wFace0 = pIndices[3*i+0];
WORD wFace1 = pIndices[3*i+1];
WORD wFace2 = pIndices[3*i+2];
D3DXVECTOR3 v0 = pVertices[wFace0].p;
D3DXVECTOR3 v1 = pVertices[wFace1].p;
D3DXVECTOR3 v2 = pVertices[wFace2].p;
// Transform vertices or transform light?
D3DXVECTOR3 vCross1(v2-v1);
D3DXVECTOR3 vCross2(v1-v0);
D3DXVECTOR3 vNormal;
D3DXVec3Cross( &vNormal, &vCross1, &vCross2 );
if( D3DXVec3Dot( &vNormal, &vLight ) >= 0.0f )
{
InsertarSegmento( pEdges, dwNumEdges, wFace0, wFace1 );
InsertarSegmento( pEdges, dwNumEdges, wFace1, wFace2 );
InsertarSegmento( pEdges, dwNumEdges, wFace2, wFace0 );
}
}
// Se construyen las caras de la sombra extrudando los segmentos en la dirección
// de la luz y una longitud 10 veces la del vector luz.
for( i = 0; i < dwNumEdges; ++i )
{
D3DXVECTOR3 v1 = pVertices[pEdges[2*i+0]].p;
D3DXVECTOR3 v2 = pVertices[pEdges[2*i+1]].p;
D3DXVECTOR3 v3 = v1 - vLight/10;
D3DXVECTOR3 v4 = v2 - vLight/10;
// Add a quad (two triangles) to the vertex list
m_pVertices[m_dwNumVertices++] = v1;
m_pVertices[m_dwNumVertices++] = v2;
m_pVertices[m_dwNumVertices++] = v3;
m_pVertices[m_dwNumVertices++] = v2;
m_pVertices[m_dwNumVertices++] = v4;
m_pVertices[m_dwNumVertices++] = v3;
}
// Delete the temporary edge list
delete[] pEdges;
// Unlock the geometry buffers
pMesh->UnlockVertexBuffer();
pMesh->UnlockIndexBuffer();
}
示例15: 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;
}