Blendfactor question?

Topics: Developer Forum, Project Management Forum, User Forum
Apr 16, 2007 at 9:14 PM
Hi Dastle.

Is it possible without changing the source code to blend 2/multiple controls to 100% with each controls?

I don't know if my point is getting through so I'll try to explain myself a little more. If I blend 2 controls with a blendfactor of .5, the rotations and translations are divided by 2 which I reasonably. What I want is skip the dividing with 2. Here's an example, let's say the first control rotates a bone back and forth in the X axis, and the other one rotates the same bone back and forth in the Y. If you blend these controls with a blendfactor of .5 the bone creates a circular motion. But the circle is half the size of what I want. I know I can just double the rotation, but then I'll "loose control" of the end result, especially when doing translates as wells.

Any ideas?
/Alfons
Coordinator
Apr 18, 2007 at 4:40 PM
Im sorry, I'm not sure I understand. Are you saying that you want to just add the transformation matrices together?

The way to solve this seems to make a default IAnimationController. In the unreleased source, you can override AnimationController, and just override the GetBoneTransform method. You would then just store two different controllers, and when asked for the transform, return controller0.GetBoneTransform(bone) + controller1.GetBoneTransform(bone). It's more difficult int he current release because I didn't make the GetBoneTransform virtual on AnimationController, and IAnimationController forces you to implement some unneccessary methods.

You could also skip all this and just create 2 controllers, and for your bone, set CurrentController to null and set DefaultTransform to the sum of the transforms every frame.
Apr 19, 2007 at 6:10 PM
Edited Apr 19, 2007 at 6:10 PM
I tried your suggestion. But I get two problems. The first is I get a scaling problem, just like if you have more then 4 influences. The other is I get the same range of movement as when blending the two controls together with a blend factor of .5f. Here is how my test method looks like:

private void MoveEyes(ModelAnimator animator, AnimationController Ycontroller, AnimationController Xontroller, float thumbstickX, float thumbstickY)
{

Ycontroller.SpeedFactor = 0;
Xcontroller.SpeedFactor = 0;

thumbstickX += 1;
float eyeX = MathHelper.Lerp(0, Ycontroller.Duration - 1, thumbstickX / 2f);
thumbstickY += 1;
float eyeY = MathHelper.Lerp(0, Xcontroller.Duration - 1, thumbstickY / 2f);
Ycontroller.ElapsedTime = (long)eyeX;
Xcontroller.ElapsedTime = (long)eyeY;

Matrix eyeYMatrix, eyeXMatrix;
BonePose eyes = animator.BonePoses"rightEye";
eyes.CurrentController = null;
Ycontroller.GetCurrentBoneTransform(eyes, out eyeYMatrix);
Xcontroller.GetCurrentBoneTransform(eyes, out eyeXMatrix);
eyes.DefaultTransform = eyeYMatrix + eyeXMatrix;
eyes = animator.BonePoses"leftEye";
eyes.CurrentController = null;
Ycontroller.GetCurrentBoneTransform(eyes, out eyeYMatrix);
Xcontroller.GetCurrentBoneTransform(eyes, out eyeXMatrix);
eyes.DefaultTransform = eyeYMatrix + eyeXMatrix;


}

Coordinator
Apr 19, 2007 at 6:13 PM
Alright then, I'm not quite sure exactly what you are trying to do. Excuse me for my ignorance, but could you try explaining again?
Apr 19, 2007 at 6:32 PM
No problem, dastle. I'll try again.

What I am trying to do is recreate a blendshape/morphtarget facial setup but with bones. How the blendshapes works is that they are additive. You start off with a neutral pose, like the bind pose. Let's add two shapes, a smile and an open mouth. You can then blend the smile with the neutral pose to make the face smile, but you could also additively add the open mouth shape to open the mouth while smiling. The two shapes affect the same vertices's. But instead of using shapes I want to create 10 frame animations, animating from the bind pose to the extreme of the shape, for some expression; open mouth, smile, frown, wide mouth and narrow mouth. Then hook these animations to sliders/controls so I can mix the different expression together to create wonderful believable animations.

I'll post youtube video in a minute of how the controls works in Maya.

Thanks a million times for you dedication.
Apr 19, 2007 at 6:40 PM
here is the URL to the youtube clip:

http://www.youtube.com/watch?v=Z13MAOKgUPw
Apr 19, 2007 at 7:10 PM
I also uploaded my XNA rig test. Here is the one using the code above:

http://www.youtube.com/watch?v=F_5JBZKyP-A

Here is the same rig using blendfactor instead:

http://www.youtube.com/watch?v=xWKk3l8raek

Here is the code for that:

private void MoveEyes(AnimationController Ycontroller, AnimationController Xcontroller, float thumbstickX, float thumbstickY, ModelAnimator animator)
{

Ycontroller.SpeedFactor = 0;
Xcontroller.SpeedFactor = 0;

thumbstickX += 1;
float eyeX = MathHelper.Lerp(0, Ycontroller.Duration - 1, thumbstickX / 2f);
thumbstickY += 1;
float eyeY = MathHelper.Lerp(0, Xcontroller.Duration - 1, thumbstickY / 2f);
Ycontroller.ElapsedTime = (long)eyeX;
Xcontroller.ElapsedTime = (long)eyeY;

BonePose eyes = animator.BonePoses"rightEye";
eyes.CurrentController = Ycontroller;
eyes.CurrentBlendController = Xcontroller;
eyes.BlendFactor = 0.5f;

eyes = animator.BonePoses"leftEye";
eyes.CurrentController = Ycontroller;
eyes.CurrentBlendController = Xcontroller;
eyes.BlendFactor = 0.5f;



}
Apr 20, 2007 at 4:20 PM
All the Youtube clips are up now and working.
Coordinator
Apr 20, 2007 at 10:36 PM
Ok, I THINK I understand what you are going for.

For the eyes, it looks like the blend shape control is square shaped. Since you are only allowing changes in the duration of the x and y controllers, there are only two degrees of freedom, so you can't achieve what you are going for with a static blend factor.

So, you'll have to do some math to find a function that translates (x,y) on the blendshape square to (time in x controller, time in y controller, blend factor).

Am I correct in this assumption? For example, if you move the eye controller is set to the top left, does that mean the eye is all the way to the left and all the way up? It's a bit confusing to me since the one control that the rig video doesn't show is the eye one, which is the one that you are trying to emulate in your xna vids.
Apr 21, 2007 at 7:48 AM
Your assumption is right. I am testing the eyes because they are easy to setup, compared to the mouth. In the future I won't be using "blendshapes" to drive the eyes. Instead I will rotate the bone manually or create a "look at" constrain.

Why do you think the scale problem appear?

I'll get back to you when I finished rigging the mouth.