Пример #1
0
 void UICanvasTestEdit::RefreshSubmeshes()
 {
     if (!editor_widget_)
         return;
         
     uint numsubmeshes = 0;
     
     Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
     if (scene.get())
     {
         Scene::EntityPtr entity = scene->GetEntity(last_entity_id_);
         if (entity.get())
         {
             OgreRenderer::EC_OgreMesh* mesh = entity->GetComponent<OgreRenderer::EC_OgreMesh>().get();
             OgreRenderer::EC_OgreCustomObject* custom = entity->GetComponent<OgreRenderer::EC_OgreCustomObject>().get();
             if (mesh)
                 numsubmeshes = mesh->GetNumMaterials();
             if (custom)
                 numsubmeshes = custom->GetNumMaterials();
         }
     }
     
     QComboBox* combo = editor_widget_->findChild<QComboBox*>("combo_subobject");    
     if (!combo)
         return;        
     combo->clear();
     for (uint i = 0; i < numsubmeshes; ++i)
         combo->addItem(QString::fromStdString(ToString<uint>(i)));
 }
Пример #2
0
void EC_UICanvas::Refresh()
{
    if (material_.isNull())
        return;
    if (!entity_)
        return;

    OgreRenderer::EC_OgreMesh* meshptr = entity_->GetComponent<OgreRenderer::EC_OgreMesh>().get();
    OgreRenderer::EC_OgreCustomObject* customptr = entity_->GetComponent<OgreRenderer::EC_OgreCustomObject>().get();

    // If have both a mesh & custom object, too weird to handle. Abort.
    if (meshptr && customptr)
        return;

    std::string mat_name = material_->getName();

    // Set material to select submeshes of EC_OgreMesh
    if (meshptr)
    {

        original_materials_.resize(meshptr->GetNumMaterials());
        for (uint i = 0; i < meshptr->GetNumMaterials(); ++i)
        {
            // If this submesh does not have the UICanvas material yet, store the material for restoring later
            {
                std::string orig_mat_name = meshptr->GetMaterialName(i);
                if (orig_mat_name != mat_name)
                    original_materials_[i] = orig_mat_name;
            }

            // Now see if this submesh should have the UICanvas material
            bool set_uicanvas = false;
            for (uint j = 0; j < submeshes_.size(); ++j)
                if (submeshes_[j] == i) set_uicanvas = true;

            if (set_uicanvas)
                meshptr->SetMaterial(i, mat_name);
            else
            {
                // Restore original if we know it
                if (meshptr->GetMaterialName(i) == mat_name)
                {
                    if (!original_materials_[i].empty())
                        meshptr->SetMaterial(i, original_materials_[i]);
                }
            }
        }
    }

    // Set material to select submeshes of EC_OgreCustomObject
    if (customptr)
    {
        // If custom object does not exist as actual committed geometry yet, can't do anything
        if (!customptr->IsCommitted())
            return;

        original_materials_.resize(customptr->GetNumMaterials());
        for (uint i = 0; i < customptr->GetNumMaterials(); ++i)
        {
            // If this submesh does not have the UICanvas material yet, store the material for restoring later
            {
                std::string orig_mat_name = customptr->GetMaterialName(i);
                if (orig_mat_name != mat_name)
                    original_materials_[i] = orig_mat_name;
            }

            // Now see if this submesh should have the UICanvas material
            bool set_uicanvas = false;
            for (uint j = 0; j < submeshes_.size(); ++j)
                if (submeshes_[j] == i) set_uicanvas = true;

            if (set_uicanvas)
                customptr->SetMaterial(i, mat_name);
            else
            {
                // Restore original if we know it
                if (customptr->GetMaterialName(i) == mat_name)
                {
                    if (!original_materials_[i].empty())
                        customptr->SetMaterial(i, original_materials_[i]);
                }
            }
        }
    }
}