public void findNewTarget()
    {
        MoveClip tar      = null;
        float    distance = float.MaxValue;

        foreach (var mc in am.clipPool)
        {
            //var dis = Vector3.Distance(mc.transform.position, rightHandAnchor.transform.position);
            var closePoint = rayPointClosestPos(rightHandAnchor.transform.position, rightHandAnchor.transform.forward, mc.transform.position);

            var dis = Vector3.Distance(mc.transform.position, closePoint);

            if (Vector3.Dot(closePoint - rightHandAnchor.transform.position, rightHandAnchor.transform.forward) < 0)
            {
                dis *= 3;
            }
            if (dis < distance && mc.selectable)
            {
                distance = dis;
                tar      = mc;
            }
        }

        am.target = tar;
        am.updateAll();
    }
Exemple #2
0
    public string findRelativePathToRoot(MoveClip current)
    {
        var parent       = current.transform.parent;
        var recordedPath = current.gameObject.name;

        while (parent != null)
        {
            if (parent == root.transform)
            {
                return(recordedPath);
            }
            recordedPath = parent.name + "/" + recordedPath;
            parent       = parent.parent;
        }
        return(null);
    }
Exemple #3
0
    public void clearTarget(MoveClip target)
    {
        if (target == null)
        {
            return;
        }
        var fs = target.frames;

        if (fs[currentFrame].keyFrame == false)
        {
            return;
        }
        fs[currentFrame].keyFrame = false;

        Frame leftKeyFrame = null;
        int   leftIndex = 0, rightIndex = 0;
        int   j = 0;

        for (j = currentFrame - 1; j >= 0; j--)
        {
            if (fs[j].keyFrame)
            {
                leftKeyFrame = fs[j];
                leftIndex    = j;
                break;
            }
        }
        Frame rightKeyFrame = null;

        j = 0;
        for (j = currentFrame + 1; j < fs.Length; j++)
        {
            if (fs[j].keyFrame)
            {
                rightKeyFrame = fs[j];
                rightIndex    = j;
                break;
            }
        }
        /////////if no keyframe found...
        if (leftKeyFrame == null && rightKeyFrame == null)
        {
            return;
        }
        else if (leftKeyFrame != null && rightKeyFrame == null)
        {
            for (int k = leftIndex + 1; k < fs.Length; k++)
            {
                fs[k].position = leftKeyFrame.position;
                fs[k].rotation = leftKeyFrame.rotation;
            }
        }
        else if (leftKeyFrame == null && rightKeyFrame != null)
        {
            for (int k = 0; k < rightIndex; k++)
            {
                fs[k].position = rightKeyFrame.position;
                fs[k].rotation = rightKeyFrame.rotation;
            }
        }
        else
        {
            for (int k = leftIndex + 1; k < rightIndex; k++)
            {
                float ratio = (1.0f * k - leftIndex) / (rightIndex - leftIndex);
                fs[k].position = Vector3.Lerp(leftKeyFrame.position, rightKeyFrame.position, ratio);
                fs[k].rotation = Quaternion.Lerp(leftKeyFrame.rotation, rightKeyFrame.rotation, ratio);
            }
        }
    }
Exemple #4
0
    public void keyTarget(MoveClip target)
    {
        if (target == null)
        {
            return;
        }
        var fs = target.frames;

        fs[currentFrame].position = target.transform.localPosition;
        fs[currentFrame].rotation = target.transform.localRotation;
        fs[currentFrame].keyFrame = true;
        //Update all the left frames before it
        Frame leftKeyFrame = null;
        int   j            = 0;

        for (j = currentFrame - 1; j >= 0; j--)
        {
            if (fs[j].keyFrame)
            {
                leftKeyFrame = fs[j];
                break;
            }
        }
        if (leftKeyFrame == null) // fill left part of the new key frame
        {
            for (int k = 0; k < currentFrame; k++)
            {
                fs[k].position = fs[currentFrame].position;
                fs[k].rotation = fs[currentFrame].rotation;
            }
        }
        else
        {
            for (int k = j + 1; k < currentFrame; k++)
            {
                float ratio = (1.0f * k - j) / (currentFrame - j);
                fs[k].position = Vector3.Lerp(leftKeyFrame.position, fs[currentFrame].position, ratio);
                fs[k].rotation = Quaternion.Lerp(leftKeyFrame.rotation, fs[currentFrame].rotation, ratio);
            }
        }

        //Update all the right frames after it:
        //Update all the left frames before it
        Frame rightKeyFrame = null;

        j = 0;
        for (j = currentFrame + 1; j < fs.Length; j++)
        {
            if (fs[j].keyFrame)
            {
                rightKeyFrame = fs[j];
                break;
            }
        }
        if (rightKeyFrame == null) // fill left part of the new key frame
        {
            for (int k = currentFrame + 1; k < fs.Length; k++)
            {
                fs[k].position = fs[currentFrame].position;
                fs[k].rotation = fs[currentFrame].rotation;
            }
        }
        else
        {
            for (int k = currentFrame + 1; k < j; k++)
            {
                float ratio = (1.0f * k - currentFrame) / (j - currentFrame);
                fs[k].position = Vector3.Lerp(fs[currentFrame].position, rightKeyFrame.position, ratio);
                fs[k].rotation = Quaternion.Lerp(fs[currentFrame].rotation, rightKeyFrame.rotation, ratio);
            }
        }
    }
Exemple #5
0
 public JsonMoveClip(MoveClip mc)
 {
     name   = mc.gameObject.name;
     frames = mc.frames;
 }