How can I enable scroll wheel zoom on rgl rayshader plots?
Older (2019) rayshader plots seemed to have this functionality by default
(I can still open the old html files and they retain the functionality.)
However, plots generated today (2022) do not have scroll wheel zooming available.
Example from rayshader vignette
library(rayshader)
#Here, I load a map with the raster package.
loadzip = tempfile()
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)
#And convert it to a matrix:
elmat = raster_to_matrix(localtif)
elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
htmlwidgets::saveWidget(rgl::rglwidget(), "rayshader ex1.html")
If you run a simple plot in rgl
and look at the mouse mode, you'll see this:
par3d("mouseMode")
#> none left right middle wheel
#> "none" "trackball" "zoom" "fov" "pull"
If you do the same after running your sample code, you'll see this:
rgl::par3d("mouseMode")
#> none left right middle wheel
#> "none" "polar" "fov" "zoom" "none"
So something in the rayshader
package has changed the setting for the mouse wheel. There's a ton of code there so I don't know where this happened (though I'm guessing it was unintentional), but the way to undo it would be to set the mouse wheel mode yourself after running your example:
rgl::par3d(mouseMode = c("none", "polar", "fov", "zoom", "pull"))
You have to do this before the saveWidget
call, or you'll save the bad setting.