[IPython-dev] WebGL example in IPython notebook based on three.js
andy at payne.org
Mon Jan 19 14:39:18 EST 2015
[*clicked send accidentally, please ignore my previous incomplete email*]
I recently managed to get 3D vector plots working in the IPython notebook,
> by statically producing three.js output. I thought I'd share it here in
> case this example is useful for anyone else, or if anyone has any
> suggestions as to how I could do things better.
Great work! Thanks for sharing that.
Did you consider or explore using require.js to load the three.js library?
You can reference and load the library once, and then not have to inline it
within each cell.
Aside for folks fiddling with Javscript libraries & the Web notebook: the
obvious approach of dropping a <script> reference in an HTML cell or result
isn't robust. When the cell is reexecuted, the browser will load the
library again, overwriting the original library name space. However, the
first instance of the library will likely still be there because of
lingering references. So you'll have a variable "foo" of type X in the old
library instance, and you'll pass it into a function call (new library
instance) and things will fail in strange ways because all the type tests
in the new library instance fail. And you will drive yourself crazy
because you'll be in the JS console and wonder why foo is clearly of type
"X", but "isinstanceof X" is giving False.
That's why David's JS code has this test:
if ( *camera instanceof THREE.Camera === false* || !
console.log("Animation loop failed: stopping");
See my example of using require.js for three.js, here:
For the dev team, this raises the issue of: what's the best idiom for JS
in a cell to access the output area? (See SO question:
you can see with my notebook (above) vs David's, the element variable
element doesn't exist in an nbconvert(ed) notebook.
David made things work by generating (effectively) a UID as part of his
consistently run into this pattern. I think the notebook could provide
some "standard" way to reference the output area for the cell, that
What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev