From 9f14ed017dd7415e13ec3fd55fe2f94244c54053 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 5 Mar 2024 19:52:06 +0000 Subject: [PATCH] touch hand-controls works now (todo: needs ratelimiter) --- src/3rd/js/aframe/index.js | 2 +- src/3rd/js/aframe/pressable.js | 22 ++++++++-------------- src/3rd/js/aframe/xrf-get.js | 5 ++++- src/3rd/js/three/xrf/href.js | 4 ---- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/3rd/js/aframe/index.js b/src/3rd/js/aframe/index.js index 5f9e84f..1d3c232 100644 --- a/src/3rd/js/aframe/index.js +++ b/src/3rd/js/aframe/index.js @@ -146,7 +146,7 @@ window.AFRAME.registerComponent('xrf', { el.addEventListener("click", clickHandler ) el.addEventListener("mouseenter", mesh.userData.XRF.href.selected(true) ) el.addEventListener("mouseleave", mesh.userData.XRF.href.selected(false) ) - el.addEventListener("pressedended", clickHandler ) + el.addEventListener("pressedstarted", clickHandler ) $('a-scene').appendChild(el) } createEl(mesh) diff --git a/src/3rd/js/aframe/pressable.js b/src/3rd/js/aframe/pressable.js index d8f5343..9d15048 100644 --- a/src/3rd/js/aframe/pressable.js +++ b/src/3rd/js/aframe/pressable.js @@ -17,6 +17,10 @@ AFRAME.registerComponent('pressable', { var handEls = this.handEls; var handEl; var distance; + + // compensate for xrf-get AFRAME component (which references non-reparented buffergeometries from the 3D model) + let object3D = this.el.object3D.child || this.el.object3D + for (var i = 0; i < handEls.length; i++) { handEl = handEls[i]; let indexTipPosition = handEl.components['hand-tracking-controls'].indexTipPosition @@ -25,29 +29,19 @@ AFRAME.registerComponent('pressable', { handEl.object3D.getWorldPosition( this.fingerWorldPosition ) this.fingerWorldPosition.add( indexTipPosition ) - //distance = this.calculateFingerDistance(this.fingerWorldPosition); - - //if (distance < this.data.pressDistance && distance !== 0.0 ) { - // if (!this.pressed) { - // this.el.emit('pressedstarted'); - // } - // this.pressed = true; - // return; - //} this.raycaster.far = 0.05 // Create a direction vector (doesnt matter because it is supershort for 'touch' purposes) const direction = new THREE.Vector3(1.0,0,0); this.raycaster.set(this.fingerWorldPosition, direction) - intersects = this.raycaster.intersectObjects([this.el.object3D]) + intersects = this.raycaster.intersectObjects([object3D],true) - this.el.object3D.getWorldPosition(this.worldPosition) + object3D.getWorldPosition(this.worldPosition) this.distance = this.fingerWorldPosition.distanceTo(this.worldPosition) - //if( xrf.debug == 10 && this.el.id == "xrf-button_teleport_me_down_there" ){ debugger } - if (intersects.length ){ - debugger //if( xrf.debug == 10 && this.el.id == "xrf-button_teleport_me_down_there" ){ debugger } + this.pressed = true + this.el.emit('pressedstarted'); } } if (this.pressed) { diff --git a/src/3rd/js/aframe/xrf-get.js b/src/3rd/js/aframe/xrf-get.js index e3d2620..ca79b57 100644 --- a/src/3rd/js/aframe/xrf-get.js +++ b/src/3rd/js/aframe/xrf-get.js @@ -38,9 +38,12 @@ window.AFRAME.registerComponent('xrf-get', { mesh.setRotationFromQuaternion(world.quat); }else{ // lets create a dummy add function so that the mesh won't get reparented during setObject3D + // as this would break animations this.el.object3D.add = (a) => a } - this.el.object3D = mesh //setObject3D('mesh',mesh) + + this.el.setObject3D('mesh',mesh) + this.el.object3D.child = mesh // keep reference (because .children will be empty) if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`) }else console.warn("xrf-get ignore: "+JSON.stringify(this.data)) diff --git a/src/3rd/js/three/xrf/href.js b/src/3rd/js/three/xrf/href.js index 1119114..2a2e346 100644 --- a/src/3rd/js/three/xrf/href.js +++ b/src/3rd/js/three/xrf/href.js @@ -36,10 +36,6 @@ xrf.frag.href = function(v, opts){ let click = mesh.userData.XRF.href.exec = (e) => { if( !mesh.material || !mesh.material.visible ) return // ignore invisible nodes - if( e.type == "pressedended" && !e.detail ){ - console.dir(e) - return - } // bubble up! mesh.traverseAncestors( (n) => n.userData && n.userData.href && n.dispatchEvent({type:e.type,data:{}}) )