Aframe 奇怪的触发问题
Aframe Strange Trigger Issue
编辑:-> 找到导致我的问题的原因https://github.com/aframevr/aframe/issues/3297 需要修复
('I have an strange issue. I have two scenes. When i press a button you switch to the other scene and there is another button which brings you back to the first scene. I activate the button with an click on it or an gazer(fuser). Now my Problem: when i gaze on button 1 and change the scene and then click on button 2 to come back, button 1 is already triggerd (so it changes scene again). If i just gaze on buttons or just click on them everthing works fine just when i gaze something and after that click it fails. Need some help here some code:')
<!-----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>
我知道使用一个解决方法:我禁用光标并仅在 VR 模式下启用它。所以问题没有出现,但换一个结论会更好。
这样我就禁用了我的光标(也设置为 false 可见):
document.getElementById('cursor').setAttribute('raycaster', 'objects: .notclickable');
如果只显示部分代码,通常更难调试。
但如果我没理解错的话,你希望能够通过凝视熔断器切换伪场景。
下面是一个带有伪场景的工作示例,希望对您的用例有所帮助:
https://curious-electric.com/w/experiments/aframe/panorama-compass-click/
我建议使用数据属性或组件而不是 class,因为它们会自动获得 added/removed to/from 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');
使用 classes,您需要使用 raycasterEl.components.raycaster.refreshObjects()
手动刷新 raycaster 对象列表。如果使用上述方法则不需要。
此问题已记录 -> https://github.com/aframevr/aframe/issues/3297。解决方法:如果你按下某个东西,整个场景和相机都会移动一些度数
编辑:-> 找到导致我的问题的原因https://github.com/aframevr/aframe/issues/3297 需要修复
('I have an strange issue. I have two scenes. When i press a button you switch to the other scene and there is another button which brings you back to the first scene. I activate the button with an click on it or an gazer(fuser). Now my Problem: when i gaze on button 1 and change the scene and then click on button 2 to come back, button 1 is already triggerd (so it changes scene again). If i just gaze on buttons or just click on them everthing works fine just when i gaze something and after that click it fails. Need some help here some code:')
<!-----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>
我知道使用一个解决方法:我禁用光标并仅在 VR 模式下启用它。所以问题没有出现,但换一个结论会更好。
这样我就禁用了我的光标(也设置为 false 可见):
document.getElementById('cursor').setAttribute('raycaster', 'objects: .notclickable');
如果只显示部分代码,通常更难调试。 但如果我没理解错的话,你希望能够通过凝视熔断器切换伪场景。
下面是一个带有伪场景的工作示例,希望对您的用例有所帮助:
https://curious-electric.com/w/experiments/aframe/panorama-compass-click/
我建议使用数据属性或组件而不是 class,因为它们会自动获得 added/removed to/from 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');
使用 classes,您需要使用 raycasterEl.components.raycaster.refreshObjects()
手动刷新 raycaster 对象列表。如果使用上述方法则不需要。
此问题已记录 -> https://github.com/aframevr/aframe/issues/3297。解决方法:如果你按下某个东西,整个场景和相机都会移动一些度数