Update:
The workaround listed below is obsolete as of Asymptote 2.17. Now, the model axes are always in alignment with the viewer axes, independent from the projection angle set in the asy
input.
The reason for the misalignment is the fact that asymptote transforms the 3D object within the x-y-z world-coordinate system of the PRC file according to the
currentprojection=orthographic(-0.1,1,0.2);
setting in the asy source. It would be better to only apply the vector given to the initial camera position in the viewer. (Someone should tell this to the asymptote developpers.)
To have the axes of the 3D object aligned with the world axes do as follows:
Use
currentprojection=orthographic(0,0,1);
in the asy source file. And compile it with
asy -keep -tex pdflatex source.asy
Then, embed the prc produced using the media9
package:
\documentclass{article}
\usepackage{media9}
\includemedia[
width=0.8\linewidth,height=0.8\linewidth,
activate=pageopen,
add3Djscript=asylabels.js,
add3Djscript=3Dspintool.js,
3Dmenu,
3Dc2c=1 1 0.2, %object-to-camera vector
%settings below found by right-click-->Generate Default View
3Dcoo=-1.2360605001449585 -2.1437549591064453 -345.6598815917969,
3Droo=377.89275461201964,
3Dlights=Headlamp,
]{\includegraphics{source+0.pdf}}{source+0.prc}
\end{document}
Two JavaScripts have been attached in this example. asylabels.js
enables "billboard" behaviour of text labels. 3Dspintool.js
enables the 3D spin tool which facilitates moving the 3D object. The initial camera position was set using the 3Dc2c
option which is the object-to-camera direction vector.
There are several options to get 3d
asy
viewable in other viewers than Acrobat reader
(without interactive 3d
feature). The options -noprc
and -render=<num>
have to be specified.
The command asy -f pdf -noprc -render=0
results in vector
output
(there are some limitations, esp. when transparency is used to draw surfaces)
and the other way is, for example, asy -f pdf -noprc -render=4
(or higher than 4
)
will generate a higher quality raster image.
This is a vector output viewed in Evince:
Versions used are:
- Evince Version: 3.2.1
- Asymptote Version: 2.24,
but it should work with your versions as well.
Best Answer
Changes in
x
,y
andz
will not rotate the3d
object, rather the camera position will be changed. A simple procedure can help to set up the projection parameters:First, set the
2d
size of the picture, e.g.Next, import some of the modules, that support
3d
:Start with some values for the camera position, imagine that this is a corner of the box, from which you are looking at the origin.
Place a simple object to start, e.g. a unit coordinate lines at the origin:
Now, you can run this
sample.asy
file:with
asy -V sample.asy > ocamera.asy
. An interactive viewer will let you change the view point as you like, and thenright-double-click
will bring a menu. ClickCamera
and current camera settings will be saved inocamera.asy
file, looking something like:which can be copied into sample.asy and edited, for example, like this:
This will give you a starting point.