how to make focus event on a-entity AFRAME? - events

i have a entity text and and side by side have event click, but when i click on the right, left event was listen and then just going to right event ?
it seems like the trigger on left must pass on the right then going to left
example
button 1 : going to '/createroom'
button 2: going to '/joingroom'
when i click button2 : it was trigger to '/createroom' then going to '/joinroom'
is that because of the width a-entity text ? or what ??
this is my a-entity
<a-text
id="createRoom"
cursor="rayOrigin: mouse;maxDistance: 30; fuse: true ; far: 10"
width="10"
position="-6 3 -5"
align="left"
value="create room"
geometry="primitive:plane"
animation="property: position; from: -6 3 -5; to: -6 3.5 -5; loop: true; dir: alternate; easing:linear;dur:1000"
>
</a-text>
// buton2
<a-text
id="joinRoom"
width="10"
align="right"
raycaster="objects: .collidable; far: 8"
position="6 0.7 -5"
cursor="rayOrigin: mouse;maxDistance: 30; fuse: true"
value="joinroom"
geometry="primitive:plane"
animation="property: position; from: 6 0.7 -5; to: 6 0.9 -5; loop: true; dir: alternate; easing:linear;dur:1000"
></a-text>

Place the cursor component either:
on the scene: <a-scene cursor="rayOrigin: mouse">
on any element which is the starting point of the ray:
<a-camera>
<a-entity cursor></a-entity>
</a-camera>
<a-entity id="vive-controller" cursor></a-entity>
Otherwise the rays may get through many "bystanding" entities, and result in multiple click events.
Correctly working fiddle here.
Fiddle with cursors on the texts (like in the question) here.

Related

AR.js trying to synchronize scene to compass north

I'm setting up augmented reality with AR.js, and I'm trying to get the camera/scene to be oriented to due North when the page loads.
Short example is that I'm trying to create a view that has a virtual compass with North/East/South/West displayed to the user.
I've got it working to a certain extent so far, but the calibration seems a little off at times. I'm using a MEAN stack and AR.js
Here's what I have:
view.html:
<a-scene embedded arjs='sourceType: webcam; debugUIEnabled: false;'>
<a-entity id="camera-entity" wasd-controls-enabled="false" position="0 -2 0" rotation="0 0 0" aframe-injected="">
<a-camera></a-camera>
</a-entity>
<a-text font="kelsonsans" width="6" position="0 0 -3.5" rotation="0 0 0" text="" value="North"></a-text>
</a-scene>
angular client controller (this section running only once on initialization):
var compass = event.webkitCompassHeading;
document.querySelector('#camera-entity').object3D.rotation.y = THREE.Math.degToRad(-compassdir);
Am I doing something incorrect with how I'm setting rotation on the camera-entity? Is there a better way to do this? Any suggestions?
I have compass bearing outputting to my development display, and it appears that the hardware is getting compass readings correctly.
Hardware: iPhone X
Reference:
Also, see this for reference regarding how aframe orients to relative phone position when opening:
https://github.com/aframevr/aframe/issues/349
And this for reference about a-frame rotation:
https://aframe.io/docs/0.8.0/components/rotation.html
If you want your items on the marker to be oriented compass-wise, then I'd suggest rotating the scene, not messing with the camera
<a-marker>
<a-entity id='parent' rotate-this-with-the-compass-readings>
<!-- Everything you want to rotate northwise --!>
</a-entity
</a-marker>
Preferably, with a aframe component, to be sure the element is ready:
AFRAME.registerComponent("rotate-this-with-the-compass-readings", {
init: function() {
var compassdir // however you get the compass reading
var pos = this.el.getAttribute('position')
pos.y = THREE.Math.degToRad(-compassdir);
this.el.setAttribute('position', pos)
}
})

The property of the object does not update in the scene

In the scene, I have two boxes. I am trying to make one box cloning the other one's rotation angle in real time.
<a-entity id="original" mixin="cube" position="0 1.6 -1" material="color: red" sleepy collision-filter="group: red; collidesWith: default, hands, blue" rotation="0 0 0">
<a-entity id="clone" mixin="cube" position="2 1.6 -1" material="color: blue" sleepy
collision-filter="group: blue; collidesWith: default, red" rotation="0 0 0">
I can see that the property of a cloned box updates correctly through console.log(), but in the scene the box does not change its angle. What am I missing?
The code below is my attempt to make it work.
var check = document.querySelector('.controllers');
var ori = document.getElementById('original');
var clo = document.getElementById('clone');
check.addEventListener('xbuttondown', () => {
var ori_pos = ori.getAttribute("rotation");
//console.log(ori_pos.x);
clo.object3D.rotation.set(
THREE.Math.degToRad(ori_pos.x),
THREE.Math.degToRad(ori_pos.y),
THREE.Math.degToRad(ori_pos.z)
);
console.log(clo.getAttribute("rotation"));
});
From the A-Frame FAQ: To improve performance, A-Frame does not update the HTML to save on stringification operations. This also means mutation observations will not fire. Use the debug component or .flushToDOM methods if you need to sync to the DOM

<a-sound> does not kick start when marker is detected

I am very new to java script and html, and I am so stack with this.
The following is what I wrote and wanted to primitive to start when the marker is detected.
However, the sound start as soon as when I access the html on a browser.
<a-marker type="pattern" url="pat/ban.patt">
<a-entity>
<a-image id="obj0" rotation="-90 0 0" src="#banto" width="5" height="5"></a-image>
<a-entity position="-0.75 1 1" rotation="-90 0 0" text-geometry="value: Head of the cleark; bevelEnabled: false; bevelSize: 0.008; bevelThickness: 0.08; size: 0.25;" material="color: cyan;"></a-entity>
<a-sound src="#bantoSound" autoplay="true"></a-sound>
</a-entity>
</a-marker>
Although the is shown only when the marker is detected....
Does not work as same as ???
I'm afraid the autoplay:true fires the sound whenever the entity is loaded in the DOM.
I suggest You disable autoplay, or stop all sounds when the scene loads, and You activate it when the marker is visible:
if(document.querySelector("a-marker").object3D.visible == true){
// play the sound
}

Mocking CSS key frame animation in K-Frame (VR)

I want to create an animation on a single property (eg: scale) of a single entity (eg: a-circle) which would run one after another, using K-Frame. Is this possible?
For example, this would be a simple case:
<a-scene>
<a-circle
position="0 1.25 -5"
color="#F55"
radius="1"
scale=".1 .1 1"
animation__scale="property: scale; dir: normal; dur: 500; easing: easeInSine; loop: true; to: 1 1 1"
>
</a-circle>
</a-scene>
I want to, say, scale from .1 .1 1 to .5 .5 1 for the first 500ms, then stay at .5 .5 1 for another 500ms, and go back to .1 .1 1 in the next 200ms, and then loop through this entire process over and over infinitely.
Is this even possible?
You can daisy-chain the animations within a component checking which animation ended and starting the next one. In Your case that would be
animation1 ended -> wait 500ms and start animation2 -> animation2 ended -> wait 200 ms and start animation1.
You can achieve this, by simply listening for the animation__[ID]-complete event, and emit another one.
If You just chained them, You could just map multiple listeners on the start event list.
However You want to give them some custom wait periods, which can be included within the mapped functions, or done manually:
el.addEventListener('animation__scale1-complete', function() {
setTimeout(function(){
el.emit('secondAnimation');
},500);
})
el.addEventListener('animation__scale2-complete', function() {
setTimeout(function(){
el.emit('firstAnimation');
},200);
})
working fiddle here: https://jsfiddle.net/gftruj/2qoz8b75/2/ Please note, that i trigger the first animation also on the loaded event in case it fires before its loaded.

aframe - Set camera position at runtime

In a a-scene, I try to change my camera position at runtime. The DOM property changes but the camera does not move.
What could have I missed ?
my js code:
document.querySelector('#myCameraPosition').setAttribute('position', '0 0 0');
My a-scene:
<a-entity id="myCameraPosition" position="0 0 50">
<a-entity id="myCamera" camera look-controls keyboard-controls>
</a-entity>
</a-entity>
Create a wrapper entity around the camera:
<a-entity id='cameraWrapper' position="0 0 0">
<a-camera></a-camera>
</a-entity>
Then change position of the wrapper:
document.querySelector("#cameraWrapper").object3D.position.set(1, 1, 1);
Had to set "look-controls" to false for javascript rotation control, otherwise wouldn't work :
function resetView(el){
el.setAttribute('look-controls','false');
el.setAttribute('rotation',{x:0,y:0,z:0});
el.setAttribute('look-controls','true');
}
On the example below I can change the position of the camera entity's parent and it works as expected:
https://aframe.io/examples/showcase/helloworld/
Is any of the openearthview or acceleration components writing the position of the camera entitiy's parent? They might be overwritting its position.
document.getElementById('myCameraPosition').setAttribute('position', {x:0, y:0, z:0});
or
document.querySelector('#myCameraPosition').setAttribute('position', {x:0, y:0, z:0});
When it comes to position you can directly change the camera position(unlike rotation where you need a wrapper entity).
so
document.getElementById('myCameraPosition').setAttribute('position', {x:0, y:0, z:0});
should work

Resources