示例#1
0
//
//  Given a list of 3 paths and compoents find the face they define and store their indices
//
MStatus meshMapUtils::validateFaceSelection( MDagPathArray& paths, MObjectArray& components, int *faceIdx, MIntArray *seedVtx )
{
	MStatus stat = MStatus::kSuccess;
	MIntArray finalFaceList;

	if ( paths.length() != 3 || components.length() != 3 )
	{
		return MStatus::kFailure;
	}

	seedVtx->clear();

	for (unsigned int i = 0; i < 3; i++)
	{
		MItMeshVertex fIt ( paths[i], components[i], &stat );
		if( stat != MStatus::kSuccess || fIt.isDone() )
		{
			MGlobal::displayError( " MItMeshVertex failed");
			return MStatus::kFailure;
		}

		seedVtx->append( fIt.index() ); // The  cv's location

		MIntArray  faceList;
		stat = fIt.getConnectedFaces ( faceList );
		if( stat != MStatus::kSuccess )
		{
			MGlobal::displayError( " getConnectedFaces failed");
			return MStatus::kFailure;
		}

		if( i == 0 )
		{
			finalFaceList = faceList;
		}
		else
		{
			meshMapUtils::intersectArrays( finalFaceList, faceList );
		}
	}

	if( finalFaceList.length() != 1 )
	{
		return MStatus::kFailure;
	}
	else
	{
		*faceIdx = finalFaceList[0];
	}

	MDagPath p0( paths[0] );
	MDagPath p1( paths[1] );
	MDagPath p2( paths[2] );

	if( !(p0 == p1 ) || !(p0 == p2 ))
	{
		return MStatus::kFailure;
	}

	return MStatus::kSuccess;
}