tylermorganwall / rayshader

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

render_floating_overlay(clear_layers=TRUE) not working #208

Closed wiesehahn closed 2 years ago

wiesehahn commented 2 years ago

To my understanding the clear_layers=TRUE option within render_floating_overlay() should clear all overlays initialized before.

However, this seems not to work. e.g.:

monterey = c(-121.892933,36.603053)
monterey_city = sf::st_sfc(sf::st_point(monterey))

#Generate Overlays
road_overlay = generate_line_overlay(monterey_roads_sf, attr(montereybay,"extent"), 
                                     heightmap = montereybay)

#Create 3D plot (water transparency set to 1 because multiple transparency layers can interfere)
montereybay %>%
  height_shade() %>%
  add_shadow(ray_shade(montereybay,zscale=50),0.3) %>% 
  plot_3d(montereybay, water = T, wateralpha = 1, windowsize = 800, watercolor = "lightblue")
render_camera(theta=-85,phi=25,zoom=0.8)

#Render Floating Overlays
render_floating_overlay(road_overlay, altitude = 10000,zscale = 50)
render_floating_overlay(road_overlay, altitude = 5000,zscale = 50, clear_layers= TRUE)

results in one road overlay at 100000m and another one at 5000m. The expected result would be one overlay at 5000m.

tylermorganwall commented 2 years ago

This is working on my system—make sure you've updated rgl to the latest version.

wiesehahn commented 2 years ago

I have rgl 0.108.3, but the error persists.

tylermorganwall commented 2 years ago

Can you provide more information on your system via sessionInfo()?

wiesehahn commented 2 years ago

sure:

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] rayshader_0.27.0

loaded via a namespace (and not attached):
 [1] rgl_0.108.3        Rcpp_1.0.8         here_1.0.1         lattice_0.20-41    png_0.1-7          prettyunits_1.1.1  class_7.3-17      
 [8] rprojroot_2.0.2    digest_0.6.29      foreach_1.5.1      utf8_1.2.2         V8_4.0.0           R6_2.5.1           e1071_1.7-9       
[15] ggplot2_3.3.5      pillar_1.7.0       rlang_1.0.0        progress_1.2.2     curl_4.3.2         geojsonlint_0.4.0  raster_3.5-15     
[22] magick_2.7.3       htmlwidgets_1.5.4  munsell_0.5.0      proxy_0.4-26       compiler_4.0.3     rmapshaper_0.4.5   xfun_0.29         
[29] pkgconfig_2.0.3    htmltools_0.5.2    tidyselect_1.1.1   tibble_3.1.6       gridExtra_2.3      httpcode_0.3.0     codetools_0.2-16  
[36] jsonvalidate_1.3.2 fansi_1.0.2        viridisLite_0.4.0  crayon_1.4.2       dplyr_1.0.7        av_0.6.0           sf_1.0-5          
[43] wk_0.6.0           crul_1.2.0         grid_4.0.3         jsonlite_1.7.3     gtable_0.3.0       lifecycle_1.0.1    DBI_1.1.2         
[50] magrittr_2.0.2     units_0.7-2        scales_1.1.1       KernSmooth_2.23-17 cli_3.1.1          renv_0.13.2        viridis_0.6.2     
[57] doParallel_1.0.16  sp_1.4-6           ellipsis_0.3.2     generics_0.1.2     vctrs_0.3.8        s2_1.0.7           iterators_1.0.13  
[64] tools_4.0.3        glue_1.6.1         purrr_0.3.4        hms_1.1.1          parallel_4.0.3     fastmap_1.1.0      colorspace_2.0-2  
[71] terra_1.5-17       classInt_0.4-3     knitr_1.37
tylermorganwall commented 2 years ago

What is the output when you call rgl::ids3d(tags = T) when both layers exist? Next, what happens to the scene when you then call rgl::pop3d(tag = c("floating_overlay","floating_overlay_tris"))?

wiesehahn commented 2 years ago
> rgl::ids3d(tags = T)
  id      type                   tag
1 31   surface               surface
2 35 triangles                  base
3 36     lines                 lines
4 37 triangles                shadow
5 38 triangles                 water
6 39 triangles                 water
7 40 triangles                 water
8 43 triangles floating_overlay_tris
9 44 triangles floating_overlay_tris

As far as I can see rgl::pop3d(tag = c("floating_overlay","floating_overlay_tris")) makes no difference.

tylermorganwall commented 2 years ago

Update to the latest version of rgl from Github (v0.108.10), the CRAN version is outdated and the rgl bug was fixed Jan 1st (https://github.com/dmurdoch/rgl/commit/f211890a89196a41d78ff3c3f5f100e12f30ae57#diff-e20bdc2af2c13e826a22366bd2c9bff5193c3b7014236666388c1ea02122f424):

https://github.com/dmurdoch/rgl

wiesehahn commented 2 years ago

Thanks Tyler, updating to rgl v0.108.13 fixes this problem.