| Type: | Package | 
| Title: | 3D Software Rasterizer | 
| Version: | 0.12.0 | 
| Date: | 2025-01-02 | 
| Maintainer: | Tyler Morgan-Wall <tylermw@gmail.com> | 
| Description: | Rasterize images using a 3D software renderer. 3D scenes are created either by importing external files, building scenes out of the included objects, or by constructing meshes manually. Supports point and directional lights, anti-aliased lines, shadow mapping, transparent objects, translucent objects, multiple materials types, reflection, refraction, environment maps, multicore rendering, bloom, tone-mapping, and screen-space ambient occlusion. | 
| License: | GPL (≥ 3) | 
| Copyright: | file inst/COPYRIGHTS | 
| Depends: | R (≥ 4.1) | 
| Imports: | Rcpp (≥ 1.0.6), grDevices, rayimage (≥ 0.15.1), png, digest, pillar (≥ 1.10.1), vctrs, tibble, withr, cli | 
| Suggests: | Rvcg, magick, raster, testthat (≥ 3.0.0) | 
| LinkingTo: | Rcpp, spacefillr, RcppThread, rayimage | 
| RoxygenNote: | 7.3.2 | 
| URL: | https://www.rayvertex.com, https://github.com/tylermorganwall/rayvertex | 
| BugReports: | https://github.com/tylermorganwall/rayvertex/issues | 
| Encoding: | UTF-8 | 
| SystemRequirements: | C++17 | 
| Config/testthat/edition: | 3 | 
| NeedsCompilation: | yes | 
| Packaged: | 2025-02-01 21:57:38 UTC; tyler | 
| Author: | Tyler Morgan-Wall | 
| Repository: | CRAN | 
| Date/Publication: | 2025-02-03 08:20:02 UTC | 
Add light
Description
Add light
Usage
add_light(lights, light)
Arguments
| lights | Current light scene. | 
| light | New light to add. | 
Value
A matrix representing the light information.
Examples
if(run_documentation()) {
#Add a light to scene (manually specify the light automatically added to the Cornell Box
lights = point_light(position=c(555/2,450,555/2),
                    falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights)
 
#Add directional lights and a point light
lights_d = add_light(lights, directional_light(direction=c(1,1.5,-1), intensity=0.2)) |>
 add_light(directional_light(direction=c(-1,1.5,-1),color="red", intensity=0.2)) |>
 add_light(point_light(position=c(555/2,50,555/2), color="blue", intensity=0.3,
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005))
                       
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_d)
}
Add Line
Description
Add Line
Usage
add_lines(lines, line)
Arguments
| lines | Existing lines or empty (0-row) matrix. | 
| line | Line to add, generated with  | 
Value
New line matrix.
Examples
if(run_documentation()) {
#Generate a cube out of lines
cube_outline = generate_line(start = c(-1, -1, -1), end = c(-1, -1, 1)) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(-1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, -1, -1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(1, -1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, -1), end = c(1, 1, -1)))
  
rasterize_lines(cube_outline,fov=90,lookfrom=c(0,0,3))
}
Add Plane UV Mapping to Mesh
Description
Applies a planar UV mapping to a mesh based on a given direction and set of U/V vectors.
If full_mesh_bbox is true, the UV mapping is scaled based on the bounding box
of the entire mesh. If false, each shape's bounding box is used.
One of direction/u/v must be NULL and will be calculated from the others.
Usage
add_plane_uv_mesh(
  mesh,
  direction = c(0, 1, 0),
  u = NULL,
  v = NULL,
  override_existing = FALSE,
  full_mesh_bbox = TRUE
)
Arguments
| mesh | The mesh to which the UV mapping will be applied. | 
| direction | Default  | 
| u | Default  | 
| v | Default  | 
| override_existing | Default  | 
| full_mesh_bbox | Default  | 
Value
Modified mesh with added UV mapping.
Examples
if(run_documentation()) {
#Let's construct a mesh from the volcano dataset
#Build the vertex matrix
vertex_list = list()
counter = 1
for(i in 1:nrow(volcano)) {
  for(j in 1:ncol(volcano)) {
    vertex_list[[counter]] = matrix(c(j,volcano[i,j]/3,i), ncol=3)
    counter = counter + 1
  }
}
vertices = do.call(rbind,vertex_list)
#Build the index matrix
index_list = list()
counter = 0
for(i in 1:(nrow(volcano)-1)) {
  for(j in 1:(ncol(volcano)-1)) {
    index_list[[counter+1]] = matrix(c(counter,counter+ncol(volcano),counter+1,
                                       counter+ncol(volcano),counter+ncol(volcano)+1,counter + 1),
                                     nrow=2, ncol=3, byrow=TRUE)
    counter = counter + 1
  }
  counter = counter + 1
}
indices = do.call("rbind",index_list)
#Create a checkerboard image
create_checkerboard_texture = function(filename, n = 16) {
  old_par = par(no.readonly = TRUE)
  on.exit(par(old_par))
  plot.new()
  par(mar = c(0, 0, 0, 0))
  checkerboard = matrix(c(1, 0), nrow = n+1, ncol = n)
  png(filename, width = 800, height = 800)
  image(1:(n+1), 1:n, checkerboard, col = c("dodgerblue", "red"),
        axes = FALSE, xlab = "", ylab = "")
  dev.off()
}
checkerboard_file = tempfile(fileext = ".png")
create_checkerboard_texture(checkerboard_file)
rayimage::plot_image(checkerboard_file)
}
if(run_documentation()) {
#Construct the mesh
volc_mesh = construct_mesh(vertices = vertices, indices = indices,
                           material = material_list(type="phong", diffuse="darkred",
                                                    ambient = "darkred", ambient_intensity=0.2))
#Set the direction so that the checkerboard will be mapped to the surface like a carpet
uv = add_plane_uv_mesh(volc_mesh, direction=c(0,200,0), u = c(1,0,0))
uv = set_material(uv, texture_location = checkerboard_file,
                  ambient = "white", ambient_intensity=0.1)
#Rasterize the scene
rasterize_scene(center_mesh(uv), lookfrom=c(200,200,200),fov=0,width=1200,height=1200,
                light_info = directional_light(c(0,1,1)) |>
                  add_light(directional_light(c(1,1,-1))),ortho_dimensions=c(120,120))
}
if(run_documentation()) {
#Set the direction so that the checkerboard will be mapped directly at the camera
uv = add_plane_uv_mesh(volc_mesh, direction=c(200,200,200), v = c(-1,1,-1))
uv = set_material(uv, texture_location = checkerboard_file,
                  ambient = "white", ambient_intensity=0.1)
#Rasterize the scene
rasterize_scene(center_mesh(uv), lookfrom=c(200,200,200),fov=0,width=1200,height=1200,
                light_info = directional_light(c(0,1,1)) |>
                add_light(directional_light(c(1,1,-1))), ortho_dimensions=c(120,120))
}
Add Shape
Description
Add shape to the scene.
Usage
add_shape(scene, shape = NULL)
Arguments
| scene | The scene to add the shape. | 
| shape | The mesh to add to the scene. | 
Value
Scene with shape added.
Examples
if(run_documentation()) {
#Generate several spheres in the cornell box
scene = generate_cornell_mesh()
set.seed(1)
for(i in 1:30) {
 col = hsv(runif(1))
 scene = add_shape(scene, sphere_mesh(position=runif(3)*400+155/2,
                                      material=material_list(diffuse=col, type="phong",
                                                             ambient=col,ambient_intensity=0.2), 
                                      radius=30))
}
rasterize_scene(scene, light_info=directional_light(direction=c(0.1,0.6,-1)))
}
Add Sphere UV Mapping to Mesh
Description
Applies a planar UV mapping to a mesh based on a spherical direction from the origin.
Usage
add_sphere_uv_mesh(mesh, origin = c(0, 0, 0), override_existing = FALSE)
Arguments
| mesh | The mesh to which the UV mapping will be applied. | 
| origin | Default  | 
| override_existing | Default  | 
Value
Modified mesh with added UV mapping.
Examples
if(run_documentation()) {
#Let's construct a mesh from the volcano dataset
}
Arrow 3D Model
Description
Arrow 3D Model
Usage
arrow_mesh(
  start = c(0, 0, 0),
  end = c(0, 1, 0),
  radius_top = 0.5,
  radius_tail = 0.25,
  tail_proportion = 0.5,
  direction = NA,
  from_center = TRUE,
  material = material_list()
)
Arguments
| start | Default  | 
| end | Default  | 
| radius_top | Default  | 
| radius_tail | Default  | 
| tail_proportion | Default  | 
| direction | Default  | 
| from_center | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate an arrow
generate_cornell_mesh() |>
  add_shape(arrow_mesh(start = c(555/2, 20, 555/2), end = c(555/2, 300, 555/2), radius_tail=50,
                       radius_top = 100,
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a blue arrow with a wide tail
generate_cornell_mesh() |>
  add_shape(arrow_mesh(start = c(555/2, 20, 555/2), end = c(555/2, 300, 555/2), radius_tail=100,
                       radius_top = 150,
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
  }
if(run_documentation()) {
#Generate a long, thin arrow and change the proportions
generate_cornell_mesh() |>
  add_shape(arrow_mesh(start = c(555/2, 20, 555/2), end = c(555/2, 400, 555/2), radius_top=30,
                       radius_tail = 10, tail_proportion = 0.8,
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Change the start and end points
generate_cornell_mesh() |>
  add_shape(arrow_mesh(start = c(500, 20, 555/2), end = c(50, 500, 555/2), radius_top=30,
                       radius_tail = 10, tail_proportion = 0.8,
                      material = material_list(diffuse="dodgerblue"))) |>
  add_shape(arrow_mesh(start = c(500, 500, 500), end = c(50, 50, 50), radius_top=30,
                       radius_tail = 10, tail_proportion = 0.8,
                      material = material_list(diffuse="red"))) |>
  add_shape(arrow_mesh(start = c(555/2, 50, 500), end = c(555/2, 50, 50), radius_top=30,
                       radius_tail = 10, tail_proportion = 0.8,
                      material = material_list(diffuse="green"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
Print out the color
Description
Print out the color
Usage
cat_color(color, var_name, default = NA, intensity = 1, spacer = "")
Value
none
Center Mesh
Description
Centers the mesh at the origin.
Usage
center_mesh(mesh)
Arguments
| mesh | The mesh object. | 
Value
Centered mesh
Examples
if(run_documentation()) {
#Center the Cornell box and the R OBJ at the origin
center_mesh(generate_cornell_mesh()) |>
  add_shape(center_mesh(obj_mesh(r_obj(),scale=100,angle=c(0,180,0)))) |>
  rasterize_scene(lookfrom=c(0,0,-1100),fov=40,lookat=c(0,0,0),
                  light_info = directional_light(c(0.4,0.4,-1)) |>
      add_light(point_light(c(0,450,0),  falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)))
}
Change Material
Description
Change individual material properties, leaving others alone.
Usage
change_material(
  mesh,
  id = NULL,
  sub_id = 1,
  diffuse = NULL,
  ambient = NULL,
  specular = NULL,
  transmittance = NULL,
  emission = NULL,
  shininess = NULL,
  ior = NULL,
  dissolve = NULL,
  illum = NULL,
  texture_location = NULL,
  normal_texture_location = NULL,
  bump_texture_location = NULL,
  specular_texture_location = NULL,
  ambient_texture_location = NULL,
  emissive_texture_location = NULL,
  diffuse_intensity = NULL,
  bump_intensity = NULL,
  specular_intensity = NULL,
  emission_intensity = NULL,
  ambient_intensity = NULL,
  culling = NULL,
  type = NULL,
  translucent = NULL,
  toon_levels = NULL,
  toon_outline_width = NULL,
  toon_outline_color = NULL,
  reflection_intensity = NULL,
  reflection_sharpness = NULL,
  two_sided = NULL
)
Arguments
| mesh | Mesh to change. | 
| id | Default  | 
| sub_id | Default  | 
| diffuse | Default  | 
| ambient | Default  | 
| specular | Default  | 
| transmittance | Default  | 
| emission | Default  | 
| shininess | Default  | 
| ior | Default  | 
| dissolve | Default  | 
| illum | Default  | 
| texture_location | Default  | 
| normal_texture_location | Default  | 
| bump_texture_location | Default  | 
| specular_texture_location | Default  | 
| ambient_texture_location | Default  | 
| emissive_texture_location | Default  | 
| diffuse_intensity | Default  | 
| bump_intensity | Default  | 
| specular_intensity | Default  | 
| emission_intensity | Default  | 
| ambient_intensity | Default  | 
| culling | Default  | 
| type | Default  | 
| translucent | Default  | 
| toon_levels | Default  | 
| toon_outline_width | Default  | 
| toon_outline_color | Default  | 
| reflection_intensity | Default  | 
| reflection_sharpness | Default  | 
| two_sided | Default  | 
Value
Shape with new material settings
Examples
if(run_documentation()) {
p_sphere = sphere_mesh(position=c(555/2,555/2,555/2), 
                      radius=40,material=material_list(diffuse="purple"))
generate_cornell_mesh() |>
 add_shape(translate_mesh(p_sphere,c(0,-100,0))) |>
 add_shape(change_material(translate_mesh(p_sphere,c(200,-100,0)),diffuse="red")) |>
 add_shape(change_material(translate_mesh(p_sphere,c(100,-100,0)),dissolve=0.5)) |>
 add_shape(change_material(translate_mesh(p_sphere,c(-100,-100,0)),type="phong")) |>
 add_shape(change_material(translate_mesh(p_sphere,c(-200,-100,0)),type="phong",shininess=30)) |>
 rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)))
}  
if(run_documentation()) {
#Change several shapes at once
p_sphere |>
 add_shape(change_material(translate_mesh(p_sphere,c(200,0,0)),diffuse="red")) |>
 add_shape(change_material(translate_mesh(p_sphere,c(100,0,0)),dissolve=0.5)) |>
 add_shape(change_material(translate_mesh(p_sphere,c(-100,0,0)),type="phong")) |>
 add_shape(change_material(translate_mesh(p_sphere,c(-200,0,0)),type="phong",shininess=30)) |>
 change_material(diffuse = "red") |> 
 add_shape(generate_cornell_mesh()) |> 
 rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)))
}
Color Lines
Description
Color Lines
Usage
color_lines(lines, color = "white")
Arguments
| lines | The line scene. | 
| color | Default  | 
Value
Colored line matrix.
Examples
if(run_documentation()) {
#Generate a cube out of lines
cube_outline = generate_line(start = c(-1, -1, -1), end = c(-1, -1, 1)) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(-1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, -1, -1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(1, -1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, -1), end = c(1, 1, -1)))
  
cube_outline |>
  color_lines(color="red") |>
  rasterize_lines()
}
Cone 3D Model
Description
Cone 3D Model
Usage
cone_mesh(
  start = c(0, 0, 0),
  end = c(0, 1, 0),
  radius = 0.5,
  direction = NA,
  from_center = FALSE,
  material = material_list()
)
Arguments
| start | Default  | 
| end | Default  | 
| radius | Default  | 
| direction | Default  | 
| from_center | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate a cone
generate_cornell_mesh() |>
  add_shape(cone_mesh(start = c(555/2, 20, 555/2), end = c(555/2, 300, 555/2),
                      radius = 100)) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a blue cone with a wide base
generate_cornell_mesh() |>
  add_shape(cone_mesh(start = c(555/2, 20, 555/2), end = c(555/2, 300, 555/2), radius=200,
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a long, thin cone
generate_cornell_mesh() |>
  add_shape(cone_mesh(start = c(555/2, 20, 555/2), end = c(555/2, 400, 555/2), radius=50,
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
Manually construct a mesh
Description
Manually construct a mesh
Usage
construct_mesh(
  vertices,
  indices,
  normals = NULL,
  norm_indices = NULL,
  texcoords = NULL,
  tex_indices = NULL,
  material = material_list()
)
Arguments
| vertices | Nx3 matrix of vertex coordinates.. | 
| indices | Nx3 integer matrix, where each row defines a triangle using the
vertices defined in  | 
| normals | Default  | 
| norm_indices | Nx3 integer matrix, where each row defines the normal for a vertex using the
normals defined in  | 
| texcoords | Default  | 
| tex_indices | Nx3 integer matrix, where each row defines the texture coordinates for a triangle
using the tex coords defined in  | 
| material | Default  | 
Value
List containing mesh info.
Examples
if(run_documentation()) {
#Let's construct a mesh from the volcano dataset
#Build the vertex matrix
vertex_list = list()
counter = 1
for(i in 1:nrow(volcano)) {
  for(j in 1:ncol(volcano)) {
    vertex_list[[counter]] = matrix(c(j,volcano[i,j],i), ncol=3)
    counter = counter + 1
  }
}
vertices = do.call(rbind,vertex_list)
#Build the index matrix
index_list = list()
counter = 0
for(i in 1:(nrow(volcano)-1)) {
  for(j in 1:(ncol(volcano)-1)) {
    index_list[[counter+1]] = matrix(c(counter,counter+ncol(volcano),counter+1,
                                       counter+ncol(volcano),counter+ncol(volcano)+1,counter + 1), 
                                     nrow=2, ncol=3, byrow=TRUE)
    counter = counter + 1
  }
  counter = counter + 1
}
indices = do.call(rbind,index_list)
#Construct the mesh
volc_mesh = construct_mesh(vertices = vertices, indices = indices,
                           material = material_list(type="phong", diffuse="darkred", 
                                                    ambient = "darkred", ambient_intensity=0.2))
#Rasterize the scene
rasterize_scene(volc_mesh, lookfrom=c(-50,230,100),fov=60,width=1200,height=1200,
                light_info = directional_light(c(0,1,1)) |>
                  add_light(directional_light(c(1,1,-1))))
}
Convert Color
Description
Convert Color
Usage
convert_color(color, as_hex = FALSE)
Arguments
| color | The color to convert. Can be either a hexadecimal code, or a numeric rgb
vector listing three intensities between  | 
Value
Color vector
Convert RGB to ANSI Color
Description
Convert RGB to ANSI Color
Usage
convert_rgb_to_ansi(color)
Arguments
| color | Length=3 numeric vector. | 
Value
ANSI color code as a string.
Cross Product
Description
Computes the cross product of two 3-dimensional vectors.
Usage
cross_prod(x, y)
Arguments
| x | A numeric vector representing the first 3D vector. | 
| y | A numeric vector representing the second 3D vector. | 
Value
A numeric vector representing the cross product of x and y.
Cube 3D Model
Description
3D obj model of the letter R
Usage
cube_mesh(
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate a cube
generate_cornell_mesh() |>
  add_shape(cube_mesh(position = c(555/2, 100, 555/2), scale = 100)) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a blue rotated cube 
generate_cornell_mesh() |>
  add_shape(cube_mesh(position = c(555/2, 100, 555/2), scale = 100, angle=c(0,45,0),
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a scaled, blue rotated cube 
generate_cornell_mesh() |>
  add_shape(cube_mesh(position = c(555/2, 100, 555/2), angle=c(0,45,0),
                      scale = c(2,0.5,0.8)*100,
                      material = material_list(diffuse="dodgerblue"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
Cylinder 3D Model
Description
Cylinder 3D Model
Usage
cylinder_mesh(
  position = c(0, 0, 0),
  radius = 0.5,
  length = 1,
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| position | Default  | 
| radius | Default  | 
| length | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate a cylinder
generate_cornell_mesh() |>
  add_shape(cylinder_mesh(position=c(555/2,150,555/2),
                          radius = 50, length=300, material = material_list(diffuse="purple"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a wide, thin disk
generate_cornell_mesh() |>
  add_shape(cylinder_mesh(position=c(555/2,20,555/2),
                          radius = 200, length=5, material = material_list(diffuse="purple"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate a narrow cylinder
generate_cornell_mesh() |>
  add_shape(cylinder_mesh(position=c(555/2,555/2,555/2),angle=c(45,-45,0),
                          radius = 10, length=500, material = material_list(diffuse="purple"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
Generate Directional Lights
Description
Generate Directional Lights
Usage
directional_light(direction = c(0, 1, 0), color = "white", intensity = 1)
Arguments
| direction | Default  | 
| color | Default  | 
| intensity | Default  | 
Value
A matrix representing the light information.
Examples
if(run_documentation()) {
#Add a light to scene (manually specify the light automatically added to the Cornell Box
lights = point_light(position=c(555/2,450,555/2),
                    falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights)
 
#Add a directional light
lights_d = add_light(lights, directional_light(direction=c(1,1.5,-1)))
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_d)
 
#Change the intensity and color
lights_d = add_light(lights, 
                    directional_light(direction=c(1,1.5,-1),color="orange", intensity=0.5))
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_d)
}
Displace a Mesh
Description
Displace a Mesh
Usage
displace_mesh(
  mesh,
  displacement_texture,
  displacement_scale = 1,
  displacement_vector = FALSE,
  id = NA,
  verbose = TRUE
)
Arguments
| mesh | The mesh. | 
| displacement_texture | Image or matrix/array that will be used to displace the mesh | 
| displacement_scale | Default  | 
| displacement_vector | Default  | 
| id | Default  | 
| verbose | Default  | 
Value
raymesh object
Examples
if(run_documentation()) {
 #Let's construct a mesh from the volcano dataset
}
Construct Displacement Sphere
Description
Construct Displacement Sphere
Usage
displacement_sphere(
  displacement_texture,
  displacement_scale = 1,
  use_cube = FALSE,
  cube_subdivision_levels = NA,
  displace = TRUE,
  verbose = TRUE,
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| displacement_texture | Image or matrix/array that will be used to displace the sphere. | 
| displacement_scale | Default  | 
| use_cube | Default  | 
| cube_subdivision_levels | Default  | 
| displace | Default  | 
| verbose | Default  | 
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
raymesh object
Examples
if(run_documentation()) {
}
Flip Orientation
Description
Flip Orientation
Usage
flip_orientation_mesh(mesh)
Arguments
| mesh | The mesh to swap orientations. | 
Value
Mesh with flipped vertex orientation
Examples
# Flip a mesh 
if(run_documentation()) {
sphere_mesh(position=c(-1,0,0)) |> 
  add_shape(flip_orientation_mesh(sphere_mesh(position=c(1,0,0)))) |> 
  rasterize_scene(debug="normals",fov=30)
}
Flip Left-Right
Description
Flip Left-Right
Usage
fliplr(x)
Arguments
| x | Matrix | 
Value
Flipped matrix
Flip Up-Down
Description
Flip Up-Down
Usage
flipud(x)
Arguments
| x | Matrix | 
Value
Flipped matrix
Format ray_shape for pillar
Description
Format ray_shape for pillar
Usage
format_pillar_shp(x)
Arguments
| x | A ray_shape object. | 
Value
A formatted character vector.
Cornell Box 3D Model
Description
Cornell Box 3D Model
Usage
generate_cornell_mesh(
  leftcolor = "#1f7326",
  rightcolor = "#a60d0d",
  roomcolor = "#bababa",
  ceiling = TRUE,
  light = TRUE
)
Arguments
| leftcolor | Default  | 
| rightcolor | Default  | 
| roomcolor | Default  | 
| ceiling | Default  | 
| light | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate and render the default Cornell box and add an object.
generate_cornell_mesh() |> 
  rasterize_scene()
}
if(run_documentation()) {
#Add an object to the scene
generate_cornell_mesh() |> 
  add_shape(obj_mesh(r_obj(),position=c(555/2,555/2,555/2),scale=300,angle=c(0,180,0))) |> 
  rasterize_scene()
}
if(run_documentation()) {
#Turn off the ceiling so the default directional light reaches inside the box
generate_cornell_mesh(ceiling=FALSE) |> 
  add_shape(obj_mesh(r_obj(),position=c(555/2,555/2,555/2),scale=300,angle=c(0,180,0))) |> 
  rasterize_scene()
}
if(run_documentation()) {
#Adjust the light to the front
generate_cornell_mesh(ceiling=FALSE) |> 
  add_shape(obj_mesh(r_obj(),position=c(555/2,555/2,555/2),scale=300,angle=c(0,180,0))) |> 
  rasterize_scene(light_info = directional_light(direction=c(0,1,-1)))
  }
if(run_documentation()) {
#Change the color palette
generate_cornell_mesh(ceiling=FALSE,leftcolor="purple", rightcolor="yellow") |> 
  add_shape(obj_mesh(r_obj(),position=c(555/2,555/2,555/2),scale=300,angle=c(0,180,0))) |> 
  rasterize_scene(light_info = directional_light(direction=c(0,1,-1)))
}
Generate Lines
Description
Generate Lines
Usage
generate_line(start = c(0, 0, 0), end = c(0, 1, 0), color = "white")
Arguments
| start | Default  | 
| end | Default  | 
| color | Default  | 
Value
Line matrix
Examples
if(run_documentation()) {
# Make a spiral of lines
t = seq(0,8*pi,length.out=361)
line_mat = matrix(nrow=0,ncol=9)
for(i in 1:360) {
  line_mat = add_lines(line_mat,
                      generate_line(start = c(0.5*sin(t[i]), t[i]/(8*pi), 0.5*cos(t[i])),
                                    end  = c(0.5*sin(t[i+1]), t[i+1]/(8*pi), 0.5*cos(t[i+1]))))
}
rasterize_lines(line_mat)
}
if(run_documentation()) {
#Change the line color
line_mat = matrix(nrow=0,ncol=9)
cols = hsv(seq(0,1,length.out=360))
for(i in 1:360) {
  line_mat = add_lines(line_mat,
                      generate_line(start = c(sin(t[i]), 2*t[i]/(8*pi), cos(t[i])),
                                   end  = c(sin(t[i+1]), 2*t[i+1]/(8*pi), cos(t[i+1])),
                                   color = cols[i]))
}
rasterize_lines(line_mat,lookfrom=c(0,10,10),fov=15)
}
if(run_documentation()) {
#Use in a scene with a mesh
obj_mesh(r_obj(simple_r = TRUE),material=material_list(diffuse="dodgerblue")) |>
 rasterize_scene(line_info = line_mat, light_info = directional_light(c(0,1,1)),
                 lookfrom=c(0,5,10),lookat=c(0,0.8,0),fov=15)
}
Generate Rotation Matrix
Description
Generate Rotation Matrix
Usage
generate_rot_matrix(angle, order_rotation)
Arguments
| angle | The angle | 
| order_rotation | Default  | 
Value
Matrix
Generate Rotation Matrix from Direction
Description
Internal function to generate a rotation matrix that aligns the Y-axis with a given direction vector. It uses the Rodrigues' rotation formula.
Usage
generate_rotation_matrix_from_direction(
  direction = c(0, 1, 0),
  up = c(0, 1, 0)
)
Arguments
| direction | Default  | 
| up | Default  | 
Value
A 3x3 rotation matrix.
Generate Surface
Description
Generate Surface
Usage
generate_surface(heightmap, zscale = 1)
Add Outline
Description
Add Outline
Usage
generate_toon_outline(single_obj, material, scale = 1)
Value
Matrix
Check Filename
Description
Check Filename
Usage
get_file_type(file)
Arguments
| file | Filename to be checked | 
Value
Flipped matrix
Get Mesh Bounding Box
Description
Calculates the bounding box of a mesh
Usage
get_mesh_bbox(mesh)
Arguments
| mesh | The mesh object. | 
Value
2x3 numeric matrix
Examples
if(run_documentation()) {
#Calculates the center of the mesh
get_mesh_bbox(generate_cornell_mesh())
}
Get Mesh Center
Description
Calculates the coordinates of the center of a mesh
Usage
get_mesh_center(mesh)
Arguments
| mesh | The mesh object. | 
Value
Length-3 numeric vector
Examples
if(run_documentation()) {
#Calculates the center of the mesh
get_mesh_center(generate_cornell_mesh())
}
Get time
Description
Get time
Usage
get_time(init = TRUE)
Value
Nothing
Print time
Description
Print time
Usage
init_time()
Value
Nothing
Material List
Description
Generate a material properties list.
Usage
material_list(
  diffuse = c(0.8, 0.8, 0.8),
  ambient = c(0, 0, 0),
  specular = c(1, 1, 1),
  transmittance = c(0, 0, 0),
  emission = c(0, 0, 0),
  shininess = 50,
  ior = 1,
  dissolve = 1,
  illum = 1,
  texture_location = "",
  normal_texture_location = "",
  bump_texture_location = "",
  specular_texture_location = "",
  ambient_texture_location = "",
  emissive_texture_location = "",
  diffuse_intensity = 1,
  bump_intensity = 1,
  specular_intensity = 1,
  emission_intensity = 1,
  ambient_intensity = 1,
  culling = "back",
  type = "diffuse",
  translucent = TRUE,
  toon_levels = 5,
  toon_outline_width = 0.05,
  toon_outline_color = "black",
  reflection_intensity = 0,
  reflection_sharpness = 1,
  two_sided = FALSE
)
Arguments
| diffuse | Default  | 
| ambient | Default  | 
| specular | Default  | 
| transmittance | Default  | 
| emission | Default  | 
| shininess | Default  | 
| ior | Default  | 
| dissolve | Default  | 
| illum | Default  | 
| texture_location | Default  | 
| normal_texture_location | Default  | 
| bump_texture_location | Default  | 
| specular_texture_location | Default  | 
| ambient_texture_location | Default  | 
| emissive_texture_location | Default  | 
| diffuse_intensity | Default  | 
| bump_intensity | Default  | 
| specular_intensity | Default  | 
| emission_intensity | Default  | 
| ambient_intensity | Default  | 
| culling | Default  | 
| type | Default  | 
| translucent | Default  | 
| toon_levels | Default  | 
| toon_outline_width | Default  | 
| toon_outline_color | Default  | 
| reflection_intensity | Default  | 
| reflection_sharpness | Default  | 
| two_sided | Default  | 
Value
List of material properties.
Examples
if(run_documentation()) {
mat_prop = material_list(diffuse="purple", type="phong", shininess = 20,
                        ambient="purple", ambient_intensity=0.3,
                        specular = "red", specular_intensity=2)
                        
p_sphere = sphere_mesh(position=c(555/2,555/2,555/2), 
                      radius=40,material=mat_prop)
                      
rasterize_scene(p_sphere, light_info=directional_light(direction=c(0.1,0.6,-1)))
}
Merge scene
Description
Merge the shapes to one
Usage
merge_scene(old_scene, flatten_materials = TRUE)
Value
Merged scene
Mesh3d 3D Model
Description
Mesh3d 3D Model
Usage
mesh3d_mesh(
  mesh,
  center = FALSE,
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  materialspath = NULL,
  material = material_list()
)
Arguments
| mesh | Mesh3d object. | 
| center | Default  | 
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| materialspath | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
  # Read in a mesh3d object and rasterize it
  library(Rvcg)
  data(humface)
  
  mesh3d_mesh(humface,position = c(0,-0.3,0),scale = 1/70,
              material=material_list(diffuse="dodgerblue4", type="phong", shininess=20,
              ambient = "dodgerblue4", ambient_intensity=0.3)) |>
    rasterize_scene(lookat = c(0,0.5,1), light_info = directional_light(c(1,0.5,1)))
 }
 
 if(run_documentation()) {
  # Subdivide the mesh for a smoother appearance
  mesh3d_mesh(humface,position = c(0,-0.3,0),scale = 1/70,
              material=material_list(diffuse="dodgerblue4", type="phong", shininess=20,
              ambient = "dodgerblue4", ambient_intensity=0.3)) |>
    subdivide_mesh() |> 
    rasterize_scene(lookat = c(0,0.5,1), light_info = directional_light(c(1,0.5,1)))
 }
OBJ Mesh 3D Model
Description
OBJ Mesh 3D Model
Usage
obj_mesh(
  filename,
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  materialspath = NULL,
  center = FALSE,
  material = NULL
)
Arguments
| filename | OBJ filename. | 
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| materialspath | Default  | 
| center | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Read in the provided 3D R mesh
generate_cornell_mesh(ceiling=FALSE) |> 
  add_shape(obj_mesh(r_obj(),position=c(555/2,555/2,555/2),scale=400,angle=c(0,180,0))) |> 
  rasterize_scene(light_info = directional_light(direction=c(0.2,0.5,-1)))
}
Pillar shaft for ray_shape
Description
Pillar shaft for ray_shape
Usage
pillar_shaft.ray_shape(x, ...)
Arguments
| x | A ray_shape object. | 
| ... | Additional arguments (unused). | 
Value
A pillar shaft object.
Pillar shaft for ray_shape_list
Description
Pillar shaft for ray_shape_list
Usage
pillar_shaft.ray_shape_list(x, ...)
Arguments
| x | A ray_shape_list object. | 
| ... | Additional arguments (unused). | 
Value
A pillar shaft object.
PLY Mesh 3D Model
Description
PLY Mesh 3D Model
Usage
ply_mesh(
  filename,
  center = FALSE,
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| filename | PLY filename. | 
| center | Default  | 
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
#See the documentation for `obj_mesh()`--no example PLY models are included with this package,
#but the process of loading a model is the same (but no materials are included in PLY files).
Point light
Description
The falloff of the point light intensity is given by the following equation (referenc:
Intensity = intensity / (constant + falloff * distance + falloff_quad * (distance * distance));
Usage
point_light(
  position = c(0, 0, 0),
  color = "white",
  intensity = 1,
  constant = 1,
  falloff = 1,
  falloff_quad = 1
)
Arguments
| position | A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced. | 
| color | Default  | 
| intensity | Default  | 
| constant | Default  | 
| falloff | Default  | 
| falloff_quad | Default  | 
Value
A matrix representing the light information.
Examples
if(run_documentation()) {
#Add point lights and vary the intensity
lights_int = point_light(position=c(100,100,400), color="white", intensity=0.125,
                      falloff_quad = 0.0, constant = 0.0002, falloff = 0.005) |>
 add_light(point_light(position=c(100,455,400), color="white", intensity=0.25,
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)) |>
 add_light(point_light(position=c(455,100,400), color="white", intensity=0.5,
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)) |>
 add_light(point_light(position=c(455,455,400), color="white", intensity=1,
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005))
                       
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_int)
 
#Add point lights and vary the color
lights_c = point_light(position=c(100,100,500), color="red", 
                      falloff_quad = 0.0, constant = 0.0002, falloff = 0.005) |>
 add_light(point_light(position=c(100,455,500), color="blue",
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)) |>
 add_light(point_light(position=c(455,100,500), color="purple", 
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005)) |>
 add_light(point_light(position=c(455,455,500), color="yellow", 
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.005))
                       
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_c)
 
#Add point lights and vary the falloff term
lights_fo = point_light(position=c(100,100,500), color="white", 
                      falloff_quad = 0.0, constant = 0.0002, falloff = 0.005) |>
 add_light(point_light(position=c(100,455,500), color="white",
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.01)) |>
 add_light(point_light(position=c(455,100,500), color="white", 
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.02)) |>
 add_light(point_light(position=c(455,455,500), color="white", 
                       falloff_quad = 0.0, constant = 0.0002, falloff = 0.04))
                       
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_fo)
 
#Add point lights and vary the quadradic falloff term
lights_quad = point_light(position=c(100,100,500), color="white", 
                      falloff_quad = 0.0001, constant = 0.0002, falloff = 0.005) |>
 add_light(point_light(position=c(100,455,500), color="white",
                       falloff_quad = 0.0002, constant = 0.0002, falloff = 0.005)) |>
 add_light(point_light(position=c(455,100,500), color="white", 
                       falloff_quad = 0.0004, constant = 0.0002, falloff = 0.005)) |>
 add_light(point_light(position=c(455,455,500), color="white", 
                       falloff_quad = 0.0008, constant = 0.0002, falloff = 0.005))
                       
generate_cornell_mesh(light=FALSE) |>
 rasterize_scene(light_info = lights_quad)
}
Print method for ray_shape
Description
Print method for ray_shape
Usage
## S3 method for class 'ray_shape'
print(x, ...)
Arguments
| x | A ray_shape object. | 
| ... | Additional arguments (unused). | 
Print method for ray_vertex_data
Description
Print method for ray_vertex_data
Usage
## S3 method for class 'ray_vertex_data'
print(x, ...)
Arguments
| x | A ray_vertex_data object. | 
| ... | Additional arguments (unused). | 
Print time
Description
Print time
Usage
print_time(verbose = FALSE, message_text = "")
Value
Nothing
R 3D Model
Description
3D obj model of R logo (created from the R SVG logo with the raybevel package),
to be used with obj_model()
Usage
r_obj(simple_r = FALSE)
Arguments
| simple_r | Default  | 
Value
File location of the 3d_r_logo.obj file (saved with a .txt extension)
Examples
#Load and render the included example R object file.
if(run_documentation()) {
obj_mesh(r_obj()) |> 
  rasterize_scene(lookfrom = c(0, 1, 10),
                  fov=7,light_info = directional_light(c(1,1,1)))
}
Rasterize Lines
Description
Render a 3D scene made out of lines using a software rasterizer.
Usage
rasterize_lines(
  line_info = NULL,
  filename = NA,
  width = 800,
  height = 800,
  alpha_line = 1,
  parallel = TRUE,
  fov = 20,
  lookfrom = c(0, 0, 10),
  lookat = NULL,
  camera_up = c(0, 1, 0),
  color = "red",
  background = "black",
  debug = "none",
  near_plane = 0.1,
  far_plane = 100,
  block_size = 4,
  ortho_dimensions = c(1, 1),
  bloom = FALSE,
  antialias_lines = TRUE
)
Arguments
| line_info | The mesh object. | 
| filename | Default  | 
| width | Default  | 
| height | Default  | 
| alpha_line | Default  | 
| parallel | Default  | 
| fov | Default  | 
| lookfrom | Default  | 
| lookat | Default  | 
| camera_up | Default  | 
| color | Default  | 
| background | Default  | 
| debug | Default  | 
| near_plane | Default  | 
| far_plane | Default  | 
| block_size | Default  | 
| ortho_dimensions | Default  | 
| bloom | Default  | 
| antialias_lines | Default  | 
Value
Rasterized image.
Examples
if(run_documentation()) {
#Generate a cube out of lines
cube_outline = generate_line(start = c(-1, -1, -1), end = c(-1, -1, 1)) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(-1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, -1, -1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(1, -1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, -1), end = c(1, 1, -1)))
rasterize_lines(cube_outline,fov=90,lookfrom=c(0,0,3))
}
if(run_documentation()) {
#Scale the cube uniformly
scaled_cube = color_lines(scale_lines(cube_outline,scale=0.5),color="red")
rasterize_lines(add_lines(cube_outline,scaled_cube),fov=90,lookfrom=c(0,0,3))
}
if(run_documentation()) {
#Scale the cube non-uniformly
scaled_cube = color_lines(scale_lines(cube_outline,scale=c(0.8,2,0.4)),color="red")
rasterize_lines(add_lines(cube_outline,scaled_cube),fov=60,lookfrom=c(3,3,3))
}
Rasterize Scene
Description
Render a 3D scene with meshes, lights, and lines using a software rasterizer.
Usage
rasterize_scene(
  scene,
  filename = NA,
  width = 800,
  height = 800,
  line_info = NULL,
  alpha_line = 1,
  parallel = TRUE,
  plot = is.na(filename),
  fov = 20,
  lookfrom = c(0, 0, 10),
  lookat = NULL,
  camera_up = c(0, 1, 0),
  fsaa = 2,
  light_info = directional_light(),
  color = "red",
  type = "diffuse",
  background = "black",
  tangent_space_normals = TRUE,
  shadow_map = TRUE,
  shadow_map_bias = 0.003,
  shadow_map_intensity = 0,
  shadow_map_dims = NULL,
  ssao = FALSE,
  ssao_intensity = 10,
  ssao_radius = 0.1,
  tonemap = "none",
  debug = "none",
  near_plane = 0.1,
  far_plane = 100,
  shader = "default",
  block_size = 4,
  shape = NULL,
  line_offset = 1e-05,
  ortho_dimensions = c(1, 1),
  bloom = FALSE,
  antialias_lines = TRUE,
  environment_map = "",
  background_sharpness = 1,
  verbose = FALSE,
  vertex_transform = NULL,
  validate_scene = TRUE
)
Arguments
| scene | The scene object. | 
| filename | Default  | 
| width | Default  | 
| height | Default  | 
| line_info | Default  | 
| alpha_line | Default  | 
| parallel | Default  | 
| plot | Default  | 
| fov | Default  | 
| lookfrom | Default  | 
| lookat | Default  | 
| camera_up | Default  | 
| fsaa | Default  | 
| light_info | Default  | 
| color | Default  | 
| type | Default  | 
| background | Default  | 
| tangent_space_normals | Default  | 
| shadow_map | Default  | 
| shadow_map_bias | Default  | 
| shadow_map_intensity | Default  | 
| shadow_map_dims | Default  | 
| ssao | Default  | 
| ssao_intensity | Default  | 
| ssao_radius | Default  | 
| tonemap | Default  | 
| debug | Default  | 
| near_plane | Default  | 
| far_plane | Default  | 
| shader | Default  | 
| block_size | Default  | 
| shape | Default  | 
| line_offset | Default  | 
| ortho_dimensions | Default  | 
| bloom | Default  | 
| antialias_lines | Default  | 
| environment_map | Default  | 
| background_sharpness | Default  | 
| verbose | Default  | 
| vertex_transform | Default  | 
| validate_scene | Default  | 
Value
Rasterized image.
Examples
if(run_documentation()) {
#Let's load the cube OBJ file included with the package
rasterize_scene(cube_mesh(),lookfrom=c(2,4,10), 
              light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Flatten the cube, translate downwards, and set to grey
base_model = cube_mesh() |>
 scale_mesh(scale=c(5,0.2,5)) |>
 translate_mesh(c(0,-0.1,0)) |>
 set_material(diffuse="grey80") 
 
rasterize_scene(base_model, lookfrom=c(2,4,10), 
              light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {           
#load the R OBJ file, scale it down, color it blue, and add it to the grey base
r_model = obj_mesh(r_obj(simple_r = TRUE)) |>
 scale_mesh(scale=0.5) |>
 set_material(diffuse="dodgerblue") |>
 add_shape(base_model)
 
rasterize_scene(r_model, lookfrom=c(2,4,10), 
              light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Zoom in and reduce the shadow mapping intensity
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,shadow_map = TRUE, shadow_map_intensity=0.3,
              light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Include the resolution (4x) of the shadow map for less pixellation around the edges
#Also decrease the shadow_map_bias slightly to remove the "peter panning" floating shadow effect
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,
              shadow_map_dims=4, 
              light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Add some more directional lights and change their color
lights = directional_light(c(0.7,1.1,-0.9),color = "orange",intensity = 1) |>
           add_light(directional_light(c(0.7,1,1),color = "dodgerblue",intensity = 1)) |>
           add_light(directional_light(c(2,4,10),color = "white",intensity = 0.5))
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,
              light_info = lights)
}
if(run_documentation()) {
#Add some point lights
lights_p = lights |>
 add_light(point_light(position=c(-1,1,0),color="red", intensity=2)) |>
 add_light(point_light(position=c(1,1,0),color="purple", intensity=2)) 
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,
              light_info = lights_p)
}
if(run_documentation()) {
#change the camera position
rasterize_scene(r_model, lookfrom=c(-2,2,-10), fov=10,
              light_info = lights_p)
}
if(run_documentation()) {
              
#Add a spiral of lines around the model by generating a matrix of line segments
t = seq(0,8*pi,length.out=361)
line_mat = matrix(nrow=0,ncol=9)
for(i in 1:360) {
  line_mat = add_lines(line_mat,
                      generate_line(start = c(0.5*sin(t[i]), t[i]/(8*pi), 0.5*cos(t[i])),
                                    end  = c(0.5*sin(t[i+1]), t[i+1]/(8*pi), 0.5*cos(t[i+1]))))
}
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10, line_info = line_mat,
              light_info = lights)
}
Constructor for ray_mesh
Description
Constructor for ray_mesh
Usage
ray_mesh(...)
Value
ray
Define the ray_shape class
Description
Define the ray_shape class
Usage
ray_shape(...)
Arguments
| ... | Objects to be included in the ray_shape. | 
Value
A new ray_shape object.
Define the ray_shape_list class
Description
Define the ray_shape_list class
Usage
ray_shape_list(...)
Arguments
| ... | Objects to be included in the ray_shape_list. | 
Value
A new ray_shape_list object.
Define the ray_vertex_data class
Description
Define the ray_vertex_data class
Usage
ray_vertex_data(data = NA)
Arguments
| data | A matrix with 2 or 3 columns representing vertex data. | 
Value
A new ray_vertex_data object.
Load an OBJ file
Description
Loads an OBJ file and return a ray_mesh list structure. No processing is done on
the object other than loading it (unlike obj_model()).
Usage
read_obj(filename, materialspath = NULL)
Arguments
| filename | Filename of the OBJ file. | 
| materialspath | Directory where the MTL file is located. Defaults to the directory of  | 
Value
ray_mesh list object
#Load an arrow OBJ
sphere = read_obj(system.file("extdata", "arrow.txt", package="rayvertex"))
Load an PLY file
Description
Load an PLY file
Usage
read_ply(filename)
Value
List
Remove Duplicates
Description
Remove Duplicates
Usage
remove_duplicate_materials(scene)
Arguments
| scene | The scene | 
Value
Scene with shape added.
Rescale
Description
Rescale
Usage
rescale(vals, to = c(0, 1))
Arguments
| vals | Values | 
| to | to vales | 
Value
Color vector
Rotate Lines
Description
Rotate Lines
Usage
rotate_lines(
  lines,
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3)
)
Arguments
| lines | The existing line scene. | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
Value
Rotated lines.
Examples
if(run_documentation()) {
#Generate a cube out of lines
cube_outline = generate_line(start = c(-1, -1, -1), end = c(-1, -1, 1)) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(-1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, -1, -1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(1, -1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, -1), end = c(1, 1, -1)))
rasterize_lines(cube_outline,lookfrom=c(0,6,10))
}
if(run_documentation()) {
#Rotate the cube 30 degrees around the y-axis
rotated_cube = color_lines(rotate_lines(cube_outline,angle=c(0,30,0)),color="red")
rasterize_lines(add_lines(cube_outline,rotated_cube),lookfrom=c(0,6,10))
}
if(run_documentation()) {
#Rotate the cube 30 degrees around each axis, in this order: x,y,z
rotated_cube = color_lines(rotate_lines(cube_outline,angle=c(30,30,30)),color="red")
rasterize_lines(add_lines(cube_outline,rotated_cube),lookfrom=c(0,6,10))
}
if(run_documentation()) {
#Rotate the cube 30 degrees around each axis, in this order: z,y,x
rotated_cube = color_lines(rotate_lines(cube_outline,angle=c(30,30,30), 
                           order_rotation = c(3,2,1)),color="red")
rasterize_lines(add_lines(cube_outline,rotated_cube),lookfrom=c(0,6,10))
}
Rotate Mesh
Description
Rotate Mesh
Usage
rotate_mesh(
  mesh,
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3)
)
Arguments
| mesh | The mesh. | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
Value
Rotated Mesh
Examples
if(run_documentation()) {
#Rotate a mesh in the Cornell box
robj = obj_mesh(r_obj(), scale=150,angle=c(0,180,0))
generate_cornell_mesh() |>
add_shape(rotate_mesh(translate_mesh(robj,c(400,100,155)),c(0,30,0), 
                      pivot_point=c(400,100,155))) |>
add_shape(rotate_mesh(translate_mesh(robj,c(555/2,200,555/2)),c(-30,60,30), 
                      pivot_point=c(555/2,200,555/2))) |>
add_shape(rotate_mesh(translate_mesh(robj,c(155,300,400)),c(-30,60,30), 
                      pivot_point=c(155,300,400), order_rotation=c(3,2,1))) |>
rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)))
}
Run Documentation
Description
This function determines if the examples are being run in pkgdown. It is not meant to be called by the user.
Usage
run_documentation()
Value
Boolean value.
Examples
# See if the documentation should be run.
run_documentation()
Save PNG
Description
Writes the hillshaded map to file.
Usage
save_png(hillshade, filename, rotate = 0)
Arguments
| hillshade | Array (or matrix) of hillshade to be written. | 
| filename | String with the filename. If  | 
| rotate | Default 0. Rotates the output. Possible values: 0, 90, 180, 270. | 
Scale Lines
Description
Scale Lines
Usage
scale_lines(lines, scale = 1)
Arguments
| lines | The line scene. | 
| scale | Default  | 
Value
Scaled line matrix.
Examples
if(run_documentation()) {
#Generate a cube out of lines
cube_outline = generate_line(start = c(-1, -1, -1), end = c(-1, -1, 1)) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(-1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, -1, -1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(1, -1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, -1), end = c(1, 1, -1)))
rasterize_lines(cube_outline,fov=90,lookfrom=c(0,0,3))
}
if(run_documentation()) {
#Scale the cube uniformly
scaled_cube = color_lines(scale_lines(cube_outline,scale=0.5),color="red")
rasterize_lines(add_lines(cube_outline,scaled_cube),fov=90,lookfrom=c(0,0,3))
}
if(run_documentation()) {
#Scale the cube non-uniformly
scaled_cube = color_lines(scale_lines(cube_outline,scale=c(0.8,2,0.4)),color="red")
rasterize_lines(add_lines(cube_outline,scaled_cube),fov=60,lookfrom=c(3,3,3))
}
Scale Mesh
Description
Scale Mesh
Usage
scale_mesh(mesh, scale = 1, center = c(0, 0, 0))
Arguments
| mesh | The mesh. | 
| scale | Default  | 
| center | Default  | 
Value
Scaled mesh
Examples
if(run_documentation()) {
#Scale a mesh in the Cornell box
robj = obj_mesh(r_obj(), scale=150,angle=c(0,180,0))
generate_cornell_mesh() |>
add_shape(scale_mesh(translate_mesh(robj,c(400,100,155)),0.5, center=c(400,100,155))) |>
add_shape(scale_mesh(translate_mesh(robj,c(555/2,200,555/2)),1.5, center=c(555/2,200,555/2))) |>
add_shape(scale_mesh(translate_mesh(robj,c(55,300,400)),c(0.5,2,0.5), center=c(155,300,400))) |>
rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)))
}
Scale Mesh to Unit Bounding Box
Description
Scale Mesh to Unit Bounding Box
Usage
scale_unit_mesh(mesh, center_mesh = FALSE)
Arguments
| mesh | The mesh. | 
| center_mesh | Default  | 
Value
Scaled mesh
Examples
if(run_documentation()) {
#Scale the Cornell box (and contents) down to the unit box.
robj = obj_mesh(r_obj(), scale=150,angle=c(0,180,0))
generate_cornell_mesh() |>
add_shape(scale_mesh(translate_mesh(robj,c(400,100,155)),0.5, center=c(400,100,155))) |>
add_shape(scale_mesh(translate_mesh(robj,c(555/2,200,555/2)),1.5, center=c(555/2,200,555/2))) |>
add_shape(scale_mesh(translate_mesh(robj,c(55,300,400)),c(0.5,2,0.5), center=c(155,300,400))) |>
scale_unit_mesh(center_mesh = TRUE) |> 
rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)), 
                lookfrom = c(0,0,-2), lookat=c(0,0,0))
}
Scene From List
Description
Fast generation of rayvertex scenes from a list of objects (much faster than calling
add_shape() on each object individually to build the scene). This returns a ray_scene object
that cdoes
Usage
scene_from_list(scene_list)
Arguments
| scene_list | List containing rayvertex mesh objects. | 
Value
ray_scene containing mesh info.
Examples
if(run_documentation()) {
 #Build a scene out of cubes including 87 * 61 = 5307 objects
 scene = list()
 volcol = rainbow(103)
 counter = 1
 for(i in 1:nrow(volcano)) {
   for(j in 1:ncol(volcano)) {
     scene[[counter]] = cube_mesh(position = c(i,(volcano[i,j]-94),j), 
                                  material = material_list(diffuse = volcol[volcano[i,j]-92],
                                                           ambient = volcol[volcano[i,j]-92],
                                                           ambient_intensity = 0.2))
     counter = counter + 1
   }
 }
 #Quickly generate the 
 new_scene = scene_from_list(scene)
 new_scene |> 
   rotate_mesh(c(0,10,0), pivot_point = c(44,0,31)) |> 
   add_shape(xz_rect_mesh(position=c(44,0,31),scale=500,
                          material = material_list(diffuse="lightblue",
                                                   ambient = "lightblue",
                                                   ambient_intensity = 0.2))) |> 
   rasterize_scene(lookfrom=c(500,500,500), lookat = c(44.00, 40.50, 31.00),
                   width=800,height=800, fov=0, ortho_dimensions = c(140,140),
                   light_info = directional_light(c(-0.6,1,0.6)))
}
Segment 3D Model
Description
Segment 3D Model
Usage
segment_mesh(
  start = c(0, -1, 0),
  end = c(0, 1, 0),
  radius = 0.5,
  direction = NA,
  from_center = TRUE,
  square = FALSE,
  material = material_list()
)
Arguments
| start | Default  | 
| end | Default  | 
| radius | Default  | 
| direction | Default  | 
| from_center | Default  | 
| square | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate a segment in the cornell box. 
generate_cornell_mesh() |>
  add_shape(segment_mesh(start = c(100, 100, 100), end = c(455, 455, 455), radius = 50)) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
if(run_documentation()) {
# Draw a line graph representing a normal distribution, but with metal:
xvals = seq(-3, 3, length.out = 30)
yvals = dnorm(xvals)
scene_list = list()
for(i in 1:(length(xvals) - 1)) {
  scene_list = add_shape(scene_list, 
                         segment_mesh(start = c(555/2 + xvals[i] * 80, yvals[i] * 800, 555/2),
                            end = c(555/2 + xvals[i + 1] * 80, yvals[i + 1] * 800, 555/2),
                            radius = 10,
                            material = material_list(diffuse="purple", type="phong")))
}
generate_cornell_mesh() |> 
  add_shape(scene_list) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
if(run_documentation()) {
#Draw the outline of a cube:
cube_outline = segment_mesh(start = c(100, 100, 100), end = c(100, 100, 455), radius = 10) |>
  add_shape(segment_mesh(start = c(100, 100, 100), end = c(100, 455, 100), radius = 10)) |>
  add_shape(segment_mesh(start = c(100, 100, 100), end = c(455, 100, 100), radius = 10)) |>
  add_shape(segment_mesh(start = c(100, 100, 455), end = c(100, 455, 455), radius = 10)) |>
  add_shape(segment_mesh(start = c(100, 100, 455), end = c(455, 100, 455), radius = 10)) |>
  add_shape(segment_mesh(start = c(100, 455, 455), end = c(100, 455, 100), radius = 10)) |>
  add_shape(segment_mesh(start = c(100, 455, 455), end = c(455, 455, 455), radius = 10)) |>
  add_shape(segment_mesh(start = c(455, 455, 100), end = c(455, 100, 100), radius = 10)) |>
  add_shape(segment_mesh(start = c(455, 455, 100), end = c(455, 455, 455), radius = 10)) |>
  add_shape(segment_mesh(start = c(455, 100, 100), end = c(455, 100, 455), radius = 10)) |>
  add_shape(segment_mesh(start = c(455, 100, 455), end = c(455, 455, 455), radius = 10)) |>
  add_shape(segment_mesh(start = c(100, 455, 100), end = c(455, 455, 100), radius = 10))
generate_cornell_mesh() |>
  add_shape(set_material(cube_outline,diffuse="dodgerblue",type="phong")) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
  }
if(run_documentation()) {
#Shrink and rotate the cube
generate_cornell_mesh() |>
  add_shape(
    scale_mesh(rotate_mesh(set_material(cube_outline,diffuse="dodgerblue",type="phong"),
                angle=c(45,45,45), pivot_point=c(555/2,555/2,555/2)),0.5,
                center=c(555/2,555/2,555/2))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
Set Material
Description
Set the material(s) of the mesh.
Usage
set_material(
  mesh,
  material = NULL,
  id = NULL,
  diffuse = c(0.5, 0.5, 0.5),
  ambient = c(0, 0, 0),
  specular = c(1, 1, 1),
  transmittance = c(0, 0, 0),
  emission = c(0, 0, 0),
  shininess = 50,
  ior = 1,
  dissolve = 1,
  illum = 1,
  texture_location = "",
  normal_texture_location = "",
  bump_texture_location = "",
  specular_texture_location = "",
  ambient_texture_location = "",
  emissive_texture_location = "",
  diffuse_intensity = 1,
  bump_intensity = 1,
  specular_intensity = 1,
  emission_intensity = 1,
  ambient_intensity = 1,
  culling = "back",
  type = "diffuse",
  translucent = TRUE,
  toon_levels = 5,
  toon_outline_width = 0.05,
  toon_outline_color = "black",
  reflection_intensity = 0,
  reflection_sharpness = 0,
  two_sided = FALSE
)
Arguments
| mesh | The target mesh. | 
| material | Default  | 
| id | Default  | 
| diffuse | Default  | 
| ambient | Default  | 
| specular | Default  | 
| transmittance | Default  | 
| emission | Default  | 
| shininess | Default  | 
| ior | Default  | 
| dissolve | Default  | 
| illum | Default  | 
| texture_location | Default  | 
| normal_texture_location | Default  | 
| bump_texture_location | Default  | 
| specular_texture_location | Default  | 
| ambient_texture_location | Default  | 
| emissive_texture_location | Default  | 
| diffuse_intensity | Default  | 
| bump_intensity | Default  | 
| specular_intensity | Default  | 
| emission_intensity | Default  | 
| ambient_intensity | Default  | 
| culling | Default  | 
| type | Default  | 
| translucent | Default  | 
| toon_levels | Default  | 
| toon_outline_width | Default  | 
| toon_outline_color | Default  | 
| reflection_intensity | Default  | 
| reflection_sharpness | Default  | 
| two_sided | Default  | 
Value
Shape with new material
Examples
if(run_documentation()) {
#Set the material of an object
generate_cornell_mesh() |>
 add_shape(set_material(sphere_mesh(position=c(400,555/2,555/2),radius=40), 
                        diffuse="purple", type="phong")) |>
 add_shape(set_material(sphere_mesh(position=c(555/2,220,555/2),radius=40),
                        dissolve=0.2,culling="none",diffuse="red")) |>
 add_shape(set_material(sphere_mesh(position=c(155,300,555/2),radius=60), 
                        material = material_list(diffuse="gold", type="phong", 
                                                 ambient="gold", ambient_intensity=0.4))) |>
 rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)))
 }
Calculate Smooth Mesh Normals
Description
Calculate Smooth Mesh Normals
Usage
smooth_normals_mesh(mesh, id = NA)
Arguments
| mesh | The mesh. | 
| id | Default  | 
Value
Mesh with new vertex normals
Examples
if(run_documentation()) {
 #Let's construct a mesh from the volcano dataset
 #Build the vertex matrix
  vertex_list = list()
  counter = 1
  for(i in 1:nrow(volcano)) {
    for(j in 1:ncol(volcano)) {
      vertex_list[[counter]] = matrix(c(j,volcano[i,j],i), ncol=3)
      counter = counter + 1
    }
  }
  vertices = do.call(rbind,vertex_list)
  
  #Build the index matrix
  index_list = list()
  counter = 0
  for(i in 1:(nrow(volcano)-1)) {
    for(j in 1:(ncol(volcano)-1)) {
      index_list[[counter+1]] = matrix(c(counter,counter+ncol(volcano),counter+1,
                                         counter+ncol(volcano),counter+ncol(volcano)+1,counter + 1), 
                                       nrow=2, ncol=3, byrow=TRUE)
      counter = counter + 1
    }
    counter = counter + 1
  }
  indices = do.call(rbind,index_list)
  #Construct the mesh
  volc_mesh = construct_mesh(vertices = vertices, indices = indices,
                             material = material_list(type="diffuse", diffuse="darkred", 
                                                      ambient = "darkred", ambient_intensity=0.2))
  #Rasterize the no-normal scene
  scale_mesh(volc_mesh, scale = c(1,1/3,1)) |> 
    center_mesh() |> 
    rasterize_scene(lookfrom=c(-50,50,100),lookat=c(7,-15,0), fov=40,width=800,height=800,
                    light_info = directional_light(c(0,1,1)) |>
                      add_light(directional_light(c(1,1,-1))))
                      
  #Smooth the mesh
  volc_mesh_smooth = smooth_normals_mesh(volc_mesh)
  
  #Rasterize the scene
  scale_mesh(volc_mesh_smooth, scale = c(1,1/3,1)) |> 
    center_mesh() |> 
    rasterize_scene(lookfrom=c(-50,50,100),lookat=c(7,-15,0), fov=40,width=800,height=800,
                    light_info = directional_light(c(0,1,1)) |>
                      add_light(directional_light(c(1,1,-1))))
}
Sphere 3D Model
Description
Sphere 3D Model
Usage
sphere_mesh(
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  radius = 1,
  low_poly = FALSE,
  normals = TRUE,
  material = material_list()
)
Arguments
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| radius | Default  | 
| low_poly | Default  | 
| normals | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate a sphere in the Cornell box.
generate_cornell_mesh() |>
  add_shape(sphere_mesh(position = c(555/2, 555/2, 555/2), radius = 100)) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
if(run_documentation()) {
#Generate a shiny sphere in the Cornell box
generate_cornell_mesh() |>
  add_shape(sphere_mesh(position = c(555/2, 100, 555/2), radius = 100, 
                    material = material_list(diffuse = "gold",type="phong"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
if(run_documentation()) {
#Generate an ellipsoid in the Cornell box
generate_cornell_mesh() |>
  add_shape(sphere_mesh(position = c(555/2, 210, 555/2), radius = 100, 
                        angle=c(0,30,0), scale = c(0.5,2,0.5),
                        material = material_list(diffuse = "dodgerblue",type="phong"))) |>
  rasterize_scene(light_info = directional_light(c(0.5,0.5,-1)))
}
Subdivide Mesh
Description
Applies Loop subdivision to the scene (or selected meshes).
Usage
subdivide_mesh(
  scene,
  id = NA,
  subdivision_levels = 2,
  simple = FALSE,
  normals = TRUE,
  verbose = FALSE
)
Arguments
| scene | The scene to subdivide. | 
| id | Default  | 
| subdivision_levels | Default  | 
| simple | Default  | 
| normals | Default  | 
| verbose | Default  | 
Value
Scene with shape added.
Examples
if(run_documentation()) {
#Subdivide the included R mesh
obj_mesh(r_obj(),position=c(-0.5,0,0)) |> 
  add_shape(subdivide_mesh(obj_mesh(r_obj(),position=c(0.5,0,0)),
                           subdivision_levels = 2)) |> 
  rasterize_scene(light_info = directional_light(direction=c(0.2,0.5,1)),fov=13)
}
Swap Y/Z Axis
Description
Swap Y/Z Axis
Usage
swap_yz(mesh)
Arguments
| mesh | A raymesh object. | 
Value
Mesh with Y and Z axis exchanged
Examples
# Flip a mesh that's originally aligned along the y-axis
if(run_documentation()) {
cyl_mat = material_list(ambient="red", ambient_intensity=0.3, 
                        diffuse="red", diffuse_intensity=0.7)
change_material(cylinder_mesh(length = 3, position=c(0,2,0), material = cyl_mat),
                diffuse="green", ambient="green") |> 
  add_shape(swap_yz(cylinder_mesh(position=c(0,2,0), length=3, material = cyl_mat))) |> 
  rasterize_scene(lookfrom=c(10,10,10), lookat=c(0,0,0), fov=40,
                  light_info = directional_light(c(1,1,-1)),
                  line_info = generate_line(end=c(10,0,0)) |> 
                  add_lines(generate_line(end=c(0,10,0),color="green")) |> 
                  add_lines(generate_line(end=c(0,0,10),color="red")))
}
Text Object
Description
Text Object
Usage
text3d_mesh(
  label,
  position = c(0, 0, 0),
  text_height = 1,
  orientation = "xy",
  font_color = "black",
  font_size = 100,
  font = "sans",
  font_lineheight = 12,
  background_color = "white",
  background_alpha = 0,
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  scale = c(1, 1, 1)
)
Arguments
| label | Text string. | 
| position | Default  | 
| text_height | Default  | 
| orientation | Default  | 
| font_color | Default  | 
| font_size | Default  | 
| font | Default  | 
| font_lineheight | Default  | 
| background_color | Default  | 
| background_alpha | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| scale | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Generate a label in the Cornell box.
generate_cornell_mesh() |> 
  add_shape(text3d_mesh(label="Cornell Box", position=c(555/2,555/2,555/2),angle=c(0,180,0),
  text_height=120)) |> 
  rasterize_scene(light_info = directional_light(c(0.1,0.4,-1)))
}
if(run_documentation()) {
#Change the orientation
generate_cornell_mesh() |> 
  add_shape(text3d_mesh(label="YZ Plane", position=c(540,555/2,555/2),text_height=180,
                    orientation = "yz",angle=c(0,180,0))) |> 
  add_shape(text3d_mesh(label="XY Plane", position=c(555/2,555/2,540),text_height=180,
                    orientation = "xy", angle=c(0,180,0))) |> 
  add_shape(text3d_mesh(label="XZ Plane", position=c(555/2,15,555/2),text_height=180,
                    orientation = "xz", angle=c(0,180,0))) |> 
  rasterize_scene(light_info = directional_light(c(0.1,0.4,-1)))
  }
if(run_documentation()) {
#Add an label in front of a sphere and change the font
generate_cornell_mesh() |> 
  add_shape(text3d_mesh(label="Cornell Box", position=c(555/2,555/2,555/2),text_height=180,
                        font = "Serif", font_color="orange",
                        angle=c(0,180,0))) |> 
  add_shape(text3d_mesh(label="Sphere", position=c(555/2,130,100),text_height=100,
                        font = "sans",
                        font_color="lightblue",angle=c(0,180,40))) |> 
  add_shape(sphere_mesh(radius=100,position=c(555/2,100,555/2),
                        material=material_list(diffuse="purple",type="phong"))) |>                  
  rasterize_scene(light_info = directional_light(c(0.1,0.4,-1)))
  }
if(run_documentation()) {
#A room full of b's
set.seed(1)
bee_scene = list()
for(i in 1:100) {
bee_scene = add_shape(bee_scene, text3d_mesh("B", position=c(20+runif(3)*525), 
                                             font_color="yellow", text_height = 100,
                                             angle=c(0,180,0)))
}
generate_cornell_mesh() |> 
  add_shape(bee_scene) |>                   
  rasterize_scene(light=directional_light(c(0,1,-1)))
}
if(run_documentation()) {
#A room full of bees
bee_scene = list()
set.seed(1)
for(i in 1:100) {
  bee_scene = add_shape(bee_scene, text3d_mesh("\U1F41D", position=c(20+runif(3)*525), 
                                               font_color="yellow", text_height = 100,
                                               angle=c(0,180,0)))
}
generate_cornell_mesh() |> 
  add_shape(bee_scene) |>                   
  rasterize_scene(light=directional_light(c(0,1,-1)))
}
Torus 3D Model
Description
Torus 3D Model
Usage
torus_mesh(
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  radius = 0.5,
  ring_radius = 0.2,
  sides = 36,
  rings = 36,
  material = material_list()
)
Arguments
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| radius | Default  | 
| ring_radius | Default  | 
| sides | Default  | 
| rings | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
#Plot a group of tori in the cornell box
generate_cornell_mesh(ceiling = FALSE) |> 
 add_shape(torus_mesh(position=c(555/2,555/3,555/2), angle=c(20,0,45),
                      radius=120, ring_radius = 40,
                      material = material_list(diffuse="dodgerblue4",type="phong",
                                               ambient="dodgerblue4",ambient_intensity=0.2))) |>
 add_shape(torus_mesh(position=c(400,400,555/2), angle=c(20,200,45),radius=80, ring_radius = 30,
                      material=material_list(diffuse="orange",type="phong",
                                             ambient="orange",ambient_intensity=0.2))) |>
 add_shape(torus_mesh(position=c(150,450,555/2), angle=c(60,180,0),radius=40, ring_radius = 20,
                      material=material_list(diffuse="red",type="phong"))) |>
 rasterize_scene(light_info = directional_light(c(0,1,-2)))
}
Translate Lines
Description
Translate Lines
Usage
translate_lines(lines, position = 1)
Arguments
| lines | The line scene. | 
| position | Default  | 
Value
Translated line matrix.
Examples
if(run_documentation()) {
#Generate a cube out of lines
cube_outline = generate_line(start = c(-1, -1, -1), end = c(-1, -1, 1)) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(-1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, -1, 1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(-1, 1, -1))) |>
  add_lines(generate_line(start = c(-1, 1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, -1, -1))) |>
  add_lines(generate_line(start = c(1, 1, -1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(1, -1, -1), end = c(1, -1, 1))) |>
  add_lines(generate_line(start = c(1, -1, 1), end = c(1, 1, 1))) |>
  add_lines(generate_line(start = c(-1, 1, -1), end = c(1, 1, -1))) 
rasterize_lines(cube_outline,fov=40,lookfrom=c(1,2,10),lookat=c(0,0,0))
}
if(run_documentation()) {
#Scale the cube uniformly
translated_cube = color_lines(translate_lines(cube_outline,c(1,1,1)),"red")
translated_cube2 = color_lines(translate_lines(cube_outline,c(-1,-1,-1)),"green")
cube_outline |>
  add_lines(translated_cube) |>
  add_lines(translated_cube2) |>
  rasterize_lines(fov=40,lookfrom=c(1,2,10),lookat=c(0,0,0))
}
Translate Mesh
Description
Translate Mesh
Usage
translate_mesh(mesh, position = c(0, 0, 0))
Arguments
| mesh | The mesh. | 
| position | Default  | 
Value
Translated mesh
Examples
if(run_documentation()) {
#Translate a mesh in the Cornell box
robj = obj_mesh(r_obj(), scale=150,angle=c(0,180,0))
generate_cornell_mesh() |>
 add_shape(translate_mesh(robj,c(400,100,155))) |>
 add_shape(translate_mesh(robj,c(555/2,200,555/2))) |>
 add_shape(translate_mesh(robj,c(155,300,400))) |>
 rasterize_scene(light_info=directional_light(direction=c(0.1,0.6,-1)))
}
Validate Mesh Data
Description
This function takes a mesh and validates it. The mesh should be a list with "shapes", "materials", "vertices", "texcoords", "normals", and "material_hashes" entries.
Usage
validate_mesh(mesh, validate_materials = TRUE)
Arguments
| mesh | List. A mesh is a list as described above. | 
| validate_materials | Default  | 
Value
A mesh.
Shapes
Each "shapes" entry should be a list with "mesh", "name", and "material" entries. Each "mesh" entry should have "indices", "tex_indices", "norm_indices", "material_ids", "has_vertex_tex", and "has_vertex_normals". The indices should not exceed the number of rows in their corresponding vertex/normal/texcoord data. There should be no NA/NaN values in the vertex/normal/texcoord data.
Materials (for rayvertex package only)
Each "materials" entry is expected to be a list with several entries with specific required lengths, as listed below:
| Attribute | Length | Type | 
| diffuse | 3 | Numeric | 
| ambient | 3 | Numeric | 
| specular | 3 | Numeric | 
| transmittance | 3 | Numeric | 
| emission | 3 | Numeric | 
| shininess | 1 | Numeric | 
| ior | 1 | Numeric | 
| dissolve | 1 | Numeric | 
| illum | 1 | Numeric | 
| diffuse_texname | 1 | Character | 
| normal_texname | 1 | Character | 
| bump_texname | 1 | Character | 
| specular_texname | 1 | Character | 
| ambient_texname | 1 | Character | 
| emissive_texname | 1 | Character | 
| diffuse_intensity | 1 | Numeric | 
| bump_intensity | 1 | Numeric | 
| specular_intensity | 1 | Numeric | 
| emission_intensity | 1 | Numeric | 
| ambient_intensity | 1 | Numeric | 
| culling | 1 | Character | 
| type | 1 | Character | 
| translucent | 1 | Logical | 
| toon_levels | 1 | Numeric | 
| toon_outline_width | 1 | Numeric | 
| toon_outline_color | 3 | Numeric | 
| reflection_intensity | 1 | Numeric | 
| reflection_sharpness | 1 | Numeric | 
| two_sided | 1 | Logical | 
Note: This materials validation only applies to the rayvertex package. Other renderers might choose to use their own information in the material list.
Examples
# validate a mesh
mesh = validate_mesh(sphere_mesh())
Validate Scene
Description
Validate Scene
Usage
validate_scene(scene)
Arguments
| scene | Make sure that there are no out of bounds issues and all the materials are valid | 
Value
Color vector
Abbreviate the ptype of ray_shape
Description
Abbreviate the ptype of ray_shape
Usage
vec_ptype_abbr.ray_shape(x, ...)
Arguments
| x | A ray_shape object. | 
| ... | Additional arguments (unused). | 
Value
A character vector with the abbreviation "ray_shp".
Abbreviate the ptype of ray_shape_list
Description
Abbreviate the ptype of ray_shape_list
Usage
vec_ptype_abbr.ray_shape_list(x, ...)
Arguments
| x | A ray_shape_list object. | 
| ... | Additional arguments (unused). | 
Value
A character vector with the abbreviation "ray_shp".
Verify Vertex Shader
Description
Verify Vertex Shader
Usage
verify_vertex_shader(vertex_shader)
Value
bool
Write the scene to an OBJ file
Description
Writes the current scene to a Wavefront OBJ file, with or without materials
Usage
write_scene_to_obj(scene, filename, materials = TRUE, fileext = ".obj")
Arguments
| scene | A rayvertex scene. | 
| filename | The filename for the OBJ file. | 
| materials | Default  | 
| fileext | Default  | 
Value
None
Examples
if(run_documentation()) {
tmpfile = tempfile(fileext = ".obj")
write_scene_to_obj(generate_cornell_mesh(), tmpfile)
}
XY Rectangle 3D Model
Description
XY Rectangle 3D Model
Usage
xy_rect_mesh(
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
generate_cornell_mesh() |>
  add_shape(xy_rect_mesh(position = c(555/2, 100, 555/2), scale=200,
             material = material_list(diffuse = "purple"),angle=c(0,180,0))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
if(run_documentation()) {
#Rotate the plane and scale 
generate_cornell_mesh() |>
  add_shape(xy_rect_mesh(position = c(555/2, 100, 555/2), scale=c(200,100,1), angle=c(0,180,0),
             material = material_list(diffuse = "purple"))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
XZ Rectangle 3D Model
Description
XZ Rectangle 3D Model
Usage
xz_rect_mesh(
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
generate_cornell_mesh() |>
  add_shape(xz_rect_mesh(position = c(555/2, 100, 555/2), scale=200,
             material = material_list(diffuse = "purple"))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
if(run_documentation()) {
#Rotate the plane and scale 
generate_cornell_mesh() |>
  add_shape(xz_rect_mesh(position = c(555/2, 100, 555/2), scale=c(200,1,100), angle=c(0,30,0),
             material = material_list(diffuse = "purple"))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
YZ Rectangle 3D Model
Description
YZ Rectangle 3D Model
Usage
yz_rect_mesh(
  position = c(0, 0, 0),
  scale = c(1, 1, 1),
  angle = c(0, 0, 0),
  pivot_point = c(0, 0, 0),
  order_rotation = c(1, 2, 3),
  material = material_list()
)
Arguments
| position | Default  | 
| scale | Default  | 
| angle | Default  | 
| pivot_point | Default  | 
| order_rotation | Default  | 
| material | Default  | 
Value
List describing the mesh.
Examples
if(run_documentation()) {
generate_cornell_mesh() |>
  add_shape(yz_rect_mesh(position = c(555/2, 100, 555/2), scale=c(200,1,200), angle=c(0,0,0),
             material = material_list(diffuse = "purple"))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}
if(run_documentation()) {
#Rotate and scale
generate_cornell_mesh() |>
  add_shape(yz_rect_mesh(position = c(555/2, 100, 555/2), scale=c(300,1,200), angle=c(0,45,0),
             material = material_list(diffuse = "purple"))) |>
  rasterize_scene(light_info = directional_light(c(0,0.5,-1)))
}