meshcat-dev / meshcat-python

WebGL-based 3D visualizer for Python
MIT License
259 stars 63 forks source link

New feature: capture image #93

Closed ManifoldFR closed 3 years ago

ManifoldFR commented 3 years ago

This PR follows https://github.com/rdeits/meshcat/pull/85.

It adds a new get_image() method to meshcat.Visualizer. This relies on the new capture_image command added in rdeits/meshcat#85 which queries an image returned to the Meshcat client as a PNG in base64 data URI form.

Design

On the Python side, the WebsocketHandler awaits the response from the Meshcat client, and when it receives the JSON from the frontend, the on_message() callback is triggered, which sends the PNG (turned into a sequence of bytes) over the ZMQ bridge.

Limitations

The design is not completely robust yet. It requires the browser window be already open to get a response in the client (the visualizer will block until then).
Maybe this behavior can be fixed by using something else to get the PNG render.

ManifoldFR commented 3 years ago

@rdeits Can we get a new release on PyPI after merging?

rdeits commented 3 years ago

Yup, I'll do that as soon as this is merged.

codecov-commenter commented 3 years ago

Codecov Report

Merging #93 (decd6ae) into master (3460c7f) will decrease coverage by 1.32%. The diff coverage is 29.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
- Coverage   74.85%   73.52%   -1.33%     
==========================================
  Files          11       11              
  Lines        1006     1035      +29     
==========================================
+ Hits          753      761       +8     
- Misses        253      274      +21     
Impacted Files Coverage Δ
src/meshcat/servers/zmqserver.py 29.23% <11.76%> (-1.10%) :arrow_down:
src/meshcat/visualizer.py 75.70% <45.45%> (-3.69%) :arrow_down:
src/meshcat/commands.py 92.45% <66.66%> (-1.55%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3460c7f...decd6ae. Read the comment docs.