yihui/knitr — Issue #74: How to handle rgl animations
Author: bryanhanson
Created: 2011-12-21 01:31:52+00:00
State: open

I would like to incorporate a typical rgl animation such as this one:

D <- matrix(rnorm(30), nrow = 10)
points3d(D)
M <- par3d("userMatrix")
play3d(par3dinterp( userMatrix=list(M,
rotate3d(M, pi, 0, 0, 1),
rotate3d(M, pi, 1, 0, 0),
rotate3d(M, pi, 0, 1, 0) ) ),
duration = 10)

This creates it's own "movie" or animation (and if play3d is replaced by movie3d it will write snapshots). Run it on its own to see what I mean So, if I embed these lines in a code chunk:

<< PlotRGL, rgl = TRUE, out.width = 0.5\textwidth, dev = png, fig.align = center, fig.show = animate, interval = 0.5, aniopts = controls; loop; autoplay, fig.path = animation/, cache = TRUE >>=
library("animation")
D <- matrix(rnorm(30), nrow = 10)
points3d(D)
M <- par3d("userMatrix")
play3d(par3dinterp( userMatrix=list(M,
rotate3d(M, pi, 0, 0, 1),
rotate3d(M, pi, 1, 0, 0),
rotate3d(M, pi, 0, 1, 0) ) ),
duration = 10)
@

Then there is a conflict among different pieces: The rgl hook (from the website examples) is trying to snag all rgl output to a snapshot, the animation library is trying to create the animation in steps and write them out, and the movie is playing continuously. To be clear, this does not cause an error or warning, but it doesn't produce any output either. The webpage examples don't really seem to cover this particular case. The only thing I can think of is to manually create a loop that re-creates the movie -- that seems more in line with the examples. But before going there, I thought I'd ask anyone watching.

Is this possible? I'd appreciate any guidance! Thanks, Bryan Hanson hanson@depauw.edu