Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XR extras rotate rotates all the entities #209

Open
diegoMontesinos opened this issue Nov 10, 2022 · 0 comments
Open

XR extras rotate rotates all the entities #209

diegoMontesinos opened this issue Nov 10, 2022 · 0 comments

Comments

@diegoMontesinos
Copy link

diegoMontesinos commented Nov 10, 2022

In the A-Frame manipulate example, is using the xrextras-two-finger-rotate component. When I have two entities, and rotate with the two finger gesture, both entities are been rotated. I wanted to rotate just a selected one.

<a-entity
        id="model"
        gltf-model="#sandCastleModel"
        class="cantap"
        xrextras-hold-drag
        xrextras-two-finger-rotate
        xrextras-pinch-scale
        scale="3 3 3"
        shadow="receive: false">
      </a-entity>

<a-entity
        id="model-2"
        gltf-model="#sandCastleModel"
        class="cantap"
        xrextras-hold-drag
        xrextras-two-finger-rotate
        xrextras-pinch-scale
        scale="3 3 3"
        shadow="receive: false">
      </a-entity>

I decide to re-implement by myself the component adding a mousedown event to grab the entity that is been rotating:

let selection = null

const twoFingerRotateComponent = {
  schema: {
    factor: {default: 5},
  },
  init() {
    this.handleMouseDownEvent = this.handleMouseDownEvent.bind(this)
    this.handleMoveEvent = this.handleMoveEvent.bind(this)
    this.handleEndEvent = this.handleEndEvent.bind(this)

    this.el.addEventListener('mousedown', this.handleMouseDownEvent)
    this.el.sceneEl.addEventListener('twofingermove', this.handleMoveEvent)
    this.el.sceneEl.addEventListener('twofingerend', this.handleEndEvent)
  },
  remove() {
    this.el.removeEventListener('mousedown', this.handleMouseDownEvent)
    this.el.sceneEl.removeEventListener('twofingermove', this.handleMoveEvent)
    this.el.sceneEl.removeEventListener('twofingerend', this.handleEndEvent)
  },
  handleMouseDownEvent(event) {
    selection = this.el
  },
  handleMoveEvent(event) {
    if (selection) {
      selection.object3D.rotation.y += event.detail.positionChange.x * this.data.factor
    }
  },
  handleEndEvent(event) {
    selection = null
  },
}

export {twoFingerRotateComponent}

And registering with:

import {twoFingerRotateComponent} from './xrextras-finger-rotate'

AFRAME.registerComponent('xrextras-finger-rotate', twoFingerRotateComponent)

Any thoughts? Can you update the XRExtras library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant