Change a model's appeareance within IGNITION Gazebo
Dear Ignition Community,
i am looking for an approach to change a model's, resp. it's visual geometry's appeareance during runtime.
Within the former Gazebo simulation, it has been able to change a model's appeareance by declaring different materials, e.g.
material green_on
{
technique
{
pass
{
lighting on
ambient 0.08207 0.64 0.040269 1
diffuse 0.08207 0.64 0.040269 1
emissive 0.08207 0.64 0.040269 1
}
}
}
material green_off
{
technique
{
pass
{
lighting on
ambient 0.3 0.3 0.3 1
diffuse 0.08207 0.64 0.040269 1
emissive 0 0 0 1
}
}
}
and then switching between those materials using dedicated messages within a ModelPlugin node's namespace, such as follows:
// Message for changing the visual appearance (setting visual states)
this->dataPtr->visualPub = this->dataPtr->node->Advertise<gazebo::msgs::Visual>("~/visual");
[...]
gazebo::msgs::Visual greenChangeMessage;
greenChangeMessage.set_parent_name(this->model->GetName());
greenChangeMessage.set_name(this->model->GetName() + "::green_light");
if(_green) {
greenChangeMessage.mutable_material()->mutable_script()->set_name("green_on");
} else {
greenChangeMessage.mutable_material()->mutable_script()->set_name("green_off");
}
this->dataPtr->visualPub->Publish(redChangeMessage);
This approach seems to be outdated for IGNITION Gazebo (e.g. fortress), is there another way to go for such functionalities? IGNITION Gazebo seems to have similar Visual message [2] ready for such types of application, but *.material files are not supported any more [1].
As stated in [3], the rendering API only affects one of both "worlds". Since i want to change the model's appeareance, so that the GUI (affecting the user), but also the server (for sensors) are affected in the same way, i am dependent on a synchronized change.
Regards and thx!
[1] https://ignitionrobotics.org/api/gazebo/6.0/migrationsdf.html
[2] https://ignitionrobotics.org/api/msgs/6.4/classignition_1_1msgs_1_1Visual.html
[3] https://ignitionrobotics.org/api/gazebo/6.1/rendering_plugins.html
Asked by Illuminatur on 2022-04-18 12:21:11 UTC
Answers
Hi there!
I'm honestly unfamiliar with the classic gazebo as you mentioned above. I've used it very short time but then go back to ign as it is very easy and comfortable for me.
I will try my best to give you some answers. I hope they are useful answers or at least, help you to find a better solution!
First of all, those links are 6.0. I think we have 7.0 as latest. Here
Secondly, Citadel and Fortress are LTS. Citadel isn't outdated...YET ;) Two more years to go!
So, the material part..I think this is removed in ign as I have not seen it anywhere in ign.
So, let's use this example from Classic Gazebo tutorial
You use this:
material green_on { technique { pass {
lighting on
ambient 0.08207 0.64 0.040269 1
diffuse 0.08207 0.64 0.040269 1
emissive 0.08207 0.64 0.040269 1 } } } material green_off { technique { pass {
lighting on
ambient 0.3 0.3 0.3 1
diffuse 0.08207 0.64 0.040269 1
emissive 0 0 0 1
} } }
As it relies on image, right?
So, in ignition..they get rid of it. It's now this new feature, see my example from github:
<material>
<ambient>0.8 0.8 0.8 1</ambient>
<diffuse>0.8 0.8 0.8 1</diffuse>
<pbr>
<metal>
<albedo_map>Track4.png</albedo_map>
<normal_map>Track4.png</normal_map>
</metal>
</pbr>
</material>
Which made my floor look pretty
No more humor. Here is the actual picture for line tracking:
So, you have this template (Feel free to look at this handsome made model)
<material>
<diffuse>x x x</diffuse>
<specular>x x x</specular>
<pbr>
<metal>
<albedo_map></albedo_map>
<normal_map></normal_map>
<metalness_map></metalness_map>
<roughness_map></roughness_map>
</metal>
</pbr>
Replace x to between 0 to 1. You can't make it more than 1.0 or less than 0. Remember this part.
As stated in [3], the rendering API only affects one of both "worlds". Since i want to change the model's appeareance,
I dont know this witchcraft from classic gazebo but what you can do is to make sdf as a "module". I was trying to make a blanket in sdf where it can move like realistic blanket (it's not even close btw)
See how you can import sdf as many as you want inside the world
So, see the blanket.sdf
..don't put anything related world in the sdf. Since you can't have two worlds or more at once. You must have one world with unlimited sdf imports. (depends on your hardware capable)
What you need to do is to load world first then you can import sdf as many as you want.
So, there is two ways (probably more than 2 but I just know 2 btw)
- See the example in
blanket_in_a_world.sdf
- You can load model inside the ign during runtime through command line or python (I don't even code Cpp btw, sorry for my sins)
So, to load it during runtime is
ign service -s /world/(YOUR_WORLD_NAME)/create --reqtype ignition.msgs.EntityFactory --reptype ignition.msgs.Boolean --timeout 300 --req 'sdf_filename: ''"your_filename.sdf" pose: {position: {x: #, y: #}} '
So, change your world name, your_filename and # in the command so you can load it easily.
I hope this brings you useful answer! If you have more questions, please feel free to ask!
Asked by kakcalu13 on 2022-04-19 09:14:43 UTC
Comments
Dear kakcalu13,
thx for you suggestions.
My question relates more to the possibility of changing the properties of an object's appeareance, if the object already exists since the start of the simulation. Such as inside a plugin , e.g. triggered by an incoming ignition topic via node subscriber.
But how can this be realized using the EntityComponentManager (ecm) programmatically, eg. by using _ecm.Component<ignition::gazebo::components::Visual>
?
BR and thx.
Asked by Illuminatur on 2022-04-25 10:46:29 UTC
Oh, I don't know that one. Sorry :(
Asked by kakcalu13 on 2022-05-17 07:38:11 UTC
Comments