Closed egourgoulhon closed 4 years ago
Description changed:
---
+++
@@ -14,7 +14,7 @@
- some features are still missing in three.js, like
- converting the view to a png image for printing
- mesh plots
- - vector field plots (via the functions `plot_vector_field` and `plot_vector_field3d` only; three.js works fine with the [plot() method of vector fields on manifolds](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/vectorfield.html#sage.manifolds.differentiable.vectorfield.VectorField.plot), the latter being based on individual arrow plots)
+ - vector field plots (via the function `plot_vector_field3d` only; three.js works fine with the [plot() method of vector fields on manifolds](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/vectorfield.html#sage.manifolds.differentiable.vectorfield.VectorField.plot), the latter being based on individual arrow plots)
- faces of polytopes look rounded, see
This is to point out that, in the current implementation, it is necessary to add the option online=True
to viewer='threejs'
to have three.js rendering in Jupyter notebooks on CoCalc, mybinder.org and nbviewer.jupyter.org. See the related discussion on sage-devel.
I know that with the Jupyter kernel it is possible for the kernel to serve files at a specific URL, though I don't know exactly how the mechanism works. We do this, for example, to serve the Sage HTML docs via the Jupyter kernel. We should do the same for any JavaScript files required for threejs, or any other widgets. That, I think, would solve the "online=True" debate. (In other words, properly implemented, it would mean we can use online=False, but the relative paths for the scripts would still be correct, even when run from binder, etc.)
Removing most of the rest of my open tickets out of the 8.7 milestone, which should be closed.
Please see #27592 for a bit of preliminary cleanup of the threejs rendering I would like to do.
I am still trying to find a solution for the issue mentioned in this ticket of rendering polyhedrons. As I mentioned in comment:42 the solution from the ThreeJS perspective is easy. But it's not clear to me how to pass something like a 'shading' option around Sage's plot3d framework in a generic manner that makes sense, or how this problem is handled by the other 3D renderers. If anyone with more experience with this codebase has any ideas I'd appreciate to hear them.
(I know there is a Texture
object, but I'm not really sure how it's used. It doesn't have threejs support yet either, apparently, though I could probably add that.)
Description changed:
---
+++
@@ -12,12 +12,12 @@
**cons**:
- some features are still missing in three.js, like
- - converting the view to a png image for printing
+ - converting the view to a png image for printing (Update: this is now #27910)
- mesh plots
- vector field plots (via the function `plot_vector_field3d` only; three.js works fine with the [plot() method of vector fields on manifolds](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/vectorfield.html#sage.manifolds.differentiable.vectorfield.VectorField.plot), the latter being based on individual arrow plots)
- - faces of polytopes look rounded, see
+ - ~~faces of polytopes look rounded, see~~
-d = dodecahedron() -d.show(viewer='threejs') +dodecahedron(viewer='threejs')
+ ==> fixed by #27836 (merged in Sage 8.8.beta7)
Description changed:
---
+++
@@ -12,9 +12,9 @@
**cons**:
- some features are still missing in three.js, like
- - converting the view to a png image for printing (Update: this is now #27910)
+ - converting the view to a png image for printing; NB: thanks to #27910 (merged in Sage 8.8.rc0), the png conversion is now possible in interactive mode; see [this discussion](https://github.com/sagemath/sage/issues/27910#comment:6)
- mesh plots
- - vector field plots (via the function `plot_vector_field3d` only; three.js works fine with the [plot() method of vector fields on manifolds](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/vectorfield.html#sage.manifolds.differentiable.vectorfield.VectorField.plot), the latter being based on individual arrow plots)
+ - vector field plots (via the function `plot_vector_field3d` only; three.js works fine with the [plot() method of vector fields on manifolds](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/vectorfield.html#sage.manifolds.differentiable.vectorfield.VectorField.plot), the latter being based on individual arrow plots) (Update: this is now #27932)
- ~~faces of polytopes look rounded, see~~
Description changed:
---
+++
@@ -14,10 +14,5 @@
- some features are still missing in three.js, like
- converting the view to a png image for printing; NB: thanks to #27910 (merged in Sage 8.8.rc0), the png conversion is now possible in interactive mode; see [this discussion](https://github.com/sagemath/sage/issues/27910#comment:6)
- mesh plots
- - vector field plots (via the function `plot_vector_field3d` only; three.js works fine with the [plot() method of vector fields on manifolds](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/vectorfield.html#sage.manifolds.differentiable.vectorfield.VectorField.plot), the latter being based on individual arrow plots) (Update: this is now #27932)
- - ~~faces of polytopes look rounded, see~~
-
-```
-dodecahedron(viewer='threejs')
-```
- ==> fixed by #27836 (merged in Sage 8.8.beta7)
+ - ~~vector field plots~~ ==> fixed by #27932 (merged in Sage 8.9.beta0)
+ - ~~faces of polytopes look rounded~~ ==> fixed by #27836 (merged in Sage 8.8.beta7)
Replying to @embray:
Please see #27592 for a bit of preliminary cleanup of the threejs rendering I would like to do.
I am still trying to find a solution for the issue mentioned in this ticket of rendering polyhedrons. As I mentioned in comment:42 the solution from the ThreeJS perspective is easy. But it's not clear to me how to pass something like a 'shading' option around Sage's plot3d framework in a generic manner that makes sense, or how this problem is handled by the other 3D renderers. If anyone with more experience with this codebase has any ideas I'd appreciate to hear them.
(I know there is a
Texture
object, but I'm not really sure how it's used. It doesn't have threejs support yet either, apparently, though I could probably add that.)
Oh, I hadn't seen that ticket before, but this was fixed already by #27836. Nice!
Do we know of any other major blockers to throwing the switch on this?
Description changed:
---
+++
@@ -13,6 +13,6 @@
- some features are still missing in three.js, like
- converting the view to a png image for printing; NB: thanks to #27910 (merged in Sage 8.8.rc0), the png conversion is now possible in interactive mode; see [this discussion](https://github.com/sagemath/sage/issues/27910#comment:6)
- - mesh plots
+ - mesh plots: implementation in progress: see #28343
- ~~vector field plots~~ ==> fixed by #27932 (merged in Sage 8.9.beta0)
- ~~faces of polytopes look rounded~~ ==> fixed by #27836 (merged in Sage 8.8.beta7)
Replying to @embray:
Do we know of any other major blockers to throwing the switch on this?
Not from my side, all the more that the last remaining "con", namely mesh plots, is being handled in #28343.
Replying to @egourgoulhon:
Replying to @embray:
For 3D graphics in the static documentation I don't know why we don't just use something like matplotlib. It outputs very nice 3D graphics these days.
Indeed.
I can write the necessary adapters...
This would be nice! Moreover, why not using them not only for the documentation, but for any static display (as we already have with tachyon), by offering a new option:
viewer='matplotlib'
?
3D plots in the documentation remain to be addressed. This new viewer sounds like a great idea.
I might be missing your point, but I don't think changing the default viewer to threejs is really related to how plots in the documentation are generated. It would still be nice to improve them, but that's a separate issue.
Replying to @embray:
I might be missing your point, but I don't think changing the default viewer to threejs is really related to how plots in the documentation are generated. It would still be nice to improve them, but that's a separate issue.
docbuild
currently uses the default viewer. There are multiple comments on this ticket indicating errors when Three.js is set to the default.
Replying to @paulmasson:
Replying to @embray:
I might be missing your point, but I don't think changing the default viewer to threejs is really related to how plots in the documentation are generated. It would still be nice to improve them, but that's a separate issue.
docbuild
currently uses the default viewer. There are multiple comments on this ticket indicating errors when Three.js is set to the default.
It would suffice to make the following change to the code of sphinx_plot
, in line 75 of src/sage/docs/conf.py
:
- graphics.save(fn)
+ graphics.save(fn, viewer='jmol')
to have all the documentation generated with Jmol, as it is currently. Of course the drawback is that the figures in the documentation will have an aspect different from what the user will get with threejs as the default. But maybe this is something we can live on at the moment...
Description changed:
---
+++
@@ -13,6 +13,6 @@
- some features are still missing in three.js, like
- converting the view to a png image for printing; NB: thanks to #27910 (merged in Sage 8.8.rc0), the png conversion is now possible in interactive mode; see [this discussion](https://github.com/sagemath/sage/issues/27910#comment:6)
- - mesh plots: implementation in progress: see #28343
+ - ~~mesh plots~~ ==> fixed by #28343 (merged in Sage 8.9.beta8)
- ~~vector field plots~~ ==> fixed by #27932 (merged in Sage 8.9.beta0)
- ~~faces of polytopes look rounded~~ ==> fixed by #27836 (merged in Sage 8.8.beta7)
Description changed:
---
+++
@@ -8,6 +8,7 @@
- three.js offers functionality absent in Jmol, notably axis labels
- three.js works better with Jupyter than Jmol, see e.g. [this report](https://groups.google.com/d/msg/sage-support/KvNuD2DfRz0/VM1BPPDPCAAJ))
- Jmol is a nightmare for packagers (for Debian, Windows, ...), see e.g. [this discussion on debian-science-sagemath](https://alioth-lists.debian.net/pipermail/debian-science-sagemath/2018-July/001228.html); in particular jsmol, which is invoked in Jupyter notebooks, is not packaged for Debian (see [comment:49](#comment%3A49))
+- Jmol, as currently shipped with Sage, is broken with recent version of Java runtime environment, e.g. on Debian Buster and Ubuntu 18.04, see this [ask.sagemath question](https://ask.sagemath.org/question/47837/jmol-stuck-at-initializing-3d-display/)
**cons**:
In answer to comments to y answer to this ask.sagemath question: threejs
still has problems handling transparencies and hidden-facets problems:
Test case: try to plot a plane and a paraboloid:
sage: P1=plot3d(lambda x,y:x^2+y^2,(-2,2),(-2,2), color="blue", opacity=0.5)
sage: P2=plot3d(lambda x,y:1,(-2,2),(-2,2), color="yellow", opacity=0.5)
sage: show(P1+P2, viewer="threejs")
Launched html viewer for Graphics3d Object
Now, in the browser window, try to change your point of view to look at the object from a little above the z==1
plane: the "lower" part of the paraboloid diseappears if no point of it can be "viewed directly". It should be seen "through the plane" (in a greenish shade...).
There are also points of view where the "directly visible" part of the paraboloid is visible but the part "hidden" by the plane is not see "through the plane" as it should.
Last, "rotating" the object exhibits moiré effects at some points of the movement.
... sorry to interrupt the discussion.
I am very much looking forward to the improvements of this ticket!
I have one small issue concerning polytopes (which is a feature that apparently a lot of people use, I receive a lot of feedback):
http://doc.sagemath.org/html/en/thematic_tutorials/geometry/polytope_tikz.html
I would be happy to migrate this tutorial to the then default viewer (especially for people where jmol would not work). Since I do not know threejs
that much I was wondering if there is an equivalent way to figure out the "angle of view data" used in the tutorial. Namely:
In jmol's console, if one clicks "State", one gets a list of three numbers next to moveto
followed by an angle of rotation between 0 and 360. These 4 numbers essentially describe the 3D-2D projection.
Is there a (fairly) easy way to get this in threejs
?
Replying to @EmmanuelCharpentier:
In answer to comments to y answer to this ask.sagemath question:
threejs
still has problems handling transparencies and hidden-facets problems:
Transparency in Three.js is rendered based on the centers of meshes. When two transparent meshes intersect they will be treated as if located entirely at each respective center, so that the problems described will not go away any time soon. One approach would be to use the WebGL 2 renderer of Three.js, as it has additional features not available in WebGL, but unfortunately this API is not universally supported mostly due to Apple.
The question is whether transparency is more important than packaging issues. Besides, Jmol will remain available as a viewer option.
Replying to @jplab:
In jmol's console, if one clicks "State", one gets a list of three numbers next to
moveto
followed by an angle of rotation between 0 and 360. These 4 numbers essentially describe the 3D-2D projection.Is there a (fairly) easy way to get this in
threejs
?
The underlying information is available from the position of the camera relative to the midpoint of the scene. The question is how to make it easily accessible, since the Three.js OrbitControls
use the mouse right click to pan the scene. Open possibility would be to add an additional icon like I did for downloading an image of the scene.
I don't think we need to worry too much about a particular browser not supporting a feature (WebGL 2) - as long as there is a browser for the OS in question that does support the feature.
Replying to @paulmasson:
Replying to @EmmanuelCharpentier:
In answer to comments to y answer to this ask.sagemath question:
threejs
still has problems handling transparencies and hidden-facets problems:Transparency in Three.js is rendered based on the centers of meshes. When two transparent meshes intersect they will be treated as if located entirely at each respective center, so that the problems described will not go away any time soon. One approach would be to use the WebGL 2 renderer of Three.js, as it has additional features not available in WebGL, but unfortunately this API is not universally supported mostly due to Apple.
dimpase
's answer is relevant...
The question is whether transparency is more important than packaging issues. Besides, Jmol will remain available as a viewer option.
Another (admittedly caricatural) example where the "transparency problem" clobbers the mathematical usefulness of the plot :
sage: P1=implicit_plot3d(E1.lhs().subs([a==2]),(x, -2, 2), (y, -2, 2), (z, -2, 2)
....: , color="blue", opacity=0.5)
sage: P2=implicit_plot3d(E2.lhs().subs([b==1]),(x, -2, 2), (y, -2, 2), (z, -2, 2)
....: , color="yellow", opacity=0.5)
sage: (P1.P2).show(viewer="threejs")
The part of the yellow cone inner to the sphere isn't visualized at all...
Replying to @dimpase:
I don't think we need to worry too much about a particular browser not supporting a feature (WebGL 2) - as long as there is a browser for the OS in question that does support the feature.
I disagree very strongly on this point: if the viewer produces wildly different results in different browsers it will produce nothing but endless questions. That is the entire reason for the existence of libraries like jQuery to ensure conformity across browsers.
Replying to @EmmanuelCharpentier:
Another (admittedly caricatural) example where the "transparency problem" clobbers the mathematical usefulness of the plot :
sage: P1=implicit_plot3d(E1.lhs().subs([a==2]),(x, -2, 2), (y, -2, 2), (z, -2, 2) ....: , color="blue", opacity=0.5) sage: P2=implicit_plot3d(E2.lhs().subs([b==1]),(x, -2, 2), (y, -2, 2), (z, -2, 2) ....: , color="yellow", opacity=0.5) sage: (P1.P2).show(viewer="threejs")
The part of the yellow cone inner to the sphere isn't visualized at all...
This example is incomplete. What are E1 and E2?
Replying to @paulmasson:
[ Snip... ]
This example is incomplete. What are E1 and E2?
Wups ! Compleed (and checked):
var("x, y, z, a, b")
E1 = x^2 + y^2 + z^2 - a^2 == 0
E2 = x^2 + y^2 - b^2*z^2 == 0
P1=implicit_plot3d(E1.lhs().subs([a==2]),(x, -2, 2), (y, -2, 2), (z, -2, 2),
color="blue", opacity=0.5)
P2=implicit_plot3d(E2.lhs().subs([b==1]),(x, -2, 2), (y, -2, 2), (z, -2, 2),
color="yellow", opacity=0.5)
(P1+P2).show(viewer="threejs")
Replying to @paulmasson:
Replying to @dimpase:
I don't think we need to worry too much about a particular browser not supporting a feature (WebGL 2) - as long as there is a browser for the OS in question that does support the feature.
I disagree very strongly on this point: if the viewer produces wildly different results in different browsers it will produce nothing but endless questions. That is the entire reason for the existence of libraries like jQuery to ensure conformity across browsers.
You either mean to say that WebGL 2 is dead and noone is using it, or you say it is technically impossible to print an error message on Safari as soon as WebGL 2 is used there...
I gather that Apple is unwilling to support WeGL 2. So what? Jupyter and SageNB never worked well in IE, and?
EDIT: jmol is just not working on some platforms (e.g. on Windows or in a VM, on various HPC clusters, etc), full stop. We are constantly helping users to work around this limitation. If something is not working in Safari, oh well, we can live with it, document, print warnings, and move on.
Replying to @EmmanuelCharpentier:
The part of the yellow cone inner to the sphere isn't visualized at all...
IMHO, these opacity issues are very minor ones: in the two provided examples, it suffices to adjust the opacity parameter of the background object to fix them, e.g. opacity=1
in P1
of comment:75 and opacity=1
in P2
of comment:78.
Replying to @egourgoulhon:
Replying to @EmmanuelCharpentier:
The part of the yellow cone inner to the sphere isn't visualized at all...
IMHO, these opacity issues are very minor ones: in the two provided examples, it suffices to adjust the opacity parameter of the background object to fix them, e.g.
opacity=1
inP1
of comment:75 andopacity=1
inP2
of comment:78.
Easy fix, indeed. But the (mathematical) point is that neither as "background". Not a problem here, more of a problem for visualizing, say, self-intersecting surfaces...
Description changed:
---
+++
@@ -13,7 +13,9 @@
**cons**:
- some features are still missing in three.js, like
- - converting the view to a png image for printing; NB: thanks to #27910 (merged in Sage 8.8.rc0), the png conversion is now possible in interactive mode; see [this discussion](https://github.com/sagemath/sage/issues/27910#comment:6)
+ - converting the view to a png image in *non-interactive* mode (e.g. when generating the reference manual, cf. [comment:66](#comment%3A66)); NB: thanks to #27910 (merged in Sage 8.8.rc0), the png conversion is now possible in *interactive* mode; see [this discussion](https://github.com/sagemath/sage/issues/27910#comment:6)
- ~~mesh plots~~ ==> fixed by #28343 (merged in Sage 8.9.beta8)
- ~~vector field plots~~ ==> fixed by #27932 (merged in Sage 8.9.beta0)
+- three.js has some issues:
- ~~faces of polytopes look rounded~~ ==> fixed by #27836 (merged in Sage 8.8.beta7)
+ - some opacity issues: cf. [comment:75](#comment%3A75) and below
I've updated the pros/cons section of the ticket description. I guess the question is not "is three.js perfect, so that it can become the default viewer?", but rather "is the ratio gain (pros) to loss (cons) high enough to make it the default viewer?". IMHO the answer is yes, given that jmol will remain available (when it works...) as an optional viewer. Probably there should be a poll on sage-devel. Before launching such a poll, I would like to test the workaround proposed in comment:66 for generating the doc. Do you have any other suggestion to deal with this last point?
Replying to @paulmasson:
The question is whether transparency is more important than packaging issues. Besides, Jmol will remain available as a viewer option.
!^ This. Different viewers will all have different issues, and fixing every known bug with ThreeJS (which is a problem beyond Sage since it involves browsers, WebGL libraries, operating systems, etc.) is not a viable blocker to making this change or it will never happen.
The ThreeJS viewer works for the most common cases, and most importantly for cases that are likely to arise in tutorials for new users, etc. For more niche applications, other viewers will still be available as alternatives until/unless the issue can be resolved with ThreeJS.
Replying to @embray:
Replying to @paulmasson:
The question is whether transparency is more important than packaging issues. Besides, Jmol will remain available as a viewer option.
!^ This. Different viewers will all have different issues, and fixing every known bug with ThreeJS (which is a problem beyond Sage since it involves browsers, WebGL libraries, operating systems, etc.) is not a viable blocker to making this change or it will never happen.
The ThreeJS viewer works for the most common cases, and most importantly for cases that are likely to arise in tutorials for new users, etc. For more niche applications, other viewers will still be available as alternatives until/unless the issue can be resolved with ThreeJS.
I mostly agree with you both : in their current respective states, threejs
is probably a more useful default than jmol
(unless sudden progress on #25026 and related tickets miraculously happens...) . However :
Probably there should be a poll on sage-devel.
Seconded. Since it probably is already too late for 8.9 (which is at the "rc" stage), and since a doc-building test must be undertaken, this pool could proceed as soon as this tests well.
Other valuable suggestions have been made, such as the addition of some widget allowing to get the current view parameters, etc. (and I may have a couple, if I can take the time to *think about them...). Unless they are trivial, they probably would deserve ticket(s) of their own, less urgent than the proposed change of default.
Replying to @EmmanuelCharpentier:
I mostly agree with you both : in their current respective states,
threejs
is probably a more useful default thanjmol
(unless sudden progress on #25026 and related tickets miraculously happens...) . However :
Let the miracle happen, #25026 needs review !
I personally need that for SDL since next version is going to migrate to Debian buster.
Author: Paul Masson, Eric Gourgoulhon
Changed branch from u/paulmasson/22408 to public/graphics/22408
Here is a first version of the complete code for making threejs the default viewer. With respect to the code in previous branch (which was only changing the 'viewer'
value in the dict SHOW_DEFAULTS
), this code makes viewer=None
equivalent to viewer='threejs'
and updates the documentation to reflect the change of the default viewer.
NB: for generating the reference manual, instead of the solution proposed in comment:66, I've made the method Graphics3d._save_image_png
fall back on jmol if the viewer is threejs.
I've checked that both the html and pdf documentation are generated without any error (with png figures produced by jmol though...) and I am setting the ticket to 'needs review' to draw the attention of the patchbots.
New commits:
ca4852b | Merge branch 'u/paulmasson/22408' of git://trac.sagemath.org/sage into Sage 8.9.rc0 |
fcac479 | Make threejs the default 3d viewer |
Reviewer: Dima Pasechnik
looks good to me, especially it's nice that it works in Jupyter notebooks and in sagenb. (on various Lines and on OSX 10.13.6)
I am setting the ticket back to 'needs_review' and the milestone to sage-8.9 to draw the attention of the patchbots (apparently having 'sage-pending' prevented the patchbots to run on this ticket).
PS: I am also opening a poll on sage-devel.
Replying to @egourgoulhon:
PS: I am also opening a poll on sage-devel.
This is https://groups.google.com/forum/#!topic/sage-devel/DmBa1bjUJ-I
moving milestone to 9.0 (after release of 8.9)
Changed branch from public/graphics/22408 to fcac479
This seems to have broken the doc building on some python3 sage:
There is also an issue when the browser does not support OpenGL, there should be some fallback in such cases: see #28589.
Re the messages like
RuntimeError: Jmol failed to create file '/home/u1/chapoton/.sage/temp/atlas/38849/dir_j7p5z38w/preview.png', see '/home/u1/chapoton/.sage/temp/atlas/38849/tmp_9z6qo292.txt'
What did the txt files say?
Replying to @jhpalmieri:
Re the messages like
RuntimeError: Jmol failed to create file '/home/u1/chapoton/.sage/temp/atlas/38849/dir_j7p5z38w/preview.png', see '/home/u1/chapoton/.sage/temp/atlas/38849/tmp_9z6qo292.txt'
What did the txt files say?
My random guess of the day is that it is caused by https://groups.google.com/d/topic/sage-devel/snx2Rr5W6xc/discussion
Now that #22389 (Make Three.js work offline) and #22261 (Three.js: Default lighting) have been merged, it is time to make threejs the default 3d viewer, in replacement of jmol.
A discussion about this started in #22389. In addition, one may note the following:
pros:
cons:
mesh plots==> fixed by #28343 (merged in Sage 8.9.beta8)vector field plots==> fixed by #27932 (merged in Sage 8.9.beta0)faces of polytopes look rounded==> fixed by #27836 (merged in Sage 8.8.beta7)CC: @paulmasson @novoselt @sagetrac-tmonteil @kcrisman @slel @williamstein @embray @infinity0 @kiwifb @egourgoulhon @strogdon @timokau @jplab
Component: graphics
Keywords: 3D, plot3d, threejs, three.js, jmol
Author: Paul Masson, Eric Gourgoulhon
Branch:
fcac479
Reviewer: Dima Pasechnik
Issue created by migration from https://trac.sagemath.org/ticket/22408