Note: Subtract operations aren't commutative: the second object is subtracted from the first.

csg_combine(object1, object2, operation = "union", radius = 0.5)

Arguments

object1

First CSG object

object2

Second CSG object

operation

Default `union`. Can be `union`, `subtract`, `intersection`, `blend`, `subtractblend`, or `mix`.

radius

Default `0.5`. Blending radius.

Value

List describing the combined csg object in the scene.

Examples

# \donttest{
#Combine two spheres:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="union"),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Subtract one sphere from another:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="subtract"),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Get the intersection of two spheres:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="intersection"),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Get the blended union of two spheres:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="blend"),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Get the blended subtraction of two spheres:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="subtractblend"),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Change the blending radius:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="blend", radius=0.2),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Change the subtract blending radius:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(x=-0.4,z=-0.4),
     csg_sphere(x=0.4,z=0.4), operation="subtractblend", radius=0.2),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(sphere(y=5,x=5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-3,5,10))

  
#Get the mixture of various objects:
generate_ground(material=diffuse(checkercolor="grey20")) %>% 
  add_object(csg_object(csg_combine(
     csg_sphere(),
     csg_box(), operation="mix"),
  material=glossy(color="dodgerblue4"))) %>%
  add_object(csg_object(csg_translate(csg_combine(
     csg_box(),
     csg_torus(), operation="mix"),z=-2.5),
  material=glossy(color="red"))) %>%
  add_object(csg_object(csg_translate(csg_combine(
     csg_pyramid(),
     csg_box(), operation="mix"),z=2.5),
  material=glossy(color="green"))) %>%
  add_object(sphere(y=10,x=-5,radius=3,material=light(intensity=10))) %>%  
  render_scene(clamp_value=10,fov=20,lookfrom=c(-15,10,10))

# }