Esempio n. 1
0
    public override void CommitHandle(int index, object restore, bool cancel)
    {
        Curve3D c = path.curve;

        if (!IsInstanceValid(c))
        {
            return;
        }

        UndoRedo ur = plugin.GetUndoRedo();

        if (index < c.GetPointCount())
        {
            if (cancel)
            {
                c.SetPointPosition(index, (Vector3)restore);
                return;
            }
            ur.CreateAction(("Set Curve Point Position"));
            ur.AddDoMethod(c, "set_point_position", index, c.GetPointPosition(index));
            ur.AddUndoMethod(c, "set_point_position", index, restore);
            ur.CommitAction();

            return;
        }

        index = index - c.GetPointCount() + 1;

        int idx = index / 2;
        int t   = index % 2;

        if (t == 0)
        {
            if (cancel)
            {
                c.SetPointIn(index, (Vector3)restore);
                return;
            }

            ur.CreateAction(("Set Curve In Position"));
            ur.AddDoMethod(c, "set_point_in", idx, c.GetPointIn(idx));
            ur.AddUndoMethod(c, "set_point_in", idx, restore);

            if (plugin.mirrorHandleAngle)
            {
                ur.AddDoMethod(c, "set_point_out", idx, plugin.mirrorHandleLength ? -c.GetPointIn(idx) : (-c.GetPointIn(idx).Normalized() * origOutLenght));
                ur.AddUndoMethod(c, "set_point_out", idx, plugin.mirrorHandleLength ? -(Vector3)restore : (-((Vector3)restore).Normalized() * origOutLenght));
            }
            ur.CommitAction();
        }
        else
        {
            if (cancel)
            {
                c.SetPointOut(idx, (Vector3)restore);
                return;
            }

            ur.CreateAction(("Set Curve Out Position"));
            ur.AddDoMethod(c, "set_point_out", idx, c.GetPointOut(idx));
            ur.AddUndoMethod(c, "set_point_out", idx, restore);

            if (plugin.mirrorHandleAngle)
            {
                ur.AddDoMethod(c, "set_point_in", idx, plugin.mirrorHandleLength ? -c.GetPointOut(idx) : (-c.GetPointOut(idx).Normalized() * origInLength));
                ur.AddUndoMethod(c, "set_point_in", idx, plugin.mirrorHandleLength ? -(Vector3)(restore) : (-((Vector3)restore).Normalized() * origInLength));
            }
            ur.CommitAction();
        }
    }