Ejemplo n.º 1
0
EntityNode& EntityNode::Get( const Helium::Path& path, bool createIfNotExisting )
{
    MFnDagNode dagFn;

    try
    {
        M_IdClassTransform::iterator findItor = s_ClassTransformsMap.find( path.Hash() );
        if( findItor != s_ClassTransformsMap.end() )
        {
            return *findItor->second;
        }
        else if ( createIfNotExisting )
        {
            // we couldn't find it, so create it and return the loaded art class
            Asset::AssetClassPtr assetClass = Asset::AssetClass::LoadAssetClass( path );

            if ( assetClass.ReferencesObject() )
            {
                tstring artFilePath = assetClass->GetPath().Get();

                MObject classTransform = dagFn.create( EntityNode::s_TypeID, assetClass->GetShortName().c_str() );
                dagFn.setDoNotWrite( true );

                EntityNode* artClass = static_cast<EntityNode*>( dagFn.userNode() );

                artClass->m_AssetPath = path;
                artClass->SetArtFilePath( artFilePath.c_str() );

                s_ClassTransformsMap[ path.Hash() ] = artClass;
                artClass->LoadArt();

                return *artClass;
            }
        }
    }
    catch (Helium::Exception& )
    {
        if ( createIfNotExisting )
        {
            MGlobal::displayError( MString("Unable to create EntityNode!") );
        }
    }

    return EntityNode::Null;
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// EntityInstanceNodeCmd::doIt
// execution of the command
//-----------------------------------------------------------------------------
MStatus EntityInstanceNodeCmd::doIt( const MArgList & args )
{
  MStatus stat;

  // parse the command line arguments using the declared syntax
  MArgDatabase argParser( syntax(), args, &stat );

  if( argParser.isFlagSet( ReloadAllArtFlagLong ) )
  {
    EntityNode::UnloadAllArt();
    EntityNode::LoadAllArt();
    return MS::kSuccess;
  }
  else if( argParser.isFlagSet( UnloadAllArtFlagLong ) )
  {
    EntityNode::UnloadAllArt();
    return MS::kSuccess;
  }
  else if( argParser.isFlagSet( UnselectFlag ) )
  {
    MGlobal::executeCommand( "select -all" );

    MSelectionList list;
    MGlobal::getActiveSelectionList( list );
    EntityNode::UnselectAll( list );
    MGlobal::setActiveSelectionList( list );

    return MS::kSuccess;
  }
  else if( argParser.isFlagSet( CreateInstanceFlag ) )
  {
      HELIUM_BREAK();
#pragma TODO( "Reimplement to use the Vault" )
    //File::FileBrowser browserDlg( NULL, -1, "Create Instance" );
    //browserDlg.AddFilter( FinderSpecs::Asset::ENTITY_DECORATION );
    //browserDlg.SetFilterIndex( FinderSpecs::Asset::ENTITY_DECORATION );

    //if ( browserDlg.ShowModal() == wxID_OK )
    //{
    //  tstring fullPath = browserDlg.GetPath();
    //  if ( FileSystem::Exists( fullPath ) )
    //  {
    //    if ( FileSystem::HasExtension( fullPath, FinderSpecs::Asset::ENTITY_DECORATION.GetDecoration() ) )
    //    {
    //      Asset::EntityPtr instance = new Asset::Entity( fullPath );
    //      std::pair< EntityNode*, EntityInstanceNode* >result = EntityNode::CreateInstance( instance );
    //      MFnDependencyNode nodeFn( result.second->thisMObject() );
    //    }
    //  }
    //}

    return MS::kSuccess;
  }
  else if( argParser.isFlagSet( FlattenLong ) )
  {
    EntityNode::FlattenInstances();    
    return MS::kSuccess;
  }

  //
  // the following flags need an EntityNode object to proceed
  //

  MSelectionList selection;
  argParser.getObjects( selection );

  MObject selectedNode;
  selection.getDependNode( 0, selectedNode );

  MFnDependencyNode nodeFn;
  nodeFn.setObject( selectedNode );

  EntityNode* classTransform = NULL;
  if( nodeFn.typeId() == EntityInstanceNode::s_TypeID )
  {
    EntityInstanceNode* node = static_cast< EntityInstanceNode* >( nodeFn.userNode( &stat ) );
    if( !node )
    {
      return MS::kFailure;
    }

    classTransform = &EntityNode::Get( node->GetBackingEntity()->GetEntity()->GetPath() );
    if( *classTransform == EntityNode::Null )
    {
      return MS::kFailure;
    }
  }
  else if ( nodeFn.typeId() == EntityNode::s_TypeID )
  {
    classTransform = static_cast< EntityNode* >( nodeFn.userNode( &stat ) );
    if( !classTransform )
    {
      return MS::kFailure;
    }
  }

  if (argParser.isFlagSet( ReloadArtLong ) )
  {
    classTransform->LoadArt();
  }
  else if( argParser.isFlagSet( SelectEntityAssetFlagLong ) )
  {
    MFnDagNode nodeFn( classTransform->thisMObject() );
    MGlobal::executeCommand( "select -r \"" + nodeFn.fullPathName() + "\"" );
  }

  return MS::kSuccess;
}