Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support lighting and shadows for scatter and mesh #342

Merged
merged 15 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ defaults:
shell: bash -l {0}

jobs:
lint:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ipyvolume-test
environment-file: environment-test.yml
python-version: ${{ matrix.python-version }}
mamba-version: "*"
auto-activate-base: false
channels: conda-forge

- name: Python PEP8 check
run: flake8 ipyvolume

build:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -51,9 +71,6 @@ jobs:
- name: Validate the labextension
run: jupyter labextension list 2>&1 | grep ipyvolume

- name: Python PEP8 check
run: flake8 ipyvolume

# - name: JavaScript prettyfier
# run: |
# yarn install
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name: Publish Package
on:
push:
tags:
- '*'

jobs:
deploy:
Expand All @@ -31,7 +32,7 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
twine upload --skip-existing dist/*
- name: Publish the NPM package
run: |
cd js
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Documentation is generated at readthedocs: [![Documentation](https://readthedocs

# Installation

If you want to use Jupyter Lab, please use version 3.0.

## Using pip

*Advice: Make sure you use conda or virtualenv. If you are not a root user and want to use the `--user` argument for pip, you expose the installation to all python environments, which is a bad practice, make sure you know what you are doing.*
Expand All @@ -67,18 +69,6 @@ $ pip install ipyvolume
$ conda install -c conda-forge ipyvolume
```

## For Jupyter lab users

The Jupyter lab extension is not enabled by default (yet).

```
$ conda install -c conda-forge nodejs # or some other way to have a recent node
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager
$ jupyter labextension install ipyvolume
$ jupyter labextension install jupyter-threejs

```


## Pre-notebook 5.3

Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/scatter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2020-03-30T10:36:00.344457Z",
Expand Down
11 changes: 8 additions & 3 deletions ipyvolume/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def klein_bottle(
texture=None,
both=False,
interval=1000,
**kwargs
):
"""Show one or two Klein bottles."""
import ipyvolume.pylab as p3
Expand All @@ -112,8 +113,8 @@ def klein_bottle(
v = np.linspace(0, 2 * pi, num=40, endpoint=endpoint)
u, v = np.meshgrid(u, v)
if both:
x1, y1, z1, _u1, _v1 = klein_bottle(endpoint=endpoint, draw=False, show=False)
x2, y2, z2, _u2, _v2 = klein_bottle(endpoint=endpoint, draw=False, show=False, figure8=True)
x1, y1, z1, _u1, _v1 = klein_bottle(endpoint=endpoint, draw=False, show=False, **kwargs)
x2, y2, z2, _u2, _v2 = klein_bottle(endpoint=endpoint, draw=False, show=False, figure8=True, **kwargs)
x = [x1, x2]
y = [y1, y2]
z = [z1, z2]
Expand All @@ -131,6 +132,9 @@ def klein_bottle(
x = 6 * cos(u) * (1 + sin(u)) + r * cos(u) * cos(v) * (u < pi) + r * cos(v + pi) * (u >= pi)
y = 16 * sin(u) + r * sin(u) * cos(v) * (u < pi)
z = r * sin(v)
x = x / 20
y = y / 20
z = z / 20
if draw:
if texture:
uv = True
Expand All @@ -145,9 +149,10 @@ def klein_bottle(
v=v / (2 * np.pi),
wireframe=wireframe,
texture=texture,
**kwargs
)
else:
mesh = p3.plot_mesh(x, y, z, wrapx=not endpoint, wrapy=not endpoint, wireframe=wireframe, texture=texture)
mesh = p3.plot_mesh(x, y, z, wrapx=not endpoint, wrapy=not endpoint, wireframe=wireframe, texture=texture, **kwargs)
if show:
if both:
p3.animation_control(mesh, interval=interval)
Expand Down
45 changes: 45 additions & 0 deletions ipyvolume/hotreload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from pathlib import Path
import logging

logger = logging.getLogger('ipyvolume')

HERE = Path(__file__).parent
_figures = []
_watching = set()


def _update_shaders(path=None, file_changed=None):
names = ['volr-fragment', 'volr-vertex', 'mesh-vertex', 'mesh-fragment', 'scatter-vertex', 'scatter-fragment', 'shadow-vertex', 'shadow-fragment']
for figure in _figures:
shaders = {}
# TODO: only read the ones we change
for name in names:
shader_path = path / (name + ".glsl")
with shader_path.open() as f:
shaders[name] = f.read()
figure._shaders = shaders


def watch(figure, path=None):
_figures.append(figure)
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

if path is None:
# this assues a editable install (pip install -e .)
path = HERE / '../js/glsl/'

class ShaderEventHandler(FileSystemEventHandler):
def on_modified(self, event):
super(ShaderEventHandler, self).on_modified(event)
if not event.is_directory:
logger.info(f'updating: {event.src_path}')
_update_shaders(path, event.src_path)

observer = Observer()
if path not in _watching:
logger.info(f'watching {path}')
observer.schedule(ShaderEventHandler(), path, recursive=True)
observer.start()
_watching.add(path)
_update_shaders(path)
Loading