Gepetto / gepetto-viewer

Graphical Interface for Pinocchio and HPP.
BSD 2-Clause "Simplified" License
42 stars 30 forks source link

mesh is always rendered in color white #172

Open proyan opened 3 years ago

proyan commented 3 years ago

Hi guys, It seems I have another bug. No matter what color I provide to a mesh, the mesh is always displayed as completely white.

I don't have any color issue in pybullet, and pybullet loads the color that is specified in the material tag of urdf. However when loading in gepetto-gui, the color doesn't seem to change.

I checked the pinocchio parser, and it is providing the good color information to gepetto-viewer. I also tried changing the color directly using the gui interface in gepetto-gui, and there is no effect.

Could you please help me figure out the issue?

IoannisDadiotis commented 3 years ago

Hi @proyan,

Did you solve this? I think I am facing the same issue (not with all robots)

For example the legs of A1 are rendered as shown below: image

jmirabel commented 3 years ago

Do you have a large scale in the URDF ?

IoannisDadiotis commented 3 years ago

The used urdf for A1 robot is the default in example-robot-data repo, can be found here. The scale of all meshes is 1.

jmirabel commented 3 years ago

The Collada files have light sources. You have to remove them.

for go in robot.visual_model.geometryObjects:
     name = robot.viz.getViewerNodeName(go, pinocchio.VISUAL)
     if "RemoveLightSources" not in gui.getPropertyNames(name):
         continue
     gui.removeLightSources(name)
IoannisDadiotis commented 3 years ago

Where am I supposed to use the above code? I have gepetto-viewer binaries installed so no contact with the source code. Can I add this on RobotLoader class?

What is the gui variable in the above code? How do you import it?

jmirabel commented 3 years ago

gui = robot.viewer.gui robot is a RobotWrapper returned by example_robot_data.load.

IoannisDadiotis commented 3 years ago

So I modified the RobotLoader class as follows:

class RobotLoader(object):
    path = ''
    urdf_filename = ''
    srdf_filename = ''
    sdf_filename = ''
    urdf_subpath = 'robots'
    srdf_subpath = 'srdf'
    sdf_subpath = ''
    ref_posture = 'half_sitting'
    has_rotor_parameters = False
    free_flyer = False
    verbose = False

    def __init__(self):
        if self.urdf_filename:
            if self.sdf_filename:
                raise AttributeError("Please choose between URDF *or* SDF")
            df_path = join(self.path, self.urdf_subpath, self.urdf_filename)
            builder = RobotWrapper.BuildFromURDF
        else:
            df_path = join(self.path, self.sdf_subpath, self.sdf_filename)
            try:
                builder = RobotWrapper.BuildFromSDF
            except AttributeError:
                raise ImportError("Building SDF models require pinocchio >= 3.0.0")
        self.model_path = getModelPath(df_path, self.verbose)
        self.df_path = join(self.model_path, df_path)
        self.robot = builder(self.df_path, [join(self.model_path, '../..')],
                             pin.JointModelFreeFlyer() if self.free_flyer else None)

        # remove lights from collada files
        for go in self.robot.visual_model.geometryObjects:
            name = self.robot.viz.getViewerNodeName(go, pin.VISUAL)
            if "RemoveLightSources" not in self.robot.viewer.gui.getPropertyNames(name):
                continue
            self.robot.viewer.gui.removeLightSources(name)

        if self.srdf_filename:
            self.srdf_path = join(self.model_path, self.path, self.srdf_subpath, self.srdf_filename)
            self.robot.q0 = readParamsFromSrdf(self.robot.model, self.srdf_path, self.verbose,
                                               self.has_rotor_parameters, self.ref_posture)

            if pin.WITH_HPP_FCL and pin.WITH_HPP_FCL_BINDINGS:
                # Add all collision pairs
                self.robot.collision_model.addAllCollisionPairs()

                # Remove collision pairs per SRDF
                pin.removeCollisionPairs(self.robot.model, self.robot.collision_model, self.srdf_path, False)

                # Recreate collision data since the collision pairs changed
                self.robot.collision_data = self.robot.collision_model.createData()
        else:
            self.srdf_path = None
            self.robot.q0 = pin.neutral(self.robot.model)

        if self.free_flyer:
            self.addFreeFlyerJointLimits()

    def addFreeFlyerJointLimits(self):
        ub = self.robot.model.upperPositionLimit
        ub[:7] = 1
        self.robot.model.upperPositionLimit = ub
        lb = self.robot.model.lowerPositionLimit
        lb[:7] = -1
        self.robot.model.lowerPositionLimit = lb

    @property
    def q0(self):
        warnings.warn("`q0` is deprecated. Please use `robot.q0`", FutureWarning, 2)
        return self.robot.q0

Then I built and installed example-robot-data but I am getting the same visualization of A1 robot.

jmirabel commented 3 years ago

I don't see where the viewer is initialized in your code.

nim65s commented 3 years ago

Hi,

This works for me, with binaries of gepetto-viewer & example-robot-data

import pinocchio
from example_robot_data import load

robot = load('a1', display=True)
gui = robot.viewer.gui

for go in robot.visual_model.geometryObjects:
     name = robot.viz.getViewerNodeName(go, pinocchio.VISUAL)
     if "RemoveLightSources" not in gui.getPropertyNames(name):
         continue
     gui.removeLightSources(name)

@IoannisDadiotis : do you have any issue with that code ?

IoannisDadiotis commented 3 years ago

@nim65s I am still getting the same visualization (with gepetto-viewer binaries and source of example-robot-data).

IoannisDadiotis commented 3 years ago

Sorry, my mistake. It works for A1. I will now test if the issue still exists with our centauro robot which was the initial reason I came to this issue and report back

IoannisDadiotis commented 3 years ago

Centauro description has been added here.

Meshes are .stl files, not .dae. Can .stl files also include light sources? In any case I tried, similar to the above, to run:

import pinocchio
from example_robot_data import load

robot = load('centauro', display=True)
gui = robot.viewer.gui

for go in robot.visual_model.geometryObjects:
     name = robot.viz.getViewerNodeName(go, pinocchio.VISUAL)
     if "RemoveLightSources" not in gui.getPropertyNames(name):
         continue
     gui.removeLightSources(name)

I am getting the following: image

jmirabel commented 3 years ago

This time, the issue may be the large scale. In the loop above, add something like

if "ApplyScale" in gui.getPropertyNames(name):
  gui.callVoidProperty(name, "ApplyScale")
IoannisDadiotis commented 3 years ago

We are getting close.

import pinocchio
from example_robot_data import load

robot = load('centauro', display=True)
gui = robot.viewer.gui

for go in robot.visual_model.geometryObjects:
     name = robot.viz.getViewerNodeName(go, pinocchio.VISUAL)
     if "RemoveLightSources" not in gui.getPropertyNames(name):
         continue
     gui.removeLightSources(name)

     if "ApplyScale" in gui.getPropertyNames(name):
         gui.callVoidProperty(name, "ApplyScale")

image

jmirabel commented 3 years ago

Your loop isn't correct. You should call ApplyScale even if RemoveLightSource is not available.

That being said, I'm not 100% sure this is your problem.

IoannisDadiotis commented 3 years ago

Indeed that's not the problem.

I don't know if this can help but I report some observations.