Gazebo | Ignition | Community
Ask Your Question

Spawn a Matrix of Objects over a Heightmap

asked 2020-02-25 10:55:01 -0500

jonamu gravatar image

I'm trying to spawn a matrix of objects to create a field. Ideally this could be done while the model is running so I thought using a plugin was the right strategy. I successfully modified this plugin to place a model at the correct height, but I cannot figure out how to change the name so I can spawn several of the same model. I used the factory portion of the tutorial (option 3) as it will be most convenient to store models in a directory and then call them and place them at the correct location. The main code is copied below. I tried several iterations of using msg.set_clone_mutable_name and some other options with no luck.

         //  Insert model from file via message passing.
      // Create a new transport node
      transport::NodePtr node(new transport::Node());

      // Initialize the node with the world name

      // Create a publisher on the ~/factory topic
      transport::PublisherPtr factoryPub = node->Advertise<msgs::Factory>("~/factory");

      // Create the messagecatkin
      msgs::Factory msg;


      physics::WorldPtr world = _parent;
      physics::ModelPtr model = world->ModelByName("heightmap");
      physics::CollisionPtr collision = model->GetLink("link")->GetCollision("collision");
      physics::HeightmapShapePtr heightmap =

      /* Spawn a matrix of cylinders, doesn't work without changing name.*/
      for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
          //  getting the height :
        float z_value = heightmap->GetHeight(i, j);

        // Pose to initialize the model to
                  ignition::math::Pose3d(ignition::math::Vector3d(i, j, z_value+0.5), ignition::math::Quaterniond(0, 0, 0)));

        // Send the message
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-02 16:19:35 -0500

I'm not an expert in this. But I feel that you are modifying only the collision part of the heightmap. You may need to do the same for visual part of the heightmap as well to see the changes in simulator

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-02-25 10:55:01 -0500

Seen: 38 times

Last updated: Feb 25