Exemplo n.º 1
0
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 );
}
Exemplo n.º 2
0
void EntityInstanceNode::SetBackingEntity( const Asset::EntityInstancePtr& entity )
{
    m_Entity = entity;
    m_UID = m_Entity->m_ID;

    m_Plug.setAttribute( s_ArtFilePath );
    m_Plug.setValue( MString (entity->GetEntity()->GetPath().c_str()) );

    Math::Matrix4 gm = m_Entity->m_GlobalTransform * s_RelativeTransform.Inverted();
    MMatrix mat;

    gm.t.x *= 100.0f;
    gm.t.y *= 100.0f;
    gm.t.z *= 100.0f;

    for (int i=0; i<4; i++)
    {
        for (int j=0; j<4; j++)
        {
            mat[i][j] = gm[i][j];
        }
    }

    MFnTransform transFn( thisMObject() );
    MTransformationMatrix transMat (mat);
    transFn.set(transMat);

    AddAttributeChangedCallback();
}