rgl 回溯性地切换 sharedMouse

问题描述

rgl 允许多个带有 mfrow3d() 的子图。这些子场景可以用 mfrow3d(...,sharedMouse=TRUE) 共同响应鼠标。

但是,我想在绘制子图之后打开/关闭共享鼠标行为。这可能吗?

解决方法

是的,您可以通过修改每个子场景的 par3d("listeners") 属性来实现。该属性列出了将“听到”鼠标事件的子场景的 ID。

例如:

library(rgl)
ids <- mfrow3d(1,2,sharedMouse = TRUE)
shade3d(cube3d(col = "red"))
next3d()
shade3d(tetrahedron3d(col = "blue"))

# This makes the the tetrahedron on the right ignore mouse actions in the cube
# on the left. The cube will still respond to actions on the right.

par3d(listeners = ids[1],subscene = ids[1])

# This stops the cube from responding,so the two subscenes 
# are now independent

par3d(listeners = ids[2],subscene = ids[2])
,

@user2554330 指示我为每个子场景设置 par3d(listeners=...),并举例说明关闭两个子场景的共享鼠标行为。

在多个子场景的情况下,使用循环/应用很方便:

library(rgl)

shared_mouse_on <- function(ids) {
  lapply(ids,function(id) {
    par3d(listeners = ids,subscene = id)
  })
}

shared_mouse_off <- function(ids) {
  lapply(subscene_ids,function(id) {
    id_listeners <- par3d("listeners",subscene = id)
    # remove any listeners that are in 'ids',for this subscene 
    #   (except this subscene's listener itself)
    id_listeners <- id_listeners[ !(id_listeners %in% setdiff(ids,id) ) ]
    par3d(listeners = id_listeners,subscene = id)
  })
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...