Hello there,
Last time my question went unanswered, but I managed to ‘stitch’ objects to follow each other (having the first bone in chain follow the last bone of the object in front) in a train-like configuration, however now I’m faced with more serious problem which I’ve been trying to solve for the past week to no avail.
Since all animation has to be done by code now smooth bending around a corner (when the pipe takes a turn) became quite challenging. Basically, my idea is to create an arch which I’ll use as a guide for the bones in each segment and then animate through it. For that purpose I’m using an imaginary point O around which I want to bend the pipe, and the arch is defined by a radius r (in this case the distance between the center of the pipe and the point O, on the axis of movement) and an angle α (which iterates from 0 to π/2 in dependence of the current animation frame/time). To give you a better idea of the setup, here is a top-down illustration of what am I trying to achieve (the y axis is irrelevant at this point, joints hierarchy is printed in the bottom left):
As the image might suggest, I’m trying to translate the pipe from the bottom right quadrant to the top left one, and I want to achieve that by moving the bones/joints along the arch. To place the joints along the arch is fairly easy when you dust-off your trigonometry knowledge. The first joint will always be at the angle for the current animation progress (t):
JNT_01(x, z) = (Ox + r * cos α(t), Oy + r * sin α(t))
To find where the next joint goes, we need to treat the bone structure as a chord predefined length (original distance between the joints) so that the mesh doesn’t get stretched. Thus, to find where we need to place the next joint, we need to find the central angle, then substract it from the current angle α(t) and then place the next joint on the arch of that angle. So:
ϴ = 2 * arcsin ( dist(JNT_01, JNT_02) / (2 * r) )
β = α(t) - ϴ
JNT_02(x, z) = (Ox + r * cos β, Oy + r * sin β)
Where dist() represents the distance between the joints. And this repeats until the angle goes bellow 0 degrees at which point I stop moving the other joints along the x axis as I don’t want to bend the joints that haven’t passed the point around which I’m bending. So far, so good, it distributes the joints correctly. An example of this distribution for the α(1) (full animation angle, π/2) can be seen on this image:
But in order to have a proper morph/bend those joints need to be rotated as well. And that’s where I hit the wall. In theory, the joints should be rotated around the y axis for the angle they are facing the next joint in the chain. That angle can be calculated by subtracting the center angle ϴ from π, and then dividing it by two as both angles on a chord are the same. This would give you the inverse angle of what you need to rotate, so adding the original angle and normalizing it should provide the correct rotation. And indeed it does. So, in theory, the above situation should look like:
However, since the joints are parented to one another, the end result looks nothing like the above - it pretty much destroys the mesh bending each joint at the inherited + added angle. I’ve tried setting local rotations, setting rotation before position, copying transformations from null objects positioned correctly (so the problem is definitely with the joint/transformations structure), and pretty much everything in-between, and I just cannot make it work. Everything just turns into a blurb
So what am I doing wrong? And am I even on the right track or I needlessly complicated it when there is something that would make this easy peasy?
Sorry for the long text, I just wanted to be as detailed as possible.
Cheers