Title: | 3D Software Rasterizer |
---|---|
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. |
Authors: | Tyler Morgan-Wall [aut, cph, cre] , Syoyo Fujita [ctb, cph], Vilya Harvey [ctb, cph], G-Truc Creation [ctb, cph], Sean Barrett [ctb, cph] |
Maintainer: | Tyler Morgan-Wall <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.11.4 |
Built: | 2024-10-31 21:08:08 UTC |
Source: | https://github.com/tylermorganwall/rayvertex |
Add light
add_light(lights, light)
add_light(lights, light)
lights |
Current light scene. |
light |
New light to add. |
A matrix representing the light information.
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) }
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
add_lines(lines, line)
add_lines(lines, line)
lines |
Existing lines or empty (0-row) matrix. |
line |
Line to add, generated with |
New line matrix.
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()) { #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)) }
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.
add_plane_uv_mesh( mesh, direction = c(0, 1, 0), u = NULL, v = NULL, override_existing = FALSE, full_mesh_bbox = TRUE )
add_plane_uv_mesh( mesh, direction = c(0, 1, 0), u = NULL, v = NULL, override_existing = FALSE, full_mesh_bbox = TRUE )
mesh |
The mesh to which the UV mapping will be applied. |
direction |
Default |
u |
Default |
v |
Default |
override_existing |
Default |
full_mesh_bbox |
Default |
Modified mesh with added UV mapping.
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)) }
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 to the scene.
add_shape(scene, shape = NULL)
add_shape(scene, shape = NULL)
scene |
The scene to add the shape. |
shape |
The mesh to add to the scene. |
Scene with shape added.
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))) }
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))) }
Applies a planar UV mapping to a mesh based on a spherical direction from the origin.
add_sphere_uv_mesh(mesh, origin = c(0, 0, 0), override_existing = FALSE)
add_sphere_uv_mesh(mesh, origin = c(0, 0, 0), override_existing = FALSE)
mesh |
The mesh to which the UV mapping will be applied. |
origin |
Default |
override_existing |
Default |
Modified mesh with added UV mapping.
if(run_documentation()) { #Let's construct a mesh from the volcano dataset }
if(run_documentation()) { #Let's construct a mesh from the volcano dataset }
Arrow 3D Model
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() )
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() )
start |
Default |
end |
Default |
radius_top |
Default |
radius_tail |
Default |
tail_proportion |
Default |
direction |
Default |
from_center |
Default |
material |
Default |
List describing the mesh.
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))) }
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))) }
Centers the mesh at the origin.
center_mesh(mesh)
center_mesh(mesh)
mesh |
The mesh object. |
Centered mesh
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))) }
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 individual material properties, leaving others alone.
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 )
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 )
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 |
Shape with new material settings
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))) }
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
color_lines(lines, color = "white")
color_lines(lines, color = "white")
lines |
The line scene. |
color |
Default |
Colored line matrix.
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() }
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
cone_mesh( start = c(0, 0, 0), end = c(0, 1, 0), radius = 0.5, direction = NA, from_center = FALSE, material = material_list() )
cone_mesh( start = c(0, 0, 0), end = c(0, 1, 0), radius = 0.5, direction = NA, from_center = FALSE, material = material_list() )
start |
Default |
end |
Default |
radius |
Default |
direction |
Default |
from_center |
Default |
material |
Default |
List describing the mesh.
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))) }
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
construct_mesh( vertices, indices, normals = NULL, norm_indices = NULL, texcoords = NULL, tex_indices = NULL, material = material_list() )
construct_mesh( vertices, indices, normals = NULL, norm_indices = NULL, texcoords = NULL, tex_indices = NULL, material = material_list() )
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 |
List containing mesh info.
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)))) }
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)))) }
3D obj model of the letter R
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() )
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() )
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
material |
Default |
List describing the mesh.
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))) }
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
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() )
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() )
position |
Default |
radius |
Default |
length |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
material |
Default |
List describing the mesh.
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))) }
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
directional_light(direction = c(0, 1, 0), color = "white", intensity = 1)
directional_light(direction = c(0, 1, 0), color = "white", intensity = 1)
direction |
Default |
color |
Default |
intensity |
Default |
A matrix representing the light information.
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) }
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
displace_mesh( mesh, displacement_texture, displacement_scale = 1, displacement_vector = FALSE, id = NA, verbose = TRUE )
displace_mesh( mesh, displacement_texture, displacement_scale = 1, displacement_vector = FALSE, id = NA, verbose = TRUE )
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 |
raymesh object
if(run_documentation()) { #Let's construct a mesh from the volcano dataset }
if(run_documentation()) { #Let's construct a mesh from the volcano dataset }
Construct Displacement Sphere
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() )
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() )
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 |
raymesh object
if(run_documentation()) { }
if(run_documentation()) { }
Flip Orientation
flip_orientation_mesh(mesh)
flip_orientation_mesh(mesh)
mesh |
The mesh to swap orientations. |
Mesh with flipped vertex orientation
# 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 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) }
Cornell Box 3D Model
generate_cornell_mesh( leftcolor = "#1f7326", rightcolor = "#a60d0d", roomcolor = "#bababa", ceiling = TRUE, light = TRUE )
generate_cornell_mesh( leftcolor = "#1f7326", rightcolor = "#a60d0d", roomcolor = "#bababa", ceiling = TRUE, light = TRUE )
leftcolor |
Default |
rightcolor |
Default |
roomcolor |
Default |
ceiling |
Default |
light |
Default |
List describing the mesh.
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))) }
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
generate_line(start = c(0, 0, 0), end = c(0, 1, 0), color = "white")
generate_line(start = c(0, 0, 0), end = c(0, 1, 0), color = "white")
start |
Default |
end |
Default |
color |
Default |
Line matrix
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) }
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) }
Calculates the bounding box of a mesh
get_mesh_bbox(mesh)
get_mesh_bbox(mesh)
mesh |
The mesh object. |
2x3 numeric matrix
if(run_documentation()) { #Calculates the center of the mesh get_mesh_bbox(generate_cornell_mesh()) }
if(run_documentation()) { #Calculates the center of the mesh get_mesh_bbox(generate_cornell_mesh()) }
Calculates the coordinates of the center of a mesh
get_mesh_center(mesh)
get_mesh_center(mesh)
mesh |
The mesh object. |
Length-3 numeric vector
if(run_documentation()) { #Calculates the center of the mesh get_mesh_center(generate_cornell_mesh()) }
if(run_documentation()) { #Calculates the center of the mesh get_mesh_center(generate_cornell_mesh()) }
Generate a material properties list.
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 )
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 )
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 |
List of material properties.
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))) }
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))) }
Mesh3d 3D Model
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() )
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() )
mesh |
Mesh3d object. |
center |
Default |
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
materialspath |
Default |
material |
Default |
List describing the mesh.
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))) }
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
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 )
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 )
filename |
OBJ filename. |
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
materialspath |
Default |
center |
Default |
material |
Default |
List describing the mesh.
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))) }
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))) }
PLY Mesh 3D Model
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() )
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() )
filename |
PLY filename. |
center |
Default |
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
material |
Default |
List describing the mesh.
#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).
#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).
The falloff of the point light intensity is given by the following equation (referenc:
Intensity = intensity / (constant + falloff * distance + falloff_quad * (distance * distance));
point_light( position = c(0, 0, 0), color = "white", intensity = 1, constant = 1, falloff = 1, falloff_quad = 1 )
point_light( position = c(0, 0, 0), color = "white", intensity = 1, constant = 1, falloff = 1, falloff_quad = 1 )
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 |
A matrix representing the light information.
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) }
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) }
3D obj model of R logo (created from the R SVG logo with the raybevel
package),
to be used with obj_model()
r_obj(simple_r = FALSE)
r_obj(simple_r = FALSE)
simple_r |
Default |
File location of the 3d_r_logo.obj file (saved with a .txt extension)
#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))) }
#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))) }
Render a 3D scene made out of lines using a software rasterizer.
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 )
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 )
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 |
Rasterized image.
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)) }
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)) }
Render a 3D scene with meshes, lights, and lines using a software rasterizer.
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 )
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 )
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 |
Rasterized image.
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) }
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) }
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()
).
read_obj(filename, materialspath = NULL)
read_obj(filename, materialspath = NULL)
filename |
Filename of the OBJ file. |
materialspath |
Directory where the MTL file is located. Defaults to the directory of |
ray_mesh
list object
#Load an arrow OBJ
sphere = read_obj(system.file("extdata", "arrow.txt", package="rayvertex"))
Rotate Lines
rotate_lines( lines, angle = c(0, 0, 0), pivot_point = c(0, 0, 0), order_rotation = c(1, 2, 3) )
rotate_lines( lines, angle = c(0, 0, 0), pivot_point = c(0, 0, 0), order_rotation = c(1, 2, 3) )
lines |
The existing line scene. |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
Rotated lines.
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)) }
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
rotate_mesh( mesh, angle = c(0, 0, 0), pivot_point = c(0, 0, 0), order_rotation = c(1, 2, 3) )
rotate_mesh( mesh, angle = c(0, 0, 0), pivot_point = c(0, 0, 0), order_rotation = c(1, 2, 3) )
mesh |
The mesh. |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
Rotated Mesh
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))) }
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))) }
This function determines if the examples are being run in pkgdown. It is not meant to be called by the user.
run_documentation()
run_documentation()
Boolean value.
# See if the documentation should be run. run_documentation()
# See if the documentation should be run. run_documentation()
Scale Lines
scale_lines(lines, scale = 1)
scale_lines(lines, scale = 1)
lines |
The line scene. |
scale |
Default |
Scaled line matrix.
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)) }
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
scale_mesh(mesh, scale = 1, center = c(0, 0, 0))
scale_mesh(mesh, scale = 1, center = c(0, 0, 0))
mesh |
The mesh. |
scale |
Default |
center |
Default |
Scaled mesh
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))) }
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
scale_unit_mesh(mesh, center_mesh = FALSE)
scale_unit_mesh(mesh, center_mesh = FALSE)
mesh |
The mesh. |
center_mesh |
Default |
Scaled mesh
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)) }
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)) }
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
scene_from_list(scene_list)
scene_from_list(scene_list)
scene_list |
List containing rayvertex mesh objects. |
ray_scene
containing mesh info.
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))) }
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
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() )
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() )
start |
Default |
end |
Default |
radius |
Default |
direction |
Default |
from_center |
Default |
square |
Default |
material |
Default |
List describing the mesh.
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))) }
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 the material(s) of the mesh.
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 )
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 )
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 |
Shape with new material
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))) }
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
smooth_normals_mesh(mesh, id = NA)
smooth_normals_mesh(mesh, id = NA)
mesh |
The mesh. |
id |
Default |
Mesh with new vertex normals
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)))) }
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
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() )
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() )
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
radius |
Default |
low_poly |
Default |
normals |
Default |
material |
Default |
List describing the mesh.
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))) }
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))) }
Applies Loop subdivision to the scene (or selected meshes).
subdivide_mesh( scene, id = NA, subdivision_levels = 2, simple = FALSE, normals = TRUE, verbose = FALSE )
subdivide_mesh( scene, id = NA, subdivision_levels = 2, simple = FALSE, normals = TRUE, verbose = FALSE )
scene |
The scene to subdivide. |
id |
Default |
subdivision_levels |
Default |
simple |
Default |
normals |
Default |
verbose |
Default |
Scene with shape added.
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) }
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
swap_yz(mesh)
swap_yz(mesh)
mesh |
A raymesh object. |
Mesh with Y and Z axis exchanged
# 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"))) }
# 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
text3d_mesh( label, position = c(0, 0, 0), text_height = 1, orientation = "xy", color = "black", angle = c(0, 0, 0), pivot_point = c(0, 0, 0), order_rotation = c(1, 2, 3), scale = c(1, 1, 1) )
text3d_mesh( label, position = c(0, 0, 0), text_height = 1, orientation = "xy", color = "black", angle = c(0, 0, 0), pivot_point = c(0, 0, 0), order_rotation = c(1, 2, 3), scale = c(1, 1, 1) )
label |
Text string. |
position |
Default |
text_height |
Default |
orientation |
Default |
color |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
scale |
Default |
List describing the mesh.
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=60)) |> 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=100, orientation = "yz",angle=c(0,180,0))) |> add_shape(text3d_mesh(label="XY Plane", position=c(555/2,555/2,540),text_height=100, orientation = "xy", angle=c(0,180,0))) |> add_shape(text3d_mesh(label="XZ Plane", position=c(555/2,15,555/2),text_height=100, orientation = "xz", angle=c(0,0,0))) |> rasterize_scene(light_info = directional_light(c(0.1,0.4,-1))) } if(run_documentation()) { #Add an label in front of a sphere generate_cornell_mesh() |> add_shape(text3d_mesh(label="Cornell Box", position=c(555/2,555/2,555/2),text_height=60, color="grey20",angle=c(0,180,0))) |> add_shape(text3d_mesh(label="Sphere", position=c(555/2,100,100),text_height=30, color="white",angle=c(0,180,0))) |> 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 bees bee_scene = list() for(i in 1:100) { bee_scene = add_shape(bee_scene, text3d_mesh("B", position=c(20+runif(3)*525), color="yellow", text_height = 50, angle=c(0,180,0))) } generate_cornell_mesh() |> add_shape(bee_scene) |> rasterize_scene(light=directional_light(c(0,1,-1))) }
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=60)) |> 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=100, orientation = "yz",angle=c(0,180,0))) |> add_shape(text3d_mesh(label="XY Plane", position=c(555/2,555/2,540),text_height=100, orientation = "xy", angle=c(0,180,0))) |> add_shape(text3d_mesh(label="XZ Plane", position=c(555/2,15,555/2),text_height=100, orientation = "xz", angle=c(0,0,0))) |> rasterize_scene(light_info = directional_light(c(0.1,0.4,-1))) } if(run_documentation()) { #Add an label in front of a sphere generate_cornell_mesh() |> add_shape(text3d_mesh(label="Cornell Box", position=c(555/2,555/2,555/2),text_height=60, color="grey20",angle=c(0,180,0))) |> add_shape(text3d_mesh(label="Sphere", position=c(555/2,100,100),text_height=30, color="white",angle=c(0,180,0))) |> 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 bees bee_scene = list() for(i in 1:100) { bee_scene = add_shape(bee_scene, text3d_mesh("B", position=c(20+runif(3)*525), color="yellow", text_height = 50, angle=c(0,180,0))) } generate_cornell_mesh() |> add_shape(bee_scene) |> rasterize_scene(light=directional_light(c(0,1,-1))) }
Torus 3D Model
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() )
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() )
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
radius |
Default |
ring_radius |
Default |
sides |
Default |
rings |
Default |
material |
Default |
List describing the mesh.
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))) }
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
translate_lines(lines, position = 1)
translate_lines(lines, position = 1)
lines |
The line scene. |
position |
Default |
Translated line matrix.
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)) }
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
translate_mesh(mesh, position = c(0, 0, 0))
translate_mesh(mesh, position = c(0, 0, 0))
mesh |
The mesh. |
position |
Default |
Translated mesh
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))) }
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))) }
This function takes a mesh and validates it. The mesh should be a list with "shapes", "materials", "vertices", "texcoords", "normals", and "material_hashes" entries.
validate_mesh(mesh, validate_materials = TRUE)
validate_mesh(mesh, validate_materials = TRUE)
mesh |
List. A mesh is a list as described above. |
validate_materials |
Default |
A mesh.
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.
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.
# validate a mesh mesh = validate_mesh(sphere_mesh())
# validate a mesh mesh = validate_mesh(sphere_mesh())
Writes the current scene to a Wavefront OBJ file, with or without materials
write_scene_to_obj(scene, filename, materials = TRUE, fileext = ".obj")
write_scene_to_obj(scene, filename, materials = TRUE, fileext = ".obj")
scene |
A rayvertex scene. |
filename |
The filename for the OBJ file. |
materials |
Default |
fileext |
Default |
None
if(run_documentation()) { tmpfile = tempfile(fileext = ".obj") write_scene_to_obj(generate_cornell_mesh(), tmpfile) }
if(run_documentation()) { tmpfile = tempfile(fileext = ".obj") write_scene_to_obj(generate_cornell_mesh(), tmpfile) }
XY Rectangle 3D Model
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() )
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() )
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
material |
Default |
List describing the mesh.
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))) }
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
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() )
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() )
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
material |
Default |
List describing the mesh.
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))) }
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
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() )
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() )
position |
Default |
scale |
Default |
angle |
Default |
pivot_point |
Default |
order_rotation |
Default |
material |
Default |
List describing the mesh.
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))) }
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))) }