Beispiel #1
0
void tm_polySlot::getMeshUVs()
{
	MDagPath dagPath = getMeshNode();
	MObject meshObject = dagPath.node();
	MFnMesh meshFn( meshObject);

	MStringArray uvSetNames;
	MString currentUVSetName;
	MFloatArray *p_uArray = NULL;
	MFloatArray *p_vArray = NULL;
	MIntArray *p_uvCounts = NULL;
	MIntArray *p_uvIds = NULL;
	unsigned uvSetsCount = meshFn.numUVSets();
	if(uvSetsCount > 0)
	{
		meshFn.getUVSetNames( uvSetNames);
		p_uArray = new MFloatArray[uvSetsCount];
		p_vArray = new MFloatArray[uvSetsCount];
		p_uvCounts = new MIntArray[uvSetsCount];
		p_uvIds = new MIntArray[uvSetsCount];
		meshFn.getCurrentUVSetName( currentUVSetName);
		for( unsigned i = 0; i < uvSetsCount; i++)
		{
			meshFn.getUVs( p_uArray[i], p_vArray[i], &uvSetNames[i]);
			meshFn.getAssignedUVs( p_uvCounts[i], p_uvIds[i], &uvSetNames[i]); 
		}
	}
#ifdef _DEBUG
MString msg;
msg = "Old uvSetsCount = " + uvSetsCount;
msg += "UvSetNames = ";
for(unsigned i=0;i<uvSetNames.length();i++) msg += uvSetNames[i] + ", ";
MGlobal::displayInfo( msg);
#endif
}
Beispiel #2
0
void tm_polySlot::getModifierNodeName()
{
	MDagPath dagPath = getMeshNode();
	MObject meshObject = dagPath.node();
	MFnDependencyNode nodeFn( meshObject);
	MPlug inMeshPlug = nodeFn.findPlug( "inMesh");
	MPlugArray connectedPlugsArray;
	if(	inMeshPlug.connectedTo( connectedPlugsArray, 1, 0))
	{
		MObject modifierNodeObj = connectedPlugsArray[0].node();
		MFnDependencyNode modifierNode( modifierNodeObj);
		modifierNodeName = modifierNode.name();
	}
}
Beispiel #3
0
void tm_polySlot::setMeshUVs()
{
	MStatus status( MStatus::kSuccess);
	MDagPath dagPath = getMeshNode();
	MObject meshObject = dagPath.node();
	MFnMesh meshFn( meshObject);
#ifdef _DEBUG
MString msg;
uvSetsCount = meshFn.numUVSets();
if(uvSetsCount > 0) meshFn.getUVSetNames( uvSetNames);
msg = "Old uvSetsCount = " + uvSetsCount;
msg += "UvSetNames = ";
for(unsigned i=0;i<uvSetNames.length();i++) msg += uvSetNames[i] + ", ";
MGlobal::displayInfo( msg);
#endif
	
/*	for( unsigned i = 0; i < uvSetNames.length(); i++)
	{
		status = meshFn.deleteUVSet( uvSetNames[i], &dgModifier);
		if(!status) MGlobal::displayError("Can't delete uvSet " + uvSetNames[i]);
	}
*/
//	i = 0;
	for( unsigned i = 0; i < uvSetsCount; i++)
	{
//		status = meshFn.setCurrentUVSetName( uvSetNames[i]);
//			if(!status) MGlobal::displayError("Can't set current " + uvSetNames[i] + " uvSet.");
//		status = meshFn.deleteUVSet( uvSetNames[i]);
//		if(!status) MGlobal::displayError("Can't delete uvSet " + uvSetNames[i]);
//		meshFn.clearUVs( &uvSetNames[i]);
//		status = meshFn.createUVSet( uvSetNames[i]);
//		if(!status) MGlobal::displayError("Can't create uvSet " + uvSetNames[i]);
		status = meshFn.setUVs( p_uArray[i], p_vArray[i], &uvSetNames[i]);
		if(!status) MGlobal::displayError("Can't set uvSet " + uvSetNames[i]);
		status = meshFn.assignUVs( p_uvCounts[i], p_uvIds[i], &uvSetNames[i]);
		if(!status) MGlobal::displayError("Can't assign uvSet " + uvSetNames[i]);
	}
}
Beispiel #4
0
// Private Methods
//
bool splitUV::validateUVs()
//
// Description:
//
//		Validate the UVs for the splitUV operation. UVs are valid only if they are shared
//		by more than one face. While the splitUVNode is smart enough to not process the
//		split if a UV is not splittable, a splitUV node is still created by the polyModifierCmd.
//		So call this method to validate the UVs before calling doModifyPoly().
//
//		validateUVs() will return true so long as there is at least one valid UV. It will
//		also prune out any invalid UVs from both the component list and UVId array.
//
{
	// Get the mesh that we are operating on
	//
	MDagPath		dagPath = getMeshNode();
	MObject			mesh = dagPath.node();

	// Get the number of faces sharing the selected UVs
	//
	MFnMesh			meshFn( mesh );
	MItMeshPolygon	polyIter( mesh );
	MIntArray		selUVFaceCountArray;

	int i;
	int j;
	int count = 0;
	int selUVsCount = fSelUVs.length();

	for( i = 0; i < selUVsCount; i++ )
	{
		for( ; !polyIter.isDone(); polyIter.next() )
		{
			if( polyIter.hasUVs() )
			{
				int polyVertCount = polyIter.polygonVertexCount();

				for( j = 0; j < polyVertCount; j++ )
				{
					int UVIndex = 0;
					polyIter.getUVIndex(j, UVIndex);

					if( UVIndex == fSelUVs[i] )
					{
						count++;
						break;
					}
				}
			}
		}

		selUVFaceCountArray.append(count);
	}

	// Now, check to make sure that at least one UV is being shared by more than one
	// face. So long as we have one UV that we can operate on, we should proceed and let
	// the splitUVNode ignore the UVs which are only shared by one face.
	//
	bool isValid = false;
	MIntArray validUVIndices;

	for( i = 0; i < selUVsCount; i++ )
	{
		if( selUVFaceCountArray[i] > 1 )
		{
			isValid = true;
			validUVIndices.append(i);
		}
	}

	if( isValid )
	{
		pruneUVs( validUVIndices );
	}

	return isValid;
}