2024-06-07 08:52:59 +00:00
|
|
|
//// this makes WebXR hand controls able to click things (by touching it)
|
|
|
|
|
|
|
|
|
|
AFRAME.registerComponent('xrf-pressable', {
|
|
|
|
|
|
|
|
|
|
init: function(){
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
tick: function(){
|
|
|
|
|
// if( this.system.indexFinger.length ) debugger
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
events:{
|
|
|
|
|
obbcollisionstarted: function(e){
|
|
|
|
|
if( !e.detail.trackedObject3D ) return
|
|
|
|
|
console.dir(e)
|
|
|
|
|
},
|
2024-06-07 09:31:17 +00:00
|
|
|
indexFingerReady: function(){
|
|
|
|
|
if( this.system.indexFinger.length == 2){
|
|
|
|
|
console.dir(this.system.indexFinger)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-07 08:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
AFRAME.registerSystem('xrf-pressable',{
|
|
|
|
|
|
|
|
|
|
init: function(){
|
|
|
|
|
this.sceneEl.addEventListener('loaded', () => this.getFingers() )
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getFingers: function(){
|
|
|
|
|
let handEls = [...document.querySelectorAll('[hand-tracking-controls]')]
|
|
|
|
|
this.indexFinger = []
|
|
|
|
|
|
2024-06-07 09:31:17 +00:00
|
|
|
const me = this
|
|
|
|
|
|
|
|
|
|
const addColliderToFingerTip = function(handEl,indexFinger){
|
|
|
|
|
// add obb-collider to index finger-tip
|
|
|
|
|
let aentity = document.createElement('a-entity')
|
|
|
|
|
trackedObject3DVariable = `parentNode.components.hand-tracking-controls.bones.${indexFinger}`;
|
|
|
|
|
handEl.appendChild(aentity)
|
|
|
|
|
aentity.setAttribute('obb-collider', {trackedObject3D: trackedObject3DVariable, size: 0.015});
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 08:52:59 +00:00
|
|
|
for( let i in handEls ){
|
|
|
|
|
let handEl = handEls[i]
|
2024-06-07 09:31:17 +00:00
|
|
|
handEl.addEventListener('model-loaded', function(e){
|
|
|
|
|
const handEl = this
|
2024-06-07 08:52:59 +00:00
|
|
|
// wait for bones get initialized
|
|
|
|
|
setTimeout( () => {
|
|
|
|
|
let bones = handEl.components['hand-tracking-controls'].bones
|
|
|
|
|
let indexFinger
|
2024-06-07 09:31:17 +00:00
|
|
|
for( let j = 0; j < bones.length; j++){
|
2024-06-07 08:52:59 +00:00
|
|
|
if( bones[j].name == "index-finger-tip" ){
|
|
|
|
|
indexFinger = j
|
2024-06-07 09:31:17 +00:00
|
|
|
me.indexFinger.push(bones[j])
|
|
|
|
|
addColliderToFingerTip(handEl,indexFinger)
|
|
|
|
|
const els = [...document.querySelectorAll('[xrf-pressable]')]
|
|
|
|
|
els.map( (el) => el.emit('indexFingerReady',{}) )
|
2024-06-07 08:52:59 +00:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},500)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 09:31:17 +00:00
|
|
|
}
|
2024-06-07 08:52:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|