当前位置: 首页>>代码示例>>C++>>正文


C++ LPD3DXMESH::LockAttributeBuffer方法代码示例

本文整理汇总了C++中LPD3DXMESH::LockAttributeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH::LockAttributeBuffer方法的具体用法?C++ LPD3DXMESH::LockAttributeBuffer怎么用?C++ LPD3DXMESH::LockAttributeBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPD3DXMESH的用法示例。


在下文中一共展示了LPD3DXMESH::LockAttributeBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:arkiny,项目名称:Direct3D,代码行数:50,代码来源:cMyASELoader.cpp

示例2: D3DXMeshCreateAttributeEnumer

HRESULT D3DXMeshCreateAttributeEnumer(LPD3DXMESH pMesh, D3DXMeshAttributeEnumer& enumer )
{
	_ASSERTE(! enumer.IsValid());
	ZeroMemory(&enumer, sizeof(D3DXMeshAttributeEnumer)); //因为外部传入的enumer是可能重用的,这里绝对要重新清空一次

	_ASSERTE(NULL != pMesh);
	KG_PROCESS_ERROR(NULL != pMesh);
	{
		HRESULT hr = pMesh->LockAttributeBuffer(0, reinterpret_cast<DWORD**>(&enumer.m_pBuffer));
		KG_COM_PROCESS_ERROR(hr);
		_ASSERTE(1 == sizeof(BYTE) && 2 == sizeof(WORD) && 4 == sizeof(DWORD));

		enumer.m_pMesh = pMesh;
		enumer.m_pMesh->AddRef();
		enumer.m_dwNumFaceCount = pMesh->GetNumFaces();

		return S_OK;
	}
Exit0:
	return E_FAIL;
}
开发者ID:1suming,项目名称:pap2,代码行数:21,代码来源:KG3DMeshHelpers.cpp

示例3: 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;
}
开发者ID:Honors2016ProjectA2,项目名称:Main,代码行数:41,代码来源:IEX_3DObject.cpp

示例4: CreateTerrainMesh

//------------------------------------------------------------------------------------------------
// Name:  CreateTerrainMesh
// Desc:  
//------------------------------------------------------------------------------------------------
bool CreateTerrainMesh(LPDIRECT3DDEVICE9 d3dDevice, LPD3DXMESH* terrainMesh)
{
    // Calculate the number of faces and vertices required
    const unsigned int faces = (TMS_COUNT + 3) * 2;
    const unsigned int vertices = (TMS_COUNT + 3) * 4;

    // The internal terrain mesh
    LPD3DXMESH internalTerrainMesh;

    // Create the mesh
    HRESULT hr = D3DXCreateMeshFVF(faces, vertices, D3DXMESH_MANAGED, D3DFVF_GEOMETRYVERTEX, d3dDevice, &internalTerrainMesh);
    if (APP_ERROR(FAILED(hr))("Unable to create the terrain mesh"))
        return false;

    // Lock the mesh buffers
    GeometryVertex* lockedVertices = 0;
    WORD* lockedIndices = 0;
    DWORD* lockedAttributes = 0;
    if (APP_ERROR(FAILED(internalTerrainMesh->LockAttributeBuffer(0, &lockedAttributes)) ||
                   FAILED(internalTerrainMesh->LockVertexBuffer(0, (VOID**)&lockedVertices)) ||
                   FAILED(internalTerrainMesh->LockIndexBuffer(0, (VOID**)&lockedIndices)))("Unable to lock terrain mesh"))
    {
        // Deallocate the mesh
        SAFE_RELEASE(internalTerrainMesh);

        // Exit the method
        return false;
    }

    // Vertices that will be rotated 4x about Y at
    // 90-degree intervals to produce the wall mesh
    GeometryVertex wallSide[] = {
        { -0.5f,  0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { -0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f, -1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { -0.5f, -1.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // The flat square with unit size
    GeometryVertex flat[] = {
        { -0.5f,  0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { +0.5f,  0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { +0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // Geometry template for the high-corner meshes,
    // with the high corner in the north-west
    GeometryVertex highCorner[] = {
        { -0.5f, +1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { +0.5f,  0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { +0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // Geometry template for the low-corner meshes,
    // with the low corner in the north-west
    GeometryVertex lowCorner[] = {
        { -0.5f, -1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { +0.5f,  0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { +0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // Geometry template for the high-side meshes,
    // with the high side to the north
    GeometryVertex highSide[] = {
        { -0.5f, +1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { +0.5f, +1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { +0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // Geometry template for the low-corner meshes,
    // with the low corner in the north-west
    GeometryVertex raisedLowCorner[] = {
        { -0.5f,  0.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { +0.5f, +1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f, +1.0f, +0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { +0.5f, +1.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // Geometry template for the low-side meshes,
    // with the low side to the north
    GeometryVertex lowSide[] = {
        { -0.5f, -1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
        { +0.5f, -1.0f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { -0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { +0.5f,  0.0f, +0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
    };

    // The subset that is currently being written
    unsigned int currentSubset = TMS_WALL_SIDES;

    // Copy the wall first--it does not have any texture rotations
    lockedVertices = CopyYRotatedGeometry(lockedVertices, wallSide, 4, 0.0f * D3DX_PI / 2.0f);
//.........这里部分代码省略.........
开发者ID:karlgluck,项目名称:Evidyon,代码行数:101,代码来源:atlaseditdialog_createterrainmesh.cpp

示例5: LoadMesh

HRESULT KModelWater::LoadMesh(LPSTR pFileName)
{
	HRESULT hr = S_OK;

	m_dwNumPoly_X = 63;     //长方形网格的长,网格数
	m_dwNumPoly_Z = 63;     //长方形网格的宽,网格数

	LPD3DXMESH pMesh = m_pWaterUp;
	LPD3DXMESH pDMesh = m_pWaterDn;

	DWORD m_dNumPloy     = m_dwNumPoly_X * m_dwNumPoly_Z;
	DWORD m_dNumFaces    = m_dNumPloy * 2;
	DWORD m_dNumVertices = (m_dwNumPoly_X+1)*(m_dwNumPoly_Z+1);

	SAFE_RELEASE(pMesh);	
	SAFE_RELEASE(pDMesh);
	WORD *pwIndices;

	//建立水面网格 
	if(FAILED(hr = g_pd3dDevice->CreateIndexBuffer(m_dNumFaces * 3 * sizeof(WORD), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
		D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_pibIndices, NULL)))
	{
		return hr;
	}

	if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pMesh)))
	{
		return hr;
	}	
	if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pDMesh)))
	{
		return hr;
	}




	VFormat::FACES_NORMAL_TEXTURE1 * pVers = NULL;
	DWORD* pIndex = NULL;
	DWORD * pAttrib = NULL;	

	VFormat::FACES_NORMAL_TEXTURE1 * pDVers = NULL;
	DWORD* pDIndex = NULL;
	DWORD * pDAttrib = NULL;	
	if(FAILED(hr = m_pibIndices->Lock(0, m_dNumFaces *3 * sizeof(WORD), (void**) &pwIndices, D3DLOCK_DISCARD)))
		return E_FAIL;
	if (FAILED(pMesh->LockVertexBuffer(0,(void**)&pVers)))
		return E_FAIL;
	if (FAILED(pMesh->LockIndexBuffer (0,(void**)&pIndex)))
		return E_FAIL;
	if (FAILED(pMesh->LockAttributeBuffer(0,(DWORD**)&pAttrib)))
		return E_FAIL;

	if (FAILED(pDMesh->LockVertexBuffer(0,(void**)&pDVers)))
		return E_FAIL;
	if (FAILED(pDMesh->LockIndexBuffer (0,(void**)&pDIndex)))
		return E_FAIL;
	if (FAILED(pDMesh->LockAttributeBuffer(0,(DWORD**)&pDAttrib)))
		return E_FAIL;

	DWORD i = 0;
	float _X = 1.0f/m_dwNumPoly_X;
	float _Z = 1.0f/m_dwNumPoly_Z;

	float m_fPolyWidth  = 200;
	float m_fPolyHeight = 200;

	for(DWORD X =0;X<=m_dwNumPoly_X;X++)
	{
		for(DWORD Y =0;Y<=m_dwNumPoly_Z;Y++)
		{
			float PX = X * m_fPolyWidth;
			float PZ = Y * m_fPolyHeight;

			D3DXVECTOR2 Pos(PX,PZ);

			pVers[i].p = D3DXVECTOR3(PX,200,PZ);

			pVers[i].Normal = D3DXVECTOR3(0,1,0);

			pVers[i].tu1 = (X * _X);
			pVers[i].tv1 = (1 - Y *_Z);
			pDVers[i].p = D3DXVECTOR3(PX,0,PZ);
			pDVers[i].Normal = D3DXVECTOR3(0,1,0);
			pDVers[i].tu1 = (X * _X);
			pDVers[i].tv1 = (1 - Y *_Z);
			i++;
		}
	}

	DWORD  Weight = m_dwNumPoly_X + 1;

	for(X =0;X<m_dwNumPoly_X;X++)
	{
		for(DWORD Y =0;Y<m_dwNumPoly_Z;Y++)
		{
			DWORD PloyIndex = Y*m_dwNumPoly_X +X;

//.........这里部分代码省略.........
开发者ID:viticm,项目名称:pap2,代码行数:101,代码来源:KModelWater.cpp

示例6: CreateBox


//.........这里部分代码省略.........

		offset += 4;

		// fill in the top face index data
		vIB.push_back( 0 + offset );
		vIB.push_back( 1 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 0 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 3 + offset );

		//fill in the top face vertex data
		vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 1.f, 0.f, 0.f, 1.f ) );
		vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, d + offsetZ, 0.f, 1.f, 0.f, 0.f, 0.f ) );
		vVB.push_back( VERTEX3( w + offsetX, h + offsetY, d + offsetZ, 0.f, 1.f, 0.f, 1.f, 0.f ) );
		vVB.push_back( VERTEX3( w + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 1.f, 0.f, 1.f, 1.f ) );

		vAB.push_back( 2 );
		vAB.push_back( 2 );

		offset += 4;

		// fill in the bottom face index data
		vIB.push_back( 0 + offset );
		vIB.push_back( 1 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 0 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 3 + offset );

		// fill in the bottom face vertex data
		vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, -1.f, 0.f, 0.f, 1.f ) );
		vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, -1.f, 0.f, 0.f, 0.f ) );
		vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, d + offsetZ, 0.f, -1.f, 0.f, 1.f, 0.f ) );
		vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, d + offsetZ, 0.f, -1.f, 0.f, 1.f, 1.f ) );

		vAB.push_back( 3 );
		vAB.push_back( 3 );

		offset += 4;

		// fill in the left face index data
		vIB.push_back( 0 + offset );
		vIB.push_back( 1 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 0 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 3 + offset );

		// fill in the left face vertex data
		vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, d + offsetZ, -1.f, 0.f, 0.f, 0.f, 1.f ) );
		vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, d + offsetZ, -1.f, 0.f, 0.f, 0.f, 0.f ) );
		vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, 0.f + offsetZ, -1.f, 0.f, 0.f, 1.f, 0.f ) );
		vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, 0.f + offsetZ, -1.f, 0.f, 0.f, 1.f, 1.f ) );

		vAB.push_back( 4 );
		vAB.push_back( 4 );

		offset += 4;

		// fill in the right face index data
		vIB.push_back( 0 + offset );
		vIB.push_back( 1 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 0 + offset );
		vIB.push_back( 2 + offset );
		vIB.push_back( 3 + offset );

		// fill in the right face vertex data
		vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, 0.f + offsetZ, 1.f, 0.f, 0.f, 0.f, 1.f ) );
		vVB.push_back( VERTEX3( w + offsetX, h + offsetY, 0.f + offsetZ, 1.f, 0.f, 0.f, 0.f, 0.f ) );
		vVB.push_back( VERTEX3( w + offsetX, h + offsetY, d + offsetZ, 1.f, 0.f, 0.f, 1.f, 0.f ) );
		vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, d + offsetZ, 1.f, 0.f, 0.f, 1.f, 1.f ) );

		vAB.push_back( 5 );
		vAB.push_back( 5 );

		offset += 4;

		D3DXCreateMeshFVF( offset / 2, offset, D3DXMESH_MANAGED | D3DXMESH_32BIT, VERTEX3::FVF, g_pEngine->core->lpd3dd9, &mesh );

		VERTEX3 *pVB = nullptr;
		mesh->LockVertexBuffer( D3DLOCK_DISCARD, reinterpret_cast< void** >( &pVB ) );
		copy( vVB.begin(), vVB.end(), pVB );
		mesh->UnlockVertexBuffer();

		DWORD *pIB = nullptr;
		mesh->LockIndexBuffer( D3DLOCK_DISCARD, reinterpret_cast< void** >( &pIB ) );
		copy( vIB.begin(), vIB.end(), pIB );
		mesh->UnlockIndexBuffer();

		DWORD *pAB = nullptr;
		mesh->LockAttributeBuffer( D3DLOCK_DISCARD, &pAB );
		copy( vAB.begin(), vAB.end(), pAB );
		mesh->UnlockAttributeBuffer();

		std::vector<DWORD> adjacencyBuffer( mesh->GetNumFaces() * 3 );
		mesh->GenerateAdjacency( 0.f, &adjacencyBuffer[ 0 ] );
		mesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, &adjacencyBuffer[ 0 ], nullptr, nullptr, nullptr );
	}
开发者ID:Lorise,项目名称:VoxelGame,代码行数:101,代码来源:functional.cpp


注:本文中的LPD3DXMESH::LockAttributeBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。