Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed light entity number #1818

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/SdfEntityCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,19 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Light *_light)
this->dataPtr->ecm->CreateComponent(lightEntity,
components::LightType(convert(_light->Type())));

// Light Visual
Entity lightVisualEntity = this->dataPtr->ecm->CreateEntity();
this->dataPtr->ecm->CreateComponent(lightVisualEntity, components::Visual());
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::Pose());
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::Name(_light->Name() + "Visual"));
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::CastShadows(false));
this->dataPtr->ecm->CreateComponent(lightVisualEntity,
components::Transparency(false));
this->SetParent(lightVisualEntity, lightEntity);

return lightEntity;
}

Expand Down
39 changes: 19 additions & 20 deletions src/rendering/RenderUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1187,27 +1187,26 @@ void RenderUtil::Update()

for (const auto &light : newLights)
{
this->dataPtr->sceneManager.CreateLight(std::get<0>(light),
std::get<1>(light), std::get<2>(light), std::get<3>(light));

// TODO(anyone) This needs to be updated for when sensors and GUI use
// the same scene
// create a new id for the light visual, if we're not loading sensors
if (!this->dataPtr->enableSensors)
auto newLightRendering = this->dataPtr->sceneManager.CreateLight(
std::get<0>(light),
std::get<1>(light),
std::get<2>(light),
std::get<3>(light));

if (newLightRendering)
{
rendering::VisualPtr lightVisual =
this->dataPtr->sceneManager.CreateLightVisual(
std::get<0>(light) + 1,
std::get<1>(light),
std::get<2>(light),
std::get<0>(light));
this->dataPtr->matchLightWithVisuals[std::get<0>(light)] =
std::get<0>(light) + 1;
}
else
{
auto attempts = 100000u;
for (auto i = 0u; i < attempts; ++i)
{
Entity id = std::numeric_limits<uint64_t>::min() + i;
if (!this->dataPtr->sceneManager.HasEntity(id))
{
rendering::VisualPtr lightVisual =
this->dataPtr->sceneManager.CreateLightVisual(
id, std::get<1>(light), std::get<2>(light), std::get<0>(light));
this->dataPtr->matchLightWithVisuals[std::get<0>(light)] = id;
break;
}
}
ignerr << "Failed to create light" << std::endl;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,13 @@ rendering::LightPtr SceneManager::CreateLight(Entity _id,
if (!this->dataPtr->scene)
return rendering::LightPtr();

if (this->HasEntity(_id))
{
ignerr << "Light with Id: [" << _id << "] can not be create there is "
"another entity with the same entity number" << std::endl;
return nullptr;
}

if (this->dataPtr->lights.find(_id) != this->dataPtr->lights.end())
{
ignerr << "Light with Id: [" << _id << "] already exists in the scene"
Expand Down