Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pinocchio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
pinocchio
Commits
16d54395
Commit
16d54395
authored
6 years ago
by
Matthieu Vigne
Browse files
Options
Downloads
Patches
Plain Diff
[python][robot_wrapper] Add transparency support for Meshcat viewer.
parent
161b1335
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/python/pinocchio/robot_wrapper.py
+8
-4
8 additions, 4 deletions
bindings/python/pinocchio/robot_wrapper.py
examples/python/meshcat-viewer.py
+5
-3
5 additions, 3 deletions
examples/python/meshcat-viewer.py
with
13 additions
and
7 deletions
bindings/python/pinocchio/robot_wrapper.py
+
8
−
4
View file @
16d54395
...
...
@@ -287,7 +287,7 @@ class RobotWrapper(object):
visualizer: the meshcat.Visualizer instance to use.
robot_name: name to give to the robot in the viewer
robot_color: optional, color to give to the robot. This overwrites the color present in the urdf.
Format is a list of
three
RGB floats (between 0 and 1)
Format is a list of
four
RGB
A
floats (between 0 and 1)
"""
import
meshcat.geometry
# Set viewer to use to gepetto-gui.
...
...
@@ -302,11 +302,11 @@ class RobotWrapper(object):
raise
IOError
(
"
Visual mesh file not found for link {}.
"
.
format
(
visual
.
name
))
# Get file type from filename extension.
_
,
file_extension
=
os
.
path
.
splitext
(
visual
.
meshPath
)
if
file_extension
==
"
.dae
"
or
file_extension
==
"
.
DAE
"
:
if
file_extension
.
lower
()
==
"
.
dae
"
:
obj
=
meshcat
.
geometry
.
DaeMeshGeometry
.
from_file
(
visual
.
meshPath
)
elif
file_extension
==
"
.obj
"
or
file_extension
==
"
.
OBJ
"
:
elif
file_extension
.
lower
()
==
"
.
obj
"
:
obj
=
meshcat
.
geometry
.
ObjMeshGeometry
.
from_file
(
visual
.
meshPath
)
elif
file_extension
==
"
.stl
"
or
file_extension
==
"
.
STL
"
:
elif
file_extension
.
lower
()
==
"
.
stl
"
:
obj
=
meshcat
.
geometry
.
StlMeshGeometry
.
from_file
(
visual
.
meshPath
)
else
:
raise
ImportError
(
"
Unknown mesh file format: {}.
"
.
format
(
visual
.
meshPath
))
...
...
@@ -317,6 +317,10 @@ class RobotWrapper(object):
else
:
meshColor
=
robot_color
material
.
color
=
int
(
meshColor
[
0
]
*
255
)
*
256
**
2
+
int
(
meshColor
[
1
]
*
255
)
*
256
+
int
(
meshColor
[
2
]
*
255
)
# Add transparency, if needed.
if
float
(
meshColor
[
3
])
!=
1.0
:
material
.
transparent
=
True
material
.
opacity
=
float
(
meshColor
[
3
])
self
.
meshcat_viewer
[
viewer_name
].
set_object
(
obj
,
material
)
# Create the scene displaying the robot meshes in gepetto-viewer
...
...
This diff is collapsed.
Click to expand it.
examples/python/meshcat-viewer.py
+
5
−
3
View file @
16d54395
...
...
@@ -24,7 +24,9 @@ robot = RobotWrapper.BuildFromURDF(romeo_model_path, [romeo_model_dir], se3.Join
vis
=
meshcat
.
Visualizer
()
# Load the robot in the viewer.
robot
.
initMeshcatDisplay
(
vis
)
# Color is needed here because the Romeo URDF doesn't contain any color, so the default color results in an
# invisible robot (alpha value set to 0).
robot
.
initMeshcatDisplay
(
vis
,
robot_color
=
[
0.0
,
0.0
,
0.0
,
1.0
])
q
=
robot
.
q0
# Separate between freeflyer and robot links.
...
...
@@ -35,8 +37,8 @@ robot.display(q)
input
(
"
Displaying a single random robot configuration. Press enter to continue
"
)
red_robot
=
RobotWrapper
.
BuildFromURDF
(
romeo_model_path
,
[
romeo_model_dir
],
se3
.
JointModelFreeFlyer
())
robot
.
initMeshcatDisplay
(
vis
,
robot_name
=
"
red_robot
"
,
robot_color
=
[
1.0
,
0.0
,
0.0
])
robot
.
initMeshcatDisplay
(
vis
,
robot_name
=
"
red_robot
"
,
robot_color
=
[
1.0
,
0.0
,
0.0
,
0.5
])
q
[
1
]
=
1.0
q
[
n_freeflyer
:]
=
np
.
matrix
(
np
.
random
.
rand
(
n_links
)).
T
robot
.
display
(
q
)
input
(
"
Displaying a second robot with color red. Press enter to exit
"
)
input
(
"
Displaying a second robot with color red
, semi-transparent
. Press enter to exit
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment