ConstObjectPtr LiveScene::readObject( double time ) const { tbb::mutex::scoped_lock l( s_mutex ); if( m_dagPath.length() == 0 && !m_isRoot ) { throw Exception( "IECoreMaya::LiveScene::readObject: Dag path no longer exists!" ); } if( fabs( MAnimControl::currentTime().as( MTime::kSeconds ) - time ) > 1.e-4 ) { throw Exception( "IECoreMaya::LiveScene::readObject: time must be the same as on the maya timeline!" ); } for ( std::vector< CustomReader >::const_reverse_iterator it = customObjectReaders().rbegin(); it != customObjectReaders().rend(); it++ ) { if ( it->m_has( m_dagPath ) ) { return it->m_read( m_dagPath ); } } // if no custom object was detected, we try the general cortex converter unsigned int childCount = 0; m_dagPath.numberOfShapesDirectlyBelow(childCount); for ( unsigned int c = 0; c < childCount; c++ ) { MDagPath childDag = m_dagPath; if( childDag.extendToShapeDirectlyBelow( c ) ) { MFnDagNode fnChildDag(childDag); if ( fnChildDag.isIntermediateObject() ) { continue; } FromMayaShapeConverterPtr shapeConverter = FromMayaShapeConverter::create( childDag ); if( shapeConverter ) { return shapeConverter->convert(); } FromMayaDagNodeConverterPtr dagConverter = FromMayaDagNodeConverter::create( childDag ); if( dagConverter ) { ObjectPtr result = dagConverter->convert(); Camera *cam = runTimeCast< Camera >( result.get() ); if( cam ) { // Cameras still carry the transform when converted from maya, // so we have to remove them after conversion. cam->setTransform( new MatrixTransform( Imath::M44f() ) ); } return result; } } } return IECore::NullObject::defaultNullObject(); }
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; }
bool LiveScene::hasObject() const { tbb::mutex::scoped_lock l( s_mutex ); if( m_isRoot ) { return false; } else if( m_dagPath.length() == 0 && !m_isRoot ) { throw Exception( "IECoreMaya::LiveScene::hasObject: Dag path no longer exists!" ); } for ( std::vector< CustomReader >::const_reverse_iterator it = customObjectReaders().rbegin(); it != customObjectReaders().rend(); it++ ) { if ( it->m_has( m_dagPath ) ) { return true; } } // if no custom object was detected, we try the general cortex converter unsigned int childCount = 0; m_dagPath.numberOfShapesDirectlyBelow(childCount); for ( unsigned int c = 0; c < childCount; c++ ) { MDagPath childDag = m_dagPath; if( childDag.extendToShapeDirectlyBelow( c ) ) { MFnDagNode fnChildDag(childDag); if ( fnChildDag.isIntermediateObject() ) { continue; } FromMayaShapeConverterPtr shapeConverter = FromMayaShapeConverter::create( childDag ); if( shapeConverter ) { return true; } FromMayaDagNodeConverterPtr dagConverter = FromMayaDagNodeConverter::create( childDag ); if( dagConverter ) { return true; } } } return false; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- 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; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- void CVstSelectCoincidentFacesCmd::GetSpecifiedMeshes( MSelectionList &meshList ) { meshList.clear(); MSelectionList optSelectionList; m_undo.ArgDatabase().getObjects( optSelectionList ); MDagPath mDagPath; MObject cObj; for ( MItSelectionList sIt( optSelectionList ); !sIt.isDone(); sIt.next() ) { if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath, cObj ) ) { if ( mDagPath.hasFn( MFn::kMesh ) ) { if ( sIt.hasComponents() || !cObj.isNull() ) { meshList.add( mDagPath, cObj ); } else { mDagPath.extendToShapeDirectlyBelow( 0U ); meshList.add( mDagPath, MObject::kNullObj, true ); } } } } if ( meshList.isEmpty() ) { for ( MItDag dIt( MItDag::kDepthFirst, MFn::kMesh ); !dIt.isDone(); dIt.next() ) { if ( dIt.getPath( mDagPath ) ) { meshList.add( mDagPath, MObject::kNullObj, true ); } } } }
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; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MStatus CVsSkinnerCmd::GetSpecifiedMeshes( const MSelectionList &iList, MSelectionList &oList ) { MStatus retVal( MS::kFailure ); oList.clear(); MDagPath mDagPath; for ( MItSelectionList sIt( iList ); !sIt.isDone(); sIt.next() ) { if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath ) ) { if ( mDagPath.hasFn( MFn::kMesh ) ) { mDagPath.extendToShapeDirectlyBelow( 0 ); oList.add( mDagPath, MObject::kNullObj, true ); retVal = MS::kSuccess; } } } MSelectionList tmpList; for ( MItSelectionList sIt( iList ); !sIt.isDone(); sIt.next() ) { if ( sIt.itemType() == MItSelectionList::kDagSelectionItem && sIt.getDagPath( mDagPath ) ) { if ( FindMeshesInHierarchy( mDagPath, tmpList ) ) { oList.merge( tmpList ); retVal = MS::kSuccess; } } } return retVal; }
ConstObjectPtr LiveScene::readAttribute( const Name &name, double time ) const { if ( !m_isRoot && m_dagPath.length() == 0 ) { throw Exception( "IECoreMaya::LiveScene::readAttribute: Dag path no longer exists!" ); } tbb::mutex::scoped_lock l( s_mutex ); if ( !m_isRoot ) { if( name == SceneInterface::visibilityName ) { bool visible = true; MStatus st; MFnDagNode dagFn( m_dagPath ); MPlug visibilityPlug = dagFn.findPlug( MPxTransform::visibility, &st ); if( st ) { visible = visibilityPlug.asBool(); } if( visible ) { MDagPath childDag; // find an object that's either a SceneShape, or has a cortex converter and check its visibility: unsigned int childCount = 0; m_dagPath.numberOfShapesDirectlyBelow(childCount); for ( unsigned int c = 0; c < childCount; c++ ) { MDagPath d = m_dagPath; if( d.extendToShapeDirectlyBelow( c ) ) { MFnDagNode fnChildDag(d); if( fnChildDag.typeId() == SceneShape::id ) { childDag = d; break; } if ( fnChildDag.isIntermediateObject() ) { continue; } FromMayaShapeConverterPtr shapeConverter = FromMayaShapeConverter::create( d ); if( shapeConverter ) { childDag = d; break; } FromMayaDagNodeConverterPtr dagConverter = FromMayaDagNodeConverter::create( d ); if( dagConverter ) { childDag = d; break; } } } if( childDag.isValid() ) { MFnDagNode dagFn( childDag ); MPlug visibilityPlug = dagFn.findPlug( MPxSurfaceShape::visibility, &st ); if( st ) { visible = visibilityPlug.asBool(); } } } return new BoolData( visible ); } } else if( name == SceneInterface::visibilityName ) { return new BoolData( true ); } std::vector< CustomAttributeReader > &attributeReaders = customAttributeReaders(); for ( std::vector< CustomAttributeReader >::const_reverse_iterator it = attributeReaders.rbegin(); it != attributeReaders.rend(); ++it ) { ConstObjectPtr attr = it->m_read( m_dagPath, name ); if( !attr ) { continue; } return attr; } if( strstr( name.c_str(), "user:"******"ieAttr_" + name.string().substr(5) ).c_str(), false, &st ); if( st ) { FromMayaConverterPtr plugConverter = FromMayaPlugConverter::create( attrPlug ); if( !plugConverter ) { return IECore::NullObject::defaultNullObject(); } return plugConverter->convert(); } } return IECore::NullObject::defaultNullObject(); }