Beispiel #1
0
        // Using "Init" here so usage can avoid per-stroke heap activity.
        public void BaseInit(Stroke stroke,
                             PointerScript pointer,
                             CanvasScript canvas)
        {
            if (stroke.m_Type != Stroke.Type.NotCreated)
            {
                UnityEngine.Debug.LogWarningFormat("Unexpected: playback stroke type {0}", stroke.m_Type);
                stroke.Uncreate();
            }
            m_pointer          = pointer;
            m_stroke           = stroke;
            m_nextControlPoint = 0;
            m_isDone           = false;

            // We make the BeginLine call, even though the stroke time may be in the future.
            // Harmless with current brushes since no geometry is generated until UpdateLinePosition.
            // We can move code to Update() if this changes.

            m_stroke.m_Object = m_pointer.BeginLineFromMemory(m_stroke, canvas);
            m_stroke.m_Type   = Stroke.Type.BrushStroke;

            if (m_stroke.m_Object == null)
            {
                if (!sm_BrushGuidWarnings.Contains(m_stroke.m_BrushGuid))
                {
                    OutputWindowScript.m_Instance.AddNewLine("Brush not found!  Guid: " + m_stroke.m_BrushGuid);
                    sm_BrushGuidWarnings.Add(m_stroke.m_BrushGuid);
                }
                m_isDone = true;
            }
        }
Beispiel #2
0
  public void Init(Stroke stroke, PointerScript pointer, CanvasScript canvas) {
    BaseInit(stroke, pointer, canvas);
    m_lastPosition = m_stroke.m_ControlPoints[0].m_Pos;

    var desc = BrushCatalog.m_Instance.GetBrush(stroke.m_BrushGuid);
    m_playBackAtStrokeGranularity = (m_parent.QuickLoad || desc.m_PlayBackAtStrokeGranularity);
  }
Beispiel #3
0
        // Only called during interactive creation.
        // isContinue is true if the line is the logical (if not physical) continuation
        // of a previous line -- ie, previous line ran out of verts and we transparently
        // stopped and started a new one.
        void InitiateLine(bool isContinue = false)
        {
            // Turn off the preview when we start drawing
            for (int i = 0; i < m_NumActivePointers; ++i)
            {
                m_Pointers[i].m_Script.DisablePreviewLine();
                m_Pointers[i].m_Script.AllowPreviewLine(false);
            }

            if (m_StraightEdgeEnabled)
            {
                // This causes the line to be drawn with a proxy brush; and also to be
                // discarded and redrawn upon completion.
                m_StraightEdgeProxyActive = MainPointer.CurrentBrush.NeedsStraightEdgeProxy;
                // Turn on the straight edge and hold on to our start position
                m_StraightEdgeGuide.ShowGuide(MainPointer.transform.position);
                for (int i = 0; i < m_NumActivePointers; ++i)
                {
                    m_Pointers[i].m_StraightEdgeXf_CS = Coords.AsCanvas[m_Pointers[i].m_Script.transform];
                }
            }

            CanvasScript canvas = App.Scene.ActiveCanvas;

            for (int i = 0; i < m_NumActivePointers; ++i)
            {
                PointerScript script       = m_Pointers[i].m_Script;
                var           xfPointer_CS = canvas.AsCanvas[script.transform];

                // Pass in parametric stroke creator.
                ParametricStrokeCreator currentCreator = null;
                if (m_StraightEdgeEnabled)
                {
                    switch (StraightEdgeGuide.CurrentShape)
                    {
                    case StraightEdgeGuideScript.Shape.Line:
                        currentCreator = new LineCreator(xfPointer_CS, flat: true);
                        break;

                    case StraightEdgeGuideScript.Shape.Circle:
                        currentCreator = new CircleCreator(xfPointer_CS);
                        break;

                    case StraightEdgeGuideScript.Shape.Sphere:
                        currentCreator = new SphereCreator(xfPointer_CS, script.BrushSizeAbsolute,
                                                           canvas.transform.GetUniformScale());
                        break;
                    }
                }

                script.CreateNewLine(
                    canvas, xfPointer_CS, currentCreator,
                    m_StraightEdgeProxyActive ? m_StraightEdgeProxyBrush : null);
                script.SetControlPoint(xfPointer_CS, isKeeper: true);
            }
        }
Beispiel #4
0
 public void CopyInternals(PointerScript rOther)
 {
     SetBrush(rOther.m_CurrentBrush);
     m_BrushSizeRange        = rOther.m_BrushSizeRange; // remove? handled by SetBrush
     BrushSizeAbsolute       = rOther.BrushSizeAbsolute;
     m_CurrentPressure       = rOther.m_CurrentPressure;
     m_AllowPreviewLineTimer = rOther.m_AllowPreviewLineTimer;
     m_AllowPreviewLine      = rOther.m_AllowPreviewLine;
     m_LastUsedBrushSize_CS  = rOther.m_LastUsedBrushSize_CS;
     SetColor(rOther.m_CurrentColor);
 }
    protected override void InitBrush(BrushDescriptor desc, TrTransform localPointerXf) {
      base.InitBrush(desc, localPointerXf);
      m_geometry.Layout = GetVertexLayout(desc);

      PointerScript ptr = PointerManager.m_Instance.MainPointer;

      m_bevelRatio = 1 - kDefaultBevelSize;
      m_bevelVerts = kDefaultBevelVerts;
      m_tessellation = kDefaultTesselation;
      m_transparency = kDefaultTransparency;
    }
Beispiel #6
0
        /// Given the position of a main pointer, find a corresponding symmetry position.
        /// Results are undefined unless you pass MainPointer or one of its
        /// dedicated symmetry pointers.
        public TrTransform GetSymmetryTransformFor(PointerScript pointer, TrTransform xfMain)
        {
            int child = pointer.ChildIndex;

            // "active pointers" is the number of pointers the symmetry widget is using,
            // including the main pointer.
            if (child == 0 || child >= m_NumActivePointers)
            {
                return(xfMain);
            }

            // This needs to be kept in sync with UpdateSymmetryPointerTransforms
            switch (m_CurrentSymmetryMode)
            {
            case SymmetryMode.SinglePlane:
            {
                return(m_SymmetryWidgetScript.ReflectionPlane.ReflectPoseKeepHandedness(xfMain));
            }

            case SymmetryMode.FourAroundY:
            {
                // aboutY is an operator that rotates worldspace objects N degrees around the widget's Y
                TrTransform aboutY;
                {
                    var   xfWidget = TrTransform.FromTransform(m_SymmetryWidget);
                    float angle    = (360f * child) / m_NumActivePointers;
                    aboutY = TrTransform.TR(Vector3.zero, Quaternion.AngleAxis(angle, Vector3.up));
                    // convert from widget-local coords to world coords
                    aboutY = aboutY.TransformBy(xfWidget);
                }
                return(aboutY * xfMain);
            }

            case SymmetryMode.DebugMultiple:
            {
                var xfLift = TrTransform.T(m_SymmetryDebugMultipleOffset * child);
                return(xfLift * xfMain);
            }

            default:
                return(xfMain);
            }
        }
Beispiel #7
0
        // Detach and record lines for all active pointers.
        void FinalizeLine(bool isContinue = false, bool discard = false)
        {
            PointerScript groupStart     = null;
            uint          groupStartTime = 0;

            //discard or solidify every pointer's active line
            for (int i = 0; i < m_NumActivePointers; ++i)
            {
                var pointer = m_Pointers[i].m_Script;
                // XXX: when would an active pointer not be creating a line?
                if (pointer.IsCreatingStroke())
                {
                    bool bDiscardLine = discard || pointer.ShouldDiscardCurrentLine();
                    if (bDiscardLine)
                    {
                        pointer.DetachLine(bDiscardLine, null, SketchMemoryScript.StrokeFlags.None);
                    }
                    else
                    {
                        SketchMemoryScript.StrokeFlags flags = SketchMemoryScript.StrokeFlags.None;
                        if (groupStart == null)
                        {
                            groupStart = pointer;
                            // Capture this, because stroke becomes invalid after being detached.
                            groupStartTime = groupStart.TimestampMs;
                        }
                        else
                        {
                            flags |= SketchMemoryScript.StrokeFlags.IsGroupContinue;
                            // Verify IsGroupContinue invariant
                            Debug.Assert(pointer.TimestampMs == groupStartTime);
                        }
                        pointer.DetachLine(bDiscardLine, null, flags);
                    }
                }
            }
        }
Beispiel #8
0
 public void Init(LinkedListNode <Stroke> memoryObjectNode,
                  PointerScript pointer, CanvasScript canvas)
 {
     m_strokeNode = memoryObjectNode;
     BaseInit(memoryObjectNode.Value, pointer, canvas);
 }