-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:brentyi/viser into adam/camera_cont…
…rols
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.. Comment: this file is automatically generated by `update_example_docs.py`. | ||
It should not be modified manually. | ||
Get Renders | ||
========================================== | ||
|
||
|
||
Example for getting renders from a client's viewport to the Python API. | ||
|
||
|
||
|
||
.. code-block:: python | ||
:linenos: | ||
import time | ||
import imageio.v3 as iio | ||
import numpy as onp | ||
import viser | ||
def main(): | ||
server = viser.ViserServer() | ||
button = server.add_gui_button("Render a GIF") | ||
@button.on_click | ||
def _(event: viser.GuiEvent) -> None: | ||
client = event.client | ||
assert client is not None | ||
client.reset_scene() | ||
images = [] | ||
for i in range(20): | ||
positions = onp.random.normal(size=(30, 3)) * 3.0 | ||
client.add_spline_catmull_rom( | ||
f"/catmull_{i}", | ||
positions, | ||
tension=0.5, | ||
line_width=3.0, | ||
color=onp.random.uniform(size=3), | ||
) | ||
images.append(client.get_render(height=1080, width=1920)) | ||
print("Writing GIF...") | ||
iio.imwrite("saved.gif", images) | ||
print("Wrote GIF!") | ||
while True: | ||
time.sleep(10.0) | ||
if __name__ == "__main__": | ||
main() |