static void FixInvalidTextureAxes(MapError *pError)
{
	CMapSolid *pSolid = (CMapSolid *)pError->pObjects[0];

	int nFaces = pSolid->GetFaceCount();
	for (int i = 0; i < nFaces; i++)
	{
		CMapFace *pFace = pSolid->GetFace(i);
		if (!pFace->IsTextureAxisValid())
		{
			pFace->InitializeTextureAxes(Options.GetTextureAlignment(), INIT_TEXTURE_FORCE | INIT_TEXTURE_AXES);
		}
	}
}
Example #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);
}