编辑: - >找到导致我的问题的原因https://github.com/aframevr/aframe/issues/3297需要修复
('我有一个奇怪的问题。我有两个场景。当我按下一个按钮你切换到另一个场景,还有另一个按钮,让你回到第一个场景。我点击它激活按钮或凝视者(定影器)现在我的问题:当我凝视按钮1,改变场景,然后点击按钮2回来,按键1已经triggerd(所以它再次改变场景),如果我只是凝视上的按钮。或只是点击它们everthing工作正常,当我凝视的东西,然后点击它失败。在这里需要一些帮助一些代码:')
<!-----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>
答案 0 :(得分: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对象列表。如果使用上述方法,则不需要这样做。
答案 1 :(得分:0)
我知道使用一种解决方法:我禁用光标,仅在VR模式下启用它。因此问题没有出现,但另一个结论仍然会更好。
为此,我禁用了光标(也将设置设置为false):
document.getElementById('cursor').setAttribute('raycaster', 'objects: .notclickable');
答案 2 :(得分:0)
如果仅显示部分代码,通常很难调试。 但是,如果我理解正确,则希望能够使用凝视保险丝在伪场景之间切换。
因此,这是一个伪场景的工作示例,希望对您的用例有所帮助:
https://curious-electric.com/w/experiments/aframe/panorama-compass-click/
答案 3 :(得分:0)
已记录此问题-> https://github.com/aframevr/aframe/issues/3297。解决方法:如果您按某些键,则可以将整个场景和摄像机移至一定角度