Rich-Harris / svelte-cubed

Svelte ❤️ Three
svelte-cubed.vercel.app
MIT License
1.19k stars 76 forks source link

Exposing quaternion of THREE.Object3D #35

Open Myrmod opened 2 years ago

Myrmod commented 2 years ago

Hello,

I would like to be able to get the quaternion (rotation) of the camera or THREE.Object3D in general. Essentially I want to be able to use functions like this:

import * as THREE from 'three'

export function getSideVector(object: THREE.Object3D): THREE.Vector3 {
  // create default plane using normal vector
  const normalVector = new THREE.Vector3(0, 1, 0)
  const normalPlane = new THREE.Plane(normalVector, 0)

  // copy rotation of object to plane
  normalPlane.normal.set(0, 1, 0).applyQuaternion(object.quaternion.clone())

  // get new normal vector
  const newNormalVector = normalPlane.normal

  // create new vector from cross product
  const crossVector = new THREE.Vector3()
  crossVector.crossVectors(newNormalVector, getForwardVector(object))

  return crossVector
}

With this function I we would be able to move an object no matter its rotation perfectly sideways. I haven't done so before, but I could try to create a pull request.

Best regards

DefinitelyMaybe commented 2 years ago

At this point in time, the little pieces that I've picked up on from @Rich-Harris's talks/interviews is that he's focusing on svelte/svelte.kit . There's been a bunch of us waiting for this particular release for a while which is why there's a bunch of PR's already but my guess is that we should set our expectations accordingly. To be clear on my thoughts, a PR is welcome but it's probably going to take Rich some time before getting back to us.

If you haven't already seen it, here's a link to one of his talks from this playlist