【问题标题】:rgl clear specific area of plotrgl 清除特定区域
【发布时间】:2013-11-14 13:55:20
【问题描述】:

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

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

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

经过一番努力:

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

【问题讨论】:

    标签: r rgl


    【解决方案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)
    

    【讨论】:

    • 谢谢,这非常有帮助!我刚刚加入,所以我还不能投票,但非常感谢......
    • 很高兴有帮助。你不可能使用 R 和 rgl 来实现俄罗斯方块,是吗 ;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    相关资源
    最近更新 更多