Adds 3D contours to the current scene, using the heightmap of the 3D surface.
Cache fallback messages are disabled by default. Set options(rayshader.verbose_scene_cache = TRUE) to print when cached metadata is reused.
render_contours(
levels = NA,
n_levels = NA,
linewidth = 1,
color = "black",
palette = NULL,
antialias = FALSE,
offset = 0,
clear_previous = FALSE,
zscale = 1,
vertical_exaggeration = 1,
heightmap = NULL,
...
)Default NA. Automatically generated with 10 levels. This argument specifies the exact height levels of each contour.
Default NA. Controls the auto-generation of levels. If levels is length-2,
this will automatically generate n_levels breaks between levels[1] and levels[2].
Default 3. The line width.
Default black. Color of the line. Use "height" to color contours by the cached plot_gg() height aesthetic palette.
Default NULL. Overrides color. Either a function that returns a color palette
of n colors, or a character vector with colors that specifies each color manually.
Default FALSE. If TRUE, the line with be have anti-aliasing applied. NOTE: anti-aliasing can cause some unpredictable behavior with transparent surfaces.
Default 5. Offset of the track from the surface, if altitude = NULL.
Default FALSE. If TRUE, clears all existing
contours. A clear-only call returns without rendering a replacement.
Default 1. The ratio between the x and y spacing (which are assumed to be equal) and the z axis. For example, if the elevation levels are in units
of 1 meter and the grid values are separated by 10 meters, zscale would be 10.
Default 1. Multiplier applied to the effective visual relief. If omitted, rayshader uses the cached scene value from plot_3d() or plot_gg() when available; pass explicitly to override for this call.
Default NULL. Height matrix for the current scene. If omitted, this is taken from the cached scene set by plot_3d() or plot_gg(). Pass explicitly to override the cached value.
Additional arguments passed to rgl::lines3d().
Deprecated argument spellings are accepted with a warning and forwarded to their current names.
#Add contours to the montereybay_spatial dataset
montereybay_spatial |>
height_shade() |>
add_shadow(ray_shade(),0.3) |>
plot_3d(theta = -45, zoom=0.9, window_size=800, vertical_exaggeration = 4)
render_contours(offset = 100)
render_snapshot()
#> Error in if (!all(temp_verts[j + 1, ] == temp_verts[j, ])) { line_scene[[line_counter]] = rayvertex::segment_mesh(start = temp_verts[j, ] - bbox_center, end = temp_verts[j + 1, ] - bbox_center, radius = temp_lwd, material = line_mat) line_counter = line_counter + 1}: missing value where TRUE/FALSE needed
#Specify the number of levels
render_contours(offset = 100, n_levels = 30,
clear_previous = TRUE)
render_snapshot()
#> Error in if (!all(temp_verts[j + 1, ] == temp_verts[j, ])) { line_scene[[line_counter]] = rayvertex::segment_mesh(start = temp_verts[j, ] - bbox_center, end = temp_verts[j + 1, ] - bbox_center, radius = temp_lwd, material = line_mat) line_counter = line_counter + 1}: missing value where TRUE/FALSE needed
#Manually specify the breaks with levels
render_contours(linewidth = 2, offset = 100,
levels = seq(-2000, 0, 100), clear_previous = TRUE)
render_snapshot()
#> Error in if (!all(temp_verts[j + 1, ] == temp_verts[j, ])) { line_scene[[line_counter]] = rayvertex::segment_mesh(start = temp_verts[j, ] - bbox_center, end = temp_verts[j + 1, ] - bbox_center, radius = temp_lwd, material = line_mat) line_counter = line_counter + 1}: missing value where TRUE/FALSE needed
#Use a color palette for the contours
volcano |>
constant_shade() |>
plot_3d(zscale = 2, solid = FALSE, zoom = 0.8)
palette = grDevices::colorRampPalette(c("red", "purple", "pink"))
render_contours(offset = 1, palette = palette, n_levels = 20)
render_snapshot()
#> Error in if (!all(temp_verts[j + 1, ] == temp_verts[j, ])) { line_scene[[line_counter]] = rayvertex::segment_mesh(start = temp_verts[j, ] - bbox_center, end = temp_verts[j + 1, ] - bbox_center, radius = temp_lwd, material = line_mat) line_counter = line_counter + 1}: missing value where TRUE/FALSE needed
#Render using `render_highquality()` for a neon light effect
render_highquality(light = FALSE, samples = 16,
line_radius = 0.1,
ground_size = 0,
rgl_materials = list(contour3d = list(
material = rayrender::light,
args = list(importance_sample = FALSE,
color = "purple", intensity = 2)
)))