【问题标题】:Aframe Strange Trigger IssueAframe 奇怪的触发器问题
【发布时间】:2023-03-20 05:56:01
【问题描述】:

edit:-> 找到导致我的问题的原因https://github.com/aframevr/aframe/issues/3297 需要解决该问题

('我有一个奇怪的问题。我有两个场景。当我按下一个按钮时,你切换到另一个场景,还有另一个按钮可以让你回到第一个场景。我点击它来激活按钮或凝视器(定影器)。现在我的问题:当我凝视按钮 1 并更改场景然后单击按钮 2 返回时,按钮 1 已被触发(因此它再次更改场景)。如果我只是凝视按钮或者只是在我凝视某些东西时单击它们一切正常,然后单击它失败。这里需要一些帮助一些代码:')

<!-----scene1------------------------------> 
  <a-entity id="browser_scene" visible="true">
    <a-entity id="scene1" visible="true">
<!--Icons-->
    <a-image id="introid" src="#introicon" position="-20 12 -13" width="9" height="9" rotation="0 75 0" transparent="true" onclick="playscene2()" event-set__enter="_event: mouseenter; color: #33ccff"
           event-set__leave="_event: mouseleave; color: #00000"></a-image>
</a-entity>

<!-----scene2-------------------------------> 
    <a-entity id="scene2" visible="false">
<!--Videosphere (intro)-->
    <a-videosphere src="#intro"></a-videosphere>                       
<!--Icons-->
    <a-image id="haus" src="#home" position="-5 -6 -1.75" width="2" height="2" rotation="35 -90 -180" transparent="true" onclick="playscene1()" event-set__enter="_event: mouseenter; color: #33ccff"
           event-set__leave="_event: mouseleave; color: #00000"></a-image>
    </a-entity>

function playscene1() {

document.getElementById('scene1').setAttribute('visible', 'true')
document.getElementById('scene2').setAttribute('visible', 'false')
document.getElementById('haus').setAttribute('visible', 'false')

var videoEl_1 = document.querySelector('#intro');

skyon()
document.querySelector('#intro').pause();
document.querySelector('#intro').currentTime = 0;

}
</script>

function playscene2() {
document.getElementById('scene1').setAttribute('visible', 'false')
document.getElementById('scene2').setAttribute('visible', 'true')
document.getElementById('haus').setAttribute('visible', 'true')

var videoEl_1 = document.querySelector('#intro'); 

document.querySelector('#intro').pause();
document.querySelector('#intro').currentTime = 0;

skyout()
videoEl_1.play();

document.getElementById('intro').addEventListener('ended',myHandler_1,false);
function myHandler_1(e) {
    if(!e) { e = window.event; }
    playscene3()
  }
}
</script>

<!--camera-->
<a-entity foo rotation="0 90 0">
  <a-camera user-height="0" look-controls>
    <a-cursor fuse="true" fusetimeout="2000"
      position="0 0 -0.1"
      geometry="primitive: ring;
      radiusInner: 0.002;
      radiusOuter: 0.003"
      material="color: red; shader: flat">
      <a-animation attribute="scale"
                      to="3 3 3"
                      dur="2000"
                      begin="cursor-fusing"
                      fill="backwards"
                      easing="linear">
      </a-animation>
   </a-cursor>
    <a-entity id="redcircle" position="0 0 -0.1" 
            geometry="primitive: ring;
            radiusInner: 0.007;
            radiusOuter: 0.0077"
            material="color: red; opacity: 0.25; shader: flat"></a-entity>
 </a-camera>  
</a-entity>  

【问题讨论】:

  • 如果有人需要更多信息或者我的问题无法理解,请询问:D
  • 请添加您的光标/光线投射器代码,以便我们查看配置。如果您可以发布一个简单演示的链接,那也会有所帮助。
  • 光标位于我发布的代码底部的相机实体中。如果@dirkk0 示例对我有帮助,我会尝试。如果没有,我尝试创建一个演示以便更好地理解。
  • 啊,对不起。不知道我是怎么错过的。

标签: jquery events triggers aframe


【解决方案1】:

我建议使用数据属性或组件而不是类,因为它们会自动添加到/从 raycaster 对象列表中删除:

<a-cursor raycaster="objects: [data-clickable];" ... ></a-cursor>

<a-entity id="button" data-clickable ... ></a-entity>

然后只需添加和删除它:

buttonEl.setAttribute('data-clickable', '');

buttonEl.removeAttribute('data-clickable');

使用类,您需要使用 raycasterEl.components.raycaster.refreshObjects() 手动刷新 raycaster 对象列表。如果使用上述方法,则不需要。

【讨论】:

  • 很遗憾它不起作用。我应该补充一点,如果您用手指按下智能手机上的按钮,光标就可以正常工作,就会发生这个问题。在我看来,如果你用手指点击某个东西,它就是双击
【解决方案2】:

我知道使用一种解决方法:我禁用光标并仅在 VR 模式下启用它。所以这个问题没有出现,但另一个结论仍然会更好。

这样我就禁用了我的光标(也设置为 false 可见):

document.getElementById('cursor').setAttribute('raycaster', 'objects: .notclickable'); 

【讨论】:

  • 我正打算以这种方式发布一些内容。不过,我建议使用数据属性或组件而不是类,因为它们会自动添加到 raycaster 对象列表中/从中删除
【解决方案3】:

如果只显示部分代码,通常会更难调试。 但如果我理解正确,您希望能够通过凝视保险丝切换伪场景。

所以这是一个带有伪场景的工作示例,希望对您的用例有所帮助:

https://curious-electric.com/w/experiments/aframe/panorama-compass-click/

【讨论】:

  • 你说得对,我使用伪场景我更改了 源并禁用/启用按钮。我会看看这个例子,如果我不能修复它,我会尝试制作一个演示以便更好地理解
【解决方案4】:

此问题已记录在案 -> https://github.com/aframevr/aframe/issues/3297。解决方法:如果您按下某个东西,则将整个场景和相机移动一些度数

【讨论】:

    猜你喜欢
    • 2020-12-19
    • 1970-01-01
    • 2019-05-05
    • 2011-03-23
    • 2010-11-06
    • 1970-01-01
    • 2010-11-02
    • 2014-06-17
    • 1970-01-01
    相关资源
    最近更新 更多