//-----------------------------------------------------------------------------
// Purpose: 
// Input  : uCmd - 
// Output : Returns TRUE on success, FALSE on failure.
//-----------------------------------------------------------------------------
BOOL CFaceEditMaterialPage::OnAlign( UINT uCmd )
{
	// Set the material tool current.
	SetMaterialPageTool( MATERIALPAGETOOL_MATERIAL );

	// mark position in undo stack
	GetHistory()->MarkUndoPosition(NULL, "Align texture");

	CFaceEditSheet *pSheet = ( CFaceEditSheet* )GetParent();
	int faceCount = pSheet->GetFaceListCount();

	for( int i = 0; i < faceCount; i++ )
	{
		CMapFace *pFace = pSheet->GetFaceListDataFace( i );

		CMapSolid *pSolid = pSheet->GetFaceListDataSolid( i );
		GetHistory()->Keep( pSolid );

		switch( uCmd )
		{
			case IDC_ALIGN_WORLD:
			{
				pFace->InitializeTextureAxes( TEXTURE_ALIGN_WORLD, INIT_TEXTURE_AXES | INIT_TEXTURE_FORCE );
				break;
			}

			case IDC_ALIGN_FACE:
			{
				pFace->InitializeTextureAxes( TEXTURE_ALIGN_FACE, INIT_TEXTURE_AXES | INIT_TEXTURE_FORCE );
				break;
			}
		}
	}

	CMapDoc::GetActiveMapDoc()->SetModifiedFlag();

	UpdateDialogData();

	return ( TRUE );
}
Пример #2
0
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);
		}
	}
}
Пример #3
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);
}