void MeshTopoData::SetCache(MNMesh &mesh, int mapChannel)
{
	FreeCache();
	this->mnMesh = new MNMesh(mesh);


	TVMaps.channel = mapChannel;

	BitArray s;
	mesh.getFaceSel(s);
	mesh.getFaceSel(mFSelPrevious);

	if ( (mesh.selLevel==MNM_SL_FACE) && (s == 0) ) 
	{
		TVMaps.SetCountFaces(0);
		TVMaps.v.SetCount(0);
		TVMaps.FreeEdges();
		TVMaps.FreeGeomEdges();
		mVSel.SetSize(0);
		mESel.SetSize(0);
		mFSel.SetSize(0);
		mGESel.SetSize(0);
		mGVSel.SetSize(0);
		return;
	}


	//get from mesh based on cahne
	int numMaps = mesh.MNum ();
	MNMapFace *tvFace=NULL;
	Point3 *tVerts = NULL;
	if (mapChannel >= numMaps) 
	{
	}
	else
	{
		tvFace = mesh.M(mapChannel)->f;
		tVerts = mesh.M(mapChannel)->v;
	}

	if (mesh.selLevel!=MNM_SL_FACE) 
	{
		//copy into our structs
		TVMaps.SetCountFaces(mesh.FNum());
		if (tVerts)
		{
			TVMaps.v.SetCount(mesh.M(mapChannel)->VNum());
			mVSel.SetSize(mesh.M(mapChannel)->VNum());
		}
		else
		{
			TVMaps.v.SetCount(mesh.VNum());
			mVSel.SetSize(mesh.VNum());
		}


		TVMaps.geomPoints.SetCount(mesh.VNum());

		for (int j=0; j<TVMaps.f.Count(); j++) 
		{
			TVMaps.f[j]->flags = 0;
			int fct;
			fct = mesh.f[j].deg;

			if (mesh.f[j].GetFlag(MN_DEAD)) fct = 0;

			if (fct > 0)
			{
				TVMaps.f[j]->t = new int[fct];
				TVMaps.f[j]->v = new int[fct];
			}
			else
			{
				TVMaps.f[j]->t = NULL;
				TVMaps.f[j]->v = NULL;
			}

			if (tvFace == NULL)
			{
				for (int k=0; k < fct;k++)
					TVMaps.f[j]->t[k] = 0;
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.f[j].material;
				TVMaps.f[j]->flags = 0;
				TVMaps.f[j]->count = fct;
				for (int k = 0; k < fct; k++)
				{
					int index = mesh.f[j].vtx[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.v[index].p;
				}
			}
			else
			{
				for (int k=0; k < fct;k++)
					TVMaps.f[j]->t[k] = tvFace[j].tv[k];
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.f[j].material;


				TVMaps.f[j]->flags = 0;
				TVMaps.f[j]->count = fct;
				for (int k = 0; k < fct; k++)
				{
					int index = mesh.f[j].vtx[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.v[index].p;
				}


			}
		}
		for ( int j=0; j<TVMaps.v.Count(); j++) 
		{
			TVMaps.v[j].SetFlag(0);
			if (tVerts)
				TVMaps.v[j].SetP(tVerts[j]);
			else TVMaps.v[j].SetP(Point3(.0f,0.0f,0.0f));
			TVMaps.v[j].SetInfluence(0.0f);
			TVMaps.v[j].SetControlID(-1);
		}
		if (tvFace == NULL) BuildInitialMapping(&mesh);

		TVMaps.mSystemLockedFlag.SetSize(TVMaps.v.Count());
		TVMaps.mSystemLockedFlag.ClearAll();

	}
	else
	{
		//copy into our structs
		TVMaps.SetCountFaces(mesh.FNum());

		int tvVertCount = 0;
		if (mapChannel < numMaps) 
		{
			tvVertCount = mesh.M(mapChannel)->VNum();
		}

		TVMaps.v.SetCount(tvVertCount);

		mVSel.SetSize(tvVertCount);

		TVMaps.geomPoints.SetCount(mesh.VNum());

		BitArray bs;
		mesh.getFaceSel(bs);

		for (int j=0; j<TVMaps.f.Count(); j++) 
		{
			TVMaps.f[j]->flags = 0;

			int fct;
			fct = mesh.f[j].deg;

			if (mesh.f[j].GetFlag(MN_DEAD)) fct = 0;


			if (fct > 0)
			{			
				TVMaps.f[j]->t = new int[fct];
				TVMaps.f[j]->v = new int[fct];
			}
			else
			{
				TVMaps.f[j]->t = NULL;
				TVMaps.f[j]->v = NULL;
			}

			if (tvFace == NULL)
			{
				for (int k=0; k < fct;k++)
					TVMaps.f[j]->t[k] = 0;
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.f[j].material;
				TVMaps.f[j]->count = fct;
				if (bs[j])
					TVMaps.f[j]->flags = 0;
				else TVMaps.f[j]->flags = FLAG_DEAD;
				for (int k = 0; k < fct; k++)
				{
					int index = mesh.f[j].vtx[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.v[index].p;
				}
			}
			else
			{
				for (int k=0; k < fct;k++)
					TVMaps.f[j]->t[k] = tvFace[j].tv[k];
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.f[j].material;
				TVMaps.f[j]->count = fct;
				if (bs[j])
					TVMaps.f[j]->flags = 0;
				else TVMaps.f[j]->flags = FLAG_DEAD;
				for ( int k = 0; k < fct; k++)
				{
					int index = mesh.f[j].vtx[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.v[index].p;
				}

			}
		}



		for (int j=0; j<TVMaps.v.Count(); j++) 
		{
			if (tVerts)
				TVMaps.v[j].SetP(tVerts[j]);
			else TVMaps.v[j].SetP(Point3(0.0f,0.0f,0.0f));
			//check if vertex for this face selected
			TVMaps.v[j].SetInfluence(0.0f);
			TVMaps.v[j].SetControlID(-1);

		}
		if (tvFace == NULL) BuildInitialMapping(&mesh);

		TVMaps.mSystemLockedFlag.SetSize(TVMaps.v.Count());
		TVMaps.mSystemLockedFlag.SetAll();

		for (int j=0; j<TVMaps.f.Count(); j++) 
		{
			if (!(TVMaps.f[j]->flags & FLAG_DEAD))
			{
				int a;
				for (int k =0 ; k < TVMaps.f[j]->count;k++)
				{
					a = TVMaps.f[j]->t[k];
					TVMaps.v[a].SetFlag(0);
					TVMaps.mSystemLockedFlag.Set(a,FALSE);
				}
			}
		}
	}
}
void MeshTopoData::SetCache(PatchMesh &patch, int mapChannel)
{
	FreeCache();
	this->patch = new PatchMesh(patch);
	//build TVMAP and edge data

	
	mFSelPrevious.SetSize(patch.patchSel.GetSize());
	mFSelPrevious = patch.patchSel;
	

	if ( (patch.selLevel==PATCH_PATCH) && (patch.patchSel.NumberSet() == 0) ) 
	{
		TVMaps.SetCountFaces(0);
		TVMaps.v.SetCount(0);
		TVMaps.FreeEdges();
		TVMaps.FreeGeomEdges();
		mVSel.SetSize(0);
		mESel.SetSize(0);
		mFSel.SetSize(0);
		mGESel.SetSize(0);
		mGVSel.SetSize(0);
		return;
	}


	//loop through all maps
	//get channel from mesh
	TVMaps.channel = mapChannel;


	//get from mesh based on cahne
	PatchTVert *tVerts = NULL;
	TVPatch *tvFace = NULL;
	if (!patch.getMapSupport(mapChannel))
	{
		patch.setNumMaps(mapChannel+1);
	}

	tVerts = patch.tVerts[mapChannel];
	tvFace = patch.tvPatches[mapChannel];




	if (patch.selLevel!=PATCH_PATCH ) 
	{
		//copy into our structs
		TVMaps.SetCountFaces(patch.getNumPatches());
		TVMaps.v.SetCount(patch.getNumMapVerts(mapChannel));

		mVSel.SetSize(patch.getNumMapVerts (mapChannel));

		TVMaps.geomPoints.SetCount(patch.getNumVerts()+patch.getNumVecs());

		for (int j=0; j<TVMaps.f.Count(); j++) 
		{
			TVMaps.f[j]->flags = 0;


			int pcount = 3;
			if (patch.patches[j].type == PATCH_QUAD) 
			{
				pcount = 4;
			}

			TVMaps.f[j]->t = new int[pcount];
			TVMaps.f[j]->v = new int[pcount];


			if (tvFace == NULL)
			{
				TVMaps.f[j]->t[0] = 0;
				TVMaps.f[j]->t[1] = 0;
				TVMaps.f[j]->t[2] = 0;
				if (pcount ==4) TVMaps.f[j]->t[3] = 0;
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = patch.getPatchMtlIndex(j);
				TVMaps.f[j]->flags = 0;
				TVMaps.f[j]->count = pcount;

				TVMaps.f[j]->vecs = NULL;
				UVW_TVVectorClass *tempv = NULL;
				//new an instance
				if (!(patch.patches[j].flags & PATCH_AUTO))
					TVMaps.f[j]->flags |= FLAG_INTERIOR;

				if (!(patch.patches[j].flags & PATCH_LINEARMAPPING))
				{
					tempv = new UVW_TVVectorClass();
					TVMaps.f[j]->flags |= FLAG_CURVEDMAPPING;
				}
				TVMaps.f[j]->vecs = tempv;	 

				for (int k = 0; k < pcount; k++)
				{
					int index = patch.patches[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = patch.verts[index].p;
					//do handles and interiors
					//check if linear
					if (!(patch.patches[j].flags & PATCH_LINEARMAPPING))
					{
						//do geometric points
						index = patch.patches[j].interior[k];
						TVMaps.f[j]->vecs->vinteriors[k] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2];
						TVMaps.f[j]->vecs->vhandles[k*2] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2+1];
						TVMaps.f[j]->vecs->vhandles[k*2+1] =patch.getNumVerts()+index;
						// do texture points do't need to since they don't exist in this case

						TVMaps.f[j]->vecs->interiors[k] =0;								
						TVMaps.f[j]->vecs->handles[k*2] =0;
						TVMaps.f[j]->vecs->handles[k*2+1] =0;

					}

				}

			}
			else
			{
				TVMaps.f[j]->t[0] = tvFace[j].tv[0];
				TVMaps.f[j]->t[1] = tvFace[j].tv[1];
				TVMaps.f[j]->t[2] = tvFace[j].tv[2];
				if (pcount ==4) TVMaps.f[j]->t[3] = tvFace[j].tv[3];
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = patch.getPatchMtlIndex(j);

				TVMaps.f[j]->flags = 0;
				TVMaps.f[j]->count = pcount;


				TVMaps.f[j]->vecs = NULL;
				UVW_TVVectorClass *tempv = NULL;

				if (!(patch.patches[j].flags & PATCH_AUTO))
					TVMaps.f[j]->flags |= FLAG_INTERIOR;
				//new an instance
				if (!(patch.patches[j].flags & PATCH_LINEARMAPPING))
				{
					BOOL mapLinear = FALSE;		
					for (int tvCount = 0; tvCount < patch.patches[j].type*2; tvCount++)
					{
						if (tvFace[j].handles[tvCount] < 0) mapLinear = TRUE;
					}
					if (!(patch.patches[j].flags & PATCH_AUTO))
					{
						for (int tvCount = 0; tvCount < patch.patches[j].type; tvCount++)
						{
							if (tvFace[j].interiors[tvCount] < 0) mapLinear = TRUE;
						}
					}
					if (!mapLinear)
					{
						tempv = new UVW_TVVectorClass();
						TVMaps.f[j]->flags |= FLAG_CURVEDMAPPING;
					}
				}
				TVMaps.f[j]->vecs = tempv;	 


				if ((patch.selLevel==PATCH_PATCH ) && (patch.patchSel[j] == 0))
					TVMaps.f[j]->flags |= FLAG_DEAD;

				for (int k = 0; k < pcount; k++)
				{
					int index = patch.patches[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = patch.verts[index].p;
					//							TVMaps.f[j].pt[k] = patch.verts[index].p;
					//do handles and interiors
					//check if linear
					if (TVMaps.f[j]->flags & FLAG_CURVEDMAPPING)
					{
						//do geometric points
						index = patch.patches[j].interior[k];
						TVMaps.f[j]->vecs->vinteriors[k] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2];
						TVMaps.f[j]->vecs->vhandles[k*2] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2+1];
						TVMaps.f[j]->vecs->vhandles[k*2+1] =patch.getNumVerts()+index;
						// do texture points do't need to since they don't exist in this case
						if (TVMaps.f[j]->flags & FLAG_INTERIOR)
						{
							index = tvFace[j].interiors[k];
							TVMaps.f[j]->vecs->interiors[k] =index;
						}
						index = tvFace[j].handles[k*2];
						TVMaps.f[j]->vecs->handles[k*2] =index;
						index = tvFace[j].handles[k*2+1];
						TVMaps.f[j]->vecs->handles[k*2+1] =index;

					}

				}



			}

		}
		for (int geomvecs =0; geomvecs < patch.getNumVecs(); geomvecs++)
		{
			TVMaps.geomPoints[geomvecs+patch.getNumVerts()] = patch.vecs[geomvecs].p;
		}

		for ( int j=0; j<TVMaps.v.Count(); j++) 
		{
			TVMaps.v[j].SetFlag(0);
			if (tVerts)
				TVMaps.v[j].SetP(tVerts[j]);
			else TVMaps.v[j].SetP(Point3(0.0f,0.0f,0.0f));
			TVMaps.v[j].SetInfluence(0.0f);
			TVMaps.v[j].SetControlID(-1);
		}
		if (tvFace == NULL) BuildInitialMapping(&patch);

		TVMaps.mSystemLockedFlag.SetSize(TVMaps.v.Count());
		TVMaps.mSystemLockedFlag.ClearAll();


	}
	else
	{

		//copy into our structs
		TVMaps.SetCountFaces(patch.getNumPatches());

		TVMaps.v.SetCount(patch.getNumMapVerts (mapChannel));

		mVSel.SetSize(patch.getNumMapVerts (mapChannel));

		TVMaps.geomPoints.SetCount(patch.getNumVerts()+patch.getNumVecs());


		for (int j=0; j<TVMaps.f.Count(); j++) 
		{
			TVMaps.f[j]->flags = 0;

			int pcount = 3;

			if (patch.patches[j].type == PATCH_QUAD) 
			{
				pcount = 4;
			}

			TVMaps.f[j]->t = new int[pcount];
			TVMaps.f[j]->v = new int[pcount];

			if (tvFace == NULL)
			{
				TVMaps.f[j]->t[0] = 0;
				TVMaps.f[j]->t[1] = 0;
				TVMaps.f[j]->t[2] = 0;
				if (pcount == 4) TVMaps.f[j]->t[3] = 0;
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = patch.patches[j].getMatID();
				if (patch.patchSel[j])
					TVMaps.f[j]->flags = 0;
				else TVMaps.f[j]->flags = FLAG_DEAD;
				TVMaps.f[j]->count = pcount;

				TVMaps.f[j]->vecs = NULL;
				UVW_TVVectorClass *tempv = NULL;

				if (!(patch.patches[j].flags & PATCH_AUTO))
					TVMaps.f[j]->flags |= FLAG_INTERIOR;

				//new an instance
				if (!(patch.patches[j].flags & PATCH_LINEARMAPPING))
				{
					tempv = new UVW_TVVectorClass();
					TVMaps.f[j]->flags |= FLAG_CURVEDMAPPING;
				}
				TVMaps.f[j]->vecs = tempv;	 


				for (int k = 0; k < pcount; k++)
				{
					int index = patch.patches[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = patch.verts[index].p;
					//							TVMaps.f[j].pt[k] = patch.verts[index].p;
					//check if linear
					if (!(patch.patches[j].flags & PATCH_LINEARMAPPING))
					{
						//do geometric points
						index = patch.patches[j].interior[k];
						TVMaps.f[j]->vecs->vinteriors[k] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2];
						TVMaps.f[j]->vecs->vhandles[k*2] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2+1];
						TVMaps.f[j]->vecs->vhandles[k*2+1] =patch.getNumVerts()+index;
						// do texture points do't need to since they don't exist in this case

						TVMaps.f[j]->vecs->interiors[k] =0;								
						TVMaps.f[j]->vecs->handles[k*2] =0;
						TVMaps.f[j]->vecs->handles[k*2+1] =0;

					}

				}

			}
			else
			{
				TVMaps.f[j]->t[0] = tvFace[j].tv[0];
				TVMaps.f[j]->t[1] = tvFace[j].tv[1];
				TVMaps.f[j]->t[2] = tvFace[j].tv[2];
				if (pcount == 4) TVMaps.f[j]->t[3] = tvFace[j].tv[3];
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = patch.patches[j].getMatID();


				if (patch.patchSel[j])
					TVMaps.f[j]->flags = 0;
				else TVMaps.f[j]->flags = FLAG_DEAD;

				int pcount = 3;
				if (patch.patches[j].type == PATCH_QUAD) 
				{
					pcount = 4;
				}
				TVMaps.f[j]->count = pcount;

				TVMaps.f[j]->vecs = NULL;
				UVW_TVVectorClass *tempv = NULL;
				if (!(patch.patches[j].flags & PATCH_AUTO))
					TVMaps.f[j]->flags |= FLAG_INTERIOR;
				//new an instance
				if (!(patch.patches[j].flags & PATCH_LINEARMAPPING))
				{
					BOOL mapLinear = FALSE;		
					for (int tvCount = 0; tvCount < patch.patches[j].type*2; tvCount++)
					{
						if (tvFace[j].handles[tvCount] < 0) mapLinear = TRUE;
					}
					if (!(patch.patches[j].flags & PATCH_AUTO))
					{
						for (int tvCount = 0; tvCount < patch.patches[j].type; tvCount++)
						{
							if (tvFace[j].interiors[tvCount] < 0) mapLinear = TRUE;
						}
					}
					if (!mapLinear)
					{
						tempv = new UVW_TVVectorClass();
						TVMaps.f[j]->flags |= FLAG_CURVEDMAPPING;
					}
				}
				TVMaps.f[j]->vecs = tempv;	 


				for (int k = 0; k < pcount; k++)
				{
					int index = patch.patches[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = patch.verts[index].p;
					//							TVMaps.f[j].pt[k] = patch.verts[index].p;
					//do handles and interiors
					//check if linear
					if (TVMaps.f[j]->flags & FLAG_CURVEDMAPPING)
					{
						//do geometric points
						index = patch.patches[j].interior[k];
						TVMaps.f[j]->vecs->vinteriors[k] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2];
						TVMaps.f[j]->vecs->vhandles[k*2] =patch.getNumVerts()+index;
						index = patch.patches[j].vec[k*2+1];
						TVMaps.f[j]->vecs->vhandles[k*2+1] =patch.getNumVerts()+index;
						// do texture points do't need to since they don't exist in this case
						if (TVMaps.f[j]->flags & FLAG_INTERIOR)
						{
							index = tvFace[j].interiors[k];
							TVMaps.f[j]->vecs->interiors[k] =index;
						}
						index = tvFace[j].handles[k*2];
						TVMaps.f[j]->vecs->handles[k*2] =index;
						index = tvFace[j].handles[k*2+1];
						TVMaps.f[j]->vecs->handles[k*2+1] =index;

					}
				}

			}
		}
		for (int j =0; j < patch.getNumVecs(); j++)
		{
			TVMaps.geomPoints[j+patch.getNumVerts()] = patch.vecs[j].p;
		}



		for (int j=0; j<TVMaps.v.Count(); j++) 
		{
//			TVMaps.v[j].SystemLocked(TRUE);
			if (tVerts)
				TVMaps.v[j].SetP(tVerts[j]);
			else TVMaps.v[j].SetP(Point3(.0f,0.0f,0.0f));
			//check if vertex for this face selected
			TVMaps.v[j].SetInfluence(0.0f);
			TVMaps.v[j].SetControlID(-1);

		}


		if (tvFace == NULL) BuildInitialMapping(&patch);
		TVMaps.mSystemLockedFlag.SetSize(TVMaps.v.Count());
		TVMaps.mSystemLockedFlag.SetAll();

		for (int j=0; j<TVMaps.f.Count(); j++) 
		{
			if (!(TVMaps.f[j]->flags & FLAG_DEAD))
			{
				
				int a;
				a = TVMaps.f[j]->t[0];
				TVMaps.v[a].SetFlag(0);
				TVMaps.mSystemLockedFlag.Set(a,FALSE);
				a = TVMaps.f[j]->t[1];
				TVMaps.v[a].SetFlag(0);
				TVMaps.mSystemLockedFlag.Set(a,FALSE);
				a = TVMaps.f[j]->t[2];
				TVMaps.v[a].SetFlag(0);
				TVMaps.mSystemLockedFlag.Set(a,FALSE);

				if (TVMaps.f[j]->count > 3)
				{
					a = TVMaps.f[j]->t[3];
					TVMaps.v[a].SetFlag(0);
					TVMaps.mSystemLockedFlag.Set(a,FALSE);
				}
				if ( (TVMaps.f[j]->flags & FLAG_CURVEDMAPPING) && (TVMaps.f[j]->vecs))
				{
					for (int m =0; m < TVMaps.f[j]->count; m++) 
					{
						int hid = TVMaps.f[j]->vecs->handles[m*2];
						TVMaps.v[hid].SetFlag(0) ;
						TVMaps.mSystemLockedFlag.Set(hid,FALSE);

						hid = TVMaps.f[j]->vecs->handles[m*2+1];
						TVMaps.v[hid].SetFlag(0) ;
						TVMaps.mSystemLockedFlag.Set(hid,FALSE);
					}
					if (TVMaps.f[j]->flags & FLAG_INTERIOR) 
					{
						for (int m =0; m < TVMaps.f[j]->count; m++) 
						{
							int iid = TVMaps.f[j]->vecs->interiors[m];
							TVMaps.v[iid].SetFlag(0);
							TVMaps.mSystemLockedFlag.Set(iid,FALSE);
						}

					}


				}
			}
		}

	}

}
Example #3
0
File: mesh.cpp Project: 2asoft/xray
BOOL UnwrapMod::InitializeMeshData(ObjectState *os, int CurrentChannel)
	{

	TriObject *tobj = (TriObject*)os->obj;
				// Apply our mapping
	Mesh &mesh = tobj->GetMesh();




//get channel from mesh
	TVMaps.channel = CurrentChannel;
					
	if ( (mesh.selLevel==MESH_FACE) && (mesh.faceSel.NumberSet() == 0) ) 
		{
		return FALSE;
		}
						
	
//get from mesh based on cahne
	TVFace *tvFace = mesh.mapFaces(CurrentChannel);
	Point3 *tVerts = mesh.mapVerts(CurrentChannel);
	if (mesh.selLevel!=MESH_FACE) 
		{
//copy into our structs
		TVMaps.SetCountFaces(mesh.getNumFaces());
		TVMaps.v.SetCount(mesh.getNumMapVerts (CurrentChannel));
		TVMaps.cont.SetCount(mesh.getNumMapVerts (CurrentChannel));

		vsel.SetSize(mesh.getNumMapVerts (CurrentChannel));
		
		TVMaps.geomPoints.SetCount(mesh.numVerts);

		for (int j=0; j<TVMaps.f.Count(); j++) 
			{
			TVMaps.f[j]->flags = 0;
			TVMaps.f[j]->t = new int[3];
			TVMaps.f[j]->v = new int[3];
			if (tvFace == NULL)
				{
				
				TVMaps.f[j]->t[0] = 0;
				TVMaps.f[j]->t[1] = 0;
				TVMaps.f[j]->t[2] = 0;
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.faces[j].getMatID();
				TVMaps.f[j]->flags = 0;
				TVMaps.f[j]->count = 3;
				for (int k = 0; k < 3; k++)
					{
					int index = mesh.faces[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.verts[index];
					}

				if (!mesh.faces[j].getEdgeVis(0))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEA;
				if (!mesh.faces[j].getEdgeVis(1))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEB;
				if (!mesh.faces[j].getEdgeVis(2))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEC;

				}
			else
				{
				TVMaps.f[j]->t[0] = tvFace[j].t[0];
				TVMaps.f[j]->t[1] = tvFace[j].t[1];
				TVMaps.f[j]->t[2] = tvFace[j].t[2];
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.faces[j].getMatID();
				

				TVMaps.f[j]->flags = 0;
				TVMaps.f[j]->count = 3;
				for (int k = 0; k < 3; k++)
					{
					int index = mesh.faces[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.verts[index];
					}

				if (!mesh.faces[j].getEdgeVis(0))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEA;
				if (!mesh.faces[j].getEdgeVis(1))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEB;
				if (!mesh.faces[j].getEdgeVis(2))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEC;
							
				}
			}
		for (    j=0; j<TVMaps.v.Count(); j++) 
			{
			TVMaps.cont[j] = NULL;
			TVMaps.v[j].flags = 0;
			if (tVerts)
				TVMaps.v[j].p  = tVerts[j];
			else TVMaps.v[j].p  = Point3(.0f,0.0f,0.0f);
			TVMaps.v[j].influence = 0.0f;
			}
		if (tvFace == NULL) BuildInitialMapping(&mesh);
		}
	else
		{
//copy into our structs
		TVMaps.SetCountFaces(mesh.getNumFaces());
		TVMaps.v.SetCount(mesh.getNumMapVerts (CurrentChannel));
		TVMaps.cont.SetCount(mesh.getNumMapVerts (CurrentChannel));

		vsel.SetSize(mesh.getNumMapVerts (CurrentChannel));

		TVMaps.geomPoints.SetCount(mesh.numVerts);


		for (int j=0; j<TVMaps.f.Count(); j++) 
			{
			TVMaps.f[j]->flags = 0;
			TVMaps.f[j]->t = new int[3];
			TVMaps.f[j]->v = new int[3];

			if (tvFace == NULL)
				{
				TVMaps.f[j]->t[0] = 0;
				TVMaps.f[j]->t[1] = 0;
				TVMaps.f[j]->t[2] = 0;
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.faces[j].getMatID();
				TVMaps.f[j]->count = 3;
				if (mesh.faceSel[j])
					TVMaps.f[j]->flags = 0;
				else TVMaps.f[j]->flags = FLAG_DEAD;
				for (int k = 0; k < 3; k++)
					{
					int index = mesh.faces[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.verts[index];
					}

				if (!mesh.faces[j].getEdgeVis(0))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEA;
				if (!mesh.faces[j].getEdgeVis(1))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEB;
				if (!mesh.faces[j].getEdgeVis(2))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEC;
				}
			else
				{
				TVMaps.f[j]->t[0] = tvFace[j].t[0];
				TVMaps.f[j]->t[1] = tvFace[j].t[1];
				TVMaps.f[j]->t[2] = tvFace[j].t[2];
				TVMaps.f[j]->FaceIndex = j;
				TVMaps.f[j]->MatID = mesh.faces[j].getMatID();
				TVMaps.f[j]->count = 3;
				if (mesh.faceSel[j])
					TVMaps.f[j]->flags = 0;
				else TVMaps.f[j]->flags = FLAG_DEAD;
				for (int k = 0; k < 3; k++)
					{
					int index = mesh.faces[j].v[k];
					TVMaps.f[j]->v[k] = index;
					TVMaps.geomPoints[index] = mesh.verts[index];
					}
				if (!mesh.faces[j].getEdgeVis(0))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEA;
				if (!mesh.faces[j].getEdgeVis(1))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEB;
				if (!mesh.faces[j].getEdgeVis(2))
					TVMaps.f[j]->flags |= FLAG_HIDDENEDGEC;

								
				}
			}
		for (j=0; j<TVMaps.v.Count(); j++) 
			{
			TVMaps.cont[j] = NULL;
			TVMaps.v[j].flags = FLAG_DEAD;
			if (tVerts)
				TVMaps.v[j].p  = tVerts[j];
			else TVMaps.v[j].p  = Point3(0.0f,0.0f,0.0f);
//check if vertex for this face selected
			TVMaps.v[j].influence = 0.0f;

			}
		if (tvFace == NULL) BuildInitialMapping(&mesh);
		for (j=0; j<TVMaps.f.Count(); j++) 
			{
			if (TVMaps.f[j]->flags != FLAG_DEAD)
				{
				int a;
				a = TVMaps.f[j]->t[0];
				TVMaps.v[a].flags = 0;
				a = TVMaps.f[j]->t[1];
				TVMaps.v[a].flags = 0;
				a = TVMaps.f[j]->t[2];
				TVMaps.v[a].flags = 0;
				}
			}


		}

	return TRUE;
	}