Gazebo | Ignition | Community
Ask Your Question

Reload material script

asked 2014-07-07 08:37:19 -0500

Herve Ludmann gravatar image

Hi everyone,

I'm trying to update the texture of a plane to display the path of a mobile robot. I use openCV to modify a picture and add red squares on the robot path.

I managed to remove & re-include the "field" model using a world plugin, however the .material script is not reloaded during this operation. Thus I always have the same starting image and not the updated image.

Should I use the OGRE commands within my plugin or is there a way to reload the .material script using only the gazebo classes ?

So far what I am doing to delete/reload the model is (called every 1 sec, the new field has a new name):

      // Delete old
      physics::ModelPtr m = this->world->GetModel(fieldName);

      // Add new
      sprintf(fieldName,"field_%d", t);

      sdf::SDF soccerFieldSDF;
      std::string soccerField=
      "<sdf version ='1.4'>\
        <model name ='field'>\
          <pose>0 0 0 0 0 0</pose>\
          <link name='link'>\
                <visual name='visual'>\
                      <normal>0 0 1</normal>\
                      <size>120 90</size>\

     sdf::ElementPtr model = soccerFieldSDF.root->GetElement("model");

Thanks for the help !

edit retag flag offensive close merge delete


Can you try publishing just a visual message to the ~/visual topic with these fields filled in: name, parent name, and material, and see if that works? There is some sample code in the constructor of the BoxMaker to show how to construct and publish a visual msg.

iche033 gravatar imageiche033 ( 2014-07-07 20:24:19 -0500 )edit

I didn't saw the comment earlier, sorry ! But I also tried that in a model plugin but I had the same problem, the .material script was still not up to date.

Herve Ludmann gravatar imageHerve Ludmann ( 2014-07-15 02:49:50 -0500 )edit

I tried the visual message, it works only if I create everytime a new picture and if the material file contains a list of materials (up1, up2, up3....) using the newly created image (up1.png, up2.png....). But it is not reliable because I get a std::bad _alloc error after around 200 updates. I tried to delete the materials&textures using OGRE but I still have this error

Herve Ludmann gravatar imageHerve Ludmann ( 2014-07-28 07:36:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-10-04 05:22:35 -0500

Herve Ludmann gravatar image

Hi everybody, I manage to find a way to perfectly display the trajectory of a robot using :

  • a world plugin which creates a new model (where you specify the size of your field) with a material called "trajectory"
  • a "trajectory.material" file without a texture specified
  • a visual plugin that uses the "createManual" function of OGRE and reuses the "trajectory" material to dynamically display the trajectory

I was not able to create a material using OGRE, that's why a reuses the "trajectory" material. The only thing required to do here is to include the world plugin into your world !

I suppressed some code lines I used for my project, so there might be a few mistakes (I don't have gazebo anymore to compile & run it).

Download here

edit flag offensive delete link more


Hi, thanks for sharing your code. BTW you may be need to mark this as answer for your question.

kpykc gravatar imagekpykc ( 2014-10-07 11:08:00 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-07-07 08:37:19 -0500

Seen: 1,056 times

Last updated: Oct 04 '14