R:rglwidget playwidget() 中的动态文本注释

R: dynamic text annotation in rglwidget playwidget()

我想使用 playwidget() 创建一个带有滑块的 rgl 小部件,包括每个子集的不同文本注释。

如果我运行以下

clear3d()

a1 <- spheres3d(xyz.coords(matrix(sample.int(100, 81), ncol = 3)), col="blue", radius = 2)
text3d(10, 10, 10, "text1")
a2 <- spheres3d(xyz.coords(matrix(sample.int(100, 27), ncol = 3)), col="red", radius = 2)
text3d(30, 5, 5, "text2")
a3 <- spheres3d(xyz.coords(matrix(sample.int(100, 9), ncol = 3)), col="green", radius = 2)
text3d(5, 5, 50, "text3")

rglwidget() %>%
  playwidget(start = 0, stop = 2, interval = 1,
             components = c("Reverse", "Play", "Slower", "Faster",
                            "Reset", "Slider", "Label"),
             labels = c("a1", "a2", "a3"),
             subsetControl(1, subsets = list(aa=a1,bb=a2,cc=a3)))

我为所有子集修复了 3 个文本注释。知道如何解决这个问题吗?

一个更普遍的问题是如何将额外的 rglLowlevel 对象(例如 box3d())绑定到每个单独的子集,以便在移动滑块时发生变化。 谢谢

spheres3dtext3d 的结果都是 rgl id,它们只是带有 class 的整数值。您可以只使用 c() 将它们连接成向量。将您的示例修改为这个并且它有效:

library(rgl)
clear3d()

a1 <- c(spheres3d(xyz.coords(matrix(sample.int(100, 81), ncol = 3)), col="blue", radius = 2),
        text3d(10, 10, 10, "text1"))
a2 <- c(spheres3d(xyz.coords(matrix(sample.int(100, 27), ncol = 3)), col="red", radius = 2),
        text3d(30, 5, 5, "text2"))
a3 <- c(spheres3d(xyz.coords(matrix(sample.int(100, 9), ncol = 3)), col="green", radius = 2), 
        text3d(5, 5, 50, "text3"))

rglwidget() %>%
  playwidget(start = 0, stop = 2, interval = 1,
             components = c("Reverse", "Play", "Slower", "Faster",
                            "Reset", "Slider", "Label"),
             labels = c("a1", "a2", "a3"),
             subsetControl(1, subsets = list(aa=a1,bb=a2,cc=a3)))