Skip to content

Commit

Permalink
Merge branch 'gz-sim9' into athenaz/texsize_tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
azeey authored Sep 5, 2024
2 parents f4b807e + f8f8a80 commit 391726a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ GlobalIlluminationCiVct::~GlobalIlluminationCiVct()
}

/////////////////////////////////////////////////
void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
bool GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
REQUIRES(this->dataPtr->serviceMutex)
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
{
return;
return false;
}

// assume there is only one engine loaded
Expand All @@ -194,24 +194,25 @@ void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
{
gzerr << "Internal error: failed to load engine [" << engineName
<< "]. GlobalIlluminationCiVct plugin won't work." << std::endl;
return;
return false;
}

if (engine->SceneCount() == 0)
return;
return false;

// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);
if (!scene)
{
gzerr << "Internal error: scene is null." << std::endl;
return;
return false;
}

if (!scene->IsInitialized() || scene->VisualCount() == 0)
if (!scene->IsInitialized() || scene->VisualCount() == 0 ||
scene->LightCount() == 0)
{
return;
return false;
}

// Create visual
Expand All @@ -225,6 +226,7 @@ void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()
<< std::endl;

gz::gui::App()->findChild<gz::gui::MainWindow *>()->removeEventFilter(this);
return false;
}
else
{
Expand Down Expand Up @@ -254,6 +256,7 @@ void GlobalIlluminationCiVct::LoadGlobalIlluminationCiVct()

this->OnRefreshCamerasImpl();
}
return true;
}

/// \brief XML helper to retrieve values and handle errors
Expand Down Expand Up @@ -358,9 +361,7 @@ void GlobalIlluminationCiVct::LoadConfig(
const tinyxml2::XMLElement *_pluginElem)
{
if (this->title.empty())
this->title = "Global Illumination (VCT)";

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
this->title = "Global Illumination (CI VCT)";

if (auto elem = _pluginElem->FirstChildElement("enabled"))
{
Expand Down Expand Up @@ -447,15 +448,25 @@ bool GlobalIlluminationCiVct::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == gz::gui::events::Render::kType)
{
// This event is called in Scene3d's RenderThread, so it's safe to make
// This event is called in the render thread, so it's safe to make
// rendering calls here

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
if (!this->dataPtr->initialized)
{
this->LoadGlobalIlluminationCiVct();
if (this->LoadGlobalIlluminationCiVct())
{
this->SetEnabled(this->dataPtr->enabled);
this->SetBounceCount(this->dataPtr->bounceCount);
this->SetHighQuality(this->dataPtr->highQuality);
this->SetAnisotropic(this->dataPtr->anisotropic);
this->SetDebugVisualizationMode(this->dataPtr->debugVisMode);
this->EnabledChanged();
this->LightingChanged();
this->DebugVisualizationModeChanged();
}
}

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
if (this->dataPtr->gi)
{
if (!this->dataPtr->visualDirty && !this->dataPtr->gi->Enabled() &&
Expand Down Expand Up @@ -563,10 +574,6 @@ bool GlobalIlluminationCiVct::eventFilter(QObject *_obj, QEvent *_event)
this->dataPtr->resetRequested = false;
}
}
else
{
gzerr << "GI pointer is not set" << std::endl;
}
}

// Standard event processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
public: bool eventFilter(QObject *_obj, QEvent *_event) override;

/// \brief Load the scene and attach LidarVisual to the scene
public: void LoadGlobalIlluminationCiVct();
/// \return True if GI CIVCT is loaded successfully, false otherwise.
public: bool LoadGlobalIlluminationCiVct();

/// \brief Set debug visualization mode GlogbalIllumination
/// \param[in] _mode Index of selected debug visualization mode
Expand Down
51 changes: 34 additions & 17 deletions src/gui/plugins/global_illumination_vct/GlobalIlluminationVct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ GlobalIlluminationVct::~GlobalIlluminationVct()
}

/////////////////////////////////////////////////
void GlobalIlluminationVct::LoadGlobalIlluminationVct()
bool GlobalIlluminationVct::LoadGlobalIlluminationVct()
REQUIRES(this->dataPtr->serviceMutex)
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
{
return;
return false;
}

// assume there is only one engine loaded
Expand All @@ -188,27 +188,28 @@ void GlobalIlluminationVct::LoadGlobalIlluminationVct()
{
gzerr << "Internal error: failed to load engine [" << engineName
<< "]. GlobalIlluminationVct plugin won't work." << std::endl;
return;
return false;
}

if (engine->SceneCount() == 0)
return;
return false;

// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);
if (!scene)
{
gzerr << "Internal error: scene is null." << std::endl;
return;
return false;
}

if (!scene->IsInitialized() || scene->VisualCount() == 0)
if (!scene->IsInitialized() || scene->VisualCount() == 0 ||
scene->LightCount() == 0)
{
return;
return false;
}

// Create lidar visual
// Create GI
gzdbg << "Creating GlobalIlluminationVct" << std::endl;

auto root = scene->RootVisual();
Expand All @@ -219,6 +220,7 @@ void GlobalIlluminationVct::LoadGlobalIlluminationVct()
<< std::endl;

gz::gui::App()->findChild<gz::gui::MainWindow *>()->removeEventFilter(this);
return false;
}
else
{
Expand All @@ -228,6 +230,7 @@ void GlobalIlluminationVct::LoadGlobalIlluminationVct()
this->dataPtr->scene = scene;
this->dataPtr->initialized = true;
}
return true;
}

/// \brief XML helper to retrieve values and handle errors
Expand Down Expand Up @@ -319,8 +322,6 @@ void GlobalIlluminationVct::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
if (this->title.empty())
this->title = "Global Illumination (VCT)";

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);

if (auto elem = _pluginElem->FirstChildElement("enabled"))
{
GetXmlBool(elem, this->dataPtr->enabled);
Expand Down Expand Up @@ -394,15 +395,35 @@ bool GlobalIlluminationVct::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == gz::gui::events::Render::kType)
{
// This event is called in Scene3d's RenderThread, so it's safe to make
// This event is called in render thread, so it's safe to make
// rendering calls here

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
if (!this->dataPtr->initialized)
{
this->LoadGlobalIlluminationVct();
if (this->LoadGlobalIlluminationVct())
{
// update properties and notify QML
this->SetEnabled(this->dataPtr->enabled);
this->SetResolutionX(this->dataPtr->resolution[0]);
this->SetResolutionY(this->dataPtr->resolution[1]);
this->SetResolutionZ(this->dataPtr->resolution[2]);
this->SetOctantCountX(this->dataPtr->octantCount[0]);
this->SetOctantCountY(this->dataPtr->octantCount[1]);
this->SetOctantCountZ(this->dataPtr->octantCount[2]);
this->SetBounceCount(this->dataPtr->bounceCount);
this->SetHighQuality(this->dataPtr->highQuality);
this->SetAnisotropic(this->dataPtr->anisotropic);
this->SetConserveMemory(this->dataPtr->conserveMemory);
this->SetThinWallCounter(this->dataPtr->thinWallCounter);
this->SetDebugVisualizationMode(this->dataPtr->debugVisMode);
this->EnabledChanged();
this->LightingChanged();
this->SettingsChanged();
this->DebugVisualizationModeChanged();
}
}

std::lock_guard<std::mutex> lock(this->dataPtr->serviceMutex);
if (this->dataPtr->gi)
{
if (this->dataPtr->resetVisual)
Expand Down Expand Up @@ -485,10 +506,6 @@ bool GlobalIlluminationVct::eventFilter(QObject *_obj, QEvent *_event)
this->dataPtr->debugVisualizationDirty = false;
}
}
else
{
gzerr << "GI pointer is not set" << std::endl;
}
}

// Standard event processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ inline namespace GZ_SIM_VERSION_NAMESPACE
public: bool eventFilter(QObject *_obj, QEvent *_event) override;

/// \brief Load the scene and attach LidarVisual to the scene
public: void LoadGlobalIlluminationVct();
/// \return True if GI VCT is loaded successfully, false otherwise.
public: bool LoadGlobalIlluminationVct();

/// \brief Set debug visualization mode GlogbalIllumination
/// \param[in] _mode Index of selected debug visualization mode
Expand Down

0 comments on commit 391726a

Please sign in to comment.