Comments (26)
I am using ar.js with aframe and have similar problem. If I am not using embedded on the a-scene images and videos are distorted and clicks accurate but when I use embedded ratios of elements (images, video) are correct but clicks are off target big time.
from ar.js.
Hello there! I've managed to fix this problem by following this Stackoverflow Question and attaching a cursor component after the scene is initialized
const scene = AFRAME.scenes[0]; if (!scene) { return; } const mouseCursor = document.createElement('a-entity'); mouseCursor.setAttribute('cursor', 'rayOrigin', 'mouse'); scene.appendChild(mouseCursor);I hope this can help us to fix the problem in its source ✌️
This worked for me! I basically just created a new Component and attached it to the . The component is like this:
AFRAME.registerComponent('custom-cursor', {
init: function () {
setTimeout(() => {
const scene = AFRAME.scenes[0];
const mouseCursor = document.createElement('a-entity');
mouseCursor.setAttribute('cursor', 'rayOrigin', 'mouse');
mouseCursor.setAttribute('raycaster', 'objects', '.clickable');
scene.appendChild(mouseCursor);
}, 2000);
},
});
and then just <a-scene arjs embedded custom-cursor>...</a-scene>
I was literally looking for an answer for days and finally came across the solution.
from ar.js.
Is this problem solved?
I have been developing similar functions recently
and have the same problem as this post and this one
In my test
It seems that the ratio of the video element (arjs-video) and canvas does not match, will causes the raycaster coordinates to be distorted
raycaster I usage
cursor="rayOrigin: mouse"
raycaster="objects: .collidable"
Coordinate formula of rayOrigin (A-frame official built-in, aframe.js)
registerComponent('cursor' ...
...
......
left = point.clientX - bounds.left;
top = point.clientY - bounds.top;
mouse.x = (left / bounds.width) * 2 - 1;
mouse.y = -(top / bounds.height) * 2 + 1;
Very similar to @XiaNi provided above
My Test
version
A-frame: 0.9.2
ar.js: 3.1.0
Test Methods
I will generate a object (3D model) on the AR marker, and click on the object with the mouse to stick on a small ball at the click position to display the raycaster coordinates.
Situation.1
<a-scene
embedded
arjs="sourceWidth:640; sourceHeight:480; displayWidth: 1920; displayHeight: 1440;">
The ratio of display (1920x1440) is setting to same as the source (640x480), both are 4:3.
-
At 1920x1440 in the browser screen
The ratio scale of 3D model and raycaster coordinates are displayed perfectly.
The ball is perfectly at the position of the object I clicked.
Because 640x480 and 1920x1440 are both 4:3 ratio. -
At 1920x1080 in the browser screen
The ratio scale of the 3D model is displayed perfectly, but the raycaster coordinates will be distorted.
The position of the ball has offset.
Because 640x480 is 4:3 and 1920x1080 is 16:9 ratio.
In the above cases, due to different screen heights, the offset can be clearly seen as the closer to the upper and lower sides of the screen, the greater the Y-axis offset, and the closer to the center point, the smaller the offset.
BTW, other screen tests can also have perfect results as long as the screen ratio setting same as source.
In this case (source=640x480, 4:3) like 1280x960/2560x1920 (4:3) can also work perfectly.
Situation.2
<a-scene
embedded
arjs="sourceWidth:640; sourceHeight:360; displayWidth: 1920; displayHeight: 1080;">
The ratio of source (640x360) is setting to same as the display (1920x1080), both are 16:9.
- At 1920x1080 in the browser screen
It looks like I should get the result I want.
Unfortunately, the raycaster coordinates are displayed perfectly.
And the ball is also perfectly at the position of the object I clicked.
BUT the ratio scale of the 3D model is distorted...
So, it seems that I cannot adjust the ratio of source to match the display.
It can only adjust the display to match the source ratio.
But as long as the display and source ratios are different, the raycaster coordinates will be distorted.
Otherwise, rewrite the coordinate formula of rayOrigin?
It is difficult to ensure that the camera (source) and screen resolution (display) supported by each device will be in the same ratio.
Like the browser window can also adjust the screen size at will.
Any suggestions? Or this problem already correcting?
Thanks!
from ar.js.
It occurs in the old and new version.
Both "basic" setups make the issue occur and the issue has existed for a while.
Resizing the window will make it better then worse again depending on how far you resize.
I am currently using the new basic version:
https://github.com/AR-js-org/AR.js/blob/master/three.js/examples/basic.html
from ar.js.
Right, you need to change THREE.Camera to THREE.PerspectiveCamera
from ar.js.
Hi @maximus123123 , thank you! Does it happens also with the other examples?
from ar.js.
Hi @maximus123123 , thank you! Does it happens also with the other examples?
I believe so. Heres another person with the same issue: jeromeetienne/AR.js#584
The issue, I think,
It's either the camera:
The camera view perhaps is different as you need to change the example's camera from new THREE.Camera to THREE.PerspectiveCamera.
Or the canvas size isn't updating correctly the size correctly for the calculation thus giving the wrong calculation. I have tried using vector3 as well but it didn't help
from ar.js.
Thank you @maximus123123, we also need to know which version of Ar.js are you using, at the moment we have ar.js and ar-nft.js because they use different version of jsartoolkit5: the first the oldest the last the newest version with NFT. Maybe this bug occur the oldest but not the newest version? Please tell me exactly you setup. 🙂
from ar.js.
Ok thank you so much! We will see how to fix this, i have not a clear idea how to solve now.
from ar.js.
Are you able to reproduce the error?
from ar.js.
Are you able to reproduce the error?
i will try later if i have time. 😄
from ar.js.
@maximus123123 with the basic example i got this error:
three.min.js:869 THREE.Raycaster: Unsupported camera type.
setFromCamera @ three.min.js:869
mousedown @ basic.html:151
basic.html:153 []
i tested only on Desktop (Ubuntu 18.04.03)
from ar.js.
I will look deeper into it when i have time, maybe it's not a bug, probably needs the right setup. 😄
from ar.js.
@maximus123123 , try to replace this part:
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1
with this:
var rect = renderer.domElement.getBoundingClientRect();
mouse.x = ( (event.clientX - rect.left) / rect.width ) * 2 - 1
mouse.y = - ( (event.clientY - rect.top) / rect.height ) * 2 + 1
from ar.js.
Same issues here. The targets are off, and they're off in different ways depending on if its a mobile sized screen or a regular desktop/laptop.
Here's a link to my codepen with the issue: https://codepen.io/riggitynick/pen/MWaOOeb?editors=1010
There are 3D shapes, and when you click on them, they should vanish, the targets are off a bit(and in really strange ways-weather I open it on my phone or laptop).
from ar.js.
Hi.
I'm also having similar issue while using AFrame and click handling.
Did anyone find a solution?
from ar.js.
how to solve this problem?
from ar.js.
hello @kalwalt, do you have any news related to this issue ? thanks !
from ar.js.
Hi anyone have an update on this problem???
from ar.js.
Hey, people. I've fallen in this problem as well.
It seems to happen only with embedded component as I've tested on #66.
Here's a visual evidence about this issue:
from ar.js.
Hello there!
I've managed to fix this problem by following this Stackoverflow Question and attaching a cursor component after the scene is initialized
const scene = AFRAME.scenes[0];
if (!scene) {
return;
}
const mouseCursor = document.createElement('a-entity');
mouseCursor.setAttribute('cursor', 'rayOrigin', 'mouse');
scene.appendChild(mouseCursor);
I hope this can help us to fix the problem in its source ✌️
from ar.js.
from ar.js.
Hello, @Yzuriha thanks for your answer that helped me a lot. However when I tried your example, the target intersection seems to be with the marker rather than the entity which has ".clickable" class. (I'm trying to use it, with an <a-plan>
which is taller than my marker)
I tried different things, but none of them work.
This line has no effect, Raycaster only detect intersection inside marker area
mouseCursor.setAttribute('raycaster', 'objects', '.clickable');
If you have a solution, I'm a taker !
from ar.js.
Hey everyone I've created this little example to show how you can make it work with aframe 0.9.2. Unfortunately it doesn't work with more recent versions than that :(
https://glitch.com/edit/#!/aframe-ar-js-issue
Hope this will help while this isn't fixed.
the working example works without the embedded tag too :D
from ar.js.
Same here with Aframe 1.2 :( Does not work, not even with @Yzuriha or @Markkop 's workarounds. Any other ideas?
from ar.js.
Has anyone examined the source code of this demo from 8th Wall? How did they overcome this problem?
https://templates.8thwall.app/placeground-aframe/ with mobile tablet or phone
from ar.js.
Related Issues (20)
- Marker Position Moves When Headset/Camera Moves
- Image tracking AR.js with React stuck on loading screen , please help! HOT 2
- Help please! image tracking work but 3d model and video not showing
- change "Twitter" to "𝕏 (Twitter)" in README.md HOT 3
- The camera cannot be controlled by external parameters, especially on phones with multiple cameras,help me please!
- Why the camera fails to be used now?
- Seems like the version is Updated but not the docs and example
- Document is so misleading HOT 2
- Module Import fails in Nuxt3 --- ar-threex-location-only.js --- Cannot read properties of undefined (reading 'THREE') HOT 2
- 将ar.js引入three.js 请求一个功能
- Location based compass orientation is incorrect. It always says North is direction when starting up. HOT 3
- Location Base - Entity is following HOT 3
- Event fired when user "see" an object (location based) HOT 1
- "click" events are not emitted on Android when scene is loaded dynamically HOT 1
- Replacing a building?
- Need help implementing AR.js
- New-location-based entity position problem HOT 1
- Location Based AR.JS project mixed with AFRAME Hit Test
- Place to list device models / OS versions which cause the "content sticking to camera" problem (#278)
- Raycaster intersects invisible marker roots. Is there any landmark to distinguish between displayed and hidden elements? (marker-based)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ar.js.