Smoothing out Noisey Input Data
Hi,
I'm currently building something similar to animojis and require a way to smooth out the head tracking input values. I'm calculating velocity to control my blend shape weights. So far the system seems to work, but the input is sometimes very sporadic causing the animations to flicker:
I know it's possible to smooth out my values using the lerp function, but I can't seem to get it to work properly for the blendshape weights.
Relevant code snippet:
currentRotation = script.objectTransform.getWorldRotation();
var lerpedRotation = quat.slerp( currentRotation, script.attachToTransform.getWorldRotation(), script.rotSmoothing * getDeltaTime() );
var lerpedEulerAngle = lerpedRotation.toEulerAngles();
// calculate angular velocity
var rotationDelta = lerpedEulerAngle.sub(rotationLast);
rotationLast = lerpedEulerAngle;
var twistWeight = rotationDelta.y / getDeltaTime() * 1;
var tiltWeight = rotationDelta.z / getDeltaTime() * 1;
script.blendShape.setBlendShape(script.tilt_left, clamp(tiltWeight, -1, 1));
script.blendShape.setBlendShape(script.twist_left, clamp(twistWeight, -1, 1));
Thanks,
Sava
Hi Sava,
For rotations, it's usually better to work in quaternions than euler angles. You can do something like this to get the Y and Z angle deltas:
Hope this helps! Looks like a really cool lens!
Hey! That works! Never thought I'd learn a useful math lesson on how Euler coordinates aren't reliable for rotation lol. My one concern is this method seems fairly resource intensive. Are there any computationaly cheap ways to approximate the Y/Z components without using arctan?
Edit: I want to use the following formula:
I'm just a little uncertain what the function does with q.z, comma q.w. is it simply arcatan(q.z/q.w)?
Hi Sava!
Glad you're thinking about performance! Did you see some performance slow down when you used it?
The Math.atan function is actually the built in javascript function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2.
The first argument is the Y coordinate, and the second is the X coordinate of a point, where the arctan is the (counter clockwise) angle to the (positive) x axis (between -PI, PI).
Can't wait to see the result! Looks awesome!
Jon
When I initially tried it the frame rate seems low, but after I restarted the app, it was running smooth. I guess I'll keep Math.atan for now, and figure out a cheap approximation later, if the need arises.
Thanks for all the help guys,
Sava