【问题标题】:In aframe, how do you make the property visible="false" ignore the raycaster?在 aframe 中,如何使属性 visible="false" 忽略光线投射器?
【发布时间】:2019-09-22 10:50:33
【问题描述】:

我在一个带有 visible="false" 的框架中有一些对象,这意味着它们不可见,但即使您看不到它们,它们仍然可以交互。有解决办法吗?

网上找了几个类似的案例,但没有明确的解决办法。

https://github.com/aframevr/aframe/issues/3551 https://github.com/aframevr/aframe/issues/979

<!-- CURSOR ENTITY -->
        <a-entity rotation="0 0 0" position="0 0 2">
            <a-entity id="camera" far: 20; camera look-controls rotation="0 0 0" wasd-controls>
                <!-- MAIN CURSOR -->
                <a-entity raycaster="interval: 200; objects: .clickable" cursor="fuse: true; maxDistance: 500; timeout: 1500;" id="cursor-main" position="0 0 -1.5" geometry="primitive: ring; radiusOuter: 0.04; radiusInner: 0.03; thetaLength: 360; thetaStart: 90;" material="color: #439DC2;">
                    <a-animation begin="cursor-fusing" attribute="geometry.thetaLength" fill="forwards" from="360" to="0" easing="ease-in"></a-animation>
                    <a-animation begin="mouseleave" attribute="geometry.thetaLength" fill="backwards" from="0" to="360" dur="0"></a-animation>
                </a-entity>
                <a-entity id="cursor-loader" position="0 0 -1.51" geometry="primitive: ring; radiusOuter: 0.04; radiusInner: 0.03;" material="color: #2ADD2A;">
                </a-entity>
            </a-entity>
        </a-entity>
        <a-entity ui-modal="triggerElement:#selection;" visible="false">

            <a-image position="-0.7 -1 1" class="clickable" src="#one" scale="0.7 0.7 0" link="href:location1.html; on: click; visualAspectEnabled: false" src-fit></a-image>

        <a-image position="0 -1 1" class="clickable" src="#two" scale="0.7 0.64 0" link="href:location2.html; on: click; visualAspectEnabled: false" src-fit></a-image>

             <a-image position="0.7 -1 1" class="clickable" src="#three" scale="0.7 0.7 0" link="href:location3.html; on: click; visualAspectEnabled: false" src-fit></a-image>

            <a-image class="clickable" src="#close" id="closing" scale="0.3 0.3 0" position="-0.5 -0.35 1.1"></a-image>

        </a-entity>

理想情况下,如果对象设置为 visible="false",则用户不应与其交互。

【问题讨论】:

    标签: aframe


    【解决方案1】:

    正如discussion 中所见,如果您想忽略某些对象,则不应依赖可见性。正确的方法是使用objects 白名单:

    <a-scene cursor raycaster='objects: .clickable>
    

    白名单使用典型的 CSS 选择器,因此在上面的示例中,光线投射器只会与具有 clickable 类的元素交互。

    您可以通过可见性添加/删除它:

    if (condition) {
      el.setAttribute('visible', 'false')
      el.classList.remove('clickable')
    } else {
      el.setAttribute('visible', 'true')
      el.classList.add('clickable')
    }
    

    您可以在this fiddle 中查看。单击球体使框可单击/不可单击。


    也可以将scale 设置为0 0 0。该元素将不可见,也无法点击。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多