美文网首页
R语言rayrender包,generate_camera_mo

R语言rayrender包,generate_camera_mo

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

    R语言rayrender包,generate_camera_motion生成的相机运动

    # Thu Jul 01 00:14:04 2021 -
    
    # 字符编码:UTF-8
    # R 版本:R x64 4.1 for window 10
    # cgh163email@163.com
    # 个人笔记不负责任,拎了个梨🍐🌷
    #.rs.restartR()
    require(rayrender)
    rm(list = ls());gc()
    
    ?   generate_camera_motion  #   生成的相机运动
    
    
    set.seed(3)
    elliplist = list()
    ellip_colors = rainbow(8)
    for(i in 1:1200) {
      elliplist[[i]] = ellipsoid(x=10*runif(1)-5,y=10*runif(1)-5,z=10*runif(1)-5,
                                 angle = 360*runif(3), a=0.1,b=0.05,c=0.1,
                                 material=glossy(color=sample(ellip_colors,1)))
    }
    ellip_scene = do.call(rbind, elliplist)
    
    camera_pos = list(c(0,1,15),c(5,-5,5),c(-5,5,-5),c(0,1,-15))
    
    #Plot the camera path and render from above using the path object:
    generate_ground(material=diffuse(checkercolor="grey20"),depth=-10) %>%
      add_object(ellip_scene) %>%
      add_object(sphere(y=50,radius=10,material=light(intensity=30))) %>%
      add_object(path(camera_pos, material=diffuse(color="red"))) %>%
      render_scene(lookfrom=c(0,20,0), width=800,height=800,samples=32,
                   camera_up = c(0,0,1),
                   fov=80)
    
    #Side view
    generate_ground(material=diffuse(checkercolor="grey20"),depth=-10) %>%
      add_object(ellip_scene) %>%
      add_object(sphere(y=50,radius=10,material=light(intensity=30))) %>%
      add_object(path(camera_pos, material=diffuse(color="red"))) %>%
      render_scene(lookfrom=c(20,0,0),width=800,height=800,samples=32,
                   fov=80)
    
    #View from the start
    generate_ground(material=diffuse(checkercolor="grey20"),depth=-10) %>%
      add_object(ellip_scene) %>%
      add_object(sphere(y=50,radius=10,material=light(intensity=30))) %>%
      add_object(path(camera_pos, material=diffuse(color="red"))) %>%
      render_scene(lookfrom=c(0,1.5,16),width=800,height=800,samples=32,
                   fov=80)
    
    #生成摄影机移动,将注视位置设置为与摄影机位置相同,但偏移
    #稍微在前面。我们将渲染12帧,但在真实动画中可能需要更多帧。
    
    camera_motion =  generate_camera_motion(positions = camera_pos, lookats = camera_pos,
                                            offset_lookat = 1, fovs=80, frames=12)
    
    dev.copy(png, "3.png");dev.off()
    #这将返回由三次贝塞尔曲线插值的各个相机位置的数据帧。
    # 摄像机运动
    #将要打印的文件名传递给设备。我们将保持路径并稍微偏移它以查看
    #我们要去哪里。这就产生了“过山车”效应。
    generate_ground(material=diffuse(checkercolor="grey20"),depth=-10) %>%
      add_object(ellip_scene) %>%
      add_object(sphere(y=50,radius=10,material=light(intensity=30))) %>%
      add_object(obj_model(r_obj(),x=10,y=-10,scale_obj=3, angle=c(0,-45,0),
                           material=dielectric(attenuation=c(1,1,0.3)))) %>%
      add_object(pig(x=-7,y=10,z=-5,scale=1,angle=c(0,-45,80),emotion="angry")) %>%
      add_object(pig(x=0,y=-0.25,z=-15,scale=1,angle=c(0,225,-20), order_rotation=c(3,2,1),
                     emotion="angry", spider=TRUE)) %>%
      add_object(path(camera_pos, y=-0.2,material=diffuse(color="red"))) %>%
      render_animation(filename = 'NA.gif', camera_motion = camera_motion,
                       clamp_value=10, width=400, height=400)
    # Thu Jul 01 00:45:06 2021 ----2gif--------------------------
    
    library(gifski)
    #f.ls <- list.files(path = getwd(),pattern = "*.png$", full.names = T);length(f.ls)
    ls <- paste0('NA.gif',1,'.png') |> as.data.frame()
    for(i in 1:12){
    ls <-rbind(paste0(getwd(),'/NA.gif',i,'.png'),ls)
    }
    ls <- ls[1:12,]
    ls;rm(i);
    gifski(ls, paste0(getwd(),'/生成的相机运动.gif'))
    utils::browseURL('生成的相机运动.gif')
    
    
    # Thu Jul 01 00:22:55 2021 --
    
    
    生成的相机运动.gif

    相关文章

      网友评论

          本文标题:R语言rayrender包,generate_camera_mo

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