R语言rayrender包,csg_combine空间体集合运算
# Wed Jun 16 00:15:22 2021 -
# 字符编码:UTF-8
# R 版本:R 4.1 x64 for window 10
# cgh163email@163.com
# 个人笔记不负责任,拎了个梨🍐🍈
#.rs.restartR()
require(rayrender)
rm(list = ls());gc()
# csg_combine减去运算
#合并两个球体:
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))
# 减去
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))
# 相交集合
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))
# 混合并集
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))
# 混合减法
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))
# 更改混合半径
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))
# Wed Jun 16 00:21:41 2021 --end
dev.copy(png, "8.png");dev.off()