Example #1
0
Scene::EntityWeakPtr Water::GetActiveWater()
{
    Scene::ScenePtr scene = owner_->GetFramework()->GetDefaultWorldScene();

    // Check that is current water entity still valid.

    if ( !activeWaterEntity_.expired() )
        if(scene->GetEntity(activeWaterEntity_.lock()->GetId()).get() != 0)
            return activeWaterEntity_;

    // Current is not valid so search new, takes first entity which has water

    for(Scene::SceneManager::iterator iter = scene->begin();
            iter != scene->end(); ++iter)
    {
        Scene::Entity &entity = **iter;
        activeWaterComponent_ = entity.GetComponent<EC_Water>().get();
        if (activeWaterComponent_ != 0)
        {
            activeWaterEntity_ = scene->GetEntity(entity.GetId());

            if ( !activeWaterEntity_.expired())
                return activeWaterEntity_;
        }
    }

    // There was any water entity so reset it to null state.

    activeWaterEntity_.reset();
    activeWaterComponent_ = 0;
    return Scene::EntityWeakPtr();
}
Example #2
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)));
 }
Example #3
0
    void UICanvasTestEdit::UnbindCanvas()
    {
        Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
        if (scene.get())
        {
            Scene::EntityPtr entity = scene->GetEntity(last_entity_id_);
            if (entity.get())
            {
                EC_UICanvas* ec = entity->GetComponent<EC_UICanvas>().get();
                if (ec)
                {
                    // Get proxy widget from 3D canvas
                    boost::shared_ptr<QtUI::UICanvas> canvas = ec->GetCanvas();
                    QGraphicsProxyWidget *proxy_widget = canvas->Remove3DProxyWidget();
                    proxy_widget->widget()->setWindowFlags(Qt::Dialog);

                    ec->ClearSubmeshes();
                    
                    // Remove proxy widget from local QList so it we wont try to delete in decostructor
                    proxy_widget_canvases_.removeOne(canvas);

                    // Get QtModule and delete the 3D canvas
                    Foundation::ModuleSharedPtr qt_module = framework_->GetModuleManager()->GetModule("QtModule").lock();
                    QtUI::QtModule *qt_ui = dynamic_cast<QtUI::QtModule*>(qt_module.get());
                    if (qt_ui)
                        qt_ui->DeleteCanvas(canvas->GetID());

                    // Add proxy widget back to 2D scene
                    boost::shared_ptr<UiServices::UiModule> ui_module = framework_->GetModuleManager()->GetModule<UiServices::UiModule>(Foundation::Module::MT_UiServices).lock();
                    ui_module->GetSceneManager()->AddProxyWidget((UiServices::UiProxyWidget *)proxy_widget);

                }
            }
        }
    }
Example #4
0
        CameraID CameraHandler::CreateCustomCamera()
        {
            Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
            if (!scene)
                return -1;

            Scene::EntityPtr cam_entity = scene->CreateEntity(scene->GetNextFreeId());
            if (!cam_entity.get())
                return -1;

            cam_entity->AddComponent(framework_->GetComponentManager()->CreateComponent(OgreRenderer::EC_OgrePlaceable::TypeNameStatic()));
            cam_entity->AddComponent(framework_->GetComponentManager()->CreateComponent(OgreRenderer::EC_OgreCamera::TypeNameStatic()));
            scene->EmitEntityCreated(cam_entity);
            Foundation::ComponentInterfacePtr component_placable = cam_entity->GetComponent(OgreRenderer::EC_OgrePlaceable::TypeNameStatic());
            OgreRenderer::EC_OgreCamera *ec_camera = cam_entity->GetComponent<OgreRenderer::EC_OgreCamera>().get();
            
            if (!component_placable.get() || !ec_camera)
                return -1;
            ec_camera->SetPlaceable(component_placable);
            
            camera_count_++;
            id_to_cam_entity_[camera_count_] = cam_entity.get();

            return camera_count_;
        }
Example #5
0
 void NoteCardManager::Update(f64 frametime)
 {
     if (!entity_create_pending_)
         return;
     // See if we have a potential entity to check
     if (new_entity_id_)
     {
         NoteCardModule::LogInfo("Checking new entity");
         Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
         Scene::EntityPtr entity;
         if (scene)
             entity = scene->GetEntity(new_entity_id_);
         if (entity)
         {
             boost::shared_ptr<RexLogic::EC_NetworkPosition> netpos = entity->GetComponent<RexLogic::EC_NetworkPosition>();
             if (netpos)
             {
                 // See if error in position is small enough to be a match
                 // Note: for some reason we can't trust the sim to give the Z position even remotely the same
                 if ((fabs(netpos->position_.x - new_entity_pos_.x) < 0.001f) &&
                     (fabs(netpos->position_.y - new_entity_pos_.y) < 0.001f) &&
                     (fabs(netpos->position_.z - new_entity_pos_.z) < 1.0f))
                 {
                     // Yes, it has to be that entity!
                     entity_create_pending_ = false;
                     // Create a new notecard EC to the entity and set its initial title, will cause sync to network
                     entity->AddComponent(framework_->GetComponentManager()->CreateComponent(EC_NoteCard::TypeNameStatic()));
                     boost::shared_ptr<EC_NoteCard> notecard = entity->GetComponent<EC_NoteCard>();
                     if (notecard)
                         notecard->SetTitle(QApplication::translate("NoteCardManager", "New notecard").toStdString());
                     else
                         NoteCardModule::LogError("Could not create notecard component to entity");
                 }
                 else
                 {
                     NoteCardModule::LogInfo("Distance was too great");
                     std::cout << netpos->position_.x << " " << netpos->position_.y << " " << netpos->position_.z << std::endl;
                     std::cout << "VS: " << new_entity_pos_.x << " " << new_entity_pos_.y << " " << new_entity_pos_.z << std::endl;
                 }
             }
             else
                 NoteCardModule::LogInfo("No networkposition EC");
         }
         new_entity_id_ = 0;
     }
     // If didn't succeed yet, increment time and see if it's time to give up
     if (entity_create_pending_)
     {
         entity_wait_time_ += frametime;
         if (entity_wait_time_ >= entity_max_wait_time_)
         {
             entity_create_pending_ = false;
             NoteCardModule::LogWarning("Wait time expired, notecard entity was not created");
         }
     }
 }
Example #6
0
    void UICanvasTestEdit::BindCanvas()
    {
        // Get ui elements
        QComboBox* combo_s = editor_widget_->findChild<QComboBox*>("combo_subobject");    
        if (!combo_s)
            return;    
        QComboBox* combo_c = editor_widget_->findChild<QComboBox*>("combo_canvas");    
        if (!combo_c)
            return;

        // Get QtModule
        Foundation::ModuleSharedPtr qt_module = framework_->GetModuleManager()->GetModule("QtModule").lock();
        QtUI::QtModule *qt_ui = dynamic_cast<QtUI::QtModule*>(qt_module.get());

        // Get UiModule
        boost::shared_ptr<UiServices::UiModule> ui_module = framework_->GetModuleManager()->GetModule<UiServices::UiModule>(Foundation::Module::MT_UiServices).lock();

        // Get Scene
        Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
        if (scene.get())
        {
            Scene::EntityPtr entity = scene->GetEntity(last_entity_id_);
            if (entity.get())
            {
                uint submesh = combo_s->currentIndex();
                QString proxy_widget_name = combo_c->currentText();
                boost::shared_ptr<QtUI::UICanvas> canvas;
                
                // Get proxy widget for selected name
                UiServices::UiProxyWidget *proxy_widget = ui_module->GetSceneManager()->GetProxyWidget(proxy_widget_name);
                if (proxy_widget)
                {
                    ui_module->GetSceneManager()->RemoveProxyWidgetFromScene(proxy_widget);
                    proxy_widget->widget()->setWindowFlags(Qt::Widget);
                    canvas = qt_ui->CreateCanvas(QtUI::UICanvas::Internal).lock();
                    canvas->SetSize(proxy_widget->size().width(), proxy_widget->size().height());
                    canvas->SetPosition(100,100);
                    canvas->AddProxyWidget(proxy_widget);
                    canvas->Show();
                    proxy_widget->show();

                    proxy_widget_canvases_.append(canvas);

                    EC_UICanvas* ec = dynamic_cast<EC_UICanvas*>(qt_ui->CreateEC_UICanvasToEntity(entity.get(), canvas).get());
                    if (ec)
                        ec->SetSubmeshes(submesh);
                }
            }
        }
                
    }
Example #7
0
    void EnvironmentModule::CreateSky()
    {
        sky_ = SkyPtr(new Sky(this));
        Scene::ScenePtr scene = GetFramework()->GetDefaultWorldScene();
        Scene::EntityPtr sky_entity = scene->CreateEntity(GetFramework()->GetDefaultWorldScene()->GetNextFreeId());
        sky_entity->AddComponent(GetFramework()->GetComponentManager()->CreateComponent("EC_OgreSky"));
        scene->EmitEntityCreated(sky_entity);
        sky_->FindCurrentlyActiveSky();

        if (!GetEnvironmentHandler()->IsCaelum())
            sky_->CreateDefaultSky();

        if ( environment_editor_ != 0 )
             environment_editor_->InitSkyTabWindow();
    }
Example #8
0
    void EnvironmentModule::CreateTerrain()
    {
        terrain_ = TerrainPtr(new Terrain(this));

        Scene::ScenePtr scene = GetFramework()->GetDefaultWorldScene();
        Scene::EntityPtr entity = scene->CreateEntity(GetFramework()->GetDefaultWorldScene()->GetNextFreeId());
        entity->AddComponent(GetFramework()->GetComponentManager()->CreateComponent("EC_Terrain"));
        scene->EmitEntityCreated(entity);
        terrain_->FindCurrentlyActiveTerrain();
        
        if ( environment_editor_ != 0 )
        {
            environment_editor_->InitTerrainTabWindow();
            environment_editor_->InitTerrainTextureTabWindow();
        }
        
    }
Example #9
0
 void NoteCardManager::SelectNoteCard()
 {
     Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
     if (!scene)
         return;
     NoteCardTreeWidgetItem* item = dynamic_cast<NoteCardTreeWidgetItem*>(tree_->currentItem());
     if (item)
     {
         entity_id_t id = item->GetId();
         
         Scene::EntityPtr entity = scene->GetEntity(id);
         if (!entity)
             return;
         boost::shared_ptr<EC_NoteCard> card = entity->GetComponent<EC_NoteCard>();
         if (card)
         {
             // Show the notecard if it was hidden
             card->Show();
         }
     }
 }
Example #10
0
 void NoteCardManager::OnEntityModified(entity_id_t id)
 {
     if (!tree_)
         return;
     
     Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
     if (!scene)
         return;
     Scene::EntityPtr entity = scene->GetEntity(id);
     if (!entity)
         return;
     boost::shared_ptr<EC_NoteCard> card = entity->GetComponent<EC_NoteCard>();
     // If entity no longer has the notecard component, trigger remove from list instead
     //! \todo this is triggered any time any entity with any serializable EC is modified. A bit unnecessary
     if (!card)
     {
         OnEntityRemoved(id);
         return;
     }
     // See if we already have this entity on our list
     for (uint i = 0; i < tree_->topLevelItemCount(); ++i)
     {
         NoteCardTreeWidgetItem* item = dynamic_cast<NoteCardTreeWidgetItem*>(tree_->topLevelItem(i));
         if (item)
         {
             // Update title from the EC
             if (item->GetId() == id)
             {
                 item->setText(0, QString::fromStdString(card->GetTitle()));
                 return;
             }
         }
     }
     // If not, create new
     NoteCardTreeWidgetItem* item = new NoteCardTreeWidgetItem(id);
     item->setText(0, QString::fromStdString(card->GetTitle()));
     tree_->addTopLevelItem(item);
 }
Console::CommandResult ScenePersistenceModule::StartPersistenceCommand(const StringVector &params)
{
    StartPersistingStorage("world.db");

    const Scene::ScenePtr scene = framework_->GetDefaultWorldScene();
    connect(scene.get(), SIGNAL(EntityCreated(Scene::Entity*, AttributeChange::Type)), this,
            SLOT(EntityCreated(Scene::Entity*, AttributeChange::Type)));

    connect(scene.get(), SIGNAL(EntityRemoved(Scene::Entity*, AttributeChange::Type)), this,
            SLOT(EntityRemoved(Scene::Entity*, AttributeChange::Type)));

    connect(scene.get(), SIGNAL(ComponentAdded(Scene::Entity*, IComponent*, AttributeChange::Type)), this,
            SLOT(ComponentAdded(Scene::Entity*, IComponent*, AttributeChange::Type)));

    connect(scene.get(), SIGNAL(ComponentRemoved(Scene::Entity*, IComponent*, AttributeChange::Type)), this,
            SLOT(ComponentRemoved(Scene::Entity*, IComponent*, AttributeChange::Type)));

    connect(scene.get(), SIGNAL(AttributeChanged(IComponent*, IAttribute*, AttributeChange::Type)), this,
            SLOT(AttributeChanged(IComponent*, IAttribute*, AttributeChange::Type)));

    return Console::ResultSuccess();
}