tl;dr:
Q: How can we turn a Graphics3D
into a manageable Graphics
object with only 2D graphics primitives for vector export?
A: I have came up with a partial solution which has room for improvement; scroll down to see it in a self-answer. To see remaining questions, head down to the bottom of this post.
There have been several questions on this subject, concerning rendering 3D graphics into vector, projecting 3D graphics onto a 2D plane, z-buffering and/or z-sorting, exporting 3D scenes, etc. etc. Here's just a small sample of such questions:
- How to export a 3D circle as a single piece PDF vectorial object?
- How to turn off depth sorting of 3D curves for Manipulate?
The above two questions stand out a bit. Exporting Graphics3D[Line[{p1,p2,p3,...}]]
in vector renders rather more like line(p1,p2), line(p2,p3), line(p3, p4)...
which is related to z-buffering, an effect that OP there direly wanted to disable.
- Converting 3D graphics to 2D for better export
- Exporting 2D & 3D graphics for use in Adobe Illustrator
- Export Plot3D in Mathematica 10.1 is Rasterized by default
- How can I export 3D plots as vector graphics?
There are many others which I may have missed. In particular, there is a beautiful QA which creates schematic drawings of 3D objects with hidden lines dashed, though it rasterizes the image.
Thus, lately, I have been wondering to myself, if we could somehow replicate the rendering engine of MMA and convert a Graphics3D
directly into Graphics
and 2D primitives.
Footnote:
The typical way a Graphics3D
can be exported as vector is something like
Graphics[{}, Epilog -> Inset[Graphics3D[...]]]
If something complicated and/or high-poly is presented there, the resulting pdf file is huge.
As I have a partial solution, I have follow-up questions (this is just an incomplete subset of possible improvements):
- Can we do better than my solution (improve or rewrite completely?)
Sphere[{x,y,z}, r]
cannot be rendered inGraphics
, but a straightforward conversion is/. Sphere -> Disk
. What else can be done to generalize things? What can be done better?- As an example, a uniformly-colored convex polyhedron with
FaceForm[Opacity[.2]]
rendered inGraphics3D
will still look like it has volume. The same polyhedron, passed through my processor will look like a flat polygon withOpacity[.4]
. Maybe we could adjust the colors of surfaces (polygons) depending on their normals and the view direction?