Viewing x3d files in a sage notebook

88 views
Skip to first unread message

alexeft...@gmail.com

unread,
Feb 8, 2014, 6:42:31 PM2/8/14
to sage-...@googlegroups.com
I have been working on a way to view sage x3d files interactively through the sage notebook. If anyone is interested, I got it working (although you have to refresh the page to see the display, I am pretty sure someone could tell me why/how to fix it).

* First, I added the following code to the cell.py file (new code starts at #new code below):

            elif F.startswith('.jmol_'):
                # static jmol data and images
                hasjmolimages=True
            #new code below
            elif F.endswith('.x3d'):
                script = '<x3d id="someUniqueId" showStat="false" showLog="false" x="0px" y="0px" width="400px" height="400px">'
                script += '<scene><inline url="%s" ></inline></scene></x3d>' % url
                images.append(script)

* Then I downloaded this javascript file to the /usr/lib/sagemath/devel/sagenb-main/sagenb/data/sage/js/ directory as 3xdom.js.
* Then I added the following line to the notebook_dynamic.js file:

{% include "js/x3dom.js" %}

Now when I save a .x3d file and refresh the page, a nice interactive screen comes up that allows me to zoom and rotate. See here for an example (not a sage notebook, but the same interactive viewer I get).

I just thought I would pass this on. I am sure someone more familiar with the inner workings of the notebook server could improve upon this technique and get it working without the page refresh.

Thanks,
Alex Eftimiades


kcrisman

unread,
Feb 8, 2014, 10:01:38 PM2/8/14
to sage-...@googlegroups.com


On Saturday, February 8, 2014 6:42:31 PM UTC-5, alexeft...@gmail.com wrote:
I have been working on a way to view sage x3d files interactively through the sage notebook. If anyone is interested, I got it working (although you have to refresh the page to see the display, I am pretty sure someone could tell me why/how to fix it).


Wow, nice work!  I opened https://github.com/sagemath/sagenb/issues/199 in the hopes that someone can add this option, assuming the js file is clean.  Since we have x3d support we might as well use it, or enable people to do so...

William Stein

unread,
Feb 8, 2014, 10:39:42 PM2/8/14
to sage-devel
On Sat, Feb 8, 2014 at 7:01 PM, kcrisman <kcri...@gmail.com> wrote:
>
>
> On Saturday, February 8, 2014 6:42:31 PM UTC-5, alexeft...@gmail.com wrote:
>>
>> I have been working on a way to view sage x3d files interactively through
>> the sage notebook. If anyone is interested, I got it working (although you
>> have to refresh the page to see the display, I am pretty sure someone could
>> tell me why/how to fix it).
>>
>
> Wow, nice work! I opened https://github.com/sagemath/sagenb/issues/199 in
> the hopes that someone can add this option, assuming the js file is clean.

Please be careful in how this is actually done, keeping in mind that
3xdom.js is 800kb, and hence is surely significantly larger than all
the rest of the Javascript in sagenb combined. If this gets added to
sagenb, make sure that 3xdom.js is only loaded if somebody actually
displays an x3d file, not on *all* loads of sagenb. I tried a little
to minify 3xdom.js and it still was nearly 800kb. (Three.js is
comparable -- it's about 400kb minified.)

> Since we have x3d support we might as well use it, or enable people to do
> so...


--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

kcrisman

unread,
Feb 10, 2014, 12:57:41 PM2/10/14
to sage-...@googlegroups.com
Great point!  I've added this to the ticket.

Alex Eftimiades

unread,
Feb 15, 2014, 1:30:24 PM2/15/14
to sage-...@googlegroups.com
I modified the extra code in cell.py to dynamically load the javascript as needed. For some reason, you still have to refresh the page to see the image. The modified steps are detailed on the ticket.

Let me know what else can be done.
Alex Eftimiades

--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/oRGbnyUxVXQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages