From e395226473d1f16bb6875741dc7c996ad625a87c Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Fri, 23 Jun 2023 16:01:16 +0200 Subject: [PATCH] example of docs on knuckles and pinch to dettach --- index.html | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index af28dfa..2cd1610 100644 --- a/index.html +++ b/index.html @@ -3421,6 +3421,38 @@ function setNearbyEditor(el){ }) } +AFRAME.registerComponent('knuckles-docs',{ + init: function () { + var el = this.el + this.worldPosition=new THREE.Vector3(); + Array.from( document.querySelectorAll(".docs") ).map( doc => { + doc.addEventListener('picked', _ => { doc.classList.remove('docs') }) + // should check on released in order to attach back if close enough + }) + }, + tick: function () { + const docs = Array.from( document.querySelectorAll(".docs") ) + var worldPosition=this.worldPosition; + const attachables = ['pinky-finger-phalanx-intermediate', 'pinky-finger-phalanx-distal', ' pinky-finger-tip'] // somehow tip not available + attachables.map( (attachable, i) => { + this.el.object3D.traverse( e => { if (e.name == attachable) { + worldPosition.copy(e.position);e.parent.updateMatrixWorld();e.parent.localToWorld(worldPosition) + rotation = e.rotation.x*180/3.14 + " " + e.rotation.y*180/3.14 + " " + e.rotation.z*180/3.14 + if (docs[i] ){ + docs[i].setAttribute("scale", '.1 .1') + docs[i].setAttribute("rotation", rotation) + docs[i].setAttribute("position", AFRAME.utils.coordinates.stringify( worldPosition ) ) + } + } + }) + }) + + }, + remove: function() { + // should remove event listeners here. Requires naming them. + } +}); + // used for testing AFRAME.registerComponent('startfunctions', { init: function () { @@ -3465,8 +3497,11 @@ AFRAME.registerComponent('startfunctions', { - + + + +