Skip to content

Setting multiple light properties using sim::Light doesn't work properly #2532

Open
@azeey

Description

@azeey

Environment

  • OS Version: all
  • Source or binary build? 8.6.0

Description

  • Expected behavior: Calling sim::Light::SetDiffuseColor followed by sim::Light::SetSpecularColor to work. Example:
gz::sim::Light light(light_entity);
light.SetDiffuseColor(ecm, gz::math::Color(1.0, 0.0, 0.0, 0.0));
light.SetSpecularColor(ecm, gz::math::Color(1.0, 0.0, 0.0, 0.0));
  • Actual behavior: Only the last set value takes effect. Looking at the code in

    gz-sim/src/Light.cc

    Lines 326 to 344 in 523b01b

    void Light::SetDiffuseColor(EntityComponentManager &_ecm,
    const math::Color &_color)
    {
    auto lightCmd =
    _ecm.Component<components::LightCmd>(this->dataPtr->id);
    msgs::Light lightMsg;
    msgs::Set(lightMsg.mutable_diffuse(), _color);
    if (!lightCmd)
    {
    _ecm.CreateComponent(
    this->dataPtr->id,
    components::LightCmd(lightMsg));
    }
    else
    {
    lightCmd->Data() = lightMsg;
    }
    }
    calling SetDiffuseColor or SetSpecularColor will set the LightCmd component. But if you call one after the other without a whole step in between, the LightCmd from one will overwrite the other. The code already checks if there's a LightCmd component, but instead of updating the value of the component, it always replaces it with a new value.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomershelp wantedWe accept pull requests!

Type

No type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions