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


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

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


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

示例1: CreateBox

void CBoundBox::CreateBox( const D3DXVECTOR3 *pVMin, const D3DXVECTOR3 *pVMax )
{
    m_fWidth = pVMax->x - pVMin->x;
	m_fHeight = pVMax->y - pVMin->y;
	m_fDepth = pVMax->z - pVMin->z;
	
	LPD3DXMESH tmpMesh;
	D3DXCreateBox( m_pDevice, m_fWidth, m_fHeight, m_fDepth, &tmpMesh, NULL );
	tmpMesh->CloneMeshFVF( tmpMesh->GetOptions(), D3DFVF_XYZ|D3DFVF_DIFFUSE, m_pDevice, &m_box );
	tmpMesh->CloneMeshFVF( tmpMesh->GetOptions(), D3DFVF_XYZ|D3DFVF_DIFFUSE, m_pDevice, &m_boxOrig );
	tmpMesh->Release();
}
开发者ID:wang35666,项目名称:3dgame,代码行数:12,代码来源:BoundBox.cpp

示例2: FreeMemory

void D3D9Mesh::CreateText(const char *string, char *FontName, int FontHeight,
                float deviation, float depth, bool bold, bool italic)
{
    //just call the DirectX function to create the text
    FreeMemory();
    LPD3DXMESH TextMesh;
    
    HDC hdc = CreateCompatibleDC( NULL );
    HFONT hFont;
    HFONT hFontOld;
    
    INT nHeight = -MulDiv( FontHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72 );
    hFont = CreateFont(nHeight, 0, 0, 0, bold ? FW_BOLD : FW_NORMAL, italic, FALSE, FALSE, DEFAULT_CHARSET, 
        OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, FontName);
    hFontOld = (HFONT)SelectObject(hdc, hFont); 

    if(FAILED(D3DXCreateText(GetD3DDevice(), hdc, string, deviation, depth, &TextMesh, NULL, NULL))) _asm int 3;

    SelectObject(hdc, hFontOld);
    DeleteObject( hFont );
    DeleteDC( hdc );

    TextMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);
    TextMesh->Release();
    SetColor(RGBColor::White);
    GenerateNormals();
}
开发者ID:kbinani,项目名称:dxrip,代码行数:27,代码来源:D3D9Mesh.cpp

示例3: checkBonePick

bool TriPickDemo::checkBonePick(LPD3DXMESH mesh, D3DXMATRIX matWorld)
{
	D3DXVECTOR3 originW(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 dirW(0.0f, 0.0f, 0.0f);
	getWorldPickingRay(originW, dirW, matWorld);
	LPD3DXMESH pMesh;

	mesh->CloneMeshFVF(D3DXMESH_MANAGED, D3DVERTEX::FVF, g_pDevice, &pMesh);
	BOOL hit = 0;
	DWORD faceIndex = -1;
	float u = 0.0f;
	float v = 0.0f;
	float dist = 0.0f;
	ID3DXBuffer* allhits = 0;
	DWORD numHits = 0;
	HR(D3DXIntersect(pMesh, &originW, &dirW, &hit,
		&faceIndex, &u, &v, &dist, &allhits, &numHits));
	SAFE_RELEASE(allhits);

	if (hit)
	{
		return true;
	}
	return false;
}
开发者ID:duoshengyu,项目名称:InverseIK,代码行数:25,代码来源:MyApp.cpp

示例4: _MDLOptimize

PROTECTED void _MDLOptimize(LPD3DXMESH mesh, const LPD3DXBUFFER pAdjacencyBuffer, int numInd, 
						  LPD3DXMESH *optMesh)
{
	HRESULT hr;
	DWORD        *rgdwAdjacencyTemp = 0;
	LPD3DXMESH	 tempMesh;
	DWORD        dw32Bit = mesh->GetOptions() & D3DXMESH_32BIT;

	// allocate a second adjacency buffer to store post attribute sorted adjacency
	if(MemAlloc((void**)&rgdwAdjacencyTemp, sizeof(DWORD)*numInd, M_ZERO) != RETCODE_SUCCESS)
	{ ASSERT_MSG(0, "Unable to allocate rgdwAdjacencyTemp", "Error in _MDLOptimize"); goto End; }

    // attribute sort - the un-optimized mesh option
    //          remember the adjacency for the vertex cache optimization
    hr = mesh->OptimizeInplace( D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT,
                                 (DWORD*)pAdjacencyBuffer->GetBufferPointer(),
                                 rgdwAdjacencyTemp, NULL, NULL);
    if( FAILED(hr) )
        goto End;

    // snapshot the attribute sorted mesh, shown as the un-optimized version
    hr = mesh->CloneMeshFVF( dw32Bit|D3DXMESH_MANAGED, mesh->GetFVF(), 
                                      g_p3DDevice, &tempMesh );
    if( FAILED(hr) )
        goto End;

    // actually do the vertex cache optimization
    hr = mesh->OptimizeInplace( D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT|D3DXMESHOPT_VERTEXCACHE,
                                 rgdwAdjacencyTemp,
                                 NULL, NULL, NULL);
    if( FAILED(hr) )
        goto End;

    // snapshot as the optimized mesh
    hr = mesh->CloneMeshFVF( dw32Bit|D3DXMESH_MANAGED, mesh->GetFVF(), 
                                      g_p3DDevice, optMesh );
    if( FAILED(hr) )
        goto End;

End:
	if(rgdwAdjacencyTemp)
		MemFree((void**)&rgdwAdjacencyTemp);
    
	if(tempMesh)
		tempMesh->Release();
}
开发者ID:PtrickH,项目名称:homies,代码行数:46,代码来源:GFX_Model.cpp

示例5: 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;
}
开发者ID:naknaknak,项目名称:3D_Game_Portfolio,代码行数:57,代码来源:SkyBox.cpp

示例6:

	Mymesh(LPDIRECT3DDEVICE9 pD3DDevice, LPSTR pFilename)
	{
		LPD3DXBUFFER materialsBuffer = NULL;
		LPD3DXMESH mesh = NULL;

		pd3d = pD3DDevice;

		// second null is D3DXEFFECTINSTANCE.
		if (FAILED(D3DXLoadMeshFromX(pFilename, D3DXMESH_SYSTEMMEM, pd3d, NULL,
			&materialsBuffer, NULL, &dwNumMaterials, &mesh))) 
		{
			// null everything
			pMesh = NULL;
			pMeshMaterials = NULL;
			pMeshTextures = NULL;

			return;
		}

		D3DXMATERIAL* matMaterials = (D3DXMATERIAL*)materialsBuffer->GetBufferPointer();

		pMeshMaterials = new D3DMATERIAL9[dwNumMaterials];
		pMeshTextures = new LPDIRECT3DTEXTURE9[dwNumMaterials];

		for (DWORD i = 0; i < dwNumMaterials; i++) 
		{
			pMeshMaterials[i] = matMaterials[i].MatD3D;

			// ambient color
			pMeshMaterials[i].Ambient = pMeshMaterials[i].Diffuse;

			if (FAILED(D3DXCreateTextureFromFile(pd3d, 
				matMaterials[i].pTextureFilename, 
				&pMeshTextures[i])))
			{
				pMeshTextures[i] = NULL;
			}
		}
		SafeRelease(materialsBuffer);

		mesh->CloneMeshFVF(D3DXMESH_MANAGED, MESH_D3DFVF_CUSTOMVERTEX, pd3d, &pMesh);
		SafeRelease(mesh);

		D3DXComputeNormals(pMesh,0);
	}
开发者ID:cdave1,项目名称:tetris,代码行数:45,代码来源:cmesh.cpp

示例7: __GetBoundBox

bool CMesh::__GetBoundBox(const LPD3DXMESH pMesh, CRectangle3D& Rect3d)
{
	if (pMesh == NULL)
		return false;

	UINT uVertexNum = pMesh->GetNumVertices();

	LPD3DXMESH pTempMesh;
	pMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_XYZ, &DEVICE, &pTempMesh);
	
	LPDIRECT3DVERTEXBUFFER9 pVertexBuffer;
	pTempMesh->GetVertexBuffer(&pVertexBuffer);

	FLOAT maxX = 0.0f, maxY = 0.0f, maxZ = 0.0f;
	FLOAT minX = 0.0f, minY = 0.0f, minZ = 0.0f;

	D3DXVECTOR3* pVertices;

	pVertexBuffer->Lock(0, 0, (void**)&pVertices, 0);

	for(UINT i = 0; i < uVertexNum; i ++)
	{
		if(pVertices[i].x > maxX)
			maxX = pVertices[i].x;
		if(pVertices[i].y > maxY)
			maxY = pVertices[i].y;
		if(pVertices[i].z > maxZ)
			maxZ = pVertices[i].z;

		if(pVertices[i].x < minX)
			minX = pVertices[i].x;
		if(pVertices[i].y < minY)
			minY = pVertices[i].y;
		if(pVertices[i].z < minZ)
			minZ = pVertices[i].z;
	}
	pVertexBuffer->Unlock();

	Rect3d.Set(minX, maxX, minY, maxY, minZ, maxZ);

	DEBUG_RELEASE(pVertexBuffer);
	DEBUG_RELEASE(pTempMesh);

	return true;
}
开发者ID:dreamsxin,项目名称:zero3d,代码行数:45,代码来源:Mesh.cpp

示例8: Unlock

void D3D9Mesh::NPatchEnhance(float segs, bool quadratic)
{
    DWORD *adj;
    Unlock();

    //get the _Mesh adjacency (needed by NPatchEnhance)
    GenerateAdj(adj);
    LPD3DXMESH sphere;

    //do the n-patching using the DirectX function
    D3DXTessellateNPatches(_Mesh, adj, segs, quadratic, &sphere, NULL);
    FreeMemory();

    //load the data into 
    sphere->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh);
    sphere->Release();
    delete[] adj;
}
开发者ID:kbinani,项目名称:dxrip,代码行数:18,代码来源:D3D9Mesh.cpp

示例9: Lock

void D3D9Mesh::SimplifyToVertices(UINT Count)
{
    Lock();
    Unlock();

    DWORD *Adj;
    Clean(1e-6f, Adj);

    LPD3DXMESH NewMesh = NULL;
    D3DAlwaysValidate(D3DXSimplifyMesh(_Mesh, Adj, NULL, NULL, Count, D3DXMESHSIMP_VERTEX, &NewMesh), "D3DXSimplifyMesh");
    _Mesh->Release();
    D3DAlwaysValidate(NewMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh), "CloneMeshFVF");
    NewMesh->Release();
    delete[] Adj;

    Lock();
    Unlock();
}
开发者ID:kbinani,项目名称:dxrip,代码行数:18,代码来源:D3D9Mesh.cpp

示例10: Assert

void D3D9Mesh::Clean(float Epsilon, DWORD* &AdjDataOut)
{
    Assert(_Mesh != NULL, "Clean called on empty _Mesh.");

    LPD3DXMESH NewMesh;
    DWORD *AdjData = new DWORD[3 * _Mesh->GetNumFaces()];
    AdjDataOut = new DWORD[3 * _Mesh->GetNumFaces()];
    DWORD *FaceRemap = new DWORD[3 * _Mesh->GetNumFaces()];

    /*D3DXWELDEPSILONS Eps;
    Eps.Position = Epsilon;
    Eps.BlendWeights = 1.0f;
    Eps.Normal = 1.0f;
    Eps.PSize = 1.0f;
    Eps.Specular = 1.0f;
    Eps.Diffuse = 1.0f;
    Eps.Tangent = 1.0f;
    Eps.Binormal = 1.0f;
    Eps.TessFactor = 1.0f;
    for(UINT _Indices = 0; _Indices < 8; _Indices++)
    {
        Eps.Texcoord[_Indices] = 1.0f;
    }*/

    CleanVerticesAndTriangles();
    Unlock();
    //D3DAlwaysValidate(_Mesh->GenerateAdjacency(Epsilon, AdjDataOut));
    //D3DAlwaysValidate(D3DXWeldVertices(_Mesh, D3DXWELDEPSILONS_WELDPARTIALMATCHES, &Eps, AdjDataOut, AdjData, FaceRemap, NULL));
    //D3DAlwaysValidate(D3DXWeldVertices(_Mesh, D3DXWELDEPSILONS_WELDALL | D3DXWELDEPSILONS_WELDPARTIALMATCHES, NULL, AdjDataOut, AdjData, FaceRemap, NULL));
    //CleanTriangles();
    D3DAlwaysValidate(_Mesh->GenerateAdjacency(Epsilon, AdjData), "GenerateAdjacency");
    D3DAlwaysValidate(D3DXCleanMesh(D3DXCLEAN_SIMPLIFICATION, _Mesh, AdjData, &NewMesh, AdjDataOut, NULL), "D3DXCleanMesh");
    _Mesh->Release();
    D3DAlwaysValidate(NewMesh->CloneMeshFVF(D3DMeshOptions, D3DMeshFVF, GetD3DDevice(), &_Mesh), "CloneMeshFVF");
    NewMesh->Release();

    Lock();
    Unlock();

    delete[] AdjData;
    delete[] FaceRemap;
}
开发者ID:kbinani,项目名称:dxrip,代码行数:42,代码来源:D3D9Mesh.cpp

示例11: D3DXMeshClone

HRESULT D3DXMeshClone(LPD3DXMESH pSrc, LPD3DXMESH* pCloned)
{
	LPD3DXMESH pMeshCloned = NULL;
	DWORD dwOption = pSrc->GetOptions();
	DWORD fvf = pSrc->GetFVF();
	LPDIRECT3DDEVICE9 pDevice = NULL;
	KG_PROCESS_ERROR(NULL != pSrc && NULL != pCloned);
	{
		HRESULT hr = pSrc->GetDevice(&pDevice);
		KG_COM_PROCESS_ERROR(hr);

		hr = pSrc->CloneMeshFVF(dwOption, fvf, pDevice, &pMeshCloned);
		SAFE_RELEASE(pDevice);

		*pCloned = pMeshCloned;
		
		SAFE_RELEASE(pDevice);
		return S_OK;
	}	
Exit0:
	SAFE_RELEASE(pMeshCloned);
	SAFE_RELEASE(pDevice);
	return E_FAIL;
}
开发者ID:1suming,项目名称:pap2,代码行数:24,代码来源:KG3DMeshHelpers.cpp

示例12: CreateMeshContainer

HRESULT AllocateHierarchy::CreateMeshContainer(
	LPCSTR Name,
	CONST D3DXMESHDATA *pMeshData,
	CONST D3DXMATERIAL *pMaterials,
	CONST D3DXEFFECTINSTANCE *pEffectInstances,
	DWORD NumMaterials,
	CONST DWORD *pAdjacency,
	LPD3DXSKININFO pSkinInfo,
	LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
    HRESULT hr;
    D3DXMESHCONTAINER_DERIVED *pMeshContainer = NULL;
    UINT NumFaces;
    UINT iMaterial;
    UINT iBone, cBones;
    LPDIRECT3DDEVICE9 pd3dDevice = NULL;

    LPD3DXMESH pMesh = NULL;

    *ppNewMeshContainer = NULL;

    // this sample does not handle patch meshes, so fail when one is found
    if (pMeshData->Type != D3DXMESHTYPE_MESH)
    {
        hr = E_FAIL;
        goto e_Exit;
    }

    // get the pMesh interface pointer out of the mesh data structure
    pMesh = pMeshData->pMesh;

    // this sample does not FVF compatible meshes, so fail when one is found
    if (pMesh->GetFVF() == 0)
    {
        hr = E_FAIL;
        goto e_Exit;
    }

    // allocate the overloaded structure to return as a D3DXMESHCONTAINER
    pMeshContainer = new D3DXMESHCONTAINER_DERIVED;
    if (pMeshContainer == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto e_Exit;
    }
    memset(pMeshContainer, 0, sizeof(D3DXMESHCONTAINER_DERIVED));

    // make sure and copy the name.  All memory as input belongs to caller, interfaces can be addref'd though
    hr = AllocateName(Name, &pMeshContainer->Name);
    if (FAILED(hr))
        goto e_Exit;        

    pMesh->GetDevice(&pd3dDevice);
    NumFaces = pMesh->GetNumFaces();

    // if no normals are in the mesh, add them
    if (!(pMesh->GetFVF() & D3DFVF_NORMAL))
    {
        pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;

        // clone the mesh to make room for the normals
        hr = pMesh->CloneMeshFVF( pMesh->GetOptions(), 
                                    pMesh->GetFVF() | D3DFVF_NORMAL, 
                                    pd3dDevice, &pMeshContainer->MeshData.pMesh );
        if (FAILED(hr))
            goto e_Exit;

        // get the new pMesh pointer back out of the mesh container to use
        // NOTE: we do not release pMesh because we do not have a reference to it yet
        pMesh = pMeshContainer->MeshData.pMesh;

        // now generate the normals for the pmesh
        D3DXComputeNormals( pMesh, NULL );
    }
    else  // if no normals, just add a reference to the mesh for the mesh container
    {
        pMeshContainer->MeshData.pMesh = pMesh;
        pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;

        pMesh->AddRef();
    }
        
    // allocate memory to contain the material information.  This sample uses
    //   the D3D9 materials and texture names instead of the EffectInstance style materials
    pMeshContainer->NumMaterials = max(1, NumMaterials);
    pMeshContainer->pMaterials = new D3DXMATERIAL[pMeshContainer->NumMaterials];
    pMeshContainer->ppTextures = new LPDIRECT3DTEXTURE9[pMeshContainer->NumMaterials];
    pMeshContainer->pAdjacency = new DWORD[NumFaces*3];
    if ((pMeshContainer->pAdjacency == NULL) || (pMeshContainer->pMaterials == NULL))
    {
        hr = E_OUTOFMEMORY;
        goto e_Exit;
    }

    memcpy(pMeshContainer->pAdjacency, pAdjacency, sizeof(DWORD) * NumFaces*3);
    memset(pMeshContainer->ppTextures, 0, sizeof(LPDIRECT3DTEXTURE9) * pMeshContainer->NumMaterials);

    // if materials provided, copy them
    if (NumMaterials > 0)            
    {
//.........这里部分代码省略.........
开发者ID:wenqvip,项目名称:MoonGame,代码行数:101,代码来源:MoonSkinmesh.cpp

示例13: checkPick

//------------------------------------------------------------------------------
//this is a check function
//------------------------------------------------------------------------------
void TriPickDemo::checkPick(LPD3DXMESH mesh, D3DXMATRIX matWorld)
{
	HRESULT hr;

	D3DXMATRIX mWorldViewProjection;
	mWorldViewProjection = matWorld * g_Camera->viewProj();

	HR(m_FX->SetTechnique("RenderScene"));

	// send matrix to shader
	HR(m_FX->SetMatrix("g_mWorldViewProjection", &mWorldViewProjection));
	HR(m_FX->SetMatrix("g_mWorld", &matWorld));
	UINT uPasses;
	V(m_FX->Begin(&uPasses, 0));

	g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);

	V(m_FX->BeginPass(0));
	//get select ray
	D3DXVECTOR3 originW(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 dirW(0.0f, 0.0f, 0.0f);
	if (gDInput->mouseButtonDown(0))
	{
		getWorldPickingRay(originW, dirW, matWorld);
		LPD3DXMESH pMesh;

		mesh->CloneMeshFVF(D3DXMESH_MANAGED, D3DVERTEX::FVF, g_pDevice, &pMesh);
		BOOL hit = 0;
		DWORD faceIndex = -1;
		float u = 0.0f;
		float v = 0.0f;
		float dist = 0.0f;
		ID3DXBuffer* allhits = 0;
		DWORD numHits = 0;
		HR(D3DXIntersect(pMesh, &originW, &dirW, &hit,
			&faceIndex, &u, &v, &dist, &allhits, &numHits));
		SAFE_RELEASE(allhits);
		//if hit
		if (hit)
		{
			IDirect3DVertexBuffer9* vb = 0;
			IDirect3DIndexBuffer9* ib = 0;
			HR(pMesh->GetVertexBuffer(&vb));
			HR(pMesh->GetIndexBuffer(&ib));

			HR(g_pDevice->SetIndices(ib));
			HR(g_pDevice->SetFVF(D3DVERTEX::FVF));
			HR(g_pDevice->SetStreamSource(0, vb, 0, sizeof(D3DVERTEX)));

			//render hit surface
			HR(g_pDevice->DrawIndexedPrimitive(
				D3DPT_TRIANGLELIST, 0, 0, pMesh->GetNumVertices(), faceIndex * 3, 1))

				g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
			SAFE_RELEASE(vb);
			SAFE_RELEASE(ib);
			SAFE_RELEASE(pMesh);
		}
	}

	HR(m_FX->EndPass());
	HR(m_FX->End());
}
开发者ID:duoshengyu,项目名称:InverseIK,代码行数:66,代码来源:MyApp.cpp

示例14: InitDeviceObjects


//.........这里部分代码省略.........
        m_mtrlMeshMaterials[i] = d3dxMaterials[i].MatD3D;
        m_mtrlMeshMaterials[i].Ambient = m_mtrlMeshMaterials[i].Diffuse;

        // Find the path to the texture and create that texture
        DXUtil_FindMediaFileCb( strMediaPath, sizeof(strMediaPath), d3dxMaterials[i].pTextureFilename );
        if( FAILED( D3DXCreateTextureFromFile( m_pd3dDevice, strMediaPath, 
                                               &m_pMeshTextures[i] ) ) )
            m_pMeshTextures[i] = NULL;
    }
    pD3DXMtrlBuffer->Release();
    pD3DXMtrlBuffer = NULL;


    // Lock the vertex buffer, to generate a simple bounding sphere
    hr = pMesh->GetVertexBuffer( &pVertexBuffer );
    if( FAILED(hr) )
        goto End;

    hr = pVertexBuffer->Lock( 0, 0, &pVertices, D3DLOCK_NOSYSLOCK );
    if( FAILED(hr) )
        goto End;

    hr = D3DXComputeBoundingSphere( (D3DXVECTOR3*)pVertices, pMesh->GetNumVertices(),
                                    D3DXGetFVFVertexSize(pMesh->GetFVF()),
                                    &m_vObjectCenter, &m_fObjectRadius );
    pVertexBuffer->Unlock();
    pVertexBuffer->Release();

    if( FAILED(hr) || m_dwNumMaterials == 0 )
        goto End;

    if ( !(pMesh->GetFVF() & D3DFVF_NORMAL) )
    {
        hr = pMesh->CloneMeshFVF( dw32BitFlag|D3DXMESH_MANAGED, pMesh->GetFVF() | D3DFVF_NORMAL, 
                                            m_pd3dDevice, &pTempMesh );
        if (FAILED(hr))
            goto End;

        D3DXComputeNormals( pTempMesh, NULL );

        pMesh->Release();
        pMesh = pTempMesh;
    }

    hr = D3DXGeneratePMesh( pMesh, (DWORD*)pAdjacencyBuffer->GetBufferPointer(),
                            NULL, NULL, 1, D3DXMESHSIMP_VERTEX, &pPMesh);
    if( FAILED(hr) )
        goto End;

    cVerticesMin = pPMesh->GetMinVertices();
    cVerticesMax = pPMesh->GetMaxVertices();

    cVerticesPerMesh = (cVerticesMax - cVerticesMin) / 10;

    m_cPMeshes = max(1, (DWORD)ceil((cVerticesMax - cVerticesMin) / (float)cVerticesPerMesh));
    m_pPMeshes = new LPD3DXPMESH[m_cPMeshes];
    if (m_pPMeshes == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto End;
    }
    memset(m_pPMeshes, 0, sizeof(LPD3DXPMESH) * m_cPMeshes);

    // clone full size pmesh
    hr = pPMesh->ClonePMeshFVF( D3DXMESH_MANAGED | D3DXMESH_VB_SHARE, pPMesh->GetFVF(), m_pd3dDevice, &m_pPMeshFull );
    if (FAILED(hr))
开发者ID:agmonr,项目名称:Emotion_for_windows,代码行数:67,代码来源:Mesh.cpp

示例15: CreateMeshContainer

//メッシュコンテナの生成
HRESULT Dx_Hierarchy::CreateMeshContainer(
	LPCTSTR Name,
	CONST D3DXMESHDATA *pMeshData,
	CONST D3DXMATERIAL *pMaterials,
	CONST D3DXEFFECTINSTANCE *pEffectInstances,
	DWORD NumMaterials, 
	CONST DWORD *pAdjacency,
	LPD3DXSKININFO pSkinInfo, 
	LPD3DXMESHCONTAINER *ppMeshContainer )
{
	HRESULT hr = S_OK;
	//生成用オブジェクトの宣言
	DxMeshContainer *pMeshContainer = NULL;
	//生成したオブジェクトの登録先を初期化
	*ppMeshContainer = NULL;

	int iFacesAmount;
	unsigned iMaterial;
	LPDIRECT3DDEVICE9 pDevice = NULL;
	LPD3DXMESH pMesh = NULL;

	// patch meshes を扱う事はできない
	//if( pMeshData->Type != D3DXMESHTYPE_MESH ) return E_FAIL;

	// FVF で記述されたメッシュ以外は読めない
	//if( pMesh->GetFVF() == 0 ) return E_FAIL;

	//DWORD					dwBoneAmt=0;

	//メッシュデータの持つメッシュポインタを取得
	pMesh = pMeshData->pMesh;

	//オブジェクトの生成
	pMeshContainer = new DxMeshContainer;
	//変数がNULLだった場合
    if (pMeshContainer == NULL)
	{
		//エラーの意味 : Direct3D が呼び出しを完了するための十分なメモリを割り当てることができませんでした。
		return E_OUTOFMEMORY;
	}
	//
	ZeroMemory(pMeshContainer, sizeof(DxMeshContainer));

	//メッシュコンテナ名の領域確保
	pMeshContainer->Name=new TCHAR[lstrlen(Name) + 1];
	//領域が確保されなかった場合
    if (!pMeshContainer->Name)
	{
		//エラーの意味 : Direct3D サブシステム内で原因不明のエラーが発生しました。
		return E_FAIL;
	}
	//名前をコピーする
	strcpy(pMeshContainer->Name,Name);

	//メッシュに関連付けられているデバイスを取得
	if(FAILED(pMesh->GetDevice(&pDevice)))
	{
		/*hr = E_FAIL;
		SAFE_RELEASE( pDevice );
		if( pMeshContainer ) DestroyMeshContainer( pMeshContainer );
		return hr;*/
	}

	//メッシュに含まれる面の数を取得
	iFacesAmount = pMesh->GetNumFaces();

    // 当該メッシュが法線を持たない場合は法線を追加する
    if (!(pMesh->GetFVF() & D3DFVF_NORMAL)) {
		//メッシュデータの種類を「メッシュ」に変更
        pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
		//FVFコードを使ってメッシュのコピーを生成
        hr = pMesh->CloneMeshFVF( pMesh->GetOptions(), 
                                    pMesh->GetFVF() | D3DFVF_NORMAL, 
                                    pDevice, &pMeshContainer->MeshData.pMesh );
		//処理が失敗した場合
        if (FAILED(hr))
		{
			//エラーの意味 : Direct3D サブシステム内で原因不明のエラーが発生しました。
			return E_FAIL;
		}

        pMesh = pMeshContainer->MeshData.pMesh;
		//pMeshに含まれる各頂点の法線を計算して出力
        D3DXComputeNormals( pMesh, NULL );

    } else{
		//メッシュコンテナ内のメッシュデータにメッシュポインタを設定
        pMeshContainer->MeshData.pMesh = pMesh;
		//メッシュデータの種類を「メッシュ」に設定
        pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
		//???
        pMesh->AddRef();
    }

	//メッシュのマテリアル設定
	//マテリアル数を設定
    pMeshContainer->NumMaterials	= max(1, NumMaterials);
	//マテリアルの数だけマテリアルの領域を確保
    pMeshContainer->pMaterials		= new D3DXMATERIAL[pMeshContainer->NumMaterials];
//.........这里部分代码省略.........
开发者ID:boxp,项目名称:Pendulum,代码行数:101,代码来源:dx_anime_mesh.cpp


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