MStatus sgCurveEditBrush_context::getShapeNode( MDagPath& path ) { MStatus status; if ( path.apiType() == MFn::kNurbsCurve ) { return MS::kSuccess; } unsigned int numShapes; status = path.numberOfShapesDirectlyBelow( numShapes ); CHECK_MSTATUS_AND_RETURN_IT( status ); for ( unsigned int i = 0; i < numShapes; ++i ) { status = path.extendToShapeDirectlyBelow( i ); CHECK_MSTATUS_AND_RETURN_IT( status ); if ( !path.hasFn( MFn::kNurbsCurve ) ) { path.pop(); continue; } MFnDagNode fnNode( path, &status ); CHECK_MSTATUS_AND_RETURN_IT( status ); if ( !fnNode.isIntermediateObject() ) { return MS::kSuccess; } path.pop(); } return MS::kFailure; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MStatus CVsSkinnerCmd::FindSkinnerNodesInHierarchy( const MDagPath &iDagPath, MSelectionList &oList ) { MStatus retVal( MS::kFailure ); MDagPath rDagPath( iDagPath ); // Root dag path while ( rDagPath.length() > 1U ) { rDagPath.pop(); } MDagPath mDagPath; MDagPath sDagPath; uint nShapes; MItDag dIt; if ( rDagPath.length() ) { dIt.reset( rDagPath ); } for ( ; !dIt.isDone(); dIt.next() ) { if ( !dIt.getPath( mDagPath ) ) continue; mDagPath.numberOfShapesDirectlyBelow( nShapes ); for ( uint i( 0U ); i != nShapes; ++i ) { sDagPath = mDagPath; sDagPath.extendToShapeDirectlyBelow( i ); if ( !IsSkinnerNode( sDagPath ) ) continue; oList.add( sDagPath, MObject::kNullObj, true ); retVal = MS::kSuccess; } if ( !ConnectedToSkinnerNode( mDagPath, sDagPath ) ) continue; oList.add( sDagPath, MObject::kNullObj, true ); retVal = MS::kSuccess; } return retVal; }
MStatus Object::setShapesVisibility(bool visible, MTypeId & typeId) { MStatus status; MDagPath dagPath = getDagPath(status); if (!status) { status.perror("Object::getDagPath"); return status; } unsigned int numShapes; if (!(status = dagPath.numberOfShapesDirectlyBelow(numShapes))) { status.perror("MDagPath::numberOfShapesDirectlyBelow"); return status; } for(unsigned int i = 0; i < numShapes; ++i) { MDagPath shape = dagPath; if (!(status = shape.extendToShapeDirectlyBelow(i))) { status.perror("MDagPath::extendToShapeDirectlyBelow"); return status; } MFnDagNode shape_dagNode(shape); if (shape_dagNode.typeId(&status) == typeId) { MPlug visibilityPlug(shape.node(), shape_dagNode.findPlug("visibility", &status)); if (!status) { status.perror("MFnDagNode::findPlug"); return status; } if (!(status = visibilityPlug.setBool(visible))) { status.perror("MPlug::setBool"); return status; } } else if (!status) { status.perror("MFnDagNode::typeId"); return status; } } return MStatus::kSuccess; }
bool Object::isAnyShapeVisible(MTypeId & typeId, MStatus & status) { MDagPath dagPath = getDagPath(status); if (!status) { status.perror("Object::getDagPath"); return false; } unsigned int numShapes; if (!(status = dagPath.numberOfShapesDirectlyBelow(numShapes))) { status.perror("MDagPath::numberOfShapesDirectlyBelow"); return false; } for(unsigned int i = 0; i < numShapes; ++i) { MDagPath shape = dagPath; if (!(status = shape.extendToShapeDirectlyBelow(i))) { status.perror("MDagPath::extendToShapeDirectlyBelow"); return false; } MFnDagNode shape_dagNode(shape); if (shape_dagNode.typeId(&status) == typeId) { MPlug visibilityPlug(shape.node(), shape_dagNode.findPlug("visibility", &status)); if (!status) { status.perror("MFnDagNode::findPlug"); return false; } if (visibilityPlug.asBool()) { status = MStatus::kSuccess; return true; } } } status = MStatus::kSuccess; return false; }
MStatus CVCurveFromObject(const Model::Object & object, MPointArray & array) { MStatus status; MDagPath dagPath = object.getDagPath(status); if (!status) { status.perror("Object::getDagPath"); return status; } MDagPath shape = dagPath; unsigned int numShapes; if (!(status = dagPath.numberOfShapesDirectlyBelow(numShapes))) { status.perror("MDagPath::numberOfShapesDirectlyBelow"); return status; } for(unsigned int i = 0; i < numShapes; ++i) { if (!(status = shape.extendToShapeDirectlyBelow(i))) { status.perror("MDagPath::extendToShapeDirectlyBelow"); return status; } if (shape.hasFn(MFn::kNurbsCurve)) { MFnNurbsCurve nurbsCurve(shape); if (!(status = nurbsCurve.getCVs(array, MSpace::kWorld))) { status.perror("MFnNurbsCurve::getCVs"); return status; } return MStatus::kSuccess; } else std::cerr << "No MFnNurbsCurve!" << std::endl; } return MStatus::kNotFound; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MSelectionList CVsSkinnerCmd::DoNewVolumes( const MDagPath &skinnerPath, const MSelectionList &skeletonList ) { MSelectionList retList; const bool optSelected( m_undo.ArgDatabase().isFlagSet( kOptSelected ) ); MSelectionList optSelection; m_undo.ArgDatabase().getObjects( optSelection ); // TODO: Maybe some fancier logic to only create volumes on joints that make sense? // Perhaps the ol' has children but no shapes gag? Watch out for vstHelperBones! MDagPath mDagPath; for ( MItSelectionList sIt( optSelection ); !sIt.isDone(); sIt.next() ) { if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath ) && mDagPath.hasFn( MFn::kTransform ) ) { if ( optSelected ) { MObject cObj( DoNewVolume( skinnerPath, mDagPath ) ); if ( cObj.isNull() ) { mwarn << "Couldn't create new volume on " << skinnerPath.partialPathName() << " using " << mDagPath.partialPathName() << " as a parent" << std::endl; } else { retList.add( skinnerPath, cObj, true ); } } else { MItDag dIt; for ( dIt.reset( mDagPath ); !dIt.isDone(); dIt.next() ) { dIt.getPath( mDagPath ); if ( mDagPath.childCount() ) { uint nShapes( 0 ); mDagPath.numberOfShapesDirectlyBelow( nShapes ); if ( nShapes == 0U || mDagPath.hasFn( MFn::kJoint ) ) { MObject cObj( DoNewVolume( skinnerPath, mDagPath ) ); if ( cObj.isNull() ) { mwarn << "Couldn't create new volume on " << skinnerPath.partialPathName() << " using " << mDagPath.partialPathName() << " as a parent" << std::endl; } else { retList.add( skinnerPath, cObj, true ); } } } } } } } return retList; }