Exemplo n.º 1
0
    // Token: 0x06000E22 RID: 3618 RVA: 0x000362C8 File Offset: 0x000344C8
    public static void RecursiveLinkTransformsByName(Transform ragdoll, Transform body)
    {
        BoneStructure component = body.GetComponent <BoneStructure>();

        if (component)
        {
            BoneStructure component2 = ragdoll.GetComponent <BoneStructure>();
            if (component2)
            {
                using (BoneStructure.ParentDownOrdered.Enumerator enumerator = component.parentDown.GetEnumerator())
                {
                    using (BoneStructure.ParentDownOrdered.Enumerator enumerator2 = component2.parentDown.GetEnumerator())
                    {
                        while (enumerator.MoveNext() && enumerator2.MoveNext())
                        {
                            Transform transform  = enumerator.Current;
                            Transform transform2 = enumerator2.Current;
                            transform2.position = transform.position;
                            transform2.rotation = transform.rotation;
                        }
                    }
                }
                return;
            }
        }
        global::RagdollHelper._RecursiveLinkTransformsByName(ragdoll, body);
    }
Exemplo n.º 2
0
    public static void RecursiveLinkTransformsByName(Transform ragdoll, Transform body)
    {
        BoneStructure component = body.GetComponent <BoneStructure>();

        if (component != null)
        {
            BoneStructure structure2 = ragdoll.GetComponent <BoneStructure>();
            if (structure2 != null)
            {
                using (BoneStructure.ParentDownOrdered.Enumerator enumerator = component.parentDown.GetEnumerator())
                {
                    using (BoneStructure.ParentDownOrdered.Enumerator enumerator2 = structure2.parentDown.GetEnumerator())
                    {
                        while (enumerator.MoveNext() && enumerator2.MoveNext())
                        {
                            Transform current    = enumerator.Current;
                            Transform transform2 = enumerator2.Current;
                            transform2.position = current.position;
                            transform2.rotation = current.rotation;
                        }
                    }
                }
                return;
            }
        }
        _RecursiveLinkTransformsByName(ragdoll, body);
    }
Exemplo n.º 3
0
    // Token: 0x06000E23 RID: 3619 RVA: 0x000363C4 File Offset: 0x000345C4
    public static bool RecursiveLinkTransformsByName(Transform ragdoll, Transform body, Transform bodyMatchTransform, out Transform ragdollMatchTransform)
    {
        if (!bodyMatchTransform)
        {
            ragdollMatchTransform = null;
            global::RagdollHelper.RecursiveLinkTransformsByName(ragdoll, body);
            return(false);
        }
        if (body == bodyMatchTransform)
        {
            ragdollMatchTransform = ragdoll;
            global::RagdollHelper.RecursiveLinkTransformsByName(ragdoll, body);
            return(true);
        }
        BoneStructure component = body.GetComponent <BoneStructure>();

        if (component)
        {
            BoneStructure component2 = ragdoll.GetComponent <BoneStructure>();
            if (component2)
            {
                using (BoneStructure.ParentDownOrdered.Enumerator enumerator = component.parentDown.GetEnumerator())
                {
                    using (BoneStructure.ParentDownOrdered.Enumerator enumerator2 = component2.parentDown.GetEnumerator())
                    {
                        while (enumerator.MoveNext() && enumerator2.MoveNext())
                        {
                            Transform transform  = enumerator.Current;
                            Transform transform2 = enumerator2.Current;
                            transform2.position = transform.position;
                            transform2.rotation = transform.rotation;
                            if (transform == bodyMatchTransform)
                            {
                                ragdollMatchTransform = transform2;
                                while (enumerator.MoveNext() && enumerator2.MoveNext())
                                {
                                    transform           = enumerator.Current;
                                    transform2          = enumerator2.Current;
                                    transform2.position = transform.position;
                                    transform2.rotation = transform.rotation;
                                }
                                return(true);
                            }
                        }
                    }
                }
                ragdollMatchTransform = null;
                return(false);
            }
        }
        bool result = false;

        ragdollMatchTransform = null;
        global::RagdollHelper._RecursiveLinkTransformsByName(ragdoll, body, bodyMatchTransform, ref ragdollMatchTransform, ref result);
        return(result);
    }
Exemplo n.º 4
0
    public static bool RecursiveLinkTransformsByName(Transform ragdoll, Transform body, Transform bodyMatchTransform, out Transform ragdollMatchTransform)
    {
        if (bodyMatchTransform == null)
        {
            ragdollMatchTransform = null;
            RecursiveLinkTransformsByName(ragdoll, body);
            return(false);
        }
        if (body == bodyMatchTransform)
        {
            ragdollMatchTransform = ragdoll;
            RecursiveLinkTransformsByName(ragdoll, body);
            return(true);
        }
        BoneStructure component = body.GetComponent <BoneStructure>();

        if (component != null)
        {
            BoneStructure structure2 = ragdoll.GetComponent <BoneStructure>();
            if (structure2 != null)
            {
                using (BoneStructure.ParentDownOrdered.Enumerator enumerator = component.parentDown.GetEnumerator())
                {
                    using (BoneStructure.ParentDownOrdered.Enumerator enumerator2 = structure2.parentDown.GetEnumerator())
                    {
                        while (enumerator.MoveNext() && enumerator2.MoveNext())
                        {
                            Transform current    = enumerator.Current;
                            Transform transform2 = enumerator2.Current;
                            transform2.position = current.position;
                            transform2.rotation = current.rotation;
                            if (current == bodyMatchTransform)
                            {
                                ragdollMatchTransform = transform2;
                                while (enumerator.MoveNext() && enumerator2.MoveNext())
                                {
                                    current             = enumerator.Current;
                                    transform2          = enumerator2.Current;
                                    transform2.position = current.position;
                                    transform2.rotation = current.rotation;
                                }
                                return(true);
                            }
                        }
                    }
                }
                ragdollMatchTransform = null;
                return(false);
            }
        }
        bool foundMatch = false;

        ragdollMatchTransform = null;
        _RecursiveLinkTransformsByName(ragdoll, body, bodyMatchTransform, ref ragdollMatchTransform, ref foundMatch);
        return(foundMatch);
    }
Exemplo n.º 5
0
    public static void RecursiveLinkTransformsByName(Transform ragdoll, Transform body)
    {
        BoneStructure component = body.GetComponent <BoneStructure>();

        if (component)
        {
            BoneStructure boneStructures = ragdoll.GetComponent <BoneStructure>();
            if (boneStructures)
            {
                BoneStructure.ParentDownOrdered.Enumerator enumerator = component.parentDown.GetEnumerator();
                try
                {
                    BoneStructure.ParentDownOrdered.Enumerator enumerator1 = boneStructures.parentDown.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext() && enumerator1.MoveNext())
                        {
                            Transform current    = enumerator.Current;
                            Transform transforms = enumerator1.Current;
                            transforms.position = current.position;
                            transforms.rotation = current.rotation;
                        }
                    }
                    finally
                    {
                        ((IDisposable)(object)enumerator1).Dispose();
                    }
                }
                finally
                {
                    ((IDisposable)(object)enumerator).Dispose();
                }
                return;
            }
        }
        RagdollHelper._RecursiveLinkTransformsByName(ragdoll, body);
    }
Exemplo n.º 6
0
    public static bool RecursiveLinkTransformsByName(Transform ragdoll, Transform body, Transform bodyMatchTransform, out Transform ragdollMatchTransform)
    {
        bool flag;

        if (!bodyMatchTransform)
        {
            ragdollMatchTransform = null;
            RagdollHelper.RecursiveLinkTransformsByName(ragdoll, body);
            return(false);
        }
        if (body == bodyMatchTransform)
        {
            ragdollMatchTransform = ragdoll;
            RagdollHelper.RecursiveLinkTransformsByName(ragdoll, body);
            return(true);
        }
        BoneStructure component = body.GetComponent <BoneStructure>();

        if (component)
        {
            BoneStructure boneStructures = ragdoll.GetComponent <BoneStructure>();
            if (boneStructures)
            {
                BoneStructure.ParentDownOrdered.Enumerator enumerator = component.parentDown.GetEnumerator();
                try
                {
                    BoneStructure.ParentDownOrdered.Enumerator enumerator1 = boneStructures.parentDown.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext() && enumerator1.MoveNext())
                        {
                            Transform current    = enumerator.Current;
                            Transform transforms = enumerator1.Current;
                            transforms.position = current.position;
                            transforms.rotation = current.rotation;
                            if (current != bodyMatchTransform)
                            {
                                continue;
                            }
                            ragdollMatchTransform = transforms;
                            while (enumerator.MoveNext() && enumerator1.MoveNext())
                            {
                                current             = enumerator.Current;
                                transforms          = enumerator1.Current;
                                transforms.position = current.position;
                                transforms.rotation = current.rotation;
                            }
                            flag = true;
                            return(flag);
                        }
                    }
                    finally
                    {
                        ((IDisposable)(object)enumerator1).Dispose();
                    }
                    ragdollMatchTransform = null;
                    return(false);
                }
                finally
                {
                    ((IDisposable)(object)enumerator).Dispose();
                }
                return(flag);
            }
        }
        bool flag1 = false;

        ragdollMatchTransform = null;
        RagdollHelper._RecursiveLinkTransformsByName(ragdoll, body, bodyMatchTransform, ref ragdollMatchTransform, ref flag1);
        return(flag1);
    }
Exemplo n.º 7
0
        public static void IKStep(ref BoneStructure boneStructure)
        {
            if (boneStructure.target == null)
            {
                Debug.LogError($"No Target Assigned For IKSystem on {boneStructure.boneNodes[boneStructure.boneNodes.Count - 1].node.name}");
                return;
            }

            //FABIK START

            //Store infomation in local vars for quicker access
            List <Vector3> nodePositions = new List <Vector3>();

            for (int i = 0; i < boneStructure.boneNodes.Count; i++)
            {
                nodePositions.Add(Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.boneNodes[i].nodeTransform.position - boneStructure.rootNode.position));
            }

            Vector3    targetPosition = Vector3.zero;
            Quaternion targetRotation = Quaternion.identity;

            //No movespeed specified
            if (boneStructure.nodeMoveSpeed < 0.0f)
            {
                targetPosition = (Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.target.position - boneStructure.rootNode.position));
                targetRotation = (Quaternion.Inverse(boneStructure.target.rotation) * boneStructure.rootNode.rotation);
            }
            //Move slower towards target
            else if (boneStructure.moveType == BoneStructure.MoveType.LINEAR)
            {
                targetPosition = (Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.target.position - boneStructure.rootNode.position));
                targetPosition = Vector3.MoveTowards(nodePositions[nodePositions.Count - 1], targetPosition, boneStructure.nodeMoveSpeed * Time.deltaTime);
                targetRotation = (Quaternion.Inverse(boneStructure.target.rotation) * boneStructure.rootNode.rotation);
                targetRotation = Quaternion.RotateTowards(boneStructure.boneNodes[boneStructure.boneNodes.Count - 1].nodeTransform.rotation, targetRotation, boneStructure.rotMoveSpeed * Time.deltaTime);
            }
            //Move along a graph
            else if (boneStructure.moveType == BoneStructure.MoveType.CUSTOM)
            {
                targetPosition = (Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.target.position - boneStructure.rootNode.position));
                targetPosition = Vector3.MoveTowards(nodePositions[nodePositions.Count - 1], targetPosition, boneStructure.nodeMoveSpeed * boneStructure.moveCurve.Evaluate(Vector3.Distance(nodePositions[nodePositions.Count - 1], targetPosition)) * Time.deltaTime);
                targetRotation = (Quaternion.Inverse(boneStructure.target.rotation) * boneStructure.rootNode.rotation);
                targetRotation = Quaternion.RotateTowards(boneStructure.boneNodes[boneStructure.boneNodes.Count - 1].nodeTransform.rotation, targetRotation, boneStructure.rotMoveSpeed * boneStructure.rotCurve.Evaluate(Vector3.Distance(nodePositions[nodePositions.Count - 1], targetPosition)) * Time.deltaTime);
            }
            //Fail safe
            else
            {
                Debug.LogError($"No behaviour set up for moveType {boneStructure.moveType} defaulting to no moveType behaviour");
                targetPosition = (Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.target.position - boneStructure.rootNode.position));
                targetRotation = (Quaternion.Inverse(boneStructure.target.rotation) * boneStructure.rootNode.rotation);
            }

            //Is the target further than we can reach?
            if ((targetPosition - (Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.boneNodes[0].nodeTransform.position - boneStructure.rootNode.position))).sqrMagnitude >= boneStructure.totalChainDistanceSquared)
            {
                //Go along a direction vector
                Vector3 dir = (targetPosition - nodePositions[0]).normalized;

                //Assign positions along vector, skip root
                for (int i = 1; i < nodePositions.Count; i++)
                {
                    nodePositions[i] = nodePositions[i - 1] + dir * boneStructure.boneNodes[i - 1].initalDistanceToChild;
                }
            }
            //If the target is within our range
            else
            {
                //For the amount of iterations
                for (int i = 0; i < boneStructure.maxSolveIterations; i++)
                {
                    //Backwards check (starts from leaf and goes to root) we can ignore moving the root bone so that it stays unaffected
                    for (int j = nodePositions.Count - 1; j > 0; j--)
                    {
                        //if leaf node
                        if (j == nodePositions.Count - 1)
                        {
                            //Set on top of target
                            nodePositions[j] = targetPosition;
                        }
                        //Look at child node and move towards it according to our distance
                        else
                        {
                            //Move node onto a direction line from it's child node with the distance being the same as it's inital distance from the child
                            nodePositions[j] = nodePositions[j + 1] + (nodePositions[j] - nodePositions[j + 1]).normalized * boneStructure.boneNodes[j].initalDistanceToChild;
                        }
                    }

                    //Forwards check (starts from root and goes to leaf)
                    for (int j = 1; j < nodePositions.Count - 1; j++)
                    {
                        //Look at parent node and move according to our distance
                        nodePositions[j] = nodePositions[j - 1] + (nodePositions[j] - nodePositions[j - 1]).normalized * boneStructure.boneNodes[j - 1].initalDistanceToChild;
                    }

                    //Is our leaf node closer than our arrive threshold to the target?
                    if ((nodePositions[nodePositions.Count - 1] - targetPosition).sqrMagnitude < boneStructure.arriveThresholdSquared)
                    {
                        break;
                    }
                }
            }

            //Bend Target
            //To bend towards a bend target we can project points on a plane and move towards the bend target
            if (boneStructure.bendTarget != null)
            {
                //For all nodes, except root
                for (int i = 1; i < nodePositions.Count - 1; i++)
                {
                    //Create the projection plane
                    Plane projectionPlane = new Plane(nodePositions[i + 1] - nodePositions[i - 1], nodePositions[i - 1]);
                    //Get Positions
                    Vector3 projectedBendLine = projectionPlane.ClosestPointOnPlane(Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.bendTarget.position - boneStructure.rootNode.position));
                    Vector3 projectedNode     = projectionPlane.ClosestPointOnPlane(Quaternion.Inverse(boneStructure.rootNode.rotation) * (boneStructure.boneNodes[i].nodeTransform.position - boneStructure.rootNode.position));
                    //Find the angle with the shortest distance to the bend target
                    float angle = Vector3.SignedAngle(projectedNode - nodePositions[i - 1], projectedBendLine - nodePositions[i - 1], projectionPlane.normal);
                    //Rotate the parent node so that our node is the closest to the bend target that is can be
                    nodePositions[i] = Quaternion.AngleAxis(angle, projectionPlane.normal) * (nodePositions[i] - nodePositions[i - 1]) + nodePositions[i - 1];
                }
            }

            //Set Positions and Rotations
            for (int i = 0; i < nodePositions.Count; i++)
            {
                //Rotations
                //Leaf
                if (i == nodePositions.Count - 1)
                {
                    boneStructure.boneNodes[i].nodeTransform.rotation = boneStructure.rootNode.rotation * (Quaternion.Inverse(targetRotation) * boneStructure.startTargetRot * Quaternion.Inverse(boneStructure.boneNodes[i].startRot));
                }
                else
                {
                    boneStructure.boneNodes[i].nodeTransform.rotation = boneStructure.rootNode.rotation * (Quaternion.FromToRotation(boneStructure.boneNodes[i].startDirTarget, nodePositions[i + 1] - nodePositions[i]) * Quaternion.Inverse(boneStructure.boneNodes[i].startRot));
                }

                //Positions
                boneStructure.boneNodes[i].nodeTransform.position = boneStructure.rootNode.rotation * nodePositions[i] + boneStructure.rootNode.position;
            }

            //FABIK END
        }