Adds 3D OBJ model to the current scene, using x/y coordinates in the reference system defined by the extent object. If no altitude is provided, the OBJ will be elevated a constant offset above the heightmap. If the OBJ goes off the edge, the OBJ will be filtered out.
Cache fallback messages are disabled by default. Set options(rayshader.verbose_scene_cache = TRUE) to print when cached metadata is reused.
If no x/y coordinates are passed in, the OBJ will be plotted in the coordinate system set by the user-specified
extent argument as-is. Use this alongside save_multipolygonz_to_obj() to plot 3D polygons imported from geospatial sources
in the proper location (but for ease of use, use render_multipolygonz() to plot this data directly).
render_obj(
filename,
location = NULL,
load_material = FALSE,
load_normals = TRUE,
color = "grey50",
obj_zscale = FALSE,
swap_yz = NULL,
angle = c(0, 0, 0),
scale = c(1, 1, 1),
lit = FALSE,
light_altitude = c(45, 30),
light_direction = c(315, 135),
light_intensity = 0.3,
light_relative = FALSE,
rgl_tag = "",
clear_previous = FALSE,
x = NULL,
y = NULL,
altitude = NULL,
xyz = NULL,
offset = 0,
lat = NULL,
long = NULL,
crs = NULL,
filter_to_extent = TRUE,
extent = NULL,
panel = NULL,
zscale = 1,
vertical_exaggeration = 1,
heightmap = NULL,
...
)Filename for the OBJ file.
Default NULL. Spatial point input used to place the rendered object(s) in the scene. Accepts sf, sfc, sfg, or sp POINT or MULTIPOINT geometries. MULTIPOINT inputs are flattened to point placements internally, and vectorized arguments such as scale, angle, color, and altitude are applied against that flattened point count. If the input carries a CRS, it will be transformed automatically into the active scene CRS. If it has no CRS, supply crs.
Default TRUE. Whether to load the accompanying MTL file to load materials for the 3D model.
Default TRUE. Whether to load normals for the 3D model.
Default black. Color of the 3D model, if load_material = FALSE. Use "height" to color placed models by the cached plot_gg() height aesthetic palette.
Default FALSE. Whether to scale the size of the OBJ by zscale to have it match
the size of the map. If zscale is very big, this will make the model very small.
Default NULL, defaults to FALSE unless plotting raw coordinates (no x/y or lat/long passed).
Whether to swap and Y and Z axes. (Y axis is vertical in
rayshader coordinates, but data is often provided with Z being vertical).
Default c(0,0,0). Angle of rotation around the x, y, and z axes. If this is a matrix or list,
each row (or list entry) specifies the rotation of the nth model specified (number of rows/length of list must
equal the length of x/y).
Default c(1,1,1). Amount to scale the 3D model in the x, y, and z axes. If this is a matrix or list,
each row (or list entry) specifies the scale of the nth model specified (number of rows/length of list must
equal the length of x/y).
Default TRUE. Whether to light the polygons.
Default c(45, 60). Degree(s) from the horizon from which to light the polygons.
Default c(45, 60). Degree(s) from north from which to light the polygons.
Default 0.3. Intensity of the specular highlight on the polygons.
Default FALSE. Whether the light direction should be taken relative to the camera,
or absolute.
Default "". Tag to add to the rgl scene id, will be prefixed by "obj"
Default FALSE. If TRUE, clears all existing objects
for rgl_tag. A clear-only call returns without rendering a replacement.
Vector of x coordinates (or other coordinate in the same coordinate reference system as extent).
Vector of y coordinates (or other coordinate in the same coordinate reference system as extent).
Default NULL. Elevation of each point, in units of the elevation matrix (scaled by zscale).
If left NULL, this will be just the elevation value at this surface, offset by offset. If a single value,
the OBJ will be rendered at that altitude. When one horizontal location is
supplied with multiple altitude values, that location is repeated to place one
OBJ at each altitude.
Default NULL, ignored. A 3 column numeric matrix, with each row specifying the x/y/z
coordinates of the OBJ model(s). Overrides x/y, lat/long, and altitude and ignores extent to plot the OBJ in raw rgl coordinates.
Default 5. Offset of the model from the surface, if altitude = NULL.
Default NULL. Alias for y for geographic workflows.
Default NULL. Alias for x for geographic workflows.
Default NULL. CRS of the input numeric x/y coordinates, or CRS to assign to CRS-less spatial data before transforming it into the active scene CRS. If spatial data already carries a CRS, that CRS is used automatically.
Default TRUE. If TRUE, object placements outside the scene extent are omitted. For scenes created with plot_gg(), filtering uses the ggplot panel extent rather than the full rendered 3D ggplot extent.
Either an object representing the spatial extent of the scene
(either from the raster, terra, sf, or sp packages),
a length-4 numeric vector specifying c("xmin", "xmax","ymin","ymax"), or the spatial object (from
the previously aforementioned packages) which will be automatically converted to an extent object.
If omitted, rayshader will use extent metadata cached by plot_3d() or plot_gg().
Default NULL. Facet panel identifier for scenes created with plot_gg(). Required
to disambiguate faceted ggplot scenes when panel-specific cached metadata is needed. Ignored
for non-ggplot scenes.
Default 1. The ratio between the x and y spacing (which are assumed to be equal) and the z axis in the original heightmap.
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 used to determine terrain
elevations and existing NA cells. 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 to pass to rgl::triangles3d().
#Render the 3D map
moss_landing_coord = c(36.806807, -121.793332)
montereybay_spatial |>
sphere_shade(vertical_exaggeration = 10) |>
plot_3d(vertical_exaggeration = 4,water=TRUE,
shadow_color="#40310a", background = "tan",
theta=210, phi=22, zoom=0.20, fov=55)
t = seq(0,2*pi,length.out=100)
circle_coords_lat = moss_landing_coord[1] + 0.3 * sin(t)
circle_coords_long = moss_landing_coord[2] + 0.3 * cos(t)
#Create a rainbow spectrum of flags
render_obj(flag_full_obj(),
lat = unlist(circle_coords_lat), long = unlist(circle_coords_long),
scale=c(2,2,2), angle=c(0,45,0),
color=rainbow(100), smooth = FALSE, clear_previous = TRUE)
render_snapshot()
#Rotate the flag to follow the circle
render_obj(flag_full_obj(),
lat = unlist(circle_coords_lat), long = unlist(circle_coords_long),
scale=c(2,2,2),
angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3),
color=rainbow(100), smooth = FALSE, clear_previous = TRUE)
render_snapshot()
#Style the pole with a different color
render_obj(flag_pole_obj(),
lat = unlist(circle_coords_lat), long = unlist(circle_coords_long),
scale=c(2,2,2),
angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3),
color="grey20", smooth = FALSE, clear_previous = TRUE)
render_obj(flag_banner_obj(),
lat = unlist(circle_coords_lat), long = unlist(circle_coords_long),
scale=c(2,2,2),
angle=matrix(c(rep(0,100), seq(0,-360,length.out=101)[-1],rep(0,100)),ncol=3),
color=rainbow(100), smooth = FALSE)
#And all of these work with `render_highquality()`
render_highquality(samples = 16)