Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

render_movie

Render Movie


Description

Renders a movie using the av package. Moves the camera around a 3D visualization using either a standard orbit, or accepts vectors listing user-defined values for each camera parameter. If the latter, the values must be equal in length to 'frames' (or of length '1', in which the value will be fixed).

Usage

render_movie(
  filename,
  type = "orbit",
  frames = 360,
  fps = 30,
  phi = 30,
  theta = 0,
  zoom = NULL,
  fov = NULL,
  title_text = NULL,
  title_offset = c(20, 20),
  title_color = "black",
  title_size = 30,
  title_font = "sans",
  title_bar_color = NULL,
  title_bar_alpha = 0.5,
  image_overlay = NULL,
  vignette = FALSE,
  title_position = "northwest",
  audio = NULL,
  progbar = interactive(),
  ...
)

Arguments

filename

Filename. If not appended with '.mp4', it will be appended automatically.

type

Default 'orbit', which orbits the 3D object at the user-set camera settings 'phi', 'zoom', and 'fov'. Other options are 'oscillate' (sine wave around 'theta' value, covering 90 degrees), or 'custom' (which uses the values from the 'theta', 'phi', 'zoom', and 'fov' vectors passed in by the user).

frames

Default '360'. Number of frames to render.

fps

Default '30'. Frames per second. Recommmend either 30 or 60 for web.

phi

Defaults to current view. Azimuth values, in degrees.

theta

Default to current view. Theta values, in degrees.

zoom

Defaults to the current view. Zoom value, between '0' and '1'.

fov

Defaults to the current view. Field of view values, in degrees.

title_text

Default 'NULL'. Text. Adds a title to the movie, using magick::image_annotate.

title_offset

Default 'c(20,20)'. Distance from the top-left (default, 'gravity' direction in image_annotate) corner to offset the title.

title_color

Default 'black'. Font color.

title_size

Default '30'. Font size in pixels.

title_font

Default 'sans'. String with font family such as "sans", "mono", "serif", "Times", "Helvetica", "Trebuchet", "Georgia", "Palatino" or "Comic Sans".

title_bar_color

Default 'NULL'. If a color, this will create a colored bar under the title.

title_bar_alpha

Default '0.5'. Transparency of the title bar.

image_overlay

Default 'NULL'. Either a string indicating the location of a png image to overlay over the whole movie (transparency included), or a 4-layer RGBA array. This image will be resized to the dimension of the movie if it does not match exactly.

vignette

Default 'FALSE'. If 'TRUE' or numeric, a camera vignetting effect will be added to the image. '1' is the darkest vignetting, while '0' is no vignetting. If vignette is a length-2 vector, the second entry will control the blurriness of the vignette effect.

title_position

Default 'northwest'. Position of the title.

audio

Default 'NULL'. Optional file with audio to add to the video.

progbar

Default 'TRUE' if interactive, 'FALSE' otherwise. If 'FALSE', turns off progress bar. Will display a progress bar when adding an overlay or title.

...

Additional parameters to pass to magick::image_annotate.

Examples

if(interactive()) {
filename_movie = tempfile()

#By default, the function produces a 12 second orbit at 30 frames per second, at 30 degrees azimuth.

montereybay %>%
 sphere_shade(texture="imhof1") %>%
 plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", 
         waterlinecolor="white", waterlinealpha=0.5)
#Un-comment the following to run:
#render_movie(filename = filename_movie)
    
filename_movie = tempfile()

#You can change to an oscillating orbit. The magnification is increased and azimuth angle set to 30.
#A title has also been added using the title_text argument.

montereybay %>%
 sphere_shade(texture="imhof1") %>%
 plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", 
         waterlinecolor="white", waterlinealpha=0.5)
#Un-comment the following to run:
#render_movie(filename = filename_movie, type = "oscillate", 
#             frames = 60,  phi = 30, zoom = 0.8, theta = -90,
#             title_text = "Monterey Bay: Oscillating")
             
filename_movie = tempfile()

#Finally, you can pass your own set of values to the 
#camera parameters as a vector with type = "custom".

phivechalf = 30 + 60 * 1/(1 + exp(seq(-7, 20, length.out = 180)/2))
phivecfull = c(phivechalf, rev(phivechalf))
thetavec = -90 + 45 * sin(seq(0,359,length.out = 360) * pi/180)
zoomvec = 0.45 + 0.2 * 1/(1 + exp(seq(-5, 20, length.out = 180)))
zoomvecfull = c(zoomvec, rev(zoomvec))

montereybay %>%
 sphere_shade(texture="imhof1") %>%
 plot_3d(montereybay, zscale=50, water = TRUE, watercolor="imhof1", 
         waterlinecolor="white", waterlinealpha=0.5)
#Un-comment the following to run
#render_movie(filename = filename_movie, type = "custom", 
#             frames = 360,  phi = phivecfull, zoom = zoomvecfull, theta = thetavec)
rgl::rgl.close()

}

rayshader

Create Maps and Visualize Data in 2D and 3D

v0.24.10
GPL-3
Authors
Tyler Morgan-Wall
Initial release
2021-04-25

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.