[IPython-dev] Conflict between IPython notebook javascript and three.js?

Jason Grout jason-sage at creativetrax.com
Fri Oct 31 09:10:30 EDT 2014


On 10/31/14, 3:19, David Powell wrote:
> I am trying to display 3D objects in IPython notebooks, and so far
> three.js looks like the most promising approach. In particular, it is
> important that the 3D plot is still visible after converting the
> notebook to html.
>
> So far I have succeeded in getting a basic example working, by
> adapting http://nbviewer.ipython.org/github/payne92/notebooks/blob/master/00%20Javascript%20In%20Notebooks.ipynb
>
> However, I run into problems when I include the trackball controls
> from three.js, and restrict the controls to input only on the cavas
> DOM element (so that clicking outside the canvas does not modify the
> perspective). The trackball controls do not work correctly, as can be
> seen by running the attached notebook example.

This may or may not be an issue on top of this, but I've had problems 
with TrackballControls and OrbitControls (which I like better) accepting 
key events in the global page.  See 
https://github.com/mrdoob/three.js/pull/5236.


>
> When I export the notebook to html, I see that the wegbl output is
> present as I wanted. Furthermore, it seems that in the html, the
> trackball controls work perfectly. This suggests that the problem is
> some kind of conflict with the notebook's javascript. Any hints as to
> the possible cause of this problem would be greatly appreciated.

Do you see any errors in the javascript console?


>
> In case it matters, I am using IPython 2.3

By the way, you may be interested in the pythreejs library, which is a 
wrapping of three.js as IPython widgets:

https://github.com/jasongrout/pythreejs/tree/ipython

(the ongoing IPython notebook work is in the ipython branch)

See the examples folder for a few simple (and possibly out-of-date) 
examples.  It's still a work in progress, but it does work quite nicely 
already.  For example, see this example:

http://nbviewer.ipython.org/github/jasongrout/pythreejs/blob/ipython/examples/Surface.ipynb

One disadvantage of using widgets, which may be a show-stopper for you 
right now, is that you can't see the 3d plot in nbviewer and with 
nbconvert.  Jon's recent work on widget persistence should fix that, 
hopefully soon.  We're reviewing his pull request now.

The nice thing about it being a system of widgets is that you can 
control and adjust any parameter interactively from python or with the 
other widget controls.

Thanks,

Jason




More information about the IPython-dev mailing list