#Load a tree and render it
library(rayvertex)
render_tree_example = function(example_tree_mesh) {
example_tree_mesh |>
add_shape(xz_rect_mesh(c(0,0,-9),
material = material_list(diffuse="tan",
ambient = "grey", diffuse_intensity = 0.7,
ambient_intensity = 0.6),
scale=25)) |>
rasterize_scene(lookat=c(0,0.5,0),
light_info = directional_light(c(0.3,1,1), intensity = 0.7),
lookfrom=c(0,3,10),
fov=8,
shadow_map_dims = 2, shadow_map_bias = 0.0005,
width = 800, height = 800,
#fsaa = 4, ssao = TRUE, ssao_intensity = 1,
background = "lightblue")
}
if(run_documentation()) {
#Render a basic 3D crown
tree_mesh("columnar",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
#Render the 2D planar version
tree_mesh("columnar",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
#Adjust the trunk/crown proportions of the overall tree using ratios
tree_mesh("columnar",
tree_height = 1,
trunk_height_ratio = 1/5,
crown_width_ratio = 1.25,
trunk_width = 0.125,
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
#The crown width is set proportional to the crown height (not the overall tree)
tree_mesh("columnar",
tree_height = 1,
trunk_height_ratio = 2/3,
crown_width_ratio = 1,
trunk_width = 0.075,
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
#Set the trunk and crown dimensions directly
tree_mesh("columnar",
trunk_height = 0.25,
trunk_width = 0.05,
crown_height = 0.75,
crown_width = 0.33,
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
#Change the crown and trunk color
tree_mesh("columnar",
solid = TRUE,
crown_color = "orange",
trunk_color = "tan",
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
#Render different tree types, both 2D and 3D versions
tree_mesh("columnar",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("columnar",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("pyramidal1",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("pyramidal1",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("pyramidal2",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("pyramidal2",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("weeping",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("weeping",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("spreading1",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("spreading1",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("oval",
solid = TRUE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("oval",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("palm",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("rounded",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("spreading2",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
if(run_documentation()) {
tree_mesh("vase",
solid = FALSE,
ambient_intensity = 0.3) |>
render_tree_example()
}
Run the code above in your browser using DataLab