void meshReorderTool::reset()
{
	MEvent e;

	fNumSelectedPoints = 0;

	fSelectedPathSrc.clear();
	fSelectedComponentSrc.clear();
	fSelectVtxSrc.clear();
	fSelectedFaceSrc = -1;

	fCurrentHelpString = "Select 1st point on mesh.";

	helpStateHasChanged( e );
}
Exemple #2
0
void meshRemapTool::reset()
{
	fNumSelectedPoints = 0;

	fSelectedPathSrc.clear();
	fSelectedComponentSrc.clear();
	fSelectVtxSrc.clear();
	fSelectedFaceSrc = -1;

	fSelectedPathDst.clear();
	fSelectedComponentDst.clear();
	fSelectVtxDst.clear();
	fSelectedFaceDst = -1;

	fCurrentHelpString = "Select 1st point on source mesh.";

	helpStateHasChanged();
}
Exemple #3
0
//
// Selects objects within the user defined area, then process them
// 
MStatus meshRemapTool::doRelease( MEvent & event )
{
	char buf[1024];

	// Perform the base actions
	MStatus stat = MPxSelectionContext::doRelease(event);

	// Get the list of selected items 
	MGlobal::getActiveSelectionList( fSelectionList );

	//
	//  Get the selection's details, we must have exactly one component selected
	//
	MObject component;
	MDagPath path;

	MItSelectionList selectionIt (fSelectionList, MFn::kComponent);

	MStringArray	selections;
	selectionIt.getStrings( selections );
	
	// There are valid cases where only the meshes are selected.
	if( selections.length() == 0 )
	{
		// Handling the case where the user's workflow is
		// 1) select src mesh, select vtx1, vtx2, vtx3 (i.e. fNumSelectedPoints == 0)
		// 2) select dst mesh, select vtx1, vtx2, vtx3 (i.e. fNumSelectedPoints == 3)
		if( fNumSelectedPoints == 0 || fNumSelectedPoints == 3 )
		{
			MItSelectionList selectionDag (fSelectionList, MFn::kDagNode);
			if (!selectionDag.isDone() && selectionDag.getDagPath(path) == MS::kSuccess)
			{
				path.extendToShape();
				// return true there is exactly one mesh selected
				if (path.hasFn(MFn::kMesh))
				{
					selectionDag.next();
					if (selectionDag.isDone())
					{
						//	If this is the destination mesh, make sure that
						//	it doesn't have history.
						if (fNumSelectedPoints == 3)
						{
							return checkForHistory(path);
						}

						return MS::kSuccess;
					}
				}
			}
		}

		// Handling the case where the user is doing the auto remap, i.e.
		// select src mesh, and then dst mesh when fNumSelectedPoints == 0.
		if( fNumSelectedPoints == 0 )
		{
			MItSelectionList selectionDag (fSelectionList, MFn::kDagNode);
			if (!selectionDag.isDone() && selectionDag.getDagPath(path) == MS::kSuccess)
			{
				path.extendToShape();
				// Confirm first selection is a mesh
				if (path.hasFn(MFn::kMesh))
				{
					selectionDag.next();
					if (!selectionDag.isDone() &&
					    selectionDag.getDagPath(path) == MS::kSuccess)
					{
						path.extendToShape();
						// Confirm second selection is a mesh
						if (path.hasFn(MFn::kMesh))
						{
							selectionDag.next();
							// Confirm there are exactly 2 selections
							if (selectionDag.isDone())
							{
								//	Make sure that the destination mesh
								//	doesn't have history.
								return checkForHistory(path);
							}
						}
					}
				}
			}
		}
	}

	if( selections.length() != 1 )
	{
		MGlobal::displayError( "Must select exactly one vertex" );
		return MS::kSuccess;
	}

	if (selectionIt.isDone ())
	{
		MGlobal::displayError( "Selected item not a vertex" );
		return MS::kSuccess;
	}

	if( selectionIt.getDagPath (path, component) != MStatus::kSuccess )
	{
		MGlobal::displayError( "Must select a mesh or its vertex" );
		return MS::kSuccess;
	}

	if (!path.node().hasFn(MFn::kMesh) && !(path.node().hasFn(MFn::kTransform) && path.hasFn(MFn::kMesh)))
	{
		MGlobal::displayError( "Must select a mesh or its transform" );
		return MS::kSuccess;
	}

	//	If this is the first vertex of the destination mesh, make sure that
	//	it doesn't have history.
	if ((fNumSelectedPoints == 3) && (checkForHistory(path) != MS::kSuccess))
	{
		return MS::kSuccess;
	}

	MItMeshVertex fIt ( path, component, &stat );
	if( stat != MStatus::kSuccess )
	{
		MGlobal::displayError( "MItMeshVertex failed");
		return MStatus::kFailure;
	}

	if (fIt.count() != 1 )
	{
		sprintf(buf, "Invalid selection '%s'. Vertices must be picked one at a time.", selections[0].asChar() );
		MGlobal::displayError( buf );
		return MS::kSuccess;
	}
	else
	{
		sprintf(buf, "Accepting vertex '%s'", selections[0].asChar() );
		MGlobal::displayInfo(  buf );
	}

	//
	// Now that we know it's valid, process the selection, the first 3 items are the source, the second
	// 3 define the target
	//

	if( fNumSelectedPoints < 3 )
	{
		fSelectedPathSrc.append( path );
		fSelectedComponentSrc.append( component );
	}
	else 
	{
		fSelectedPathDst.append( path );
		fSelectedComponentDst.append( component );
	}

	//
	//  When each of the source/target are defined, process them. An error/invalid selection will restart the selection for
	//  that particular mesh.
	//  
	if( fNumSelectedPoints == 2 )
	{
		if( ( stat = meshMapUtils::validateFaceSelection( fSelectedPathSrc, fSelectedComponentSrc, &fSelectedFaceSrc, &fSelectVtxSrc ) ) != MStatus::kSuccess )
		{
			MGlobal::displayError("Selected vertices don't define a unique face on source mesh");
			reset();
			return stat;
		}
	}

	//
	// Once the target is defined, invoke the command
	//
	if( fNumSelectedPoints == 5 )
	{
		if( ( stat = meshMapUtils::validateFaceSelection( fSelectedPathDst, fSelectedComponentDst, &fSelectedFaceDst, &fSelectVtxDst ) ) != MStatus::kSuccess )
		{
			MGlobal::displayError("Selected vertices don't define a unique face on destination mesh");
			reset();
			return stat;
		}

		executeCmd();
	}
	else
	{
		//
		// We don't have all the details yet, just move to the next item
		//
		fNumSelectedPoints++;	
	}

	helpStateHasChanged();

	return stat;
}
Exemple #4
0
MStatus meshRemapTool::resolveMapping()
{
	// Get the list of selected items 
	MGlobal::getActiveSelectionList( fSelectionList );
	if( fSelectionList.length() != 2)
	{
		reset();
		helpStateHasChanged();
		return MStatus::kFailure;
	}

	MDagPath dagPath;
	MObject  component;
	if( fSelectionList.getDagPath(0, dagPath, component) != MStatus::kSuccess)
	{
		MGlobal::displayError(" Invalid source mesh");
		return MStatus::kFailure;
	}
	dagPath.extendToShape();
	// Repeat this 3 times one for each vertex
	fSelectedPathSrc.append(dagPath);
	fSelectedPathSrc.append(dagPath);
	fSelectedPathSrc.append(dagPath);

	if( fSelectionList.getDagPath(1, dagPath, component) != MStatus::kSuccess)
	{
		MGlobal::displayError(" Invalid destination mesh");
		return MStatus::kFailure;
	}
	dagPath.extendToShape();
	// Repeat this 3 times one for each vertex
	fSelectedPathDst.append(dagPath);
	fSelectedPathDst.append(dagPath);
	fSelectedPathDst.append(dagPath);

	// Find the vertices in Object Space of the first polygon
	MPointArray srcPts;
	MIntArray   srcVertIds, dstVertIds;
	MItMeshPolygon faceIterSrc(fSelectedPathSrc[0]);
	unsigned srcFaceId = faceIterSrc.index();
	faceIterSrc.getPoints(srcPts, MSpace::kObject);
	faceIterSrc.getVertices(srcVertIds);

	// Tranfrom the vertices to dst World Space
	unsigned i, j;
	MMatrix m = fSelectedPathDst[0].inclusiveMatrix();
	for(i = 0; i < srcPts.length(); i++)
	{
	    srcPts[i] = srcPts[i] * m;
	}

	MItMeshPolygon faceIterDst(fSelectedPathDst[0]);
	while (!faceIterDst.isDone())
	{
		MPointArray dstPts;
		faceIterDst.getPoints(dstPts, MSpace::kWorld);
		if (arePointsOverlap(srcPts, dstPts))
		{
			// Set face and vertex indices
			fSelectedFaceSrc = srcFaceId;
			fSelectedFaceDst = faceIterDst.index();
			fSelectVtxSrc.append(srcVertIds[0]);
			fSelectVtxSrc.append(srcVertIds[1]);
			fSelectVtxSrc.append(srcVertIds[2]);

			faceIterDst.getVertices(dstVertIds);
			for (j = 0; j < dstPts.length(); j++)
			{
				MVector v = dstPts[j] - srcPts[0];
				if (v * v < epsilon)
				{
					fSelectVtxDst.append(dstVertIds[j]);
					break;
				}
			}

			for (j = 0; j < dstPts.length(); j++)
			{
				MVector v = dstPts[j] - srcPts[1];
				if (v * v < epsilon)
				{
					fSelectVtxDst.append(dstVertIds[j]);
					break;
				}
			}

			for (j = 0; j < dstPts.length(); j++)
			{
				MVector v = dstPts[j] - srcPts[2];
				if (v * v < epsilon)
				{
					fSelectVtxDst.append(dstVertIds[j]);
					break;
				}
			}

			return MStatus::kSuccess;
		}
		faceIterDst.next();
	}
	return MStatus::kFailure;
}
//
// Selects objects within the user defined area, then process them
// 
MStatus meshReorderTool::doRelease( MEvent & event )
{
	char buf[1024];

	// Perform the base actions
	MStatus stat = MPxSelectionContext::doRelease(event);

	// Get the list of selected items 
	MGlobal::getActiveSelectionList( fSelectionList );

	//
	//  If there's nothing selected, don't worry about it, just return
	//
	if( fSelectionList.length() != 1 )
	{
		MGlobal::displayWarning( "Components must be selected one at a time" );
		return MS::kSuccess;
	}

	//
	//  Get the selection's details, we must have exactly one component selected
	//
	MObject component;
	MDagPath path;

	MItSelectionList selectionIt (fSelectionList, MFn::kComponent);

	MStringArray	selections;
	selectionIt.getStrings( selections );
	
	if( selections.length() != 1 )
	{
		MGlobal::displayError( "Must select exactly one vertex" );
		return MS::kSuccess;
	}

	if (selectionIt.isDone ())
	{
		MGlobal::displayError( "Selected item not a vertex" );
		return MS::kSuccess;
	}

	if( selectionIt.getDagPath (path, component) != MStatus::kSuccess )
	{
		MGlobal::displayError( "Must select a mesh or its vertex");
		return MS::kSuccess;
	}

	if (!path.node().hasFn(MFn::kMesh) && !(path.node().hasFn(MFn::kTransform) && path.hasFn(MFn::kMesh)))
	{
		MGlobal::displayError( "Must select a mesh or its transform" );
		return MS::kSuccess;
	}

	MFnMesh	meshFn(path);
	MPlug	historyPlug = meshFn.findPlug("inMesh", true);
	if (historyPlug.isDestination())
	{
		MGlobal::displayError( "Mesh has history. Its geometry cannot be modified" );
		return MS::kSuccess;
	}

	MItMeshVertex fIt ( path, component, &stat );
	if( stat != MStatus::kSuccess )
	{
		MGlobal::displayError( "MItMeshVertex failed");
		return MStatus::kFailure;
	}

	if (fIt.count() != 1 )
	{
		sprintf(buf, " Invalid selection '%s'. Vertices must be picked one at a time.", selections[0].asChar() );
		MGlobal::displayError( buf );
		return MS::kSuccess;
	}
	else
	{
		sprintf(buf, "Accepting vertex '%s'", selections[0].asChar() );
		MGlobal::displayInfo(  buf );
	}

	//
	// Now that we know it's valid, process the selection
	//

	fSelectedPathSrc.append( path );
	fSelectedComponentSrc.append( component );

	//
	//  When each of the mesh defined, process it. An error/invalid selection will restart the selection for
	//  that particular mesh.
	//  
	if( fNumSelectedPoints == 2 )
	{
		if( ( stat = meshMapUtils::validateFaceSelection( fSelectedPathSrc, fSelectedComponentSrc, &fSelectedFaceSrc, &fSelectVtxSrc ) ) != MStatus::kSuccess )
		{
			MGlobal::displayError("Must select vertices from the same face of a mesh");
			reset();
			return stat;
		}


		char cmdString[200];
		sprintf(cmdString, "meshReorder %s.vtx[%d] %s.vtx[%d] %s.vtx[%d]", 
		                    fSelectedPathSrc[0].partialPathName().asChar(), fSelectVtxSrc[0],
		                    fSelectedPathSrc[1].partialPathName().asChar(), fSelectVtxSrc[1],
		                    fSelectedPathSrc[2].partialPathName().asChar(), fSelectVtxSrc[2]);

		stat = MGlobal::executeCommand(cmdString, true, true);
		if (stat)
		{
			MGlobal::displayInfo( "Mesh reordering complete" );
		}

		//
		// Empty the selection list since the reodering may move the user's current selection on screen
		//
		MSelectionList empty;
		MGlobal::setActiveSelectionList( empty );

		// 
		// Start again, get new meshes
		//
		reset();	
	}
	else
	{
		//
		// We don't have all the details yet, just move to the next item
		//
		fNumSelectedPoints++;	
	}

	helpStateHasChanged( event );

	return stat;
}
Exemple #6
0
//
// Selects objects within the user defined area, then process them
// 
MStatus meshRemapTool::doRelease( MEvent & event )
{
	char buf[1024];

	// Perform the base actions
	MStatus stat = MPxSelectionContext::doRelease(event);

	// Get the list of selected items 
	MGlobal::getActiveSelectionList( fSelectionList );

	//
	//  If there's nothing selected, don't worry about it, just return
	//
	if( fSelectionList.length() != 1 )
	{
		MGlobal::displayWarning( "Components must be selected one at a time" );
		return MS::kSuccess;
	}

	//
	//  Get the selection's details, we must have exactly one component selected
	//
	MObject component;
	MDagPath path;

	MItSelectionList selectionIt (fSelectionList, MFn::kComponent);

	MStringArray	selections;
	selectionIt.getStrings( selections );
	
	if( selections.length() != 1 )
	{
		MGlobal::displayError( "Components must be selected one at a time" );
		return MS::kSuccess;
	}

	if (selectionIt.isDone ())
	{
		MGlobal::displayError( "Selected Item not a component" );
		return MS::kSuccess;
	}

	if( selectionIt.getDagPath (path, component) != MStatus::kSuccess )
	{
		MGlobal::displayError( "Can't get path for selection");
		return MS::kSuccess;
	}

	if (!path.node().hasFn(MFn::kMesh) && !(path.node().hasFn(MFn::kTransform) && path.hasFn(MFn::kMesh)))
	{
		MGlobal::displayError( " Invalid type! Only a mesh or its transform can be specified." );
		return MS::kSuccess;
	}

	MItMeshVertex fIt ( path, component, &stat );
	if( stat != MStatus::kSuccess )
	{
		MGlobal::displayError( " MItMeshVertex failed");
		return MStatus::kFailure;
	}

	if (fIt.count() != 1 )
	{
		sprintf(buf, " Invalid selection '%s'. Vertices must be picked one at a time.", selections[0].asChar() );
		MGlobal::displayError( buf );
		return MS::kSuccess;
	}
	else
	{
		sprintf(buf, "Accepting vertex '%s'", selections[0].asChar() );
		MGlobal::displayInfo(  buf );
	}

	//
	// Now that we know it's valid, process the selection, the first 3 items are the source, the second
	// 3 define the target
	//

	if( fNumSelectedPoints < 3 )
	{
		fSelectedPathSrc.append( path );
		fSelectedComponentSrc.append( component );
	}
	else 
	{
		fSelectedPathDst.append( path );
		fSelectedComponentDst.append( component );
	}

	//
	//  When each of the source/target are defined, process them. An error/invalid selection will restart the selection for
	//  that particular mesh.
	//  
	if( fNumSelectedPoints == 2 )
	{
		if( ( stat = meshMapUtils::validateFaceSelection( fSelectedPathSrc, fSelectedComponentSrc, &fSelectedFaceSrc, &fSelectVtxSrc ) ) != MStatus::kSuccess )
		{
			MGlobal::displayError("Selected vertices don't define a unique face on source mesh");
			reset();
			return stat;
		}
	}

	//
	// Once the target is defined, invoke the command
	//
	if( fNumSelectedPoints == 5 )
	{
		if( ( stat = meshMapUtils::validateFaceSelection( fSelectedPathDst, fSelectedComponentDst, &fSelectedFaceDst, &fSelectVtxDst ) ) != MStatus::kSuccess )
		{
			MGlobal::displayError("Selected vertices don't define a unique face on source mesh");
			reset();
			return stat;
		}

		fCmd = new meshRemapCommand;
		fCmd->setSeedInfo( true, fSelectedPathSrc[0], fSelectedFaceSrc, fSelectVtxSrc[0], fSelectVtxSrc[1] );
		fCmd->setSeedInfo( false, fSelectedPathDst[0], fSelectedFaceDst, fSelectVtxDst[0], fSelectVtxDst[1] );
		fCmd->redoIt();

		//
		// Empty the selection list since the reodering may move the user's current selection on screen
		//
		MSelectionList empty;
		MGlobal::setActiveSelectionList( empty );

		MGlobal::displayInfo( "Mesh remapping complete" );

		// 
		// Start again, get new meshes
		//
		reset();	
	}
	else
	{
		//
		// We don't have all the details yet, just move to the next item
		//
		fNumSelectedPoints++;	
	}

	helpStateHasChanged();

	return stat;
}