void 
UsdMayaGLSoftSelectHelper::_PopulateWeights()
{
    // we don't want to fallback to the active selection if there is no sot
    // select
    bool defaultToActiveSelection = false;
    MRichSelection softSelect;
    MGlobal::getRichSelection(softSelect, defaultToActiveSelection);
    MSelectionList selection;
    softSelect.getSelection(selection);

    for (MItSelectionList iter( selection, MFn::kInvalid); !iter.isDone(); iter.next() )  {
        MDagPath dagPath;
        MObject component;

        iter.getDagPath(dagPath, component);
        // component.isNull() indcates that we're selecting a whole object, as
        // opposed to a component.
        if (!component.isNull()) {
            continue;
        }

        float weight = 0.0f;
        _dagPathsToWeight[dagPath] = weight;
    }
}
Exemplo n.º 2
0
MStatus richMoveCmd::action( int flag )
//
// Description
// 		Do the actual work here to move the objects	by vector
//
{
	MStatus stat;
	MVector vector = delta;

	switch( flag )
	{
		case UNDOIT:	// undo
			vector.x = -vector.x;
			vector.y = -vector.y;
			vector.z = -vector.z;
			break;
		case REDOIT:	// redo
			break;
		case DOIT:		// do command
			break;
		default:
			break;
	}

	// Create a selection list iterator
	//
	MSelectionList slist;
	MSpace::Space spc = MSpace::kWorld;
	MRichSelection rs;
	MGlobal::getRichSelection( rs);

	// Translate all selected objects
	//
	rs.getSelection( slist);
	if( !slist.isEmpty())
	{
		for ( MItSelectionList iter( slist, MFn::kInvalid); !iter.isDone(); iter.next() ) 
		{
			// Get path and possibly a component
			//
			MDagPath 	mdagPath;		// Item dag path
			MObject 	mComponent;		// Current component
			iter.getDagPath( mdagPath, mComponent );
			MPlane seam;
			rs.getSymmetryPlane( mdagPath, spc, seam);

			if( mComponent.isNull())
			{
				// Transform move
				MFnTransform transFn( mdagPath, &stat );
				if ( MS::kSuccess == stat ) {
					stat = transFn.translateBy( vector, spc );
					CHECKRESULT(stat,"Error doing translate on transform");
					continue;
				}
			}
			else
			{
				// Component move
				iter.getDagPath( mdagPath, mComponent );
				for( MItGeometry geoIter( mdagPath, mComponent); !geoIter.isDone(); geoIter.next())
				{
					MVector origPosition = geoIter.position( spc);
					MWeight weight = geoIter.weight();

					// Calculate the soft move
					MVector position = origPosition + vector * weight.influence();

					// Calculate the soft seam
					position += seam.normal() * (weight.seam() * (seam.directedDistance( origPosition) - seam.directedDistance( position)));
					geoIter.setPosition( position, spc);
				}
			}
		}
	}

	// Translate all symmetry objects
	//
	slist.clear();
	rs.getSymmetry( slist);
	if( !slist.isEmpty())
	{
		for ( MItSelectionList iter( slist, MFn::kInvalid); !iter.isDone(); iter.next() ) 
		{
			// Get path and possibly a component
			//
			MDagPath 	mdagPath;		// Item dag path
			MObject 	mComponent;		// Current component
			iter.getDagPath( mdagPath, mComponent );
			MPlane seam;
			rs.getSymmetryPlane( mdagPath, spc, seam);

			// Reflect our world space move
			//
			MMatrix symmetryMatrix;
			rs.getSymmetryMatrix( mdagPath, spc, symmetryMatrix);
			MVector symmetryVector =  vector * symmetryMatrix;

			if( mComponent.isNull())
			{
				// Transform move
				MFnTransform transFn( mdagPath, &stat );
				if ( MS::kSuccess == stat ) {
					stat = transFn.translateBy( symmetryVector, spc );
					CHECKRESULT(stat,"Error doing translate on transform");
					continue;
				}
			}
			else
			{
				// Component move
				iter.getDagPath( mdagPath, mComponent );
				for( MItGeometry geoIter( mdagPath, mComponent); !geoIter.isDone(); geoIter.next())
				{
					MVector origPosition = geoIter.position( spc);
					MWeight weight = geoIter.weight();

					// Calculate the soft move
					MVector position = origPosition + symmetryVector * weight.influence();

					// Calculate the soft seam
					position += seam.normal() * (weight.seam() * (seam.directedDistance( origPosition) - seam.directedDistance( position)));
					geoIter.setPosition( position, spc);
				}
			}
		}
	}

	return MS::kSuccess;
}