if(run_documentation()) {
#Specify the points for the path to travel though and the ground material
points = list(c(0,0,1),c(-0.5,0,-1),c(0,1,-1),c(1,0.5,0),c(0.6,0.3,1))
ground_mat = material=diffuse(color="grey50",
checkercolor = "grey20",checkerperiod = 1.5)
}
if(run_documentation()) {
#Default path shape is a circle
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.25,
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0.5),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Change the width evenly along the tube
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.25,
width_end = 0.5,
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0.5),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Change the width along the full length of the tube
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points,
width=0.25*sinpi(0:72*20/180),
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0.5),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Specify the exact parametric x positions for the width values:
custom_width = data.frame(x=c(0,0.2,0.5,0.8,1), y=c(0.25,0.5,0,0.5,0.25))
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points,
width=custom_width,
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0.5),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Generate a star polygon
angles = seq(360,0,length.out=21)
xx = c(rep(c(1,0.75,0.5,0.75),5),1) * sinpi(angles/180)/4
yy = c(rep(c(1,0.75,0.5,0.75),5),1) * cospi(angles/180)/4
star_polygon = data.frame(x=xx,y=yy)
#Extrude a path using a star polygon
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.5,
polygon = star_polygon,
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,1),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Specify a circle polygon
angles = seq(360,0,length.out=21)
xx = sinpi(angles/180)/4
yy = cospi(angles/180)/4
circ_polygon = data.frame(x=xx,y=yy)
#Transform from the circle polygon to the star polygon and change the end cap material
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.5,
polygon=circ_polygon, polygon_end = star_polygon,
material_cap = diffuse(color="white"),
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0.5),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Add three and a half twists along the path, and make sure the breaks are evenly spaced
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.5, twists = 3.5,
polygon=star_polygon, linear_step = TRUE, breaks=360,
material_cap = diffuse(color="white"),
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Smooth the normals for a less sharp appearance:
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.5, twists = 3.5,
polygon=star_polygon,
linear_step = TRUE, breaks=360,
smooth_normals = TRUE,
material_cap = diffuse(color="white"),
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Only generate part of the curve, specified by the u_min and u_max arguments
generate_studio(depth=-0.4,material=ground_mat) %>%
add_object(extruded_path(points = points, width=0.5, twists = 3.5,
u_min = 0.2, u_max = 0.8,
polygon=star_polygon, linear_step = TRUE, breaks=360,
material_cap = diffuse(color="white"),
material=diffuse(color="red"))) %>%
add_object(sphere(y=3,z=5,x=2,material=light(intensity=15))) %>%
render_scene(lookat=c(0.3,0.5,0),fov=12, width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
if(run_documentation()) {
#Render a Mobius strip with 1.5 turns
points = list(c(0,0,0),c(0.5,0.5,0),c(0,1,0),c(-0.5,0.5,0))
square_polygon = matrix(c(-1, -0.1, 0,
1, -0.1, 0,
1, 0.1, 0,
-1, 0.1, 0)/10, ncol=3,byrow = T)
generate_studio(depth=-0.2,
material=diffuse(color = "dodgerblue4", checkercolor = "#002a61",
checkerperiod = 1)) %>%
add_object(extruded_path(points = points, polygon=square_polygon, closed = TRUE,
linear_step = TRUE, twists = 1.5, breaks = 720,
material = diffuse(noisecolor = "black", noise = 10,
noiseintensity = 10))) %>%
add_object(sphere(y=20,x=0,z=21,material=light(intensity = 1000))) %>%
render_scene(lookat=c(0,0.5,0), fov=10, samples=16, sample_method = "sobol_blue",
width = 800, height=800)
}
if(run_documentation()) {
#Create a green glass tube with the dielectric priority interface
#and fill it with a purple neon tube light
generate_ground(depth=-0.4,material=diffuse(color="grey50",
checkercolor = "grey20",checkerperiod = 1.5)) %>%
add_object(extruded_path(points = points, width=0.7, linear_step = TRUE,
polygon = star_polygon, twists = 2, closed = TRUE,
polygon_end = star_polygon, breaks=500,
material=dielectric(priority = 1, refraction = 1.2,
attenuation=c(1,0.3,1),
attenuation_intensity=20))) %>%
add_object(extruded_path(points = points, width=0.4, linear_step = TRUE,
polygon = star_polygon,twists = 2, closed = TRUE,
polygon_end = star_polygon, breaks=500,
material=dielectric(priority = 0,refraction = 1))) %>%
add_object(extruded_path(points = points, width=0.05, closed = TRUE,
material=light(color="purple", intensity = 5,
importance_sample = FALSE))) %>%
add_object(sphere(y=10,z=-5,x=0,radius=5,material=light(color = "white",intensity = 5))) %>%
render_scene(lookat=c(0,0.5,1),fov=10,
width=800,height=800, clamp_value = 10,
aperture=0.025, samples=16, sample_method="sobol_blue")
}
Run the code above in your browser using DataLab