最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python - Can't set the transparency of models - Stack Overflow

matteradmin4PV0评论

When I reproduced gcs-science-robotics in the latest version of drake and ran prm_comparison.ipynb, I met this problem.

RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_16980/4066659220.py in <module>
----> 1 visualize_trajectory(meshcat, [linear_gcs_traj],
      2                      show_path=True,
      3                      robot_configurations=execute_task,
      4                      transparency=0.3)

~/lhc-gcs-science-robotics/reproduction/prm_comparison/helpers.py in visualize_trajectory(meshcat, trajectories, show_path, robot_configurations, transparency, regions)
    246 
    247     # Set transparency of main arm and gripper.
--> 248     set_transparency_of_models(plant,
    249                                [iiwa.model_instance, wsg.model_instance],
    250                                transparency, scene_graph)

~/lhc-gcs-science-robotics/reproduction/prm_comparison/helpers.py in set_transparency_of_models(plant, model_instances, alpha, scene_graph)
    122                                                        Role.kIllustration):
    123                 properties = inspector.GetIllustrationProperties(geometry_id)
--> 124                 phong = properties.GetProperty("phong", "diffuse")
    125                 phong.set(phong.r(), phong.g(), phong.b(), alpha)
    126                 properties.UpdateProperty("phong", "diffuse", phong)

RuntimeError: GetProperty(): Trying to read property ('phong', 'diffuse'), but the group does not exist.

then I found that properties group name was '__default__'. I want to know that if API changed what should I do to change the transparency of models.

When I reproduced gcs-science-robotics in the latest version of drake and ran prm_comparison.ipynb, I met this problem.

RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_16980/4066659220.py in <module>
----> 1 visualize_trajectory(meshcat, [linear_gcs_traj],
      2                      show_path=True,
      3                      robot_configurations=execute_task,
      4                      transparency=0.3)

~/lhc-gcs-science-robotics/reproduction/prm_comparison/helpers.py in visualize_trajectory(meshcat, trajectories, show_path, robot_configurations, transparency, regions)
    246 
    247     # Set transparency of main arm and gripper.
--> 248     set_transparency_of_models(plant,
    249                                [iiwa.model_instance, wsg.model_instance],
    250                                transparency, scene_graph)

~/lhc-gcs-science-robotics/reproduction/prm_comparison/helpers.py in set_transparency_of_models(plant, model_instances, alpha, scene_graph)
    122                                                        Role.kIllustration):
    123                 properties = inspector.GetIllustrationProperties(geometry_id)
--> 124                 phong = properties.GetProperty("phong", "diffuse")
    125                 phong.set(phong.r(), phong.g(), phong.b(), alpha)
    126                 properties.UpdateProperty("phong", "diffuse", phong)

RuntimeError: GetProperty(): Trying to read property ('phong', 'diffuse'), but the group does not exist.

then I found that properties group name was '__default__'. I want to know that if API changed what should I do to change the transparency of models.

Share Improve this question asked Mar 23 at 10:50 LiHaochuanLiHaochuan 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I believe the error comes from the fact that your plant has geometries with an Illustration role, but they don't already have the ("phong", "diffuse") property assigned.

Specifically, set_transparency_of_models() is assuming that the property has already been assigned (so it simply calls GetProperty()). When the property doesn't already exist, it blows up as you've observed.

So, there are two ways to resolve this:

  1. Make sure that every geometry in your plant with the IllustrationRole has the expected property assigned, and/or

  2. Modify the code in question so that instead of calling GetProperty() it calls GetPropertyOrDefault() and have the function provide a default Rgba to use in the absence of a pre-assigned diffuse color.

Post a comment

comment list (0)

  1. No comments so far