美文网首页
R语言rayrender包,path路径对象

R语言rayrender包,path路径对象

作者: youmigo | 来源:发表于2021-08-27 14:59 被阅读0次

    R语言rayrender包,path路径对象

    # Sat Jul 17 00:41:09 2021 -
    
    # 字符编码:UTF-8
    # R 版本:R 4.1 x64 for window 11
    # cgh163email@163.com
    # 个人笔记不负责任,拎了个梨🍐🍈
    #.rs.restartR()
    require(rayrender)
    rm(list = ls());gc()
    
    ?   path    #   路径对象
    
    
    #生成一条波浪线,显示该线穿过指定点:
    wave = list(c(-2,1,0),c(-1,-1,0),c(0,1,0),c(1,-1,0),c(2,1,0))
    point_mat = glossy(color="green")
    generate_studio(depth=-1.5) %>%
      add_object(path(points = wave,material=glossy(color="red"))) %>%
      add_object(sphere(x=-2,y=1,radius=0.1,material=point_mat)) %>%
      add_object(sphere(x=-1,y=-1,radius=0.1,material=point_mat)) %>%
      add_object(sphere(x=0,y=1,radius=0.1,material=point_mat)) %>%
      add_object(sphere(x=1,y=-1,radius=0.1,material=point_mat)) %>%
      add_object(sphere(x=2,y=1,radius=0.1,material=point_mat)) %>%
      add_object(sphere(z=5,x=5,y=5,radius=2,material=light(intensity=15))) %>%
      render_scene(samples=500, clamp_value=10,fov=30)
    
    #这里我们通过设置“直线=真”来使用直线:
    generate_studio(depth=-1.5) %>%
      add_object(path(points = wave,straight = TRUE, material=glossy(color="red"))) %>%
      add_object(sphere(z=5,x=5,y=5,radius=2,material=light(intensity=15))) %>%
      render_scene(samples=500, clamp_value=10,fov=30)
    
    #我们还可以传递一个值矩阵,指定x/y/z坐标。在这里,
    #我们将创建一条随机曲线:
    set.seed(21)
    random_mat = matrix(runif(3*9)*2-1, ncol=3)
    generate_studio(depth=-1.5) %>%
      add_object(path(points=random_mat, material=glossy(color="red"))) %>%
      add_object(sphere(y=5,radius=1,material=light(intensity=30))) %>%
      render_scene(samples=500, clamp_value=10)
    
    #We can ensure the curve is closed by setting `closed = TRUE`
    generate_studio(depth=-1.5) %>%
      add_object(path(points=random_mat, closed = TRUE, material=glossy(color="red"))) %>%
      add_object(sphere(y=5,radius=1,material=light(intensity=30))) %>%
      render_scene(samples=500, clamp_value=10)
    
    #Finally, let's render a pretzel to show how you can render just a subset of the curve:
    pretzel = list(c(-0.8,-0.5,0.1),c(0,-0.2,-0.1),c(0,0.3,0.1),c(-0.5,0.5,0.1), c(-0.6,-0.5,-0.1),
                   c(0,-0.8,-0.1),
                   c(0.6,-0.5,-0.1),c(0.5,0.5,-0.1), c(0,0.3,-0.1),c(-0,-0.2,0.1), c(0.8,-0.5,0.1))
    
    #Render the full pretzel:
    generate_studio() %>%
      add_object(path(pretzel, width=0.17,  material = glossy(color="#db5b00"))) %>%
      add_object(sphere(y=5,x=2,z=4,material=light(intensity=20,spotlight_focus = c(0,0,0)))) %>%
      render_scene(samples=500, clamp_value=10)
    
    #Here, we'll render only the first third of the pretzel by setting `u_max = 0.33`
    generate_studio() %>%
      add_object(path(pretzel, width=0.17, u_max=0.33, material = glossy(color="#db5b00"))) %>%
      add_object(sphere(y=5,x=2,z=4,material=light(intensity=20,spotlight_focus = c(0,0,0)))) %>%
      render_scene(samples=500, clamp_value=10)
    
    #Here's the last third, by setting `u_min = 0.66`
    generate_studio() %>%
      add_object(path(pretzel, width=0.17, u_min=0.66, material = glossy(color="#db5b00"))) %>%
      add_object(sphere(y=5,x=2,z=4,material=light(intensity=20,spotlight_focus = c(0,0,0)))) %>%
      render_scene(samples=500, clamp_value=10)
    
    #Here's the full pretzel, decomposed into thirds using the u_min and u_max coordinates
    generate_studio() %>%
      add_object(path(pretzel, width=0.17, u_max=0.33, x = -0.8, y =0.6,
                      material = glossy(color="#db5b00"))) %>%
      add_object(path(pretzel, width=0.17, u_min=0.66, x = 0.8, y =0.6,
                      material = glossy(color="#db5b00"))) %>%
      add_object(path(pretzel, width=0.17, u_min=0.33, u_max=0.66, x=0,
                      material = glossy(color="#db5b00"))) %>%
      add_object(sphere(y=5,x=2,z=4,material=light(intensity=20,spotlight_focus = c(0,0,0)))) %>%
      render_scene(samples=500, clamp_value=10, lookfrom=c(0,3,10))
    
    dev.copy(png, "1.png");dev.off()
    
    
    image.png

    相关文章

      网友评论

          本文标题:R语言rayrender包,path路径对象

          本文链接:https://www.haomeiwen.com/subject/plvipltx.html