rgl清楚特定区域的情节

时间:2013-11-14 13:55:21

标签: r rgl

我一直在使用rgl绘制块模型 - 使用shade3d来渲染块。

我想使用交互式流程替换某些块。问题是渲染是累积的,所以如果我在alpha 1的蓝色立方体上覆盖alpha 0.5的白色立方体,我仍然会看到蓝色立方体。 [见下文]。我看了clear3d,但似乎只在全球范围内工作。有什么想法吗?

  shade3d(translate3d(cube3d(),
                      1,
                      1,
                      1),
          col="blue",
          alpha = 1)

经过一番工作:

  shade3d(translate3d(cube3d(),
                      1,
                      1,
                      1),
          col="white",
          alpha = 0.5)

1 个答案:

答案 0 :(得分:1)

正如您所发现的,

clear3d()会删除所有对象。要删除单个对象,您需要rgl.pop()

只要您知道给定形状的对象ID(即它在绘制对象堆栈上的位置),您就可以使用rgl.pop()将其删除。因此,关键的簿记细节是您必须跟踪以后可能要删除的任何对象的对象ID。

(方便的是,副作用用于将对象绘制到rgl设备的大多数 rgl 函数返回对象ID(或ID的向量)作为其返回值。或者,使用rgl.ids()访问当前设备上绘制的所有对象的对象ID。)

来自?rgl.pop的更多细节:

RGL holds two stacks. One is for shapes and the other is for
lights.  'clear3d' and 'rgl.clear' clear the specified stack, or
restore the defaults for the bounding box (not visible) or
viewpoint.  By default with 'id=0' 'rgl.pop' removes the top-most
(last added) node on the shape stack.  The 'id' argument may be
used to specify arbitrary item(s) to remove from the specified
stack.

所以在你的情况下你可能会这样做:

library(rgl)

ii <- shade3d(translate3d(cube3d(), 1, 1, 1), col="blue", alpha = 1)
shade3d(translate3d(cube3d(), 1, 1, 1), col="white", alpha = 0.5)
rgl.pop(id = ii)

enter image description here