[Tex/LaTex] 3D PDF cycling between views animation

3djavascriptmedia9movie15pdf

I'm creating a 3D pdf with latex and movie15 and I added some views for my u3d object…
Then I added turntable.js to manually change a view of the object…
till now everything is fine

It is possible to add a jscript to automatically cycle all the views i.e. changing the view each second?

The best would be to associate the start stop to the standard animation toolbar button

here is the code

\documentclass{article}
\usepackage[3D]{movie15}
\usepackage{hyperref}
\begin{document}
\includemovie[
poster,
toolbar,
label=dice,
text=(dice.u3d),
3Droo=27,
3Dlights=Cube,
3Djscript=turntable.js,
3Dviews2=dice.vws
]{.5\linewidth}{.5\linewidth}{dice.u3d}\\
\movieref[3Dviewindex=N]{dice}{Click here} ...\\
\movieref[3Dcalculate=60]{dice}{This link} ...
\end{document}
  1. dice.u3d
  2. dice.vws
  3. turntable.js

Best Answer

The media9 package should be used instead of the obsolete movie15, as in the example below.

Here is a JavaScript that cycles through the predefined views. The view changes every 5 seconds. As requested, the toolbar Play/Pause button can be used to pause/resume the animation. For further info about 3D JavaScript, see here.

var time=0; 
var curViewIdx=0;

timeEvHnd=new TimeEventHandler();
timeEvHnd.onEvent=function(event) {
  time += event.deltaTime;
  if (time>=5) {
    time = 0;
    curViewIdx++;
    if(curViewIdx == runtime.viewCount) curViewIdx=0;
    runtime.setView(curViewIdx, true);
  }
}

runtime.addEventHandler(timeEvHnd);
// runtime.pause();

The complete example (except dice.u3d)

\documentclass{article}
\usepackage{media9}
\usepackage{mwe} %example image file used as poster for 3D content
\usepackage{graphicx}
\usepackage{filecontents}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{filecontents*}{changeView.js}
var time=0; 
var curViewIdx=0;

timeEvHnd=new TimeEventHandler();
timeEvHnd.onEvent=function(event) {
  time += event.deltaTime;
  if (time>=5) {
    time = 0;
    curViewIdx++;
    if(curViewIdx == runtime.viewCount) curViewIdx=0;
    runtime.setView(curViewIdx, true);
  }
}

runtime.addEventHandler(timeEvHnd);
// runtime.pause();
\end{filecontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{filecontents*}{dice.vws}
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*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\includemedia[
  width=0.5\linewidth,height=0.5\linewidth,
  activate=pageopen,
  3Dtoolbar, 3Dmenu,
  3Dviews=dice.vws,
  add3Djscript=3Dspin­tool.js, % turntable rotation of 3D object
  add3Djscript=changeView.js
]{\includegraphics{example-image}}{dice.u3d}

\end{document}