Directly saving html file of Three.js graphic

74 views
Skip to first unread message

Peter Mueller

unread,
Jul 30, 2020, 10:22:09 AM7/30/20
to sage-support
If G is a 3d graphics object, then displaying it via G.show(viewer='threejs') the web browser allows to save the corresponding html code. However, for computing a large number of graphics on a server, it would be more convenient to save the html code directly. I would have expected something like 
G.save('name.html', viewer='threejs')
should work. However, it does not and I don't see if the intended task is implemented somehow.

-- Peter Mueller

Joshua Campbell

unread,
Aug 11, 2020, 5:28:58 AM8/11/20
to sage-support
Peter,

The ability to save directly to an HTML file as in the snippet you posted will be included in the upcoming 9.2 release. I had been wanting this feature myself, and implementing it made another change to the threejs viewer easier.

Regards,
Joshua Campbell

slelievre

unread,
Aug 11, 2020, 4:28:12 PM8/11/20
to sage-support
2020-08-11 09:28:58 UTC, Joshua Campbell:

>
> The ability to save directly to an HTML file as in the snippet
> you posted will be included in the upcoming 9.2 release.

Cool! Can you say which ticket makes that possible?

Joshua Campbell

unread,
Aug 11, 2020, 4:48:46 PM8/11/20
to sage-support
It was implemented as part of #29194 (Three.js-based Animations).

slelievre

unread,
Aug 11, 2020, 8:13:13 PM8/11/20
to sage-support
2020-08-11 20:48:46 UTC, Joshua Campbell:
>
> It was implemented as part of #29194 (Three.js-based Animations).

Thanks! Could you contribute a list of exciting new things
in Sage graphics to the release tour for SageMath 9.2?

- https://wiki.sagemath.org/ReleaseTours/sage-9.2

Joshua Campbell

unread,
Aug 12, 2020, 12:05:47 AM8/12/20
to sage-support
Will do!

Ricardo Acuna

unread,
Jul 25, 2021, 3:07:52 PM7/25/21
to sage-support
Hi,

There's a bug in 9.3, I don't know how to use Sage trac so I'm posting here.

When I use the save option I get an html with: 

<script src="/nbextensions/threejs/build/three.min.js"></script>                                                       

<script>                                                                                                               

  if ( !window.THREE ) document.write(' \                                                                              

<script src="https://cdn.jsdelivr.net/gh/sagemath/threejs-sage@122/build/three.min.js"><\/script> \                    

            ');                                                                                                        

</script>   

However from the tree.js example in the website I get: 

<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r110/build/three.min.js"></script>                            

<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r110/examples/js/controls/OrbitControls.js"></script>         

However, this is not quite right because it's an older version of mrdoob's version of three.js.

What works is: 

<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r117/build/three.min.js"></script>                            

<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r117/examples/js/controls/OrbitControls.js"></script>         


Now the link:

https://cdn.jsdelivr.net/gh/sagemath/threejs-sage@122/build/three.min.js

is broken, so I think that's where the error started. A quick fix would be for someone with access to the sage user's CDN to merge the files three.min.js and OrbitControls.js and upload them to https://cdn.jsdelivr.net/gh/sagemath/threejs-sage@122/build/three.min.js. A quick hack I know, but I'm not sure where it is in the source code to fix it and push a commit such that it's fixed in 9.4.

Best,

RJ Acuña

Reply all
Reply to author
Forward
0 new messages