In light of the Coronavirus crisis, please help make sure nothing stands in the way of social distancing in the VFX industry.

This petition asks the MPAA to act accordingly:


Sign the petition on Change.org

Be safe, everyone.

Euler Filter script

Idea ID:
11
Author:
Midgardsormr
Posted:
Wed Feb 05, 2020 12:28 pm
Rating:
Status:
New
User avatar
Midgardsormr
Fusionator
Posts: 1591
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 11
Location: Los Angeles, CA, USA
Been thanked: 51 times
Contact:

Euler Filter script

#1

Post by Midgardsormr » Wed Feb 05, 2020 12:28 pm

As pointed out in viewtopic.php?f=16&t=3759&p=28927 , Fusion doesn't understand rotations beyond 360 degrees. We therefore wind up in a situation where rotating objects suddenly make a complete rotation, sometimes flipping back and forth repeatedly across the threshold, which creates quite a problem when motion blur is turned on.

For one or two objects, this is reasonably easy to fix, but if you have dozens, or hundreds, of 3d objects it can become prohibitive to address them all.

An Euler Filter script could detect incorrect rotational windup and repair it by adding or subtracting 360 from keyframes where adjacent keyframes are found to have differences close to 360.

https://en.wikipedia.org/wiki/Euler_filter

User avatar
SirEdric
Fusionator
Posts: 2262
Joined: Tue Aug 05, 2014 10:04 am
Answers: 9
Real name: Eric Westphal
Been thanked: 28 times
Contact:

Re: Euler Filter script

#2

Post by SirEdric » Sat Feb 08, 2020 11:26 am

Since this happens in all sorts of scenarios related to importing/exporting 3D files
(heck....animate some 360+° rotation in Fusion, export as FBX, import again, and the same thing happens!)
10 thumbs up!

howiem
Posts: 29
Joined: Fri Jun 07, 2019 3:08 am
Been thanked: 6 times

Re: Euler Filter script

#3

Post by howiem » Tue Feb 18, 2020 2:31 am

Ha! Just hitting the ole' Euler discontinuity thing with my Houdini --> Fusion camera exporter thingy.

Seems there are two issues: wrapping at 360 degrees, and the axis-flipping thing that comes from decomposing matrices or quats.

Discontinuities:
If anyone can point me at some pseudo-code, that'd be extremely helpful; I've found lots of mentions of Euler filters but no actual procedure. It looks like it's a case of adding or subtracting 180 degrees from all the axes once you've noticed a bigger-than-something jump in the values.

Is it as simple as just "for each rot channel, if the channel's frame-to-frame delta exceeds some threshold value (say, 90 degrees), then add or subtract 180 according to the sign of the delta"?

I was coming up with an overly complicated algorithm trying to work out how the sign of the delta in x-rotation ought to affect the sign of the correction in the other two axes, and a system of flagging whether there had been a previous correction, but I'm wondering whether that's actually necessary. After all, if a discontinuity happens and you correct it for that frame, that'll effectively push the discontinuity on by one frame, where it'll get handled again in the same way.

So as long as your threshold is set appropriately so it doesn't get triggered by intended animation values, just doing a dumb "oh this axis has suddenly rotated by +178 deg so let's knock 180 off it" oughta work. No need to remember whether a correction is in place from frame to frame.

360 degree wrapping:
Same kinda deal, surely? No need to do any flaggy semaphory state stuff, just correct this frame and push the problem onto the next one.


Or is this approach naive? (I like to flip between naive and over-engineered as often as possible in any given working day)

User avatar
Midgardsormr
Fusionator
Posts: 1591
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 11
Location: Los Angeles, CA, USA
Been thanked: 51 times
Contact:

Re: Euler Filter script

#4

Post by Midgardsormr » Tue Feb 18, 2020 7:00 am

Hmmm.... You're going to be doing a comparison between two points at every keyframe either way. And you're going to add a number to each offending point either way. I can't see where a point-by-point approach is going to be any slower than flag-and-correct.

I haven't encountered any actual algorithms, either. I haven't looked really hard, but a cursory search only turned up other people asking for one. Or descriptions of how to use a filter already included with software.

Added in 59 seconds:
Since it sounds like you're already thinking about it, do you want to go ahead and hit the "add" button up there in the original post to start a Dev topic?

howiem
Posts: 29
Joined: Fri Jun 07, 2019 3:08 am
Been thanked: 6 times

Re: Euler Filter script

#5

Post by howiem » Tue Feb 18, 2020 7:22 am

Yup. Point by point wins by simplicity for me.

I'm probably gonna incorporate filtering into my Houdini exporter rather than try getting my head round Lua, at least for now. I'll post it here once tidied; the Houdini exporter works fine but is sooo hacky, so childishly coded, it'd basically make me unemployable on sight

User avatar
Midgardsormr
Fusionator
Posts: 1591
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 11
Location: Los Angeles, CA, USA
Been thanked: 51 times
Contact:

Re: Euler Filter script

#6

Post by Midgardsormr » Tue Feb 18, 2020 7:25 am

lol. I'm looking forward to seeing it! I handle Houdini-Fusion interface, too, so anything I can learn will be of benefit.

howiem
Posts: 29
Joined: Fri Jun 07, 2019 3:08 am
Been thanked: 6 times

Re: Euler Filter script

#7

Post by howiem » Fri Mar 20, 2020 4:13 am

I've updated my Houdini-Fusion script so it now handles
- Rotation wind-up
- Euler flipping (albeit crudely - it seems to work on my limited set of tests; it'd be could to have some test data that breaks it)
- Redundant keyframe culling

https://gist.github.com/howiemnet/9ab71 ... dfdbdf4385

The Euler flipping thing is one of those "bass-player skills" things, it seems; easy to get it working okayish but to do it properly is going to take a fair bit of effort. Interesting to note that the Euler Filter CHOP within Houdini asks for a rotation hint - a set of Euler axis rotations to use as a starting point for its filtering.

My current project has the camera rotating on all axes, but I'd imagine Euler filtering could be made a lot more reliable if you were able to tell it, say, "I need yaw and pitch but no roll". More work to be done on this at some point... but for now it's time to wash the hands and keep working while I can