里面包含一个三维动画。
还有截图到plot面板和添加标题。标题不支持中文。。。无语。
# Tue Oct 13 17:02:04 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.2 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
rm(list=ls());gc()
# render_compass函数,设定3D视角
require(rayshader)
# 更改场景周围摄像机的位置和属性。 如果未输入任何值,则打印并返回当前值。
#
# Tue Oct 13 17:19:38 2020 --
montereybay %>%
sphere_shade() %>%
plot_3d(montereybay,zscale = 50, water = TRUE, waterlinecolor="white")
render_snapshot()
render_camera(theta = -45, phi = 45)
# 截图进来plot面板:
render_snapshot(title_text = enc2utf8("不支持中文" ),# 转换为utf-8编码,
title_bar_color = "#FF99CC",# 文字背景色
theta=45,phi=75,fov=135,
zoom=2
)
# theta
# 默认为当前值。 旋转角度。
#
# phi
# 默认为当前值。 方位角。 最高为'90'。
#
# zoom
# 默认为当前值。 表示相机放大倍率的正值。
#
# fov
# 默认为当前值。 摄像机的视野。 最高180
#切换到俯视图(并更改文本/标题栏颜色)
render_camera(theta = 0, phi = 90, zoom = 0.9)
render_snapshot(title_text = "Monterey Bay, CA不支持中文",
title_color = "white",
title_bar_color = "darkgreen")
# 移至正视图并添加晕影效果:
render_camera(theta = -90, phi = 30,zoom = 0.8)
render_snapshot(title_text = "Monterey Bay, CA",
title_color = "white",
title_bar_color = "blue",
vignette = TRUE)
# 更改视野(fov),并使标题栏不透明。:
render_camera(theta = -90, phi = 30,zoom = 0.5,fov = 130)
render_snapshot(title_text = "Monterey Bay, CA",
title_color = "black",
title_bar_alpha = 1,
title_bar_color = "lightblue",
vignette = TRUE)
# Wed Oct 14 11:41:58 2020 -三维动画展示-----------------------------
# 在这里,我们渲染了一系列帧,以便以后将它们缝合在一起成为电影。
phivec = 20 + 70 * 1/(1 + exp(seq(-5, 10, length.out = 180)))
phivecfull = c(phivec, rev(phivec))
thetavec = 270 + 45 * sin(seq(0,359,length.out = 360) * pi/180)
zoomvechalf = 0.5 + 0.5 * 1/(1 + exp(seq(-5, 10, length.out = 180)))
zoomvec = c(zoomvechalf, rev(zoomvechalf))
for(i in 1:360) {
render_camera(theta = thetavec[i],phi = phivecfull[i],zoom = zoomvec[i])
# 取消注释下一行以将每个框架保存到工作目录
#render_snapshot(paste0("frame", i, ".png"))
}
#Run this command in the command line using ffmpeg to stitch together a video:
#ffmpeg -framerate 60 -i frame%d.png -vcodec libx264 raymovie.mp4
#And run this command to convert the video to post to the web:
#ffmpeg -i raymovie.mp4 -pix_fmt yuv420p -profile:v baseline -level 3 -vf scale=-2:-2 rayweb.mp4
#Or we can use render_movie() to do this all automatically with type="custom" (uncomment to run):
#render_movie(filename = tempfile(fileext = ".mp4"), type = "custom",
# theta = thetavec, phi = phivecfull, zoom = zoomvec, fov=0)
rgl::rgl.close()