Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mdsumner/331bb94c617dcfe705400ee3d7825ccb to your computer and use it in GitHub Desktop.
Save mdsumner/331bb94c617dcfe705400ee3d7825ccb to your computer and use it in GitHub Desktop.
#remotes::install_cran(c("anglr", "silicate"))

library(silicate)
library(anglr)
library(rgl)
## volcano is heightmap, doesn't exist in geo-space in R so we map it do the extent of
## these spatial polygons 
poly <- silicate::minimal_mesh
# xmin       : 0 
# xmax       : 1.23 
# ymin       : 0 
# ymax       : 1 

## arbitrarily drape polygons over raster
hmap <- raster::setExtent(raster::raster(volcano), raster::extent(0, 1.23, 0, 1))

## use DEL0 so we can control triangle area (not possible with decido, without
## post-hoc subdivision)
triangles <- copy_down(DEL0(poly, max_area = 0.001), hmap)


mesh1 <- as.mesh3d(triangles)


open3d();plot3d(mesh1)
aspect3d(1, 1, 0.5)


# that was just polygons + raster, so now make an image from the raster and
# texture it on (this could be a photograph, a map, just needs to be a 3-layer RGB raster)
im <- palr::image_raster(hmap, col = viridis::viridis(32))

mesh2 <- as.mesh3d(triangles, image_texture = im)

open3d(); plot3d(mesh2)
aspect3d(1, 1, 0.2)
@mdsumner
Copy link
Author

2020-05-20 19_18_43-anglr+silicate_elevate_polygons_image md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment