-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from maartenbreddels/feat_pythreejs_controls
Feature: pythreejs controls
- Loading branch information
Showing
4 changed files
with
229 additions
and
18 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 |
---|---|---|
|
@@ -134,6 +134,7 @@ Contents | |
examples | ||
api | ||
vr | ||
pythreejs | ||
|
||
|
||
Changelog | ||
|
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,155 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Integration with pythreejs\n", | ||
"ipyvolume uses parts of pythreejs, giving a lot of flexibility to tweak the visualizations or behaviour.\n", | ||
"## Materials\n", | ||
"The Scatter object has a `material` and `line_material` object, which both are a ShaderMaterial pythreejs object: `https://pythreejs.readthedocs.io/en/stable/api/materials/ShaderMaterial_autogen.html`.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipywidgets as widgets\n", | ||
"import numpy as np\n", | ||
"import ipyvolume as ipv" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# a scatter plot\n", | ||
"x, y, z = np.random.normal(size=(3, 100))\n", | ||
"fig = ipv.figure()\n", | ||
"scatter = ipv.scatter(x, y, z, marker='box')\n", | ||
"scatter.connected = True # draw connecting lines\n", | ||
"ipv.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Using `scatter.material` we can tweak the material setting:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"scatter.material.visible = False" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Or even connect a toggle button to a `line_material` property." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"toggle_lines = widgets.ToggleButton(description=\"Show lines\")\n", | ||
"widgets.jslink((scatter.line_material, 'visible'), (toggle_lines, 'value'))\n", | ||
"toggle_lines" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Controls\n", | ||
"ipyvolume has builtin controls. For more flexibility, a Controls class from https://pythreejs.readthedocs.io/en/stable/api/controls/index.html can be contructed." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pythreejs\n", | ||
"import ipyvolume as ipv\n", | ||
"import numpy as np\n", | ||
"fig = ipv.figure()\n", | ||
"scatter = ipv.scatter(x, y, z, marker='box')\n", | ||
"ipv.show()\n", | ||
"\n", | ||
"control = pythreejs.OrbitControls(controlling=fig.camera)\n", | ||
"# assigning to fig.controls will overwrite the builtin controls\n", | ||
"fig.controls = control\n", | ||
"control.autoRotate = True\n", | ||
"# the controls does not update itself, but if we toggle this setting, ipyvolume will update the controls\n", | ||
"fig.render_continuous = True\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"control.autoRotate = True\n", | ||
"toggle_rotate = widgets.ToggleButton(description=\"Rotate\")\n", | ||
"widgets.jslink((control, 'autoRotate'), (toggle_rotate, 'value'))\n", | ||
"toggle_rotate" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Camera\n", | ||
"The camera property of ipyvolume is by default a PerspectiveCamera, but other cameras should also work: https://pythreejs.readthedocs.io/en/stable/api/cameras/index.html\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"text = widgets.Text()\n", | ||
"widgets.jslink((fig.camera, 'position'), (text, 'value'))\n", | ||
"text" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
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