flatland_viz/src/spawn_model_tool.cpp
void SpawnModelTool::onInitialize() {
  // hide 3d model until the user clicks the span model tool button
  model_state = m_hidden;

  // make an arrow to show axis of rotation
  arrow_ = new rviz::Arrow(scene_manager_, NULL, 2.0f, 0.2f, 0.5f, 0.35f);
  arrow_->setColor(0.0f, 0.0f, 1.0f, 1.0f);  // blue
  arrow_->getSceneNode()->setVisible(
      false);  // will only be visible during rotation phase

  // set arrow to point up (along z)
  Ogre::Quaternion orientation(Ogre::Radian(M_PI), Ogre::Vector3(1, 0, 0));
  arrow_->setOrientation(orientation);

  // full path to the model file
  model_resource_ = "package://flatland_viz/media/simple.dae";

  // load the 3d model
  if (rviz::loadMeshFromResource(model_resource_).isNull()) {
    ROS_ERROR("SpawnModelTool: failed to load model resource '%s'.",
              model_resource_.c_str());
    return;
  }

  // create an Ogre child scene node
  moving_model_node_ =
      scene_manager_->getRootSceneNode()->createChildSceneNode();

  // create an Ogre entity
  Ogre::Entity *entity = scene_manager_->createEntity(model_resource_);

  // attach the object to the entity
  moving_model_node_->attachObject(entity);
  moving_model_node_->setVisible(false);

  SetMovingModelColor(Qt::green);
}
// onInitialize() is called by the superclass after scene_manager_ and
// context_ are set.  It should be called only once per instantiation.
// This is where most one-time initialization work should be done.
// onInitialize() is called during initial instantiation of the tool
// object.  At this point the tool has not been activated yet, so any
// scene objects created should be invisible or disconnected from the
// scene at this point.
//
// In this case we load a mesh object with the shape and appearance of
// the model, create an Ogre::SceneNode for the moving model, and then
// set it invisible.
onInitialize() is called by the superclass after scene_manager_ and
context_ are set.  It should be called only once per instantiation.
This is where most one-time initialization work should be done.
onInitialize() is called during initial instantiation of the tool
object.  At this point the tool has not been activated yet, so any
scene objects created should be invisible or disconnected from the
scene at this point.

In this case we load a mesh object with the shape and appearance of
the model, create an Ogre::SceneNode for the moving model, and then
set it invisible.
onInitialize () is called by the superclass after scene_manager_ and context_ are set . It should be called only once per instantiation . This is where most one - time initialization work should be done . onInitialize () is called during initial instantiation of the tool object . At this point the tool has not been activated yet so any scene objects created should be invisible or disconnected from the scene at this point . In this case we load a mesh object with the shape and appearance of the model create an Ogre :: SceneNode for the moving model and then set it invisible .
void SpawnModelTool::onInitialize() {
  model_state = m_hidden;
  arrow_ = new rviz::Arrow(scene_manager_, NULL, 2.0f, 0.2f, 0.5f, 0.35f);
  arrow_->setColor(0.0f, 0.0f, 1.0f, 1.0f);  
  arrow_->getSceneNode()->setVisible(
      false);  
  Ogre::Quaternion orientation(Ogre::Radian(M_PI), Ogre::Vector3(1, 0, 0));
  arrow_->setOrientation(orientation);
  model_resource_ = "package://flatland_viz/media/simple.dae";
  if (rviz::loadMeshFromResource(model_resource_).isNull()) {
    ROS_ERROR("SpawnModelTool: failed to load model resource '%s'.",
              model_resource_.c_str());
    return;
  }
  moving_model_node_ =
      scene_manager_->getRootSceneNode()->createChildSceneNode();
  Ogre::Entity *entity = scene_manager_->createEntity(model_resource_);
  moving_model_node_->attachObject(entity);
  moving_model_node_->setVisible(false);
  SetMovingModelColor(Qt::green);
}
void SpawnModelTool :: onInitialize ( ) { model_state = m_hidden ; arrow_ = new rviz :: Arrow ( scene_manager_ , NULL , 2.0f , 0.2f , 0.5f , 0.35f ) ; arrow_ -> setColor ( 0.0f , 0.0f , 1.0f , 1.0f ) ; arrow_ -> getSceneNode ( ) -> setVisible ( false ) ; Ogre :: Quaternion orientation ( Ogre :: Radian ( M_PI ) , Ogre :: Vector3 ( 1 , 0 , 0 ) ) ; arrow_ -> setOrientation ( orientation ) ; model_resource_ = " " ; if ( rviz :: loadMeshFromResource ( model_resource_ ) . isNull ( ) ) { ROS_ERROR ( " " , model_resource_ . c_str ( ) ) ; return ; } moving_model_node_ = scene_manager_ -> getRootSceneNode ( ) -> createChildSceneNode ( ) ; Ogre :: Entity * entity = scene_manager_ -> createEntity ( model_resource_ ) ; moving_model_node_ -> attachObject ( entity ) ; moving_model_node_ -> setVisible ( false ) ; SetMovingModelColor ( Qt :: green ) ; }
onInitialize() is called by the superclass after scene_manager_ and
context_ are set.
onInitialize () is called by the superclass after scene_manager_ and context_ are set .
// hide 3d model until the user clicks the span model tool button // make an arrow to show axis of rotation // blue // will only be visible during rotation phase // set arrow to point up (along z) // full path to the model file // load the 3d model // create an Ogre child scene node // create an Ogre entity // attach the object to the entity