Beispiel #1
0
        //this method is called by vvvv when the node is created
        public void SetPluginHost(IPluginHost Host)
        {
            //assign host
            FHost = Host;

            var guids = new System.Guid[1];

            guids[0] = SkeletonNodeIO.GUID;

            //create inputs
            FHost.CreateStringInput("Joint Name", TSliceMode.Single, TPinVisibility.True, out FJointNameInput);
            FHost.CreateTransformInput("Base Transform", TSliceMode.Single, TPinVisibility.True, out FBaseTransformInput);
            String[] dimensions = new String[2];
            dimensions[0] = "Min";
            dimensions[1] = "Max";
            FHost.CreateValueInput("Rotation Constraints", 2, dimensions, TSliceMode.Dynamic, TPinVisibility.True, out FRotationConstraintsInput);
            FRotationConstraintsInput.SetSubType2D(-1.0, 1.0, 0.1, -1.0, 1.0, false, false, false);
            INodeIn node;

            FHost.CreateNodeInput("Child1", TSliceMode.Single, TPinVisibility.True, out node);
            node.SetSubType(guids, "Skeleton");
            FChildPins.Add(node);

            FHost.CreateValueConfig("Children Count", 1, null, TSliceMode.Single, TPinVisibility.OnlyInspector, out FChildrenCountInput);
            FChildrenCountInput.SetSubType(0, 50, 1.0, 1.0, false, false, true);

            // create outputs
            FHost.CreateNodeOutput("Skeleton", TSliceMode.Single, TPinVisibility.True, out FSkeletonOutput);
            FSkeletonOutput.SetSubType(guids, "Skeleton");
            FSkeletonOutput.MarkPinAsChanged();
        }
Beispiel #2
0
        public override void Flush(bool force = false)
        {
            if (force || IsChanged)
            {
                SetLength(Length);
                for (int i = 0; i < Length; i++)
                {
                    var keyboardState         = this.Buffer[i];
                    var previousKeyboardState = FKeyboardStates[i];
                    if (keyboardState != previousKeyboardState)
                    {
                        var subject  = FSubjects[i];
                        var keyDowns = keyboardState.KeyCodes.Except(previousKeyboardState.KeyCodes);
                        foreach (var keyDown in keyDowns)
                        {
                            subject.OnNext(new KeyDownNotification(keyDown));
                        }
                        var keyUps = previousKeyboardState.KeyCodes.Except(keyboardState.KeyCodes);
                        foreach (var keyUp in keyUps)
                        {
                            subject.OnNext(new KeyUpNotification(keyUp));
                        }
                    }
                    FKeyboardStates[i] = keyboardState;
                }

                FNodeOut.SliceCount = Length;
                FNodeOut.MarkPinAsChanged();
            }
            base.Flush(force);
        }
Beispiel #3
0
 public void Evaluate(int SpreadMax)
 {
     if (FInput.SliceCount == 0)
     {
         V1SkeletonOut.SliceCount = 0;
         return;
     }
     if (!FInput.IsChanged && !FCopy.IsChanged)
     {
         return;
     }
     if (!FInput.IsConnected)
     {
         return;
     }
     if (FCopy[0])
     {
         V1SkeletonOut.SetInterface(FInput[0].DeepCopy());
     }
     else
     {
         V1SkeletonOut.SetInterface(FInput[0]);
     }
     V1SkeletonOut.MarkPinAsChanged();
 }
Beispiel #4
0
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            FColladaModel = FColladaModelIn.SliceCount > 0 ? FColladaModelIn[0] : null;
            if (FColladaModel == null)
            {
                return;
            }

            if (FColladaModelIn.IsChanged || FIndex.IsChanged)
            {
                int index = FIndex[0];

                List <Model.SkinnedInstanceMesh> skinnedMeshes = new List <Model.SkinnedInstanceMesh>();
                foreach (Model.InstanceMesh mesh in FColladaModel.InstanceMeshes)
                {
                    if (mesh is Model.SkinnedInstanceMesh)
                    {
                        skinnedMeshes.Add((Model.SkinnedInstanceMesh)mesh);
                    }
                }

                if (skinnedMeshes.Count > 0)
                {
                    if (FSelectedMesh != skinnedMeshes[index % skinnedMeshes.Count])
                    {
                        FSelectedMesh = skinnedMeshes[index % skinnedMeshes.Count];
                    }
                }
                else
                {
                    FSelectedMesh = null;
                }
            }

            if (FSelectedMesh == null)
            {
                return;
            }

            if (FColladaModelIn.IsChanged || FIndex.IsChanged || FTimeInput.IsChanged)
            {
                float time = FTimeInput[0];

                if (FColladaModelIn.IsChanged || FIndex.IsChanged)
                {
                    FSkeleton.ClearAll();
                    CreateSkeleton(FSkeleton, FSelectedMesh.RootBone, FSelectedMesh.Bones);
                }

                foreach (Model.Bone bone in FSelectedMesh.Bones)
                {
                    FSkeleton.JointTable[bone.Name].BaseTransform = bone.GetTransformMatrix(time).ToMatrix4x4();
                }

                FSkeletonOutput.SetInterface(FSkeleton);
                FSkeletonOutput.MarkPinAsChanged();
            }
        }
Beispiel #5
0
 public override void Flush(bool force = false)
 {
     if (force || IsChanged)
     {
         FNodeOut.SliceCount = Length;
         FNodeOut.MarkPinAsChanged();
     }
     base.Flush(force);
 }
Beispiel #6
0
 public override void Flush()
 {
     if (IsChanged)
     {
         FNodeOut.SliceCount = Length;
         FNodeOut.MarkPinAsChanged();
     }
     base.Flush();
 }
        public void Evaluate(int SpreadMax)
        {
            if (this.FInScene.PluginIO.IsConnected)
            {
                this.FSkeletonOutput.SliceCount = 1;

                if (this.FInScene.IsChanged || this.FInRoot.IsChanged)
                {
                    FSkeleton.ClearAll();

                    List <AssimpNode> allnodes = new List <AssimpNode>();
                    this.RecurseNodes(allnodes, this.FInScene[0].RootNode);

                    AssimpNode found = null;
                    foreach (AssimpNode node in allnodes)
                    {
                        if (node.Name == this.FInRoot[0])
                        {
                            found = node;
                        }
                    }

                    if (found != null)
                    {
                        int id = 0;
                        CreateSkeleton(ref FSkeleton, found, "", ref id);
                    }

                    FSkeletonOutput.SetInterface(FSkeleton);
                    FSkeletonOutput.MarkPinAsChanged();
                }
            }
            else
            {
                this.FSkeletonOutput.SliceCount = 0;
            }
        }
Beispiel #8
0
        public override void Flush(bool force = false)
        {
            if (force || IsChanged)
            {
                FSubjects.ResizeAndDispose(Length);
                FMouseStates.ResizeAndDismiss(Length);
                FMouses.ResizeAndDismiss(
                    Length,
                    slice =>
                {
                    var subject = FSubjects[slice];
                    return(new Mouse(subject));
                }
                    );
                for (int i = 0; i < Length; i++)
                {
                    var mouseState         = this.Buffer[i];
                    var previousMouseState = FMouseStates[i];
                    if (mouseState != previousMouseState)
                    {
                        var subject  = FSubjects[i];
                        var v        = new Vector2D(mouseState.X, mouseState.Y);
                        var position = ToMousePoint(v);
                        if (mouseState.X != previousMouseState.X || mouseState.Y != previousMouseState.Y)
                        {
                            subject.OnNext(new MouseMoveNotification(position, FClientArea));
                        }
                        if (mouseState.Buttons != previousMouseState.Buttons)
                        {
                            if (mouseState.IsLeft && !previousMouseState.IsLeft)
                            {
                                subject.OnNext(new MouseDownNotification(position, FClientArea, MouseButtons.Left));
                            }
                            else if (!mouseState.IsLeft && previousMouseState.IsLeft)
                            {
                                subject.OnNext(new MouseUpNotification(position, FClientArea, MouseButtons.Left));
                            }
                            if (mouseState.IsMiddle && !previousMouseState.IsMiddle)
                            {
                                subject.OnNext(new MouseDownNotification(position, FClientArea, MouseButtons.Middle));
                            }
                            else if (!mouseState.IsMiddle && previousMouseState.IsMiddle)
                            {
                                subject.OnNext(new MouseUpNotification(position, FClientArea, MouseButtons.Middle));
                            }
                            if (mouseState.IsRight && !previousMouseState.IsRight)
                            {
                                subject.OnNext(new MouseDownNotification(position, FClientArea, MouseButtons.Right));
                            }
                            else if (!mouseState.IsRight && previousMouseState.IsRight)
                            {
                                subject.OnNext(new MouseUpNotification(position, FClientArea, MouseButtons.Right));
                            }
                            if (mouseState.IsXButton1 && !previousMouseState.IsXButton1)
                            {
                                subject.OnNext(new MouseDownNotification(position, FClientArea, MouseButtons.XButton1));
                            }
                            else if (!mouseState.IsXButton1 && previousMouseState.IsXButton1)
                            {
                                subject.OnNext(new MouseUpNotification(position, FClientArea, MouseButtons.XButton1));
                            }
                            if (mouseState.IsXButton2 && !previousMouseState.IsXButton2)
                            {
                                subject.OnNext(new MouseDownNotification(position, FClientArea, MouseButtons.XButton2));
                            }
                            else if (!mouseState.IsXButton2 && previousMouseState.IsXButton2)
                            {
                                subject.OnNext(new MouseUpNotification(position, FClientArea, MouseButtons.XButton2));
                            }
                        }
                        if (mouseState.MouseWheel != previousMouseState.MouseWheel)
                        {
                            var wheelDelta = previousMouseState.MouseWheel - mouseState.MouseWheel;
                            subject.OnNext(new MouseWheelNotification(position, FClientArea, wheelDelta * Const.WHEEL_DELTA));
                        }
                    }
                    FMouseStates[i] = mouseState;
                }

                FNodeOut.SliceCount = Length;
                FNodeOut.MarkPinAsChanged();
            }
            base.Flush(force);
        }
Beispiel #9
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            bool recalculate = false;

            if (FInput.PinIsChanged)
            {
                FInput.GetValue(0, out input);
                recalculate = true;
            }

            object currInterface;

            for (int i = 0; i < FPoseNodes.Count; i++)
            {
                if (FPoseNodes[i].PinIsChanged)
                {
                    if (FPoseNodes[i].IsConnected)
                    {
                        FPoseNodes[i].GetUpstreamInterface(out currInterface);
                        IJoint currPose = ((Skeleton)currInterface).Root;
                        FPoses[i] = currPose;
                    }
                    else
                    {
                        FPoses[i] = null;
                        if (i == 0)
                        {
                            FOutputJoint = null;
                        }
                    }
                    recalculate = true;
                }
            }

            if (recalculate)
            {
                int    index1  = (int)Math.Floor(input);
                int    index2  = (int)Math.Min(Math.Ceiling(input), poseCount - 1);
                double amount2 = input - index1;
                double amount1 = (input - index2) * -1;

                if (amount2 == 0)
                {
                    FOutputJoint = FPoses[index1];
                    if (passthrough != index1)
                    {
                        FSkeleton.Root = FOutputJoint;
                        FSkeleton.BuildJointTable();
                    }
                    passthrough = index1;
                }
                else if (amount1 == 0)
                {
                    FOutputJoint = FPoses[index2];
                    if (passthrough != -1)
                    {
                        FSkeleton.Root = FOutputJoint;
                        FSkeleton.BuildJointTable();
                    }
                    passthrough = index2;
                }
                else
                {
                    if (FOutputJoint == null || passthrough >= 0)
                    {
                        FOutputJoint   = FPoses[index1].DeepCopy();
                        FSkeleton.Root = FOutputJoint;
                        FSkeleton.BuildJointTable();
                    }
                    else
                    {
                        copyAttributes(FPoses[index1], FOutputJoint);
                    }
                    mixJoints(FOutputJoint, FPoses[index1], amount1, FPoses[index2], amount2);
                    passthrough = -1;
                }

                FSkeleton.Root = FOutputJoint;
                FPoseOutput.MarkPinAsChanged();
            }

            FPoseOutput.SetInterface(FSkeleton);
        }
Beispiel #10
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FFileNameIn.IsChanged)
            {
                if (FFileNameIn[0].EndsWith(".bvh"))
                {
                    FSkeleton = null;

                    //load BVH file
                    if (FBVHLoader.Load(FFileNameIn[0]))
                    {
                        //set frame count and second per frame
                        FFramesOut.SliceCount    = 1;
                        FFrameTimeOut.SliceCount = 1;
                        FFramesOut[0]            = FBVHLoader.FrameCount;
                        FFrameTimeOut[0]         = FBVHLoader.FrameTime;

                        //set Skeleton Output
                        FSkeleton = FBVHLoader.Skeleton;
                        FSkeletonOutput.SliceCount = 1;
                        FSkeletonOutput.SetInterface(FSkeleton);
                        FSkeletonOutput.MarkPinAsChanged();
                    }
                    else
                    {
                        //reset frame count and second per frame
                        FFramesOut.SliceCount    = 0;
                        FFrameTimeOut.SliceCount = 0;

                        //reset Skeleton Output
                        FSkeletonOutput.SliceCount = 0;
                        FSkeletonOutput.MarkPinAsChanged();

                        FLogger.Log(LogType.Debug, "BVH load error");
                    }
                }
                else
                {
                    FSkeleton = null;

                    FBVHLoader.Unload();

                    //reset frame count and second per frame
                    FFramesOut.SliceCount    = 0;
                    FFrameTimeOut.SliceCount = 0;

                    //reset Skeleton Output
                    FSkeletonOutput.SliceCount = 0;
                    FSkeletonOutput.MarkPinAsChanged();
                }
            }

            if (FFrameIn.IsChanged)
            {
                if (FSkeleton != null)
                {
                    //update Skeleton (be sure frame ID <= frame count)
                    FBVHLoader.UpdateSkeleton(FFrameIn[0] % FBVHLoader.FrameCount);

                    //set Skeleton Output
                    FSkeleton = FBVHLoader.Skeleton;
                    FSkeletonOutput.SetInterface(FSkeleton);
                    FSkeletonOutput.MarkPinAsChanged();
                }
            }

            //FLogger.Log(LogType.Debug, "Logging to Renderer (TTY)");
        }
Beispiel #11
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs


            bool   recalculate = false;
            object currInterface;

            for (int i = 0; i < poseNodes.Count; i++)
            {
                if (poseNodes[i].PinIsChanged)
                {
                    if (poseNodes[i].IsConnected)
                    {
                        poseNodes[i].GetUpstreamInterface(out currInterface);
                        IJoint currPose = ((Skeleton)currInterface).Root;
                        poses[i] = currPose;
                    }
                    else
                    {
                        poses[i] = null;
                        if (i == 0)
                        {
                            outputJoint = null;
                        }
                    }
                    recalculate = true;
                }
                if (amountNodes[i].PinIsChanged)
                {
                    double amount;
                    amountNodes[i].GetValue(0, out amount);
                    amounts[i]  = amount;
                    recalculate = true;
                }
            }


            if (recalculate)
            {
                // the following would be much nicer, if mixJoints() would take a dynamic number of poses and amounts
                if (outputJoint == null)
                {
                    outputJoint         = poses[0].DeepCopy();
                    outputSkeleton.Root = outputJoint;
                    outputSkeleton.BuildJointTable();
                }
                else
                {
                    copyAttributes(poses[0], outputJoint);
                }
                double amount = amounts[0];
                IJoint interimPose;
                for (int i = 0; i < poses.Count - 1; i++)
                {
                    if (poses[i + 1] == null)
                    {
                        continue;
                    }
                    interimPose = outputJoint;
                    mixJoints(outputJoint, interimPose, amount, poses[i + 1], amounts[i + 1]);
                    amount = 1.0;
                }
                outputSkeleton.Root = outputJoint;
                FPoseOutput.MarkPinAsChanged();
            }


            FPoseOutput.SetInterface(outputSkeleton);
        }
Beispiel #12
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs

            bool recalculate = false;


            if (FJointNameInput.PinIsChanged)
            {
                jointNames = new List <string>();
                string jointName;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    FJointNameInput.GetString(i, out jointName);
                    jointNames.Add(jointName);
                }
                recalculate = true;
            }

            if (FSkeletonInput.PinIsChanged || recalculate)
            {
                if (FSkeletonInput.IsConnected)
                {
                    object currInterface;
                    FSkeletonInput.GetUpstreamInterface(out currInterface);
                    s = (Skeleton)currInterface;
                    if (inputSkeleton == null || !s.Uid.Equals(inputSkeleton.Uid))
                    {
                        inputSkeleton = (Skeleton)s.DeepCopy();
                    }
                    else
                    {
                        foreach (KeyValuePair <string, IJoint> pair in s.JointTable)
                        {
                            if (!jointNames.Exists(delegate(string name) { return(name == pair.Key); }))
                            {
                                inputSkeleton.JointTable[pair.Key].BaseTransform      = pair.Value.BaseTransform;
                                inputSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform;
                            }
                            inputSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints;
                        }
                    }
                }
                else
                {
                    inputSkeleton = null;
                }
            }

            if (FSkeletonInput.PinIsChanged || FAnimationTransformInput.PinIsChanged || FBaseTransformInput.PinIsChanged || FParentNameInput.PinIsChanged || FConstraintsInput.PinIsChanged || recalculate)
            {
                if (inputSkeleton != null)
                {
                    IJoint currJoint;
                    for (int i = 0; i < jointNames.Count; i++)
                    {
                        currJoint = inputSkeleton.JointTable[jointNames[i]];
                        Matrix4x4 currAnimationT;
                        Matrix4x4 currBaseT;
                        string    currParentName;
                        if (currJoint != null)
                        {
                            if (FAnimationTransformInput.IsConnected)
                            {
                                FAnimationTransformInput.GetMatrix(i, out currAnimationT);
                                currJoint.AnimationTransform = currAnimationT;
                            }
                            else
                            {
                                currJoint.AnimationTransform = s.JointTable[currJoint.Name].AnimationTransform;
                            }

                            if (FBaseTransformInput.IsConnected)
                            {
                                FBaseTransformInput.GetMatrix(i, out currBaseT);
                                currJoint.BaseTransform = currBaseT;
                            }
                            else
                            {
                                currJoint.BaseTransform = s.JointTable[currJoint.Name].BaseTransform;
                            }

                            /*if (FRotationInput.IsConnected)
                             * {
                             *      currRotation = new Vector3D(0);
                             *      FRotationInput.GetValue3D(i, out currRotation.x, out currRotation.y, out currRotation.z);
                             *      //currJoint.Rotation = currRotation;
                             *
                             * }
                             */

                            /*if (FConstraintsInput.IsConnected)
                             * {
                             *      currConstraints = new List<Vector2D>();
                             *      Vector2D currConstraint;
                             *      for (int j=0; j<3; j++)
                             *      {
                             *              currConstraint = new Vector2D(0);
                             *              FConstraintsInput.GetValue2D(i*3, out currConstraint.x, out currConstraint.y);
                             *              currConstraints.Add(currConstraint);
                             *      }
                             *      currJoint.Constraints = currConstraints;
                             * }
                             */

                            FParentNameInput.GetString(i, out currParentName);
                            if (currParentName != null && (FParentNameInput.SliceCount > 1 || !string.IsNullOrEmpty(currParentName)))
                            {
                                IJoint parent = inputSkeleton.JointTable[currParentName];
                                if (parent != null)
                                {
                                    currJoint.Parent = parent;
                                }
                            }
                        }
                    }
                }

                FSkeletonOutput.MarkPinAsChanged();
            }

            FSkeletonOutput.SetInterface(inputSkeleton);
        }
Beispiel #13
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            bool recalculate            = false;
            bool chainRangeChanged      = false;
            bool recalculateOrientation = false;

            if (FChainStart.PinIsChanged)
            {
                FChainStart.GetString(0, out chainStart);
                recalculate       = true;
                chainRangeChanged = true;
            }

            if (FChainEnd.PinIsChanged)
            {
                FChainEnd.GetString(0, out chainEnd);
                recalculate       = true;
                chainRangeChanged = true;
            }

            object currInterface;

            if (FPoseInput.PinIsChanged || chainRangeChanged)
            {
                if (FPoseInput.IsConnected)
                {
                    FPoseInput.GetUpstreamInterface(out currInterface);
                    Skeleton s = (Skeleton)currInterface;
                    if (outputSkeleton == null || !s.Uid.Equals(outputSkeleton.Uid))
                    {
                        outputSkeleton = (Skeleton)((Skeleton)currInterface).DeepCopy();
                        outputSkeleton.BuildJointTable();
                        workingSkeleton = (Skeleton)outputSkeleton.DeepCopy();
                        workingSkeleton.BuildJointTable();
                        chainRangeChanged = true;
                    }
                    else
                    {
                        foreach (KeyValuePair <string, IJoint> pair in s.JointTable)
                        {
                            if (!jointChain.Exists(delegate(IJoint j) { return(j.Name == pair.Key); }))
                            {
                                outputSkeleton.JointTable[pair.Key].BaseTransform       = pair.Value.BaseTransform;
                                outputSkeleton.JointTable[pair.Key].AnimationTransform  = pair.Value.AnimationTransform;
                                workingSkeleton.JointTable[pair.Key].BaseTransform      = pair.Value.BaseTransform;
                                workingSkeleton.JointTable[pair.Key].AnimationTransform = pair.Value.AnimationTransform;
                            }
                            outputSkeleton.JointTable[pair.Key].Constraints  = pair.Value.Constraints;
                            workingSkeleton.JointTable[pair.Key].Constraints = pair.Value.Constraints;
                        }
                    }
                    workingSkeleton.CalculateCombinedTransforms();
                    recalculate = true;
                }
                else
                {
                    outputSkeleton = null;
                }
            }

            if (FVelocityInput.PinIsChanged)
            {
                double x;
                FVelocityInput.GetValue(0, out x);
                iterationsPerFrame = (int)(x * 10);
            }

            if (iterationsPerFrame > 0)
            {
                if (FTargetInput.PinIsChanged)
                {
                    targetPosW = new Vector3D();
                    FTargetInput.GetValue3D(0, out targetPosW.x, out targetPosW.y, out targetPosW.z);
                    recalculate = true;
                }

                if (FEpsilonInput.PinIsChanged)
                {
                    FEpsilonInput.GetValue(0, out epsilon);
                    recalculate = true;
                }

                if (FPoleTargetInput.PinIsChanged || FEnablePoleTargetInput.PinIsChanged)
                {
                    double x;
                    FEnablePoleTargetInput.GetValue(0, out x);
                    enablePoleTarget = x > 0.0;
                    poleTargetW      = new Vector3D();
                    FPoleTargetInput.GetValue3D(0, out poleTargetW.x, out poleTargetW.y, out poleTargetW.z);
                    recalculateOrientation = true;
                }

                if (chainRangeChanged && outputSkeleton != null)
                {
                    initRotations();
                }

                double delta = VMath.Dist(endPosW, targetPosW);
                if ((delta > epsilon || recalculate) && outputSkeleton != null && !string.IsNullOrEmpty(chainStart) && !string.IsNullOrEmpty(chainEnd))
                {
                    List <Vector2D> constraints = new List <Vector2D>();
                    for (int i = 0; i < iterationsPerFrame; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            IJoint currJoint = workingSkeleton.JointTable[chainEnd];
                            endPosW = currJoint.CombinedTransform * new Vector3D(0);
                            while (currJoint.Name != chainStart)
                            {
                                currJoint = currJoint.Parent;
                                Vector3D rotationAxis = new Vector3D(0, 0, 0);
                                rotationAxis[j] = 1;
                                double   torque = calculateTorque(currJoint, rotationAxis);
                                Vector3D rot    = rotations[currJoint.Name];
                                if ((rot[j] + torque) < currJoint.Constraints[j].x * 2 * Math.PI || (rot[j] + torque) > currJoint.Constraints[j].y * 2 * Math.PI)
                                {
                                    torque = 0;
                                }
                                Matrix4x4 newTransform = VMath.Rotate(torque * rotationAxis.x, torque * rotationAxis.y, torque * rotationAxis.z) * currJoint.AnimationTransform;
                                Vector3D  testVec      = newTransform * new Vector3D(0);
                                if (!Double.IsInfinity(testVec.x) && !Double.IsNaN(testVec.x))                         // an evil bug fix, to avoid n.def. values in animation transform matrix. the actual reason, why this would happen has not been found yet.
                                {
                                    rot[j] += torque;
                                    rotations[currJoint.Name]    = rot;
                                    currJoint.AnimationTransform = newTransform;
                                    outputSkeleton.JointTable[currJoint.Name].AnimationTransform = currJoint.AnimationTransform;
                                }
                            }
                        }
                        try
                        {
                            Matrix4x4 pre;
                            if (workingSkeleton.JointTable[chainStart].Parent != null)
                            {
                                pre = workingSkeleton.JointTable[chainStart].Parent.CombinedTransform;
                            }
                            else
                            {
                                pre = VMath.IdentityMatrix;
                            }
                            ((JointInfo)workingSkeleton.JointTable[chainStart]).CalculateCombinedTransforms(pre);
                        }
                        catch (Exception)
                        {
                            workingSkeleton.CalculateCombinedTransforms();
                        }
                    }


                    FPoseOutput.MarkPinAsChanged();
                }

                if ((recalculate || recalculateOrientation) && enablePoleTarget && outputSkeleton != null && !string.IsNullOrEmpty(chainStart) && !string.IsNullOrEmpty(chainEnd))
                {
                    endPosW = workingSkeleton.JointTable[chainEnd].CombinedTransform * new Vector3D(0);
                    Vector3D poleTargetLocal = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * poleTargetW;
                    Vector3D t = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * endPosW;                                                                                  // endpoint in local coords
                    Vector3D a = VMath.Inverse(workingSkeleton.JointTable[chainStart].CombinedTransform) * (workingSkeleton.JointTable[chainStart].Children[0].CombinedTransform * new Vector3D(0)); // next child in local coords
                    Vector3D x = t * ((a.x * t.x + a.y * t.y + a.z * t.z) / Math.Pow(VMath.Dist(new Vector3D(0), t), 2));
                    Vector3D y = t * ((poleTargetLocal.x * t.x + poleTargetLocal.y * t.y + poleTargetLocal.z * t.z) / Math.Pow(VMath.Dist(new Vector3D(0), t), 2));

                    Vector3D c     = poleTargetLocal - y;
                    Vector3D b     = a - x;
                    double   angle = vectorAngle(b, c);
                    Vector3D n     = new Vector3D();
                    n.x = c.y * b.z - c.z * b.y;
                    n.y = c.z * b.x - c.x * b.z;
                    n.z = c.x * b.y - c.y * b.x;
                    n   = n / VMath.Dist(new Vector3D(0), n);
                    FDebugOutput.SetValue(0, angle);
                    chainRotation = RotateAroundAxis(angle, n);

                    FPoseOutput.MarkPinAsChanged();
                }
                if (!enablePoleTarget)
                {
                    chainRotation = VMath.IdentityMatrix;
                }

                outputSkeleton.JointTable[chainStart].AnimationTransform = chainRotation * outputSkeleton.JointTable[chainStart].AnimationTransform;
            }

            FPoseOutput.SetInterface(outputSkeleton);
        }
Beispiel #14
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs

            bool recalculate = false;

            if (FJointNameInput.PinIsChanged || FBaseTransformInput.PinIsChanged || FOffsetModeInput.PinIsChanged || FParentNameInput.PinIsChanged || FConstraintsInput.PinIsChanged || recalculate)
            {
                skeleton = new Skeleton();

                int currId = 0;
                for (int i = 0; i < FJointNameInput.SliceCount; i++)
                {
                    string jointName;
                    string parentName;
                    FJointNameInput.GetString(i % FJointNameInput.SliceCount, out jointName);
                    FParentNameInput.GetString(i % FParentNameInput.SliceCount, out parentName);
                    IJoint    currJoint = new JointInfo(jointName);
                    Matrix4x4 baseTransform;
                    FBaseTransformInput.GetMatrix(i % FBaseTransformInput.SliceCount, out baseTransform);
                    currJoint.BaseTransform = baseTransform;             //VMath.Translate(basePositionX, basePositionY, basePositionZ);
                    currJoint.Constraints.Clear();
                    for (int j = i * 3; j < i * 3 + 3; j++)
                    {
                        double constraintMin, constraintMax;
                        FConstraintsInput.GetValue2D(j % FConstraintsInput.SliceCount, out constraintMin, out constraintMax);
                        currJoint.Constraints.Add(new Vector2D(constraintMin, constraintMax));
                    }
                    if (string.IsNullOrEmpty(parentName))
                    {
                        if (skeleton.Root == null)
                        {
                            skeleton.Root = currJoint;
                            currJoint.Id  = currId;
                            currId++;
                            skeleton.BuildJointTable();
                        }
                    }
                    else
                    {
                        if (skeleton.JointTable.ContainsKey(parentName))
                        {
                            currJoint.Parent = skeleton.JointTable[parentName];
                            currJoint.Id     = currId;
                            currId++;
                        }
                        skeleton.BuildJointTable();
                    }
                }

                int positionInWorldSpace = 0;
                FOffsetModeInput.GetOrd(0, out positionInWorldSpace);
                if (positionInWorldSpace > 0)
                {
                    List <Vector3D> offsetList = new List <Vector3D>();
                    foreach (KeyValuePair <string, IJoint> pair in skeleton.JointTable)
                    {
                        Vector3D worldPos = pair.Value.BaseTransform * (new Vector3D(0));
                        Vector3D parentWorldPos;
                        if (pair.Value.Parent != null)
                        {
                            parentWorldPos = pair.Value.Parent.BaseTransform * (new Vector3D(0));
                        }
                        else
                        {
                            parentWorldPos = new Vector3D(0);
                        }
                        Vector3D offset = worldPos - parentWorldPos;
                        offsetList.Add(offset);
                    }
                    int i = 0;
                    foreach (KeyValuePair <string, IJoint> pair in skeleton.JointTable)
                    {
                        pair.Value.BaseTransform = VMath.Translate(offsetList[i]);
                        i++;
                    }
                }


                FSkeletonOutput.MarkPinAsChanged();
            }

            FSkeletonOutput.SetInterface(skeleton);
        }