# Beamer class and U3D Views

I want to switch 3D views in my presentation. I have read in the movie15 package that it is possible with the command: (dice example from movie15.pdf page 16)

\movieref[3Dviewindex=N]{dice}{Click here}


But in this case I have to click with my mouse on a button. It is possible to bind the command on a key or to call the button via a key or combine this with the command \pause ?

Regards,

Grandement.

First of all, don't use movie15 anymore. Package media9 is meant to replace it.

We can make use of a PDF feature called Sub-Page Navigation to bind GoTo3DView actions to the left <-- and right --> keyboard keypress events. Only after executing the complete sequence of actions, the Reader proceeds to the next/previous document page.

Note that this feature requires the Full-Screen mode.

The code below defines the command \ThreeDPresSteps which takes a comma separated list of {<3D label>,<number of views>} pairs as its argument. (Braces around pairs are mandatory, even for a single one.)

\ThreeDPresSteps{...} is to be used before the code of a beamer frame containing 3D objects. The views of the 3D objects referenced by the command are went through in the order given by the views files and in the order of <3D label>s in the command argument.

Remember that only the left and right arrow keys allow you to navigate in both directions between the presentation steps within a page. The other arrow and PgUp/PgDn keys only go in the forward direction (AR-9 for Linux).

...

% initialise 3D presentation steps for the next frame
\ThreeDPresSteps{{3DobjA,7},{3DobjB,5}}

\begin{frame}{...}
\includemedia[label=3DobjA,3Dviews=3DviewsA.txt,...]{...}{...}
\includemedia[label=3DobjB,3Dviews=3DviewsB.txt,...]{...}{...}
\end{frame}

% clear 3D presentation steps before next frame
\ThreeDPresStepsReset

...


Minimal example with two 3D objects (2 xdice.u3d) in a beamer frame:

\documentclass{beamer}
\usepackage{media9}[2015/11/02]

%write file with 7 predefined 3D views
\usepackage{filecontents}
\begin{filecontents*}{3Dviews.txt}
VIEW=Front
ROO=27
END
VIEW=Back
ROO=27
C2C=0 1 0
END
VIEW=Left
ROO=27
C2C=-1 0 0
END
VIEW=Right
ROO=27
C2C=1 0 0
END
VIEW=Top
ROO=27
C2C=0 0 1
END
VIEW=Bottom
ROO=27
C2C=0 0 -1
END
VIEW=Fish Eye at Centre
AAC=130
END
\end{filecontents*}

\ExplSyntaxOn
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% command to build presentation steps for navigating through 3D views
% Argument: comma separated list of {label,number of views} pairs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\ThreeDPresSteps[1]{
\tl_set:Nn\l_initactn_tl{}
\clist_map_inline:nn{#1}{\tl_if_exist:cT{ann@\clist_item:nn{##1}{1}}{
\pbs_pdfobj:nnn{}{dict}{ %init. actions for all 3D objects -> goto 1st view
/S/GoTo3DView/V~0/TA~\use:c{ann@\clist_item:nn{##1}{1}}
}
\tl_put_right:Nx\l_initactn_tl{~\pbs_pdflastobj:}
}}
\pbs_pdfobj:nnn{}{dict}{} %reserve pdf obj for the Next' nav. node
\tl_set:Nx\l_nextnode_tl{\pbs_pdflastobj:}
%primary nav. node, initialise all 3D objects in the page
\pbs_pdfobj:nnn{}{dict}{
/NA<</S/Named/N/NOP/Next[\l_initactn_tl]>>/Next~\l_nextnode_tl
}
\tl_set:Nn\l_prevactn_tl{}\tl_set:Nx\l_prevnode_tl{/Prev~\pbs_pdflastobj:}
\tl_set_eq:NN\l_currnode_tl\l_nextnode_tl
\sys_if_output_pdf:TF{
\edef\pdfpageattrsave{\the\pdfpageattr}
\tl_set:Nx\l_temp_tl{\pdfpageattrsave/PresSteps~\pbs_pdflastobj:}
\immediate\pdfpageattr\exp_after:wN{\l_temp_tl}
}{
\bool_if:NTF\g_pbs_dvipdfmx_bool{ %dvipdfmx/XeTeX
\special{pdf:put~@thispage <</PresSteps~\pbs_pdflastobj:>>~}
}{
\special{ps:~
mark~{ThisPage}~<</PresSteps~\pbs_pdflastobj:>>/PUT~pdfmark~
}
}
}
\clist_map_inline:nn{#1}{
\tl_if_exist:cT{ann@\clist_item:nn{##1}{1}}{
\int_step_inline:nnnn{1}{1}{\int_eval:n{\clist_item:nn{##1}{2}-1}}{
\pbs_pdfobj:nnn{}{dict}{} %reserve pdf obj for the Next' nav. node
\tl_set:Nx\l_nextnode_tl{\pbs_pdflastobj:}
\l_prevactn_tl\l_prevnode_tl
/NA<</S/GoTo3DView/V/N/TA~\use:c{ann@\clist_item:nn{##1}{1}}>>
/Next~\l_nextnode_tl
}
\tl_set:Nx\l_prevactn_tl{
/PA<</S/GoTo3DView/V/P/TA~\use:c{ann@\clist_item:nn{##1}{1}}>>}
\tl_set:Nx\l_prevnode_tl{/Prev~\pbs_pdflastobj:}
\tl_set_eq:NN\l_currnode_tl\l_nextnode_tl
}
}
}
\pbs_pdfobj:nnn{\l_currnode_tl}{dict}{\l_prevactn_tl\l_prevnode_tl}
}
\newcommand\ThreeDPresStepsReset{ %cmd for resetting pres. steps
\bool_if:nT{
\sys_if_output_pdf_p: && \cs_if_exist_p:N\pdfpageattrsave}{
\immediate\pdfpageattr\exp_after:wN{\pdfpageattrsave}}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatother
\ExplSyntaxOff

\begin{document}

\begin{frame}{Intro}
\end{frame}

% initialise 3D presentation steps for the next frame
\ThreeDPresSteps{{diceA,7},{diceB,7}}

\begin{frame}{Go forth and back through 3D views using $\leftarrow$ and $\rightarrow$}
\centering

\includemedia[
label=diceA,
width=0.3\textheight,height=0.3\textheight,
activate=pageopen,deactivate=pageclose,
3Dviews=3Dviews.txt,
]{}{dice.U3D}
\includemedia[
label=diceB,
width=0.3\textheight,height=0.3\textheight,
activate=pageopen,deactivate=pageclose,
3Dviews=3Dviews.txt,
]{}{dice.U3D}

\end{frame}

% clear 3D presentation steps
\ThreeDPresStepsReset

\begin{frame}{The End}
\dots
\end{frame}

\end{document}

• @Grandement I am about rewriting the code to also navigating the views in both directions using the PgUp/Dn keys. – AlexG Feb 23 '15 at 9:36
• This is great, I will try it today and I will consider your hint about the media15 package. I will use the media9 package for my next work. – Grandement Feb 25 '15 at 9:13
• @Grandement The current code above is quite robust. My attempt to be able to go forth and back through the views has not been successful yet. – AlexG Feb 25 '15 at 10:18
• I have tested your code and I'm really happy with this solution. A forth and back method would be nice, but in the current code is a problem. For example when you have a 3D object with 2 views and you enter the slide and you don't go to the 2nd view but you go a slide back and forth then you get the 2nd view and not again the 1th view. It is possible to fix it? Maybe your new code fixes this anyway. – Grandement Feb 26 '15 at 15:33
• @Grandement Now the forth and back method should work. The arrow keys <-- and --> are required, though. – AlexG Mar 2 '15 at 8:31