-
Notifications
You must be signed in to change notification settings - Fork 14
vanilla touch UI demo of touching button with indexfinger #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't test it yet, just left some comments.
Can you rename the directory example to examples, we may add other examples later.
|
||
function onTouch(){ | ||
let $msg = document.querySelector('#msg') | ||
msg.innerText = String(new Date()).substr(15,10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the dollar in the variable. The code is working because in javascript all ids are variables in the global scope.
} | ||
}, | ||
detectPress: function(){ | ||
if( !this.el.sceneEl.renderer.xr.isPresenting ) return // ignore events in desktop mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!this.el.sceneEl.is("vr-mode"))
is a more common way to check if we're in not vr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case we need to add a check for "ar-mode" too then (I can do that, not the end of the world)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep isPresenting. I see that the ar-hit-test component is using it like this as well.
let minDistance = 5 | ||
|
||
// compensate for an object inside a group | ||
let object3D = this.el.object3D.type == "Group" ? this.el.object3D.children[0] : this.el.object3D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what case this.el.object3D is not a group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is twofold:
- raycasters cannot cast with object3D type 'Group'
- AFRAME uses type 'Group' for
this.el.object3D
Perhaps better would be object3D.getObjectByProperty("Mesh")
(gets the first object3D of type Mesh).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes so the check is unneeded, this is what I'm saying. It could have just been
let object3D = this.el.object3D.children[0];
but yes better use here:
let object3D = this.el.getObject3D('mesh')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps object3D.getObjectByProperty("Mesh")
would be a safer/flexible bet.
'mesh' is AFRAME-only (ArrayMap), and is empty quite often, depending on the implementation of certain components, or when dealing with an object from an glTF.
Another approach could be, what obb-collider does, it tries to mitigate this by offering an object3Dpath (or something similar).
We could also do both, to avoid silent false positives:
let object3D = this.getMesh(this.data.trackedObject3D) || this.el.object3D.getObjectByProperty("Mesh")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it's "html" not "mesh" we want here
aframe-htmlmesh/src/aframe-html.js
Line 60 in 6caf36f
this.el.setObject3D('html', mesh); |
and I guess you want that pressable component to work not only with htmlmesh entities.
We can do something similar to flattenObject3DMaps
in aframe raycaster component https://github.com/aframevr/aframe/blob/96c37a38dbe1be9df477adb9b9bf2be4d69d9682/src/components/raycaster.js#L411
getting all meshes from el.object3DMap.
this.handEls = document.querySelectorAll('[hand-tracking-controls]'); | ||
this.pressed = false; | ||
this.distance = -1 | ||
// we throttle by distance, to support scenes with loads of clickable objects (far away) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clickable -> pressable
My resources are limited, before amending this PR I first need to get a heads up from AdaRoseCannon on this. |
You probably won't have any feedback from her. She gave me the rights on all the repositories, so this is me that will do the merge. |
awesome, I'll try to amend the PR asap then |
There is no hurry, you can amend the PR whenever you have time. |
This, it's tricky for me to do OSS right now Thanks @vincentfretin I really appreciate your continued support of these projects. |
Besides the awesome handy-works, here's an example on how to click a button via indexfinger-press in a vanilla AFRAME scene.