Exemplo n.º 1
0
        public void Solve(IKJoint anchor, float l)
        {
            // TODO : ajoute une position (avec AddPosition) qui repositionne _position à la distance l
            // en restant sur l'axe entre la position et la position de anchor

            Vector3 unit = (position - anchor.position).normalized;

            AddPosition(anchor.position + l * unit);
        }
Exemplo n.º 2
0
 public void Merge(IKJoint j)
 {
     if (First().name == j.name)
     {
         joints[0] = j;
     }
     if (Last().name == j.name)
     {
         joints[joints.Count - 1] = j;
     }
 }
Exemplo n.º 3
0
        //private static List<IKJoint> jointExporedList = new List<IKJoint>();


        // Un cylndre entre chaque articulation (Joint). N-1 cylindres.
        //private List<GameObject> cylinders = new List<GameObject>();



        // Créer la chaine d'IK en partant du noeud endNode et en remontant jusqu'au noeud plus haut, ou jusqu'à la racine
        public IKChain(Transform _endNode, Transform _rootTarget = null, Transform _endTarget = null)
        {
            Debug.Log("=== IKChain::createChain: ===");
            // TODO : construire la chaine allant de _endNode vers _rootTarget en remontant dans l'arbre.
            // Chaque Transform dans Unity a accès à son parent 'tr.parent'

            while (_endNode.name != _rootTarget.name)
            {
                IKJoint addedJoint = new IKJoint(_endNode);
                joints.Add(addedJoint);

                _endNode = _endNode.parent;
            }

            rootTarget = new IKJoint(_rootTarget);
            //endTarget = new IKJoint(_endTarget);
            endTarget = _endTarget;
        }
Exemplo n.º 4
0
        public void Backward()
        {
            //Debug.Log(" 1 : " + joints[1].name + " 2 : " + First().name);
            float nextLength = (joints[1].position - First().position).magnitude;

            First().SetPosition(endTarget.position);

            IKJoint oldn = First();

            for (int i = 1; i < joints.Count; i++)
            {
                float length = nextLength;
                if (i + 1 < joints.Count)
                {
                    nextLength = (joints[i + 1].position - joints[i].position).magnitude;
                }
                joints[i].Solve(oldn, length);

                oldn = joints[i];
            }
        }
Exemplo n.º 5
0
        public void Forward()
        {
            // TODO : une passe descendante de FABRIK. Placer le noeud 0 sur son origine puis on descend.
            // Codez et deboguez déjà Backward avant d'écrire celle-ci.

            float nextLength = (joints[joints.Count - 2].position - Last().position).magnitude;

            Last().SetPosition(rootTarget.position);
            IKJoint oldn = Last();

            for (int i = joints.Count - 2; i >= 0; i--)
            {
                float length = nextLength;
                if (i - 1 > 0)
                {
                    nextLength = (joints[i - 1].position - joints[i].position).magnitude;
                }
                joints[i].Solve(oldn, length);

                oldn = joints[i];
            }
        }