tylermorganwall / rayshader

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

render_shapelist3d function for visualizing arbitrary mesh objects. #314

Open kenarab opened 3 months ago

kenarab commented 3 months ago

Using this function can include sample polyhedra from RGL package

render_snapshot(clear=TRUE)
montshadow = ray_shade(montereybay, zscale = 50, lambert = FALSE)
montamb = ambient_shade(montereybay, zscale = 50)
montereybay %>%
  sphere_shade(zscale = 10, texture = "imhof1") %>%
  add_shadow(montshadow, 0.5) %>%
  add_shadow(montamb, 0) %>%
  plot_3d(montereybay, zscale = 50, fov = 0, theta = -45, phi = 45,
          windowsize = c(1000, 800), zoom = 0.75,
          water = TRUE, waterdepth = 0, wateralpha = 0.5, watercolor = "lightblue",
          waterlinecolor = "white", waterlinealpha = 0.5)
shape.scale <- 100
set.seed(1833204)
material3d(color = c("yellow"), lit = TRUE, ambient = "#000020", alpha = 0.4)
render_shapelist3d(shapelist3d(icosahedron3d(), x = rnorm(5, mean = - shape.scale / 2, sd = shape.scale),
                               y = rnorm(5, mean = shape.scale, sd = shape.scale / 2),
                               z = rnorm(5, mean = 0, sd = shape.scale),
                               size = 10, plot = FALSE))

rayshaderMontereyBayIcosahedrons

An example for visualizing polyhedra from Rpolyhedra database

montshadow = ray_shade(montereybay, zscale = 50, lambert = FALSE)
montamb = ambient_shade(montereybay, zscale = 50)
montereybay %>%
    sphere_shade(zscale = 10, texture = "imhof1") %>%
    add_shadow(montshadow, 0.5) %>%
    add_shadow(montamb, 0) %>%
    plot_3d(montereybay, zscale = 50, fov = 0, theta = -45, phi = 45,
            windowsize = c(1000, 800), zoom = 0.75,
            water = TRUE, waterdepth = 0, wateralpha = 0.5, watercolor = "lightblue",
            waterlinecolor = "white", waterlinealpha = 0.5)
Sys.sleep(0.2)

# For using extended database have to switch to full database
#switchToFullDatabase()
geodesic.polyhedron <- getPolyhedron(source = "dmccooey",
              polyhedron.name = "geodesic icosahedron pattern 10 [5,0]")
stopifnot(!is.null(geodesic.polyhedron))
material3d(color = c("light blue"), lit = TRUE, ambient = "#000020", alpha = 0.4)
render_shapelist3d(shapelist3d(geodesic.polyhedron$getRGLModel(),
                               x = 70, y = 0,
                               z = -30, col = 2, alpha = 0.4, size = 100, plot = FALSE))

rayshaderRenderGeodesicDome

kenarab commented 2 months ago

Improved examples code. Corrected devtools::check.

There are some windows issues seemly. Don't have now a windows machine available, I think it has not to do with the function added, but will check later this week.