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

Plugin to spawn lights #587

Merged
merged 26 commits into from
Feb 18, 2021
Merged

Plugin to spawn lights #587

merged 26 commits into from
Feb 18, 2021

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Jan 27, 2021

I created a plugin to spawn lights in ignition-gazebo.

lights_spawn

I have some questions and issues:

  • Do you want to see the visual in the component inspector ? the same way we are visualizing link, collisions or lights for models ?
  • I'm getting sometimes this error:
terminate called after throwing an instance of 'Ogre::RenderingAPIException'
 what():  OGRE EXCEPTION(3:RenderingAPIException): Fragment Program 537068800PixelShader_ps failed to compile. See compile log above for details. in GLSLShader::compile at /var/lib/jenkins/workspace/ogre-2.1-debbuilder/repo/RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp (line 305)

Signed-off-by: ahcorde ahcorde@gmail.com

Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde self-assigned this Jan 27, 2021
@github-actions github-actions bot added the 🏢 edifice Ignition Edifice label Jan 27, 2021
@osrf-triage osrf-triage added this to Inbox in Core development Jan 27, 2021
@iche033
Copy link
Contributor

iche033 commented Jan 28, 2021

Do you want to see the visual in the component inspector ? the same way we are visualizing link, collisions or lights for models ?

you mean the light visuals? I think it's fine to leave them out

I'm getting sometimes this error:

I see this when spawning a directional light. It could be that we can't have more than one directional lights in the scene. If that's the case, we can print a warning that only 1 directional light is supported for now

Where and how is the best place to create the LightVisual ? Right now it's in the RenderUtil.cc but when I remove the light from Gazebo in the component inspector the visual it's still there. Probably I should attach the Visual to the Light. Is this possible ?

yes you can attach LightVisual to Light. Since the they are all ign-rendering nodes, you can just do light->AddChild(lightVisual)

@chapulina chapulina moved this from Inbox to In review in Core development Jan 28, 2021
@chapulina chapulina added close the gap Features from Gazebo-classic GUI Gazebo's graphical interface (not pure Ignition GUI) labels Jan 28, 2021
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Jan 28, 2021

@iche033 I improved the implementation.

The issue with the lights is the following: When point lights and directionals are mixed the segfault appears

error2

error1

Signed-off-by: ahcorde <ahcorde@gmail.com>
@iche033
Copy link
Contributor

iche033 commented Jan 29, 2021

ok narrowed the the point vs directional light issue a bit more. Disabling the point light shadows makes them work now:

--- a/src/gui/plugins/lights/Lights.cc
+++ b/src/gui/plugins/lights/Lights.cc
@@ -86,7 +86,7 @@ void Lights::OnMode(const QString &_mode)
                                  "<sdf version=\"1.6\">"
                                  "<light type='point' name='pointlight'>"
                                    "<pose>0 0 2 0 0 0</pose>"
-                                   "<cast_shadows>true</cast_shadows>"
+                                   "<cast_shadows>false</cast_shadows>"
                                    "<diffuse>0.5 0.5 0.5 1</diffuse>"
                                    "<specular>0.5 0.5 0.5 1</specular>"
                                    "<attenuation>"

Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde ahcorde marked this pull request as ready for review January 29, 2021 06:56
@ahcorde ahcorde added the needs upstream release Blocked by a release of an upstream library label Jan 29, 2021
@ahcorde
Copy link
Contributor Author

ahcorde commented Jan 29, 2021

@iche033 It's ready for a review, thank you for the catch with the lights.

include/ignition/gazebo/components/LightType.hh Outdated Show resolved Hide resolved
else if (_light->Type() == sdf::LightType::SPOT)
{
this->dataPtr->ecm->CreateComponent(lightEntity,
components::LightType(std::string("Spot")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating a convert function from sdf::LightType to std::string in Conversions.hh? It would be better to reuse the same logic in many places. I'm concerned that different plugins may use different strings (i.e. spot, SPOT...).

I can even see this function living in libSDFormat.

Also, I think that we should store the types as lowercase. The GUI can capitalize them as needed.

src/SdfEntityCreator.cc Outdated Show resolved Hide resolved
src/gui/plugins/component_inspector/ComponentInspector.cc Outdated Show resolved Hide resolved
src/gui/plugins/lights/Lights.cc Outdated Show resolved Hide resolved
src/gui/plugins/lights/Lights.cc Outdated Show resolved Hide resolved
src/gui/plugins/lights/Lights.cc Show resolved Hide resolved
src/gui/plugins/lights/Lights.hh Outdated Show resolved Hide resolved
src/rendering/SceneManager.cc Outdated Show resolved Hide resolved
src/rendering/SceneManager.cc Outdated Show resolved Hide resolved
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
include/ignition/gazebo/components/LightType.hh Outdated Show resolved Hide resolved
src/rendering/RenderUtil.cc Outdated Show resolved Hide resolved
src/rendering/SceneManager.cc Outdated Show resolved Hide resolved
iche033 and others added 3 commits February 3, 2021 08:12
* light visual as child of light

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* remove comment

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: ahcorde <ahcorde@gmail.com>
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 5, 2021

@iche033, I addressed the comment from @chapulina 2a79677

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great with the event change we talked about.

Besides the comment below, I have 2 requests:

  • We should add the Lights plugin to the top toolbar next to the shapes in gui.config.
  • Now that the lights have a visual, most example worlds will have a green square near the origin for the sun. This may confuse users. On Gazebo classic, I've seen many users confused about the floating green square, imagine if it's on the ground 😅 I suggest we move all suns in the examples to z=10, so it's in a more "sun-like" position. I think it's ok if this comes in a future PR though.

include/ignition/gazebo/components/LightType.hh Outdated Show resolved Hide resolved
src/gui/plugins/lights/Lights.cc Outdated Show resolved Hide resolved

// create a new id for the light visual
auto timeout = 100000u;
for (auto i = 0u; i < timeout; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to block the render thread. If this may take time to be completed, I suggest we queue it and process it when possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the right name for this variable is attempts, this loop has no relation with time or sleep. It's looking for an available entity ID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh ok understood! I wonder if there's a chance of entity ID collision when new entities are inserted into the simulation from the backend. I didn't notice problems in my manual testing earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this method I can't access the ECM to call CreateEntity. Is there any other way to get an empty ID ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the entity preview when spawning, there's this method in the Scene3D plugin:

https://github.com/ignitionrobotics/ign-gazebo/blob/766bb23eaca85ff60941e2ef852c4f286356fbcc/src/gui/plugins/scene3d/Scene3D.cc#L927-L937

That plugin isn't accessible from RenderUtil. But I think it could make sense to move the light visual logic from RenderUtil to Scene3d. The light visuals are only supposed to show on the client scene, not on the server. But RenderUtil is used by both scenes. I think this would be a big change and it may take longer to merge this PR though 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can open an issue and merge this PR. Waht do you think @chapulina ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

friendly ping @chapulina

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue sounds good, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue created #633

src/rendering/SceneManager.cc Show resolved Hide resolved
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 9, 2021

  • Now that the lights have a visual, most example worlds will have a green square near the origin for the sun. This may confuse users. On Gazebo classic, I've seen many users confused about the floating green square, imagine if it's on the ground sweat_smile I suggest we move all suns in the examples to z=10, so it's in a more "sun-like" position. I think it's ok if this comes in a future PR though

@chapulina I made a quick review in the example folder. The suns' poses are already z=10

   <light type="directional" name="sun">
     <cast_shadows>true</cast_shadows>
     <pose>0 0 10 0 0 0</pose>
     <diffuse>1 1 1 1</diffuse>
     <specular>0.5 0.5 0.5 1</specular>
     <attenuation>
       <range>1000</range>
       <constant>0.9</constant>
       <linear>0.01</linear>
       <quadratic>0.001</quadratic>
     </attenuation>
     <direction>-0.5 0.1 -0.9</direction>
   </light>

@chapulina chapulina removed the needs upstream release Blocked by a release of an upstream library label Feb 17, 2021
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's working for me! One last thing I noticed is that the directional light is spawned higher than the others, which may confuse users depending on their zoom level:

Peek 2021-02-17 13-07

I think this is good to merge when the last 2 details are addressed, and if CI is happy.

src/gui/gui.config Outdated Show resolved Hide resolved
Signed-off-by: ahcorde <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 17, 2021

@chapulina I fixed the two suggestions:

Feel free to squash and merge it

@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 18, 2021

Failing tests are unrelated:

INTEGRATION_touch_plugin.test_ran
INTEGRATION_depth_camera.test_ran

Merging!

@ahcorde ahcorde merged commit 6b39bc2 into main Feb 18, 2021
Core development automation moved this from In review to Done Feb 18, 2021
@ahcorde ahcorde deleted the ahcorde/spawn/ligths branch February 18, 2021 07:09
@adlarkin adlarkin mentioned this pull request Sep 13, 2021
8 tasks
@j-rivero j-rivero removed this from Done in Core development May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
close the gap Features from Gazebo-classic 🏢 edifice Ignition Edifice GUI Gazebo's graphical interface (not pure Ignition GUI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants