SamuKata
colortwist
colortwist

patreon


Strap Solver Part II: Revenge of the Evil Math

Well that took a bit longer than I expected.

As it turns out, solving for the tangents between two arbitrary curves in 3D space is not exactly as straightforward as I thought it would be. There is no direct solution, since there is no guarantee that the tangents are actually pointing at each other. This basically means that you're looking for the "closest possible" solution instead, which poses a unique challenge unto itself and falls within the category of metaheuristics and finding the global minima of a multi-dimensional function.

I've lost track of how many different methods I tried to solve this particular problem. I wrote probably a dozen different attempts to solve it myself, and while most worked under ideal circumstances, they weren't very rugged and tended to fail when pushed to the extreme. I tried a whole bunch of different algorithms detailed in various research papers scattered about the internet, and while some of them worked they didn't work very fast. I had a hard runtime requirement of (1 / 60 / 8) seconds (or 2.08 milliseconds) in order to maintain 60fps within the viewport, and actually hitting that landed up being the biggest problem by far. Eventually I settled on an adaptive solution that executes in < 0.7 milliseconds on average with just under 500 spline samples per run, though in very rare situations that can jump to ~1.5ms and 1500+ samples depending on the complexity and interactions between each of the input curves (which, depending on how they're positioned, can present hundreds or even thousands of individual local minima- all of which will yield an incorrect result compared to the actual solution that lines up both tangents as closely as possible).

Aaaanyways...

I could probably write about this stuff for hours, given how much of it I've plowed through in the past three weeks. Long story short, I think I now have a fairly solid system for handling "tight" strap rigging in 3D. This all really just boils down to solving for various tangents between curves in 3D space, and once you can do that it then becomes possible to simulate strapping in a fairly deterministic and non-simulated fashion.

The above GIF shows the final system (in 2D for clarity though, I'll probably have some 3D demos soon once I redo the body morphs and swimsuit geometry for my characters). The important thing to note here is that there are no set driven keys or animated trickery with the tangents being generated (the green lines with the yellow indicators above them). The tangents between the curves are being solved in realtime, even as one morphs around and changes shape.

Furthermore, while I'm not sure if this feature is going to land up in the next version of my characters- the same system responsible for solving curve <-> curve tangents can also be used to solve curve <-> point tangents as well. This makes it possible to perform a kind of "double lookup", where the curve-to-curve calculation builds a matrix relative to the tangents of each spline, and from that you can parent a "pluck" controller to the tangent-space matrix and recalculate for the tangents between the control point and each of the curves. In essence, this lets you simulate dynamic interactive straps in the viewport with zero physics or clothing simulation. Everything is 100% predictable and because of that, it's very easy to integrate into an existing rig without having to worry about how the strapping might react in odd or peculiar situations.

Strap Solver Part II: Revenge of the Evil Math

Comments

That's good to hear because all you create involves odd or peculiar situations. :)

Dan


More Creators