vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
555 stars 92 forks source link

Embedding 3D frame into 2D picture #283

Closed zzdatura closed 2 years ago

zzdatura commented 2 years ago

System

Configuration

// .asy/config.asy - Asymptote configuration file
import settings;

outformat = "pdf";      // for opacity, even though xelatex defaults to pdf
tex       = "xelatex";
pdfviewer = "xdg-open";
batchMask = true;
render    = 4;
iconify   = true;
prc       = false;

Description of the problem

I want to be able to embed a 3D frame into a 2D picture, this way I could for instance align multiple 3D pictures in a single page, maybe frame them, put titles above each of them or even connect them with drawing elements like lines or arrows which could be useful for presentations and so on. I know I could use mogrify or other software for this kind of things but I’d like to do it from asymptote in a single go.

It was possible to do it before but recently there was a regression. For now I don't have the exact commit that caused this but I noticed a lot of work being done in 3D recently.

Example

Looking at the documentation, I suppose I could get something like this to work:

import graph3;

// make a red frame
size(5cm);
draw(box((-1,-1), (1, 1)), 4+red);

// draw something in 3d in another picture
picture pic;
size(pic, 5cm);
draw(pic, unitsphere);

// try to attach a 3d frame inside our frame
// none of these options seem to work

//add(currentpicture, pic.fit());           // fit picture size
//add(currentpicture, pic.fit(), (0,0));    // 'pair position' overload (add)
//add(currentpicture, pic.fit(), (0,0,0));  // 'triple position' overload
//attach(currentpicture, pic.fit());        // attach the frame
//add(currentpicture, pic.fit3(), (0,0));   // 'pair position' overload (add)
//add(currentpicture, pic.fit3(), (0,0,0)); // 'triple position' overload

However, none of these option for adding the pic frame into currentpicture gives me the desired result and the 3D sphere does not appear. In my system, I can make a standalone 3D picture without any problems, it's embedding them into a 2D “background” that doesn’t work.

johncbowman commented 2 years ago

You can't embed a 3D picture into a 2D picture unless you are willing to render the 3D picture to a 2D bitmap first. Is that what you want?

zzdatura commented 2 years ago

Yes! That's exactly what I want!

johncbowman commented 2 years ago

This regression is now fixed in commit 588d4d204cb0874c1e4a4229c5b8108e9785e049. Fitting 2D bitmaps of 3D pictures into a 2D picture works again:

import graph3;

// make a red frame                                                             
size(6cm);
draw(box((-1,-1),(1, 1)),red+4);

picture pic;
size(pic,5cm);
draw(pic,unitsphere);
add(currentpicture,pic.fit());