std::pair< EntityNode*, EntityInstanceNode*> EntityNode::CreateInstance( const Asset::EntityInstancePtr& entity ) { EntityNode* artClass = &Get( entity->GetEntity()->GetPath() ); M_EntityNode::iterator instItor = artClass->m_Instances.find( entity->m_ID ); EntityInstanceNode* entityNode = NULL; if( instItor == artClass->m_Instances.end() ) { MFnDagNode nodeFn; MObject instanceObject = nodeFn.create( EntityInstanceNode::s_TypeID, entity->GetName().c_str() ); nodeFn.setDoNotWrite( true ); entityNode = static_cast< EntityInstanceNode* >( nodeFn.userNode() ); artClass->m_Instances[ entity->m_ID ] = entityNode; entityNode->SetBackingEntity( entity ); entityNode->Show( *artClass ); } else { entityNode = instItor->second; entityNode->SetBackingEntity( entity ); } return std::pair< EntityNode*, EntityInstanceNode* >( artClass, entityNode ); }
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; }