Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coderofsalvation
Copy link

image

Besides the awesome handy-works, here's an example on how to click a button via indexfinger-press in a vanilla AFRAME scene.

Copy link
Collaborator

@vincentfretin vincentfretin left a 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)
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Author

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)

Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Author

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).

Copy link
Collaborator

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')

Copy link
Author

@coderofsalvation coderofsalvation Mar 31, 2025

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")

Copy link
Collaborator

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

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clickable -> pressable

@coderofsalvation
Copy link
Author

My resources are limited, before amending this PR I first need to get a heads up from AdaRoseCannon on this.
I cannot afford working on zombie PR's.

@vincentfretin
Copy link
Collaborator

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.

@coderofsalvation
Copy link
Author

coderofsalvation commented Mar 31, 2025

awesome, I'll try to amend the PR asap then

@vincentfretin
Copy link
Collaborator

There is no hurry, you can amend the PR whenever you have time.
I had noted in my todo list to review that PR, just got time to look into it 2 weeks later, sorry about that, you may have lose your momentum on it.

@AdaRoseCannon
Copy link
Owner

AdaRoseCannon commented Mar 31, 2025

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.

This, it's tricky for me to do OSS right now

Thanks @vincentfretin I really appreciate your continued support of these projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants