Closed danieljfarrell closed 5 years ago
Definitely! I would certainly appreciate a PR :slightly_smiling_face:
Fortunately, this doesn't require any changes to the javascript side of the code. We just need to add a few new Python classes. In threejs, Line
, LineSegments
, and LineLoop
are all types of objects (just like Mesh
is). So, on the python side, we would make classes for them just like we do for Mesh
. Starting from https://github.com/rdeits/meshcat-python/blob/d26423c5efe776a811319a09c9fb0304211b5a2a/src/meshcat/geometry.py#L261-L262 , I think the classes should be as simple as:
class Line(Object):
_type = u"Line"
and the same for LineSegments
and LineLoop
.
You would then be able to construct one like this:
import meshcat
import meshcat.geometry as g
vis = meshcat.Visualizer()
vis.set_object(g.LineSegments(g.PointsGeometry(vertices)))
where vertices
is a 3xN
numpy array. I haven't tested the above code, so it may need a few tweaks, but I think the general idea is right.
If that works, we can consider making a more convenient function to avoid needing to type LineSegments(PointsGeometry(...))
every time.
I’ll take a look! Thanks.
Added pull request #43.
I did not yet go ahead and add the convenience functions because I didn't know what you would prefer. Also the best names seem to have already been taken by the other classes. Maybe something like LineGroup
as an equivalent to PointCloud
might be good.
I also added the ability (in a separate pull request #44 ) to load mesh data which is already in memory. We didn't discuss this before hand but seems useful.
Closed by #43 !
I'd be happy to do a pull request to add lines to meshcat. Is that something you would like to include? If so, would you give me some pointers on how to go about adding that?