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


C++ SMesh::AddMeshBuffer方法代码示例

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


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

示例1: CreateMesh

//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IUnknown::drop() for more information.
SMesh* MDLFileLoader::CreateMesh(FileReader* file)
{
	studiohdr_t* pMDLFile = (studiohdr_t*)new byte[file->GetSize()];
	g_pActiveStudioHdr = pMDLFile;
	file->Read(pMDLFile, file->GetSize());
	mstudiobodyparts_t* pBodyparts = pMDLFile->pBodypart(0);
	mstudiomodel_t* pModel = pBodyparts->pModel(0);
	const mstudio_modelvertexdata_t* pVertexdata = pModel->GetVertexData();

	stringc vtxFile = file->GetFileName();
	vtxFile = vtxFile.subString(0, vtxFile.findLast('.') + 1);
	vtxFile += "dx90.vtx";
	file = m_pFileSystem->CreateAndOpenFile(vtxFile.c_str());

	FileHeader_t* pVtxFile = (FileHeader_t*)new byte[file->GetSize()];
	file->Read(pVtxFile, file->GetSize());
	BodyPartHeader_t* pBodypart = pVtxFile->pBodyPart(0);
	ModelHeader_t* pVtxModel = pBodypart->pModel(0);
	ModelLODHeader_t* pLod = pVtxModel->pLOD(0);

	SMesh* pPirateMesh = new SMesh();
	IDirect3DVertexBuffer9* pVertexBuffer = NULL;

	for (int i=0; i<pLod->numMeshes; i++)
	{
		MeshHeader_t* pMesh = pLod->pMesh(i);
		StripGroupHeader_t* pStripGroup = pMesh->pStripGroup(0);
//		StripHeader_t* pStrip = pStripGroup->pStrip(0);

		SD3D9MeshBuffer* pMeshBuffer = new SD3D9MeshBuffer(m_pDriver, MdlVertexDecl);
		if (i==0)
		{
			pMeshBuffer->CreateVertexBuffer(0, sizeof(MDL_VT), pModel->numvertices, D3DUSAGE_WRITEONLY);
			pVertexBuffer = pMeshBuffer->GetVertexBuffer(0);
			MDL_VT* pVert = NULL;

			pVertexBuffer->Lock(0, 0, (void**)&pVert, 0);
			for (int j=0; j<pModel->numvertices; j++)
			{
				const Vector* p = pVertexdata->Position(j);
				const Vector* n = pVertexdata->Normal(j);
				const Vector2D* t = pVertexdata->Texcoord(j);
				pVert[j].Position[0] = p->x; pVert[j].Position[1] = p->y; pVert[j].Position[2] = p->z;
				pVert[j].Normal[0] = n->x; pVert[j].Normal[1] = n->y; pVert[j].Normal[2] = n->z;
				pVert[j].Texcoord[0] = t->x; pVert[j].Texcoord[1] = t->y;
			}
			pVertexBuffer->Unlock();
		}
		else
		{
			pMeshBuffer->SetVertexBuffer(0, pModel->numvertices, pVertexBuffer);
		}

		mstudiomesh_t* pStudioMesh = pModel->pMesh(i);

		pMeshBuffer->CreateIndexBuffer(pStripGroup->numIndices, D3DUSAGE_WRITEONLY, TRUE);
		u16* pIndices = NULL;

		pMeshBuffer->GetIndexBuffer()->Lock(0, 0, (void**)&pIndices, 0);
		for (int j=0; j<pStripGroup->numIndices; j++)
		{
			pIndices[j] = pStripGroup->pVertex(*(pStripGroup->pIndex(j)))->origMeshVertID + pStudioMesh->vertexoffset;
		}
		pMeshBuffer->GetIndexBuffer()->Unlock();


		mstudiotexture_t* pTexture =  pMDLFile->pTexture(i);
		stringc textureName = file->GetFileName();
		textureName = textureName.subString(0, textureName.findLast('/') + 1);
		textureName = textureName + pTexture->pszName() + ".tga";
		D3D9Texture* pD3DTexture = m_pDriver->GetTexture(textureName.c_str());
		pMeshBuffer->m_Material.Textures[0] = pD3DTexture;

		pPirateMesh->AddMeshBuffer(pMeshBuffer);
		pMeshBuffer->Drop();
	}

	delete[] pVtxFile;
	if (pMDLFile->pVertexBase)
		delete pMDLFile->pVertexBase;
	delete[] pMDLFile;

	file->Drop();

	return pPirateMesh;
}
开发者ID:zheka20012,项目名称:pirate3d,代码行数:90,代码来源:MDLFileLoader.cpp


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