### Install rayvertex from GitHub Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Install the rayvertex package from GitHub using the devtools package. Ensure devtools is installed first. ```r # install.packages("devtools") devtools::install_github("tylermorganwall/rayvertex") ``` -------------------------------- ### Install Latest Package Version Source: https://github.com/tylermorganwall/rayvertex/blob/main/CONTRIBUTING.md Install the latest version of a package from GitHub using the remotes package. This is a preliminary step for debugging issues. ```r remotes::install_github("tylermorganwall/{package name}") ``` -------------------------------- ### Add Point Lights to a Scene Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This example demonstrates how to add point lights to an existing scene configuration. It shows how to combine multiple lights using `add_light` and then rasterize the scene with these lights. ```r #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 ) ``` -------------------------------- ### Render Scene with R OBJ on a Flat Surface Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This example demonstrates creating a scene with an R OBJ model placed on a flat base, with materials applied to both. ```r base_model = cube_mesh() |> scale_mesh(scale = c(5, 0.2, 5)) |> translate_mesh(c(0, -0.1, 0)) |> set_material(diffuse = "white") r_model = obj_mesh(r_obj(simple_r = TRUE)) |> scale_mesh(scale = 0.5) |> set_material(diffuse = "red") |> add_shape(base_model) rasterize_scene( r_model, lookfrom = c(2, 4, 10), fov = 20, light_info = directional_light(direction = c(0.8, 1, 0.7)) ) ``` -------------------------------- ### Add 3D Lines to a Scene Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This example shows how to generate and add a spiral of 3D lines to a scene. It involves creating a sequence of points, generating lines between them, and then rasterizing the scene with the line information. ```r 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 ) ``` -------------------------------- ### Render Scene with Increased Shadow Map Resolution Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This example demonstrates rendering the R OBJ scene with higher shadow map fidelity by setting `shadow_map_dims` to 2, which can reduce shadow pixelation. ```r rasterize_scene( r_model, lookfrom = c(2, 4, 10), fov = 10, shadow_map_dims = 2, light_info = directional_light(direction = c(0.8, 1, 0.7)) ) ``` -------------------------------- ### Generate and Rasterize Cornell Box Scene Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Generates a standard Cornell box mesh and then rasterizes it to produce a render. This is a foundational example for scene rendering. ```r generate_cornell_mesh() %>% rasterize_scene() ``` -------------------------------- ### Change Camera Position Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet illustrates how to modify the camera's viewpoint by adjusting the `lookfrom` argument in `rasterize_scene`. The scene is rendered with the same point lights as the previous example. ```r #change the camera position rasterize_scene( r_model, lookfrom = c(-2, 2, -10), fov = 10, light_info = lights_p ) ``` -------------------------------- ### Render Scene with Reflections and Environment Map Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet demonstrates creating a scene with multiple shapes, applying different materials, and rendering it with an environment map for reflections. It includes torus, sphere, and OBJ meshes. ```r tempfilehdr = tempfile(fileext = ".hdr") download.file("https://www.tylermw.com/data/venice_sunset_2k.hdr", tempfilehdr) scene = torus_mesh( position = c(0.4, 0, 0), angle = c(-30, 20, -30), material = material_list( diffuse = c(1, 1, 1), type = "color", reflection_intensity = 1.0, reflection_sharpness = 0.2 ), ring_radius = 0.05, radius = 0.2 ) |> add_shape(torus_mesh( position = c(0.4, 0.5, 0), angle = c(-30, 20, -130), material = material_list( diffuse = "green", ambient = "green", type = "phong", ambient_intensity = 0.2, diffuse_intensity = 0.8, reflection_intensity = 0.5, reflection_sharpness = 0.05 ), ring_radius = 0.05, radius = 0.2 )) |> add_shape(sphere_mesh( position = c(-0.4, 0, 0), material = material_list(diffuse = "white", type = "color", ior = 1.6), radius = 0.2 )) |> add_shape(obj_mesh( r_obj(simple_r = TRUE), position = c(-0.4, 0.35, 0), scale = 0.2, angle = c(0, -30, 0), material = material_list(diffuse = "purple", type = "color", ior = 1.6) )) |> add_shape(sphere_mesh( position = c(0, 0.25, 0), material = material_list( diffuse = "white", type = "color", reflection_intensity = 1.0 ), radius = 0.2 )) rasterize_scene( scene, lookat = c(0, 0.25, 0), light_info = directional_light(direction = c(0.5, 1, 1)), lookfrom = c(0, 0.5, 2.5), fov = 30, environment_map = tempfilehdr ) ``` -------------------------------- ### Create and Render a Translucent Red and Blue Model Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet shows how to create two translucent models with different colors and then rasterize the scene with directional lights. It demonstrates setting materials and adding shapes. ```r r_model_t = obj_mesh(r_obj(simple_r = TRUE)) |> scale_mesh(scale = 0.5) |> set_material(diffuse = "red", dissolve = 0.5, translucent = T) |> add_shape(base_model) r_model_t = obj_mesh(r_obj(simple_r = TRUE), position = c(-2, 0, 0.3)) |> scale_mesh(scale = 0.5) |> set_material(diffuse = "dodgerblue", dissolve = 0.5, translucent = T) |> add_shape(r_model_t) rasterize_scene( r_model_t, lookfrom = c(2, 4, 10), fov = 15, lookat = c(-0.5, 0, 0), light_info = directional_light(direction = c(0.8, 1, 0.7), intensity = 0.5) |> add_light(directional_light(direction = c(-0.8, 1, 0.7), intensity = 0.5)) ) ``` -------------------------------- ### Render Scene with Blurred Background and Sharp Reflections Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet shows how to render the same scene as above but with a blurred background while keeping reflections sharp by adjusting the `background_sharpness` parameter. ```r rasterize_scene(scene, lookat=c(0,0.25,0), light_info=directional_light(direction=c(0.5,1,1)), lookfrom=c(0,0.5,2.5), fov=30, environment_map = tempfilehdr, background_sharpness = 0.5) ``` -------------------------------- ### Preview Material Properties Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Saves a scene with a sphere and a textured rectangle, then prints the material properties of the scene. Useful for inspecting material configurations. ```r scene_save = generate_cornell_mesh() %>% add_shape(sphere_mesh( position = c(300, 555, 555) / 2, radius = 80, material = mat )) %>% add_shape(xy_rect_mesh( position = c(555 / 2, 555 / 2, 530), angle = c(180, 0, 0), scale = c(400, 400, 1), material = mat_sunset )) print(scene_save$material) ``` -------------------------------- ### Render Spheres with Toon Shading Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Renders a scene of 30 spheres with random colors and toon shading. Requires the 'rayvertex' package. ```r set.seed(1) col = hsv(runif(1)) scene_list = list() for (i in 1:30) { col = hsv(runif(1)) scene_list[[i]] = sphere_mesh( position = runif(3), material = material_list( diffuse = col, type = "toon", toon_levels = 3, toon_outline_width = 20, ambient = col, ambient_intensity = 0.2 ), radius = 0.1 ) } rasterize_scene( scene_from_list(scene_list), light_info = directional_light(direction = c(0.5, 0.8, 1)), background = "white", fov = 10 ) ``` -------------------------------- ### Render Scene with Multiple Directional Lights Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet shows how to add and configure multiple directional lights with different colors and intensities to illuminate the R OBJ scene. ```r lights = directional_light( c(0.7, 1.1, -0.9), color = "orange", intensity = 0.7 ) |> add_light(directional_light( c(0.7, 1, 1), color = "dodgerblue", intensity = 0.7 )) |> add_light(directional_light(c(2, 4, 10), color = "white", intensity = 0.3)) rasterize_scene(r_model, lookfrom = c(2, 4, 10), fov = 10, light_info = lights) ``` -------------------------------- ### Render Cornell Box with Multiple Basic Shapes and Materials Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Renders a Cornell box scene including sphere, segment, cube, torus, cone, arrow, OBJ, and humface meshes with distinct materials. Requires 'rayvertex' and 'Rvcg' packages. ```r library(Rvcg) data(humface) cols = hsv(seq(0, 1, length.out = 6)) mats = list() for (i in 1:5) { mats[[i]] = material_list( diffuse = cols[i], ambient = cols[i], type = "phong", ambient_intensity = 0.2 ) } generate_cornell_mesh(ceiling = FALSE) |> add_shape(sphere_mesh( position = c(555, 555, 555) / 2, radius = 80, material = mat )) |> add_shape(segment_mesh( start = c(555 / 2, 0, 555 / 2), end = c(555 / 2, 196, 555 / 2), radius = 30, material = mat2 )) |> add_shape(cube_mesh( position = c(555 / 2, 555 / 2 - 90, 555 / 2), scale = c(160, 20, 160), material = mat2 )) |> add_shape(torus_mesh( position = c(100, 100, 100), radius = 50, ring_radius = 20, angle = c(45, 0, 45), material = mats[[1]] )) |> add_shape(cone_mesh( start = c(555 - 100, 0, 100), end = c(555 - 100, 150, 100), radius = 50, material = mats[[2]] )) |> add_shape(arrow_mesh( start = c(555 - 100, 455, 555 - 100), end = c(100, 455, 555 - 100), radius_top = 50, radius_tail = 10, tail_proportion = 0.8, material = mats[[3]] )) |> add_shape(obj_mesh( r_obj(simple_r = TRUE), position = c(100, 200, 555 / 2), angle = c(-10, 200, 0), scale = 80, material = mats[[4]] )) |> add_shape(mesh3d_mesh( humface, position = c(555 - 80, 220, 555 / 2), scale = 1, material = mats[[5]], angle = c(0, 180, -30) )) |> rasterize_scene(light_info = directional_light(c(0.4, 0.2, -1))) ``` -------------------------------- ### Render Scene with Reduced Shadow Intensity Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet shows how to render the R OBJ scene with shadows, reducing the `shadow_map_intensity` to prevent shadows from being completely black. ```r #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.8, 1, 0.7)) ) ``` -------------------------------- ### Gather System Information Source: https://github.com/tylermorganwall/rayvertex/blob/main/CONTRIBUTING.md Collect system information using the Sys.info() function. This is required for bug reports to help diagnose environment-specific issues. ```r Sys.info() ``` -------------------------------- ### Render Cornell Box with Angled Directional Light Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Renders a Cornell box scene with a sphere, segment, and cube, using a directional light angled from the front. Requires the 'rayvertex' package. ```r generate_cornell_mesh(ceiling = FALSE) |> add_shape(sphere_mesh( position = c(555, 555, 555) / 2, radius = 80, material = mat )) |> add_shape(segment_mesh( start = c(555 / 2, 0, 555 / 2), end = c(555 / 2, 196, 555 / 2), radius = 30, material = mat2 )) |> add_shape(cube_mesh( position = c(555 / 2, 555 / 2 - 90, 555 / 2), scale = c(160, 20, 160), material = mat2 )) |> rasterize_scene(light_info = directional_light(c(0.4, 0.2, -1))) ``` -------------------------------- ### Generate Cornell Box with Sphere, Segment, and Cube Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Renders a Cornell box scene with a sphere, a segment, and a cube. Requires the 'rayvertex' package. ```r mat2 = material_list( diffuse = "grey80", ambient = "grey80", ambient_intensity = 0.2 ) generate_cornell_mesh(ceiling = FALSE) |> add_shape(sphere_mesh( position = c(555, 555, 555) / 2, radius = 80, material = mat )) |> add_shape(segment_mesh( start = c(555 / 2, 0, 555 / 2), end = c(555 / 2, 196, 555 / 2), radius = 30, material = mat2 )) |> add_shape(cube_mesh( position = c(555 / 2, 555 / 2 - 90, 555 / 2), scale = c(160, 20, 160), material = mat2 )) |> rasterize_scene() ``` -------------------------------- ### Generate and Print Cornell Box Scene Data Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md This snippet generates the Cornell Box mesh and prints its scene description, including summary statistics, bounding box, and details about shapes, vertices, texture coordinates, normals, and materials. ```r library(rayvertex) generate_cornell_mesh() ``` ```r #> -- Scene Description ---------------------------------------------------------- #> #> • Summary - #> Meshes: 5 | #> Unique Materials: 3 #> #> ℹ XYZ Bounds - #> Min: c(-10.00, -10.00, 0.00) | #> Max: c(565.00, 565.00, 565.00) #> #> shapes vertices texcoords normals materials #> #> < > < > < > < > < > #> #> 1 <8x3> <4x2> <6x3> #> 2 <8x3> <4x2> <6x3> #> 3 <8x3> <4x2> <6x3> ``` -------------------------------- ### Check on Windows Source: https://github.com/tylermorganwall/rayvertex/blob/main/CONTRIBUTING.md Perform checks on Windows to ensure compatibility with this operating system. This is important for compiled code changes. ```r rhub::check_on_windows() ``` -------------------------------- ### Run CRAN Checks Source: https://github.com/tylermorganwall/rayvertex/blob/main/CONTRIBUTING.md Perform comprehensive checks for CRAN compliance using rhub::check_for_cran(). This ensures the package meets CRAN standards. ```r rhub::check_for_cran() ``` -------------------------------- ### Check on Solaris Source: https://github.com/tylermorganwall/rayvertex/blob/main/CONTRIBUTING.md Perform checks on Solaris to ensure compatibility with this operating system. This is important for compiled code changes. ```r rhub::check_on_solaris() ``` -------------------------------- ### Add Sphere and Texture to Cornell Box Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Adds a purple sphere and a dragon texture to the back wall of a Cornell box scene. Demonstrates adding custom shapes and materials with textures. ```r sunset_file = tempfile(fileext = ".png") rayimage::ray_write_image(rayimage::sunset_image, sunset_file) mat = material_list( diffuse = "purple", type = "phong", ambient = "purple", ambient_intensity = 0.2 ) mat_sunset = material_list( ambient_texture_location = sunset_file, ambient = "white", diffuse_intensity = 0, type = "phong" ) generate_cornell_mesh() %>% add_shape(sphere_mesh( position = c(300, 555, 555) / 2, radius = 80, material = mat )) %>% add_shape(xy_rect_mesh( position = c(555 / 2, 555 / 2, 530), angle = c(0, 180, 0), scale = c(400, 400, 1), material = mat_sunset )) %>% add_shape(xy_rect_mesh( position = c(555 / 2, 555 / 2, 540), angle = c(0, 180, 0), scale = c(420, 420, 1), material = material_list(diffuse="grey20", type="phong") )) %>% rasterize_scene(fov = 40) ``` -------------------------------- ### Check on macOS Source: https://github.com/tylermorganwall/rayvertex/blob/main/CONTRIBUTING.md Perform checks on macOS to ensure compatibility with this operating system. This is important for compiled code changes. ```r rhub::check_on_macos() ``` -------------------------------- ### Define Cornell Box without Ceiling Source: https://github.com/tylermorganwall/rayvertex/blob/main/README.md Generates a Cornell Box scene, excluding the ceiling, and adds a sphere. This is useful for scenes where the ceiling would obstruct lighting or camera views. Requires the `rayvertex` package. ```r generate_cornell_mesh(ceiling = FALSE) |> add_shape(sphere_mesh( position = c(555, 555, 555) / 2, radius = 80, material = mat )) |> rasterize_scene() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.