gftruj / aframe-hand-tracking-controls-extras

a-frame hand tracking extras
MIT License
48 stars 15 forks source link

not able to move objects using the pinching gesture #5

Open addy1997 opened 1 year ago

addy1997 commented 1 year ago

Hi @gftruj,

Objective: to move the objects by pinching them in any direction. Issue: The moment I pinch with my left hand the objects disappear from the scene JsFiddle: link

This is the component I wrote to move the object

   AFRAME.registerComponent('pinch-to-move-sickle', {

        dependencies: ['pinchable'],

        init: function() {
          var sceneEl = document.querySelector('a-scene');          
          var trackedEl = sceneEl.querySelector('#leftHand');
          this.el.trackedEl = trackedEl;
          var targetEl = sceneEl.querySelector("#sickle");
          targetEl.setAttribute('pinchable', {
            pinchDistance: 0.05
          })          
          trackedEl.addEventListener('pinchmoved', this.onPinchMoved);
          this.onPinchMoved = this.onPinchMoved.bind(this);
          //var event = new Event("pinchmoved") 
          //trackedEl.dispatchEvent(event)
          this.el.targetEl = targetEl;
        },

        onPinchMoved: function(evt) {
          var targetEl = document.querySelector("#sickle");
          var trackedEl = document.querySelector('#leftHand');
          var localPosition = this.localPosition;
          var evtDetail = this.evtDetail;
          var localPosition = new THREE.Vector3();
          var offset = new THREE.Vector3();
          localPosition.copy(evt.detail.position);
          targetEl.object3D.updateMatrixWorld();
          targetEl.object3D.worldToLocal(localPosition);
          targetEl.object3D.position.z = localPosition.z;
          targetEl.object3D.position.y = localPosition.y;
          evtDetail.value = (targetEl.object3D.position.x, targetEl.object3D.position.y, targetEl.object3D.position.z);
          targetEl.emit('positionchanged', evtDetail);
          trackedEl.emit('pinchmoved');
        }
      });

Video of the issue

https://github.com/gftruj/aframe-hand-tracking-controls-extras/assets/29406906/bfb09e8b-ffa9-47df-8605-755b008df962

Please could you help?

addy1997 commented 1 year ago

Hi @gftruj,

Can you please help me with this?

gftruj commented 1 year ago

hi, sorry for the late reply, I won't have access to my oculus for the next two weeks, but i love the idea. I guess like in an game engine editor, You'd like to move, rotate and scale any pinched object?

I would like to combine my stuff with Ada's handy work, so for example a gesture would trigger a specific functionality and then my stuff would do the rotation / scaling / moving.

addy1997 commented 1 year ago

@gftruj, yes, I want to be able to rotate, move, and scale the tools in the scene. I already wrote the code for that for it seems to not work properly. For the time being, can you please let me know what is the mistake I am making in my code?