public bool RemoveKnotAtPosition(Vector3 pos) {
    CameraPathKnot removeKnot = m_Path.GetKnotAtPosition(pos);
    if (removeKnot != null) {
      // If we're removing the last position knot, just destroy the whole path.
      if (removeKnot is CameraPathPositionKnot && m_Path.NumPositionKnots == 1) {
        WidgetManager.m_Instance.DeleteCameraPath(this);
      } else {
        TrTransform knotXf = TrTransform.TR(pos, removeKnot.transform.rotation);

        // Gather all the knots affected by this removal.
        List<CameraPathKnot> pks = m_Path.GetKnotsOrphanedByKnotRemoval(removeKnot);
        // If we have any knots affected by this change, we need to remove those first, before
        // we remove the original knot.  This is because, on undo, we need to add the parent
        // first, before adding all the orphaned knots.
        if (pks.Count > 0) {
          BaseCommand parent = new BaseCommand();
          for (int i = 0; i < pks.Count; ++i) {
            TrTransform childXf = TrTransform.TR(pos, pks[i].transform.rotation);
            new RemovePathKnotCommand(this, pks[i], childXf, parent);
          }
          new RemovePathKnotCommand(this, removeKnot, knotXf, parent);
          SketchMemoryScript.m_Instance.PerformAndRecordCommand(parent);
        } else {
          SketchMemoryScript.m_Instance.PerformAndRecordCommand(
              new RemovePathKnotCommand(this, removeKnot, knotXf));
        }
      }

      // Reset collision results after a delete.
      for (int i = 0; i < m_LastCollisionResults.Length; ++i) {
        m_LastCollisionResults[i].Set(null, CameraPathKnot.kDefaultControl, null, null);
      }
    }
    return removeKnot != null;
  }
        public RemovePathKnotCommand(CameraPathWidget widget, CameraPathKnot knot,
                                     TrTransform removeXf, BaseCommand parent = null)
            : base(parent)
        {
            Knot        = knot;
            m_Widget    = widget;
            m_RemovedXf = removeXf;

            // If we're removing a position knot, remember its ordered index. This is necessary
            // because it's probable that the path will change after removal and Undo won't be able
            // to place the knot back on the path at the current position.
            if (Knot.KnotType == CameraPathKnot.Type.Position)
            {
                m_KnotIndex = m_Widget.Path.PositionKnots.IndexOf((CameraPathPositionKnot)Knot);
                m_PathT     = new PathT();
            }
            else
            {
                m_PathT = Knot.PathT;
            }
        }
Example #3
0
        protected override void OnRedo()
        {
            // The scale of path widgets is arbitrary.  However, the scale should be one at knot creation
            // time so newly added knots have appropriate mesh scales.
            m_Widget.transform.localScale = Vector3.one;
            if (m_CreatedKnot == null)
            {
                switch (m_KnotType)
                {
                case CameraPathKnot.Type.Position:
                    m_CreatedKnot = m_Widget.Path.CreatePositionKnot(m_SpawnXf.translation);
                    break;

                case CameraPathKnot.Type.Rotation:
                    m_CreatedKnot = m_Widget.Path.CreateRotationKnot(m_PathT, m_SpawnXf.rotation);
                    break;

                case CameraPathKnot.Type.Speed:
                    m_CreatedKnot = m_Widget.Path.CreateSpeedKnot(m_PathT);
                    break;

                case CameraPathKnot.Type.Fov:
                    m_CreatedKnot = m_Widget.Path.CreateFovKnot(m_PathT);
                    break;

                default:
                    Debug.Log("CreatePathKnotCommand knot type unsupported.");
                    break;
                }
            }

            switch (m_KnotType)
            {
            case CameraPathKnot.Type.Position:
                int knotIndex = m_PathT.Floor();
                // If we're inserting a point and it's at the head, take on the characteristics of
                // the head knot.  This will cause InsertPositionKnot to register the path as looping,
                // which is what we want.
                if (m_Widget.Path.IsPositionNearHead(m_CreatedKnot.transform.position) &&
                    knotIndex == m_Widget.Path.NumPositionKnots)
                {
                    CameraPathPositionKnot cppkCreated = (CameraPathPositionKnot)m_CreatedKnot;
                    CameraPathPositionKnot cppkHead    = m_Widget.Path.PositionKnots[0];
                    cppkCreated.transform.rotation = cppkHead.transform.rotation;
                    cppkCreated.TangentMagnitude   = cppkHead.TangentMagnitude;
                }
                m_Widget.Path.InsertPositionKnot((CameraPathPositionKnot)m_CreatedKnot, knotIndex);
                break;

            case CameraPathKnot.Type.Rotation:
                m_Widget.Path.AddRotationKnot((CameraPathRotationKnot)m_CreatedKnot, m_PathT);
                break;

            case CameraPathKnot.Type.Speed:
                m_Widget.Path.AddSpeedKnot((CameraPathSpeedKnot)m_CreatedKnot, m_PathT);
                break;

            case CameraPathKnot.Type.Fov:
                m_Widget.Path.AddFovKnot((CameraPathFovKnot)m_CreatedKnot, m_PathT);
                break;

            default:
                Debug.Log("CreatePathKnotCommand knot type unsupported.");
                break;
            }

            m_CreatedKnot.gameObject.SetActive(true);
            App.Switchboard.TriggerCameraPathKnotChanged();
            WidgetManager.m_Instance.CameraPathsVisible = true;
        }
 public void TintKnot(CameraPathKnot knot) {
   knot.ActivateTint(true);
   m_TintedKnots.Add(knot);
   enabled = true;
 }