Skip to content

COLLADA mesh's material is not visualized correctly  #751

Closed

Description

@garaemon

when a collada file is used as marker, it's not visualized correctly. Always the color
of the model is rendered as white. However if we use texture mapping in a collada file, rviz
can visualize it correctly.

On the other hand, if that file is used as robot_description, RobotModel can visualize it correctly.

https://github.com/garaemon/rviz_collada_marker
this is the package includes the test code and you can test it by roslaunch rviz_collada_marker test.launch

screenshot from 2014-04-24 21 38 22

Activity

  1. wjwwood commented on Apr 24, 2014

    @wjwwood
    Member

    Thanks for the report, I don't have time to look into this issue right now, maybe one of the other developers has some spare cycles? @dgossow @hersh

    If, in the mean time, you find a solution, please let us know.

  2. hersh commented on Apr 24, 2014

    @hersh
    Contributor

    This is a very nice bug report, you made a whole package for us to reproduce the bug. Sadly I don't have time to work on it now either. It certainly looks like a bug in rviz since it displays correctly in other contexts, and the content of your visualization_msgs/Marker message looks correct.

  3. jbrindza commented on Apr 24, 2014

    @jbrindza
    Contributor

    The mesh marker is explicitly using the color from the marker message and overriding the mesh colors. I am not sure why but it seemed like it was done intentionally.

    Here is a diff you can try. It worked for me for the test case you have. it will use the message color value if mesh_use_embedded_materials == false otherwise it will use the mesh materials.

    diff --git a/src/rviz/default_plugin/markers/mesh_resource_marker.cpp b/src/rviz/default_plugin/markers/mesh_resource_marker.cpp
    index 616f0f4..b15a488 100644
    --- a/src/rviz/default_plugin/markers/mesh_resource_marker.cpp
    +++ b/src/rviz/default_plugin/markers/mesh_resource_marker.cpp
    @@ -87,8 +87,6 @@ void MeshResourceMarker::onNewMessage(const MarkerConstPtr& old_message, const M
     {
       ROS_ASSERT(new_message->type == visualization_msgs::Marker::MESH_RESOURCE);
    
    -  bool need_color = false;
    -
       scene_node_->setVisible(false);
    
       if( !entity_ ||
    @@ -120,7 +118,6 @@ void MeshResourceMarker::onNewMessage(const MarkerConstPtr& old_message, const M
         std::string id = ss.str();
         entity_ = context_->getSceneManager()->createEntity(id, new_message->mesh_resource);
         scene_node_->attachObject(entity_);
    -    need_color = true;
    
         // create a default material for any sub-entities which don't have their own.
         ss << "Material";
    @@ -172,28 +169,20 @@ void MeshResourceMarker::onNewMessage(const MarkerConstPtr& old_message, const M
         handler_->addTrackedObject( entity_ );
       }
    
    -  if( need_color ||
    -      old_message->color.r != new_message->color.r ||
    -      old_message->color.g != new_message->color.g ||
    -      old_message->color.b != new_message->color.b ||
    -      old_message->color.a != new_message->color.a )
    +  // if not using embedded materials and the color changed
    +  if (new_message->mesh_use_embedded_materials == false
    +      && (!old_message
    +          || old_message->mesh_use_embedded_materials == true
    +          || old_message->color.r != new_message->color.r
    +          || old_message->color.g != new_message->color.g
    +          || old_message->color.b != new_message->color.b
    +          || old_message->color.a != new_message->color.a))
       {
         float r = new_message->color.r;
         float g = new_message->color.g;
         float b = new_message->color.b;
         float a = new_message->color.a;
    
    -    // Old way was to ignore the color and alpha when using embedded
    -    // materials, which meant you could leave them unset, which means
    -    // 0.  Since we now USE the color and alpha values, leaving them
    -    // all 0 will mean the object will be invisible.  Therefore detect
    -    // the situation where RGBA are all 0 and treat that the same as
    -    // all 1 (full white).
    -    if( new_message->mesh_use_embedded_materials && r == 0 && g == 0 && b == 0 && a == 0 )
    -    {
    -      r = 1; g = 1; b = 1; a = 1;
    -    }
    -
         Ogre::SceneBlendType blending;
         bool depth_write;
  4. garaemon commented on Apr 25, 2014

    @garaemon
    ContributorAuthor

    that patch works on my environment too.

    screenshot from 2014-04-25 13 48 07

  5. wjwwood commented on Apr 25, 2014

    @wjwwood
    Member

    Thanks for drafting a patch @brindza! Can you open a pull request for the patch? That way you'll get attribution for the commit.

    I'll review this and test it myself as soon as possible, but it looks ok to me. I'll try to dig a bit and understand the existing logic to see if there was a good reason for this behavior.

  6. hersh commented on Apr 25, 2014

    @hersh
    Contributor

    The reason for that code is to enable the nice feature of being able to use the original textures but also tint them with a color, or set the alpha value.

    It works for a bunch of situations, and I would like it to work in this one as well.

    I just looked at the patch casually, but it seems to just disable the feature.

  7. jbrindza commented on Apr 27, 2014

    @jbrindza
    Contributor

    The current implementation just overrides the ambient and diffuse color properties of all passes with whatever is in the color message (or 1,1,1,1 if it is 0,0,0,0). I would expect it to work as intended for any for materials that don't specify those color properties.

    It fails here because the material just uses the color properties which are being overwritten by the color value in the message. To get the intended tinting behavior it should probably be inserting a new pass into all the materials to do the tinting, not change the materials color properties directly.

    @garaemon Would it be possible to add the texture mapped version to your example repo?

  8. garaemon commented on Apr 28, 2014

    @garaemon
    ContributorAuthor
  9. wjwwood commented on Apr 28, 2014

    @wjwwood
    Member

    @garaemon what is the expected behavior of your modified package? Should the PR2 base be tinted with another color?

  10. garaemon commented on Apr 29, 2014

    @garaemon
    ContributorAuthor

    I assume that pr2 base should be visualized with texture mapping

    2014年4月29日火曜日、William [email protected]さんは書きました:

    @garaemon https://github.com/garaemon what is the expected behavior of
    your modified package? Should the PR2 base be tinted with another color?

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/751#issuecomment-41594247
    .

    from iPhone

  11. wjwwood commented on May 1, 2014

    @wjwwood
    Member

    Closed by #752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions