Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilhem Saurel
pinocchio
Commits
db2ee654
Verified
Commit
db2ee654
authored
Sep 17, 2021
by
Justin Carpentier
Browse files
python/viewer: fix viewing of ConvexMesh + minor optimization of the processing
parent
1ca9c789
Changes
1
Hide whitespace changes
Inline
Side-by-side
bindings/python/pinocchio/visualize/meshcat_visualizer.py
View file @
db2ee654
...
...
@@ -6,6 +6,7 @@ from . import BaseVisualizer
import
os
import
warnings
import
numpy
as
np
from
distutils.version
import
LooseVersion
try
:
import
hppfcl
...
...
@@ -24,21 +25,34 @@ def isMesh(geometry_object):
return
False
def
load
BVH
(
bv
h
):
def
load
Mesh
(
mes
h
):
import
meshcat.geometry
as
mg
num_vertices
=
bvh
.
num_vertices
num_tris
=
bvh
.
num_tris
vertices
=
np
.
empty
((
num_vertices
,
3
))
faces
=
np
.
empty
((
num_tris
,
3
),
dtype
=
int
)
if
isinstance
(
mesh
,
hppfcl
.
BVHModelBase
):
num_vertices
=
mesh
.
num_vertices
num_tris
=
mesh
.
num_tris
call_triangles
=
mesh
.
tri_indices
call_vertices
=
mesh
.
vertices
elif
isinstance
(
mesh
,
hppfcl
.
Convex
):
num_vertices
=
mesh
.
num_points
num_tris
=
mesh
.
num_polygons
call_triangles
=
mesh
.
polygons
call_vertices
=
mesh
.
points
faces
=
np
.
empty
((
num_tris
,
3
),
dtype
=
int
)
for
k
in
range
(
num_tris
):
tri
=
bvh
.
tri_indic
es
(
k
)
tri
=
call_triangl
es
(
k
)
faces
[
k
]
=
[
tri
[
i
]
for
i
in
range
(
3
)]
for
k
in
range
(
num_vertices
):
vert
=
bvh
.
vertices
(
k
)
vertices
[
k
]
=
vert
if
LooseVersion
(
hppfcl
.
__version__
)
>=
LooseVersion
(
"1.7.7"
):
vertices
=
call_vertices
()
else
:
vertices
=
np
.
empty
((
num_vertices
,
3
))
for
k
in
range
(
num_vertices
):
vertices
[
k
]
=
call_vertices
(
k
)
vertices
=
vertices
.
astype
(
np
.
float32
)
if
num_tris
>
0
:
...
...
@@ -137,6 +151,8 @@ class MeshcatVisualizer(BaseVisualizer):
obj
=
meshcat
.
geometry
.
Box
(
npToTuple
(
2.
*
geom
.
halfSide
))
elif
isinstance
(
geom
,
hppfcl
.
Sphere
):
obj
=
meshcat
.
geometry
.
Sphere
(
geom
.
radius
)
elif
isinstance
(
geom
,
hppfcl
.
ConvexBase
):
obj
=
loadMesh
(
geom
)
else
:
msg
=
"Unsupported geometry type for %s (%s)"
%
(
geometry_object
.
name
,
type
(
geom
)
)
warnings
.
warn
(
msg
,
category
=
UserWarning
,
stacklevel
=
2
)
...
...
@@ -183,7 +199,7 @@ class MeshcatVisualizer(BaseVisualizer):
obj
=
self
.
loadMesh
(
geometry_object
)
is_mesh
=
True
elif
WITH_HPP_FCL_BINDINGS
and
isinstance
(
geometry_object
.
geometry
,
hppfcl
.
BVHModelBase
):
obj
=
load
BVH
(
geometry_object
.
geometry
)
obj
=
load
Mesh
(
geometry_object
.
geometry
)
else
:
msg
=
"The geometry object named "
+
geometry_object
.
name
+
" is not supported by Pinocchio/MeshCat for vizualization."
warnings
.
warn
(
msg
,
category
=
UserWarning
,
stacklevel
=
2
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment