Пример #1
0
void EntityNode::ImportNodeAddedCallback( MObject &addedNode, void* param )
{
    MAYA_START_EXCEPTION_HANDLING();

    MObjectArray (*nodeArrays)[NodeArrays::Count] = (MObjectArray (*)[NodeArrays::Count])param;


    MObjectHandle handle( addedNode );
    if( !handle.isValid() ) 
    {
        return;
    }

    MFnDependencyNode nodeFn( addedNode );
    nodeFn.setDoNotWrite( true ); 

    // don't gather certain nodes
    if( addedNode.hasFn( MFn::kReference ) ||
        addedNode.hasFn( MFn::kPartition ) ||
        addedNode.hasFn( MFn::kDisplayLayerManager ) ||
        addedNode.hasFn( MFn::kDisplayLayer ) ||
        addedNode.hasFn( MFn::kRenderLayerManager ) ||
        addedNode.hasFn( MFn::kRenderLayer ) ||
        addedNode.hasFn( MFn::kScript ) ||
        addedNode.hasFn( MFn::kLightLink ) )
    {
        return;
    }

    // don't gather reference objects
    if( nodeFn.isFromReferencedFile() )
    {
        return;
    }

    // don't gather maya-designated "shared" nodes
    if( nodeFn.isShared() )
    {
        return;
    }

#ifdef _DEBUG
    MString name = nodeFn.name();
    MString type = nodeFn.typeName();
    std::cout << " - Importing: " << name.asTChar() << " " << type.asTChar() << std::endl;
#endif

    nodeArrays[ NodeArrays::KeepNodes ]->append( addedNode );

    MAYA_FINISH_EXCEPTION_HANDLING();
}
Пример #2
0
Helium::TUID Maya::GetNodeID( const MObject& node, bool create )
{
  if (node == MObject::kNullObj)
  {
    return Helium::TUID::Null;
  }

  MObject attr = MObject::kNullObj;
  MStatus status = MS::kFailure;
  MFnDependencyNode nodeFn (node);

  if ( create )
  {
    //
    // GUID->TUID legacy handling
    //

    // look for the old GUID attribute
    attr = nodeFn.attribute(MString (s_GUIDAttributeName), &status);

    // if we found it
    if ( status == MS::kSuccess && !attr.isNull() )
    {
      // get the GUID value
      MString str;
      MPlug plug (node, attr);
      status = plug.getValue(str);
      HELIUM_ASSERT( status != MS::kFailure );

      // parse it
      Helium::GUID id;
      bool parsed = id.FromString(str.asTChar());
      HELIUM_ASSERT( parsed );

      // convert it to a TUID and set the new attribute
      Helium::TUID tuid;
      tuid.FromGUID( id );
      status = SetNodeID( node, tuid );
      HELIUM_ASSERT( status != MS::kFailure );

      // check to see if we are a locked node
      bool nodeWasLocked = nodeFn.isLocked();
      if ( nodeWasLocked )
      {
        // turn off any node locking so an attribute can be added
        nodeFn.setLocked( false );
      }

      // unlock the attribute
      status = plug.setLocked( false );
      HELIUM_ASSERT( status != MS::kFailure );

      // remove the attribute
      status = nodeFn.removeAttribute( attr );
      HELIUM_ASSERT( status != MS::kFailure );

      // reset to the prior state of wasLocked
      if ( nodeWasLocked )
      {
        nodeFn.setLocked( nodeWasLocked );
      }
    }
  }

  // look for the TUID attribute
  attr = nodeFn.attribute(MString (s_TUIDAttributeName));

  // retrieve the attribute value (may be empty if we are not creating a new id)
  MString str;
  MPlug plug (node, attr);
  plug.getValue(str);

  // if we don't have an existing id and we should create one
  if ( str.length() == 0 && create )
  {
    // generate a new ID
    Helium::TUID id( Helium::TUID::Generate() );

    // set the new ID value on the node
    if( SetNodeID( node, id ) )
    {
      return id;
    }
    else
    {
      return Helium::TUID::Null;
    }
  }

  // parse the value (this may be null if we did not create the attribute)
  Helium::TUID id;
  id.FromString(str.asTChar());
  return id;
}
Пример #3
0
void EntityNode::LoadArt()
{
    MStatus stat;
    bool callbackRemoved = false;
    if( s_EditNodeAddedCBId != -1 )
    {
        MDGMessage::removeCallback( s_EditNodeAddedCBId );
        s_EditNodeAddedCBId = -1;
        callbackRemoved = true;
    }

    UnloadArt();

    MString artFilePath;
    GetArtFilePath( artFilePath );
    std::cout << "Importing from: " << artFilePath.asTChar() << "..." << std::endl;

    // add the callback to catch all the imported objects
    MObjectArray objectArrays[NodeArrays::Count];
    s_ImportNodeAddedCBId = MDGMessage::addNodeAddedCallback( ImportNodeAddedCallback, kDefaultNodeType, &objectArrays );

    // import stuff
    MFileIO::import( artFilePath, NULL, false );

    // remove the callback
    MDGMessage::removeCallback( s_ImportNodeAddedCBId );

    // add all imported stuff under this guy's transform
    MFnDagNode nodeFn( thisMObject() );
    for( u32 i=0; i<objectArrays[NodeArrays::KeepNodes].length(); ++i )
    {
        if( objectArrays[NodeArrays::KeepNodes][i].isNull() )
        {
            continue;
        }

        MObjectHandle handle( objectArrays[NodeArrays::KeepNodes][i] );
        if ( !handle.isValid() )
        {
            continue;
        }

        // We should be getting only MFnDagNode in here, but just in case
        MFnDagNode dagFn( objectArrays[NodeArrays::KeepNodes][i], &stat );
        if ( stat == MStatus::kSuccess )
        {
            stat = dagFn.setDoNotWrite( true );
        }
        else
        {
            MFnDependencyNode depNodeFn( objectArrays[NodeArrays::KeepNodes][i], &stat );
            stat = depNodeFn.setDoNotWrite( true );
        }

#ifdef _DEBUG
        MString name = dagFn.name();
        MString type = dagFn.typeName();
        std::string nodeTypeStr( objectArrays[NodeArrays::KeepNodes][i].apiTypeStr() );

        if ( name.length() )
        {
            std::cout << " - Importing Child: " << name.asTChar() << " " << type.asTChar() << "(" << nodeTypeStr << ")" << std::endl;
        }
#endif

        AddImportNode( objectArrays[NodeArrays::KeepNodes][i] );   
        nodeFn.addChild( objectArrays[NodeArrays::KeepNodes][i] );
    }

    for( u32 i=0; i<objectArrays[NodeArrays::DeleteNodes].length(); ++i )
    {
        MGlobal::deleteNode( objectArrays[NodeArrays::DeleteNodes][i] );
    }

    MFnDagNode otherFn;
    for( u32 i=0 ; i<nodeFn.childCount(); ++i )
    {
        MObject child = nodeFn.child( i );
        if( !child.hasFn( MFn::kDagNode ) ) 
        {
            continue;
        }

        otherFn.setObject( child );
        if( otherFn.typeId() == EntityNode::s_TypeID )
        {
            MDagModifier mod;
            u32 numChild = otherFn.childCount();
            for( u32 j = 0; j < numChild; ++j )
            {
                stat = mod.reparentNode( otherFn.child( j ), thisMObject() );
            }
            mod.doIt();

            MGlobal::deleteNode( child );
            break;
        }
    }

    std::cout << "Done" << std::endl;

}
Пример #4
0
void EntityNode::AddImportNode( const MObject& object )
{
    MStatus stat;
    MObjectHandle handle( object );
    if( !handle.isValid() )
    {
        return;
    }

    MFnDependencyNode nodeFn( object, &stat );
    MCheckNoErr( stat, "Unable to create depenency node fn set" );
    nodeFn.setDoNotWrite( true );

    //MItDependencyGraph childrenIt (MItDependencyGraph::kUpstream);
    //for ( childrenIt.reset( nodeFn.object() ); !childrenIt.isDone(); childrenIt.next() )
    //{
    //  MFnDependencyNode( childrenIt.item() ).setDoNotWrite( true );
    //}

    MString name = nodeFn.name( &stat );
    MCheckNoErr( stat, "Unable to get node name" );

    if( name == "" )
    {
        return;
    }

    // don't connect dag nodes to the ImportNodes attributeb array
    if( object.hasFn( MFn::kDagNode ) )
    {
        return;
    }

#ifdef _DEBUG
    std::cout << "Adding: " << name.asTChar() << std::endl;
#endif

    //create ImportMessage attrib on the imported object if necessary
    if( !nodeFn.hasAttribute( "ImportMessage", &stat ) )
    {
        MFnMessageAttribute mAttr;
        MObject importMessage = mAttr.create( "ImportMessage", "imp", &stat );
        MCheckNoErr(stat, "Unable to create attr: ImportMessage");

        stat = nodeFn.addAttribute( importMessage );
        MCheckNoErr(stat, "Unable to add attr: ImportNodes"); 
    }

    MPlug importMsg = nodeFn.findPlug( "ImportMessage", &stat );
    MCheckNoErr(stat, "Unable to find attr: ImportMessage");

    MPlug importPlug( thisMObject(), m_ImportNodes );
    u32 currentIdx = importPlug.numConnectedElements();
    MPlug importElement = importPlug.elementByLogicalIndex( currentIdx );

    MDGModifier mod;

    //if it's currently connected, disconnect it
    if( importMsg.isConnected() )
    {
        MPlugArray plugs;
        importMsg.connectedTo( plugs, true, false );
        if( plugs.length() == 1 )
        {
            mod.disconnect( importMsg, plugs[0] );
        }
    }
    stat = mod.connect( importMsg, importElement );
    mod.doIt();
}
Пример #5
0
void EntityNode::SetArtFilePath( const MString& artFilePath )
{
    MPlug plug( thisMObject(), s_ArtFilePath );
    plug.setValue( MString(artFilePath.asTChar()) );
}