Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle colors in sdf files #57

Closed
diegoferigo opened this issue Jul 24, 2017 · 7 comments
Closed

Handle colors in sdf files #57

diegoferigo opened this issue Jul 24, 2017 · 7 comments
Assignees

Comments

@diegoferigo
Copy link
Member

diegoferigo commented Jul 24, 2017

Fixing #56 should be enough to handle the urdf side, adding something similar to the model:

simmechanics:

<MaterialProp>
    <color>0.666667,0.666667,0.666667</color>
    <transparency>0</transparency>
</MaterialProp>

urdf:

<material name="r_forearm_color">
    <color rgba="0.666667 0.666667 0.666667 1.0"/>
</material>

However, this doesn't seem to be enough for Gazebo, which uses OGRE colors. In my opinion using the default colors is not general enough, and it would require setting a kind of map between what is exported from the CAD (or specified in the simmechanics file) to the OGRE color keywords. One of the possible option to overcome this would be adding into the generator toolchain the possibility to generate a custom color file and export it where gazebo can find it.

Eventually, these lines are required in the urdf for importing colors in gazebo:

<gazebo reference="r_forearm">
    <visual>
        <material>
            <script>
                <uri>file://media/myfile.material</uri>
                <name>r_forearm_color</name>
            </script>
        </material>
    </visual>
</gazebo>

The resulting sdf would be:

<material>
    <script>
        <uri>file://media/myfile.material</uri>
        <name>r_forearm_color</name>
    </script>
</material>

Note that the media folder is relative to GAZEBO_RESOURCE_PATH.

cc @traversaro @nunoguedelha

Resources:

@traversaro
Copy link
Member

traversaro commented Jul 24, 2017

Perhaps it is not documented, but apparently the SDF format has the capability of specifying the colors of the material directly in the in the ambient/diffuse / specular / emissive of the material tag: http://sdformat.org/spec?ver=1.6&elem=material . I do not know if those tags are correctly loaded by Gazebo.

This capabilities seem to be alternative to the script tag, at least from the description of the script tag: "Name of material from an installed script file. This will override the color element if the script exists." Assuming that by "color" element they are assuming the ambient/diffuse / specular / emissive.

However I think it is worth to open an issue in https://bitbucket.org/osrf/sdformat/issues about the confusing documentation of the script tag, i.e. referencing a "color" element that does not exists in SDF.

Other related issues:

@diegoferigo
Copy link
Member Author

diegoferigo commented Jul 24, 2017

That way would avoid the installation of an additional script file, simpler is better, true. Although it is not trivial to my eyes how to convert those properties (examples in the Heidelberg model) to the format taken by Gazebo (example here).

@traversaro
Copy link
Member

The documentation of the data contained in the MaterialProp tag is given in http://it.mathworks.com/help/physmod/smlink/ref/pmitvismatprop.html .
I am not an expert, but I think those format can be converted in the format taken by Gazebo by multiplying the "intensity" (from 0.0 to 1.0) of each component of the light for the material color for the first three elements of the Gazebo "color", and the transparency (fourth element of each Gazebo "color") can be copied directly from the transparency MaterialProp element.

@lucaTagliapietra
Copy link

From the one-shot experience I had the only time I tried it, I can confirm your thoughts @traversaro

@diegoferigo
Copy link
Member Author

robotology/simmechanics-to-urdf#28 includes the support to gazebo colors elements as XML blobs.

As a reference, this is the simmechanics code:

<MaterialProp>
    <color>0.666667,0.666667,0.666667</color>
    <ambient>0.4</ambient>
    <diffuse>0.85</diffuse>
    <specular>0.9</specular>
    <shininess>0.3</shininess>
    <transparency>0</transparency>
    <emission>0.35</emission>
</MaterialProp>

That is translate to this urdf code:

<link name="r_forearm">
...
  <visual>
    ...
    <material name="r_forearm_color">
      <color rgba="0.666667 0.666667 0.666667 1.0"/>
    </material>
  </visual>
  ...
</link>
...
<gazebo reference="r_forearm">
  <visual>
    <material>
      <ambient>0.2666668 0.2666668 0.2666668 1.0</ambient>
      <diffuse>0.56666695 0.56666695 0.56666695 1.0</diffuse>
      <specular>0.6000003 0.6000003 0.6000003 1.0</specular>
    </material>
  </visual>
</gazebo>

The last snipper of code is then included in Gazebo directly into the <visual> element of the sdf (note that the method specified in the top post is deprecated. The preferred way is this one).

@traversaro
Copy link
Member

note that the method specified in the top post is deprecated. The preferred way is this one

Where did you find this information?

@diegoferigo
Copy link
Member Author

diegoferigo commented Jul 28, 2017

Where did you find this information?

It was my very personal understanding of the comments in the parser_urdf.cc. I didn't spend much time on this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants