Esempio n. 1
0
/*********************************************************************************
  *Function:  operator=(const VMesh& fromMesh)
  *Description: 重载操作符operator =
  *Input:  fromMesh-源网格
  *Return: 拷贝后的网格 
              *CREATED BY:  [7/30/2015 niewenchao]
**********************************************************************************/
VMesh& VMesh::operator=(const VMesh& fromMesh)
{
	CopyVerts(fromMesh);														//拷贝顶点
	CopyFaces(fromMesh);														//拷贝面片
	CopyVertColors(fromMesh);
	return (*this);
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
// Computes LOD vertices for a model piece.
//-----------------------------------------------------------------------------
static void UnifyModelLODs( s_model_t *pSrcModel )
{
	CUtlVector<s_source_t *> lods;
	int nNumLODs = g_ScriptLODs.Count();
	lods.AddMultipleToTail( nNumLODs );
	
	if( Q_stricmp( pSrcModel->name, "blank" ) == 0 )
		return;
	
	// lod source are not gauranteed to be unique
	// an lod's source may be the same source at multiple lods
	// and therefore shared
	GetLODSources( lods, pSrcModel );
	
	// each lod has a unique vertex mapping table
	int nLodID;
	int *pMeshVertIndexMaps[MAX_NUM_LODS];
	for ( nLodID = 0; nLodID < MAX_NUM_LODS; nLodID++ )
	{
		if ( nLodID < nNumLODs && lods[nLodID] )
		{
			pMeshVertIndexMaps[nLodID] = new int[lods[nLodID]->numvertices];
#ifdef _DEBUG
			memset( pMeshVertIndexMaps[nLodID], 0xDD, lods[nLodID]->numvertices * sizeof(int) );
#endif
		}
		else
		{
			pMeshVertIndexMaps[nLodID] = NULL;
		}
	}

	// These hold the aggregate data for the model that grows as lods are processed
	CVertexDictionary vertexDictionary;
	CUtlVector<s_face_t> faces;
	CUtlVector<s_mesh_t> meshes;
	
	meshes.AddMultipleToTail( MAXSTUDIOSKINS );
	Assert( meshes.Count() == MAXSTUDIOSKINS );
	memset( meshes.Base(), 0, meshes.Count() * sizeof( s_mesh_t ) );

	int nMeshID;
	for( nMeshID = 0; nMeshID < pSrcModel->source->nummeshes; nMeshID++ )
	{
		s_mesh_t *pVertexDictMesh = &meshes[pSrcModel->source->meshindex[nMeshID]];
		
		pVertexDictMesh->numvertices = 0;
		pVertexDictMesh->vertexoffset = vertexDictionary.VertexCount();
		pVertexDictMesh->numfaces = 0;
		pVertexDictMesh->faceoffset = faces.Count();
		
		// First build up information for LOD 0
		if ( !lods[0] )
			continue;

		// lookup the material used by this mesh
		int nMaterialID = lods[0]->meshindex[nMeshID];
		s_mesh_t *pLOD0Mesh = FindMeshByMaterial( lods[0], nMaterialID );
		if ( !pLOD0Mesh )
			continue;

		// populate with all vertices from LOD 0
		int nStart = vertexDictionary.VertexCount();
		CopyVerts( 0, lods[0], pLOD0Mesh, vertexDictionary, pVertexDictMesh, pMeshVertIndexMaps[0] );
		vertexDictionary.SetRootVertexRange( nStart, vertexDictionary.VertexCount() );
	
		MarkRootLODBones( vertexDictionary );

		// only fix up the faces for the highest lod since the lowest ones are going
		// to be reprocessed later.
		CopyFaces( lods[0], pLOD0Mesh, faces, pVertexDictMesh );

		// Now, for each LOD, try to build meshes using the vertices in LOD 0.
		// Ideally, vertices used in an LOD would be in LOD 0 for the benefit of shared vertices.
		// If we don't find vertices in LOD 0, this code will add vertices into LOD 0's list
		// of vertices for the next LOD to find
		for ( nLodID = 1; nLodID < nNumLODs; ++nLodID )
		{
			s_source_t *pCurrLOD = lods[nLodID];
			if ( !pCurrLOD )
				continue;

			// Find the mesh that matches the material
			// mesh may not be present or could be culled due to $removemesh commands
			s_mesh_t *pCurrLODMesh = FindOrCullMesh( nLodID, pCurrLOD, nMaterialID );
			if ( !pCurrLODMesh )
				continue;

			CreateLODVertsInDictionary( nLodID, lods[0], pCurrLOD, pCurrLODMesh, pVertexDictMesh, vertexDictionary, pMeshVertIndexMaps[nLodID]);
		}
	}

#ifdef _DEBUG
	Msg( "Total vertex count: %d\n", vertexDictionary.VertexCount() );
#endif

	// save the data we just built into the processed data section
	// The processed data has all of the verts that are needed for all LODs.
	SetProcessedWithDictionary( lods, vertexDictionary, faces, meshes, pMeshVertIndexMaps );
//	PrintSourceVerts( lods[0] );
}
Esempio n. 3
0
/*********************************************************************************
  *Function:  VMesh(const VMesh& fromMesh)
  *Description: 拷贝构造函数
  *Input:  原网格
  *Return: 无 
              *CREATED BY:  [7/30/2015 niewenchao]
**********************************************************************************/
VMesh::VMesh(const VMesh& fromMesh)
{
	CopyVerts(fromMesh);														//拷贝顶点
	CopyVertColors(fromMesh);														//拷贝顶点颜色
	CopyFaces(fromMesh);														//拷贝面片
}