touch hand-controls works now (todo: needs ratelimiter)
This commit is contained in:
parent
c6f4b2fc77
commit
9f14ed017d
4 changed files with 13 additions and 20 deletions
|
|
@ -146,7 +146,7 @@ window.AFRAME.registerComponent('xrf', {
|
||||||
el.addEventListener("click", clickHandler )
|
el.addEventListener("click", clickHandler )
|
||||||
el.addEventListener("mouseenter", mesh.userData.XRF.href.selected(true) )
|
el.addEventListener("mouseenter", mesh.userData.XRF.href.selected(true) )
|
||||||
el.addEventListener("mouseleave", mesh.userData.XRF.href.selected(false) )
|
el.addEventListener("mouseleave", mesh.userData.XRF.href.selected(false) )
|
||||||
el.addEventListener("pressedended", clickHandler )
|
el.addEventListener("pressedstarted", clickHandler )
|
||||||
$('a-scene').appendChild(el)
|
$('a-scene').appendChild(el)
|
||||||
}
|
}
|
||||||
createEl(mesh)
|
createEl(mesh)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ AFRAME.registerComponent('pressable', {
|
||||||
var handEls = this.handEls;
|
var handEls = this.handEls;
|
||||||
var handEl;
|
var handEl;
|
||||||
var distance;
|
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++) {
|
for (var i = 0; i < handEls.length; i++) {
|
||||||
handEl = handEls[i];
|
handEl = handEls[i];
|
||||||
let indexTipPosition = handEl.components['hand-tracking-controls'].indexTipPosition
|
let indexTipPosition = handEl.components['hand-tracking-controls'].indexTipPosition
|
||||||
|
|
@ -25,29 +29,19 @@ AFRAME.registerComponent('pressable', {
|
||||||
handEl.object3D.getWorldPosition( this.fingerWorldPosition )
|
handEl.object3D.getWorldPosition( this.fingerWorldPosition )
|
||||||
this.fingerWorldPosition.add( indexTipPosition )
|
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
|
this.raycaster.far = 0.05
|
||||||
// Create a direction vector (doesnt matter because it is supershort for 'touch' purposes)
|
// Create a direction vector (doesnt matter because it is supershort for 'touch' purposes)
|
||||||
const direction = new THREE.Vector3(1.0,0,0);
|
const direction = new THREE.Vector3(1.0,0,0);
|
||||||
this.raycaster.set(this.fingerWorldPosition, direction)
|
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)
|
this.distance = this.fingerWorldPosition.distanceTo(this.worldPosition)
|
||||||
|
|
||||||
//if( xrf.debug == 10 && this.el.id == "xrf-button_teleport_me_down_there" ){ debugger }
|
|
||||||
|
|
||||||
if (intersects.length ){
|
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) {
|
if (this.pressed) {
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,12 @@ window.AFRAME.registerComponent('xrf-get', {
|
||||||
mesh.setRotationFromQuaternion(world.quat);
|
mesh.setRotationFromQuaternion(world.quat);
|
||||||
}else{
|
}else{
|
||||||
// lets create a dummy add function so that the mesh won't get reparented during setObject3D
|
// 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.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}`)
|
if( !this.el.id ) this.el.setAttribute("id",`xrf-${mesh.name}`)
|
||||||
}else console.warn("xrf-get ignore: "+JSON.stringify(this.data))
|
}else console.warn("xrf-get ignore: "+JSON.stringify(this.data))
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,6 @@ xrf.frag.href = function(v, opts){
|
||||||
let click = mesh.userData.XRF.href.exec = (e) => {
|
let click = mesh.userData.XRF.href.exec = (e) => {
|
||||||
|
|
||||||
if( !mesh.material || !mesh.material.visible ) return // ignore invisible nodes
|
if( !mesh.material || !mesh.material.visible ) return // ignore invisible nodes
|
||||||
if( e.type == "pressedended" && !e.detail ){
|
|
||||||
console.dir(e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// bubble up!
|
// bubble up!
|
||||||
mesh.traverseAncestors( (n) => n.userData && n.userData.href && n.dispatchEvent({type:e.type,data:{}}) )
|
mesh.traverseAncestors( (n) => n.userData && n.userData.href && n.dispatchEvent({type:e.type,data:{}}) )
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue