2024-06-07 07:33:00 +00:00
|
|
|
//// this makes WebXR hand controls able to click things (by touching it)
|
2024-03-05 11:56:06 +00:00
|
|
|
|
|
|
|
|
AFRAME.registerComponent('pressable', {
|
2024-03-18 17:14:16 +00:00
|
|
|
|
2024-06-07 07:33:00 +00:00
|
|
|
init: function(){
|
|
|
|
|
let handEls = [...document.querySelectorAll('[hand-tracking-controls]')]
|
2024-03-05 19:52:06 +00:00
|
|
|
|
2024-06-07 07:33:00 +00:00
|
|
|
for( let i in handEls ){
|
|
|
|
|
let handEl = handEls[i]
|
|
|
|
|
handEl.addEventListener('model-loaded', () => {
|
|
|
|
|
if( handEl.pressable ) return
|
2024-03-05 19:52:06 +00:00
|
|
|
|
2024-06-07 07:33:00 +00:00
|
|
|
// wait for bones get initialized
|
|
|
|
|
setTimeout( () => {
|
|
|
|
|
let bones = handEl.components['hand-tracking-controls'].bones
|
|
|
|
|
let indexFinger
|
|
|
|
|
for( let i = 0; i < bones.length; i++){
|
|
|
|
|
if( bones[i].name == "index-finger-tip" ){
|
|
|
|
|
indexFinger = i
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// add obb-collider to index finger-tip
|
|
|
|
|
let aentity = document.createElement('a-entity')
|
|
|
|
|
trackedObject3DVariable = `parentNode.components.hand-tracking-controls.bones.${indexFinger}`;
|
|
|
|
|
console.log(trackedObject3DVariable)
|
|
|
|
|
handEl.appendChild(aentity)
|
|
|
|
|
aentity.setAttribute('obb-collider', {trackedObject3D: trackedObject3DVariable, size: 0.015});
|
|
|
|
|
},500)
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-03-05 11:56:06 +00:00
|
|
|
|
2024-06-07 07:33:00 +00:00
|
|
|
},
|
2024-03-05 17:30:54 +00:00
|
|
|
|
|
|
|
|
|
2024-06-07 07:33:00 +00:00
|
|
|
events:{
|
|
|
|
|
obbcollisionstarted: function(e){
|
|
|
|
|
if( !e.detail.trackedObject3D ) return
|
|
|
|
|
if( e.currentTarget && e.currentTarget.emit ){
|
|
|
|
|
//e.currentTarget.emit('click',
|
|
|
|
|
}
|
|
|
|
|
console.dir(e)
|
|
|
|
|
},
|
|
|
|
|
"xrf-get": function(){
|
|
|
|
|
//this.el.setAttribute('obb-collider',{trackedObject3D: 'el.object3D.child' }) // set collider on xrf-get object
|
|
|
|
|
let aentity = document.createElement('a-entity')
|
|
|
|
|
trackedObject3DVariable = this.el.object3D.child ? `parentNode.object3D.child` : `parentNode.object3D`
|
|
|
|
|
console.log(trackedObject3DVariable)
|
|
|
|
|
this.el.appendChild(aentity)
|
|
|
|
|
aentity.setAttribute('obb-collider', {trackedObject3D: trackedObject3DVariable});
|
2024-03-05 11:56:06 +00:00
|
|
|
}
|
2024-06-07 07:33:00 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|