WebGL 剪切部分 3D 图像(在 RGL 查看器中工作正常)

WebGL cuts part of the 3D image (works fine in RGL viewer)

我正在尝试从 plot3D() 函数中导出 3D 图:

library(maptools)
library(raster)
srtm <- getData("SRTM", lon=-15.59972, lat=27.965)

library(rgdal)
library(rasterVis)
library(rgl)
library(htmlwidgets)

open3d() # Open a new RGL device
plot3D(srtm)

当我运行 R 中的代码时,一切正常。该图在 RGL 设备中正确呈现 window。

但是,当我想导出到 html 或将其嵌入到 RMarkdown 中时,部分 3D 图被剪切了。

按照下面的link,您可以看到来自

的html
writeWebGL(dir = "webGL", filename = file.path(getwd(), "index.html"), width = 1000, height = 1000)

browseURL(paste("file://", writeWebGL(dir=file.path(getwd(), "webGL"), width=1000), sep=""))

html from writeWebGL

我还尝试了以下方法将情节嵌入到 RMarkdown 中:

library(knitr)
knit_hooks$set(webgl = hook_webgl)
options(rgl.printRglwidget = TRUE)

open3d()
plot3D(srtm)
rglscene <- scene3d()
# render the saved rgl scene as widget in the markdown page
rglwidget(rglscene,webGLoptions = list(preserveDrawingBuffer = FALSE))

Here is the RMarkdown that got produced

有人知道为什么情节在 html 中被删减了吗?顺便说一句,如果我绘制其他国家,我也会看到同样的情况。谢谢!

正如 ?writeWebGL 中的文档所说,在许多浏览器中,WebGL 中的对象中的顶点数限制为 65536 个。你的表面对象是 316 x 316,这给它大约 100000 个顶点。您需要将它分成两部分或更多部分,或者以较低的分辨率绘制它。