tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.06k stars 214 forks source link

no rgl window and other issues #164

Closed martin473 closed 3 years ago

martin473 commented 3 years ago

When I run this code it wont render. I tried reinstalling everything. Rayrender I reinstalled from install.packages. Everything else I installed from the github command.

>   library(rayshader) 
>   library(rayvista)
>   library(rayrender)
>   .lat <- 41.828840
>   .long <- -71.392150
>   
>   #added fillholes=FALSE to make this
>   helens <- plot_3d_vista(lat = .lat, long = .long, phi=30
+                           , zscale = 1.5, radius = 2000,
+                           elevation_detail = 14, overlay_detail = 16)
Downloading overlay...
Error in rc$merge(opt) : std::bad_alloc
In addition: There were 50 or more warnings (use warnings() to see the first 50)
>   warnings()
Warning messages:
1: [rast] unknown extent

((There are 50 of these warning messages and they are all exactly the same))

>   render_camera(theta = 200, phi = 30, zoom = 0.75, fov = 0)
Error in render_camera(theta = 200, phi = 30, zoom = 0.75, fov = 0) : 
  No rgl window currently open.
>   Sys.sleep(0.2)
>   #render_highquality('helens', lightintensity = 500, samples = 400,
>   render_snapshot()
Error in render_snapshot() : No rgl window currently open.

When I run this it renders completely fine, opens up an rgl window and everything

library(rayshader)
library(dplyr)
library(rgdal)

#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") %>%
  add_shadow(ray_shade(elmat, zscale = 3), 0.5) %>%
  add_shadow(ambient_shade(elmat), 0) %>%
  plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, water = TRUE, waterdepth = 100, wateralpha = 0.5, watercolor = "lightblue", waterlinecolor = "white", waterlinealpha = 0.5, phi = 45, windowsize = c(1000, 800))
Sys.sleep(0.2)
render_snapshot()
h-a-graham commented 3 years ago

Hi Martin, This looks like a rayvista issue rather than rayshader - perhaps better to file here: https://github.com/h-a-graham/rayvista/issues However, I can't reproduce this error and the above code is working for me. I suspect this is due to another outdated package. Have you recently installed rayvista as follows: devtools::install_github("h-a-graham/rayvista", dependencies=TRUE) This should make sure that a recent version of {rgdal} is installed. That warning message however, may be being thrown by {terra}. Can you try updating both {terra} and {rgdal} and then see what happens? Thanks