How to get a Quaternion Rotation as vec4 from script to patch

I want to keep track the orientation or rotation of a null child from 2 animated object in the scene.
I hope quaternion rotation can help me build some trigger logic from it but I’m confused on how to pass it as reactive signal that are updated live in vec4(x,y,z,w) or vec4(w,x,y,z) from script to patch editor. can someone help me?

I guess the patch bridge doesn’t support the QuaternionSignal type, but you can grab the component ScalarSignals and send them individually.

const Scene = require('Scene')
const {watch, log} = require('Diagnostics')
const Patches = require('Patches')

const init = (async function () {

  const plane = await Scene.root.findFirst('plane0')
  const quat = plane.worldTransform.rotation

  // no matching method, doesn't work
  // watch('quat', quat)

  // this does work
  watch('quatx', quat.x)
  watch('quaty', quat.y)
  watch('quatz', quat.z)
  watch('quatw', quat.w)

  // doesn't work, incorrect type
  // Patches.inputs.setVector('quat', quat)

  // does work!
  Patches.inputs.setScalar('quatx', quat.x)
  Patches.inputs.setScalar('quaty', quat.y)
  Patches.inputs.setScalar('quatz', quat.z)
  Patches.inputs.setScalar('quatw', quat.w)

})() (11.6 KB)

I feel like this isn’t supported because there are no patches that operate on quaternions. Are you building some quaternion patches of your own?

yup that is exactly what I need. Thanks Josh!
I wonder if instead of outputting per component, we just output them as vec4 using something like this?

Patches.inputs.setVector(‘Q’, Reactive.vector(quat.x, quat.y, quat.z, quat.w))

just for convenience.

And yes I’m trying to build some quaternion patch that hopefuly can solve a gimbal lock and/or rotation based logic that infamous for being such a frustrating matter to do in euler. Idk if it’s possible tho but at least by being able to access the quaternion values from script to patch, that process would be more accessible for all creators without having to really understand how quaternion works under the hood.

Hmm that might work. I was trying to use Reactive.pack, but it wouldn’t send to patches for some reason. Would be huge if you solve the gimbal lock problem with device motion! I think it might be a little inefficient to use for general purpose stuff since you need to convert back to euler again to assign the rotation in patches, but maybe the conversion is fast enough so it won’t make a big impact.