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))); }
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); } } } }
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"); } } }
void MumbleVoipModule::Update(f64 frametime) { if (!link_plugin_->IsRunning()) return; time_from_last_update_ms_ += 1000*frametime; if (time_from_last_update_ms_ < UPDATE_TIME_MS_) return; time_from_last_update_ms_ = 0; RexLogic::RexLogicModule *rex_logic_module = dynamic_cast<RexLogic::RexLogicModule *>(framework_->GetModuleManager()->GetModule(Foundation::Module::MT_WorldLogic).lock().get()); if (!rex_logic_module) return; RexLogic::AvatarPtr avatar = rex_logic_module->GetAvatarHandler(); if (avatar) { Scene::EntityPtr entity = avatar->GetUserAvatar(); if (!entity) return; const Foundation::ComponentInterfacePtr &placeable_component = entity->GetComponent("EC_OgrePlaceable"); if (placeable_component) { OgreRenderer::EC_OgrePlaceable *ogre_placeable = checked_static_cast<OgreRenderer::EC_OgrePlaceable *>(placeable_component.get()); Quaternion q = ogre_placeable->GetOrientation(); Vector3df position_vector = ogre_placeable->GetPosition(); Vector3df front_vector = q*Vector3df(1,0,0); Vector3df top_vector(0,0,1); link_plugin_->SetAvatarPosition(position_vector, front_vector, top_vector); } } Scene::EntityPtr camera = rex_logic_module->GetCameraEntity().lock(); if (camera) { const Foundation::ComponentInterfacePtr &placeable_component = camera->GetComponent("EC_OgrePlaceable"); if (placeable_component) { OgreRenderer::EC_OgrePlaceable *ogre_placeable = checked_static_cast<OgreRenderer::EC_OgrePlaceable *>(placeable_component.get()); Quaternion q = ogre_placeable->GetOrientation(); Vector3df position_vector = ogre_placeable->GetPosition(); Vector3df front_vector = q*Vector3df(1,0,0); Vector3df top_vector(0,0,1); link_plugin_->SetCameraPosition(position_vector, front_vector, top_vector); } } link_plugin_->SendData(); }
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); } } } }
void Water::CreateWaterGeometry(float height) { // Here we assume that there is only one water in one scene (and it is ocean). if ( !GetActiveWater().expired()) RemoveWaterGeometry(); Scene::ScenePtr active_scene = owner_->GetFramework()->GetDefaultWorldScene(); Scene::EntityPtr entity = active_scene->CreateEntity(active_scene->GetNextFreeId()); entity->AddComponent(owner_->GetFramework()->GetComponentManager()->CreateComponent(EC_Water::NameStatic())); activeWaterComponent_ = entity->GetComponent<EC_Water>().get(); activeWaterComponent_->SetWaterHeight(height); activeWaterEntity_ = entity; emit WaterCreated(); }
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(); } }
void Water::RemoveWaterGeometry() { // Adjust that we are removing correct water if( GetActiveWater().expired()) return; // Remove component if ( activeWaterComponent_ != 0) { Scene::EntityPtr entity = activeWaterEntity_.lock(); entity->RemoveComponent(entity->GetComponent(EC_Water::NameStatic())); activeWaterComponent_ = 0; } // Remove entity from scene Scene::ScenePtr active_scene = owner_->GetFramework()->GetDefaultWorldScene(); active_scene->RemoveEntity(activeWaterEntity_.lock()->GetId()); activeWaterEntity_.reset(); emit WaterRemoved(); }