Exemplo n.º 1
0
        private void mixJoints(IJoint result, IJoint joint1, double amount1, IJoint joint2, double amount2)
        {
            double   enableJoint1 = 1.0;
            double   enableJoint2 = 1.0;
            Vector3D p;

            p = joint1.AnimationTransform * new Vector3D(1, 1, 1);     // check, if AnimationTransform is Identity Matrix... for the lazy ones...
            if (p.x == 1 && p.y == 1 && p.z == 1)
            {
                enableJoint1 = 0;
            }
            p = joint2.AnimationTransform * new Vector3D(1, 1, 1);
            if (p.x == 1 && p.y == 1 && p.z == 1)
            {
                enableJoint2 = 0;
            }

            Matrix4x4 resultAnimationT = result.AnimationTransform;

            Matrix4x4Utils.Blend(joint1.AnimationTransform, joint2.AnimationTransform, amount1 * enableJoint1, amount2 * enableJoint2, out resultAnimationT);

            result.AnimationTransform = resultAnimationT;

            for (int i = 0; i < result.Children.Count; i++)
            {
                mixJoints(result.Children[i], joint1.Children[i], amount1, joint2.Children[i], amount2);
            }
        }
Exemplo n.º 2
0
        public void Evaluate(int SpreadMax)
        {
            if (Pins.InputPins.Count == 0 || Pins.InputSpreadMin == 0)
            {
                FOut.SliceCount = 0;
                return;
            }
            if (Pins.InputPins.Values.Any(pin => pin.Spread[0] == null))
            {
                return;
            }
            if (Pins.InputChanged)
            {
                FOut.Stream.IsChanged = true;
                var currposecount = Pins.InputPins.Count / 2;
                for (int i = 0; i < FOut.SliceCount; i++)
                {
                    if (FOut[i] == null)
                    {
                        FOut[i] = new Skeleton();
                    }
                    else
                    {
                        ((ISkeleton)Pins.InputPins["Pose 0"].Spread[i]).CopyData(FOut[i]);
                    }
                    var outSkeleton = FOut[i];
                    var outAmount   = (double)Pins.InputPins["Amount 0"].Spread[i];
                    var outAmDiv    = 1;
                    for (int j = 1; j < currposecount; j++)
                    {
                        var currSkeleton = (ISkeleton)Pins.InputPins[$"Pose {j}"].Spread[i];
                        var currAmount   = (double)Pins.InputPins[$"Amount {j}"].Spread[i];
                        foreach (var joint in outSkeleton.JointTable.Keys)
                        {
                            if (!currSkeleton.JointTable.ContainsKey(joint))
                            {
                                continue;
                            }

                            Matrix4x4 result;
                            if (!FAnimOnly[0])
                            {
                                var currBase = currSkeleton.JointTable[joint].BaseTransform;
                                var outBase  = outSkeleton.JointTable[joint].BaseTransform;
                                Matrix4x4Utils.Blend(outBase, currBase, outAmount / outAmDiv, currAmount, out result);
                                outSkeleton.JointTable[joint].BaseTransform = result;
                            }

                            var currAnim = currSkeleton.JointTable[joint].AnimationTransform;
                            var outAnim  = outSkeleton.JointTable[joint].AnimationTransform;
                            Matrix4x4Utils.Blend(outAnim, currAnim, outAmount / outAmDiv, currAmount, out result);
                            outSkeleton.JointTable[joint].AnimationTransform = result;
                        }
                        outAmount += currAmount;
                        outAmDiv++;
                    }
                }
            }
            else
            {
                FOut.Stream.IsChanged = false;
            }
        }