R语言rayrender包,csg_combine空间体集合运算

R语言rayrender包,csg_combine空间体集合运算

8.png

1.png
2.png
3.png
4.png
5.png
6.png
7.png
# 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()

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容