nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
657 stars 168 forks source link

Export images in PDF or SVG format #978

Closed ChristianRohde closed 1 year ago

ChristianRohde commented 1 year ago

Hi,

I am using nglviewer through https://github.com/nvelden/NGLVieweR/. In my Shiny-App I can make a snapshot to save the current view as an PNG image. I would like to export images in a scalable vector format such as SVG or PDF. I quickly went through the issues, but so far nobody asked for this feature?

I already asked in the NGLVieweR issues, but there seems to be no support for other image formats: https://github.com/nvelden/NGLVieweR/issues/3. Also in the manual NGLVieweR forwards me to you: 'For a full list of options, see "makeImage" and "ImageParameters" in the official NGL.js manual'. I looked at the options but I do not find a option to choose the image format. Is this correct?

Best, Christian

ppillot commented 1 year ago

Hi @ChristianRohde ! Exporting a 3D scene as a 2D vector image is far from being trivial. One could write some routines to convert the 3D meshes in 2D triangles in a SVG document, but I doubt that the result will be any good. NGL leverages the Three.js library which has an SVG renderer, but the results are esthetically subpar with what can be seen in a 3D view (an example here that can give an idea). I might miss something though... Unfortunately given the current resources for NGL development, I doubt that adding this feature would be feasible.

But if what you want is to get images with a high resolution, you can export as PNG and increase the resolution. There are options in the cartoon representations to augment the number of subdivisions in the spline to avoid artifacts at higher resolutions.