//-----------------------------------------------------------------------------
// Purpose: Fixes duplicate face IDs by assigning the face a unique ID within
//			the world.
// Input  : pError - Holds the world and the face that is in error.
//-----------------------------------------------------------------------------
static void FixDuplicateFaceIDs(MapError *pError)
{
	CMapWorld *pWorld = (CMapWorld *)pError->pObjects[0];
	CMapFace *pFace = (CMapFace *)pError->dwExtra;

	pFace->SetFaceID(pWorld->FaceID_GetNext());
}
Esempio n. 2
0
void CSSolid::ToMapSolid(CMapSolid *p)
{
	// so we can pass NULL (default) or another solid (to copy):
	CMapSolid *pSolid;
	if (p)
	{
		pSolid = p;
	}
	else
	{
		pSolid = m_pMapSolid;
	}

	pSolid->SetFaceCount(0);

	for (int i = 0; i < m_nFaces; i++)
	{
		CSSFace &face = m_Faces[i];
		CMapFace SolidFace;

		//
		// Copy original texture information and face ID back.
		//
		memcpy(&SolidFace.texture, &face.texture, sizeof(TEXTURE));
		SolidFace.SetTexture(SolidFace.texture.texture);
		SolidFace.SetFaceID(face.m_nFaceID);

		//
		// Create face from new points.
		//
		Vector *pts = CreatePointList(face);
		if (pts)
		{
			SolidFace.CreateFace(pts, face.nEdges);

			//
			// Vertex manipulation; the face orientation may have changed. If one of the texture axes is now
			// perpendicular to the face, recalculate the texture axes using the default alignment (world or face).
			// Ideally we would transform the texture axes so that their orientation relative to the face is preserved.
			// By reinitializing the axes we risk having the axes rotate unpredictably.
			//
			if (!SolidFace.IsTextureAxisValid())
			{
				SolidFace.InitializeTextureAxes(Options.GetTextureAlignment(), INIT_TEXTURE_AXES | INIT_TEXTURE_FORCE);
			}
				
			// Attempt to update the displacement - if there is one.
			if ( face.m_hDisp != EDITDISPHANDLE_INVALID )
			{
				EditDispHandle_t hDisp = EditDispMgr()->Create();
				CMapDisp *pSolidDisp = EditDispMgr()->GetDisp( hDisp );
				CMapDisp *pDisp = EditDispMgr()->GetDisp( face.m_hDisp );
				pSolidDisp->CopyFrom( pDisp, false );
				int iStart = pSolidDisp->GetSurfPointStartIndex();
				pSolidDisp->SetSurfPointStartIndex( (iStart+3)%4 );
				pSolidDisp->InitDispSurfaceData( &SolidFace, false );
				pSolidDisp->Create();
				SolidFace.SetDisp( hDisp );
			}

			pSolid->AddFace(&SolidFace);

			delete[] pts;
		}
	}

	pSolid->PostUpdate(Notify_Changed);
}