示例#1
0
        private void State_ProcessingStraightEdge(bool terminate)
        {
            int cpPerFrame = Mathf.Max(
                m_StraightEdgeControlPoints_CS.Count / STRAIGHTEDGE_DRAWIN_FRAMES, 2);

            TrTransform xfCanvas = Coords.CanvasPose;

            for (int p = 0; p < cpPerFrame &&
                 m_StraightEdgeControlPointIndex < m_StraightEdgeControlPoints_CS.Count;
                 p++, m_StraightEdgeControlPointIndex++)
            {
                ControlPoint cp        = m_StraightEdgeControlPoints_CS[m_StraightEdgeControlPointIndex];
                TrTransform  xfPointer = xfCanvas * TrTransform.TR(cp.m_Pos, cp.m_Orient);
                SetMainPointerPosition(xfPointer.translation);
                SetMainPointerRotation(xfPointer.rotation);
                for (int i = 0; i < m_NumActivePointers; ++i)
                {
                    m_Pointers[i].m_Script.UpdateLineFromObject();
                }

                var stencil = WidgetManager.m_Instance.ActiveStencil;
                if (stencil != null)
                {
                    stencil.AdjustLift(1);
                }
            }

            // we reached the end!
            if (terminate || m_StraightEdgeControlPointIndex >= m_StraightEdgeControlPoints_CS.Count)
            {
                FinalizeLine();
                m_CurrentLineCreationState = LineCreationState.WaitingForInput;
            }
        }
示例#2
0
        private void Transition_RecordingInput_ProcessingStraightEdge(List <ControlPoint> cps)
        {
            Debug.Assert(m_StraightEdgeProxyActive);

            //create straight line
            m_StraightEdgeProxyActive = false;
            m_StraightEdgeGuide.HideGuide();

            m_StraightEdgeControlPoints_CS  = cps;
            m_StraightEdgeControlPointIndex = 0;

            // Reset pointer to first control point and init all active pointers.
            SetMainPointerPosition(Coords.CanvasPose * m_StraightEdgeControlPoints_CS[0].m_Pos);

            var canvas = App.Scene.ActiveCanvas;

            for (int i = 0; i < m_NumActivePointers; ++i)
            {
                var         p     = m_Pointers[i];
                TrTransform xf_CS = canvas.AsCanvas[p.m_Script.transform];

                p.m_Script.CreateNewLine(canvas, xf_CS, null);
                p.m_Script.SetPressure(STRAIGHTEDGE_PRESSURE);
                p.m_Script.SetControlPoint(xf_CS, isKeeper: true);
            }

            // Ensure that snap is disabled when we start the stroke.
            m_StraightEdgeGuide.ForceSnapDisabled();

            //do this operation over a series of frames
            m_CurrentLineCreationState = LineCreationState.ProcessingStraightEdge;
        }
示例#3
0
        private void Transition_WaitingForInput_RecordingInput()
        {
            // Can't check for null as Color is a struct
            // But it's harmless to call this if the color really has been set to black
            if (m_lastChosenColor == Color.black)
            {
                m_lastChosenColor = PointerColor;
            }

            if (JitterEnabled)
            {
                // Bypass the code in the PointerColor setter
                // Size is jittered in PointerScript. Should we also do color there?
                ChangeAllPointerColorsDirectly(GenerateJitteredColor(MainPointer.CurrentBrush.m_ColorLuminanceMin));
            }


            if (m_StraightEdgeEnabled)
            {
                StraightEdgeGuide.SetTempShape(StraightEdgeGuideScript.Shape.Line);
                StraightEdgeGuide.ResolveTempShape();
                m_StraightEdgeGesture.InitGesture(MainPointer.transform.position,
                                                  m_GestureMinCircleSize, m_GestureBeginDist, m_GestureCloseLoopDist,
                                                  m_GestureStepDist, m_GestureMaxAngle);
            }

            InitiateLine();
            m_CurrentLineCreationState = LineCreationState.RecordingInput;
            WidgetManager.m_Instance.WidgetsDormant = true;
        }
示例#4
0
        private void Transition_WaitingForInput_RecordingInput()
        {
            if (m_StraightEdgeEnabled)
            {
                StraightEdgeGuide.SetTempShape(StraightEdgeGuideScript.Shape.Line);
                StraightEdgeGuide.ResolveTempShape();
                m_StraightEdgeGesture.InitGesture(MainPointer.transform.position,
                                                  m_GestureMinCircleSize, m_GestureBeginDist, m_GestureCloseLoopDist,
                                                  m_GestureStepDist, m_GestureMaxAngle);
            }

            InitiateLine();
            m_CurrentLineCreationState = LineCreationState.RecordingInput;
            WidgetManager.m_Instance.WidgetsDormant = true;
        }
示例#5
0
        // ---- Unity events

        void Awake()
        {
            m_Instance = this;

            Debug.Assert(m_MaxPointers > 0);
            m_Pointers = new PointerData[m_MaxPointers];

            for (int i = 0; i < m_Pointers.Length; ++i)
            {
                //set our main pointer as the zero index
                bool       bMain = (i == 0);
                var        data  = new PointerData();
                GameObject obj   = (GameObject)Instantiate(bMain ? m_MainPointerPrefab : m_AuxPointerPrefab);
                obj.transform.parent = transform;
                data.m_Script        = obj.GetComponent <PointerScript>();
                data.m_Script.EnableDebugViewControlPoints(bMain && m_DebugViewControlPoints);
                data.m_Script.ChildIndex = i;
                data.m_UiEnabled         = bMain;
                m_Pointers[i]            = data;
                if (bMain)
                {
                    m_MainPointerData = data;
                }
            }

            m_CurrentLineCreationState = LineCreationState.WaitingForInput;
            m_StraightEdgeProxyActive  = false;
            m_StraightEdgeGesture      = new CircleGesture();

            if (m_SymmetryWidget)
            {
                m_SymmetryWidgetScript = m_SymmetryWidget.GetComponent <SymmetryWidget>();
            }

            //initialize rendering requests to default to hiding everything
            m_PointersRenderingRequested = false;
            m_PointersRenderingActive    = true;

            m_FreePaintPointerAngle =
                PlayerPrefs.GetFloat(PLAYER_PREFS_POINTER_ANGLE, m_DefaultPointerAngle);
        }
示例#6
0
        /// State-machine update function; always called once per frame.
        public void UpdateLine()
        {
            bool playbackPointersAvailable = m_NumActivePointers <= NumFreePlaybackPointers();

            switch (m_CurrentLineCreationState)
            {
            case LineCreationState.WaitingForInput:
                if (m_LineEnabled)
                {
                    if (playbackPointersAvailable)
                    {
                        Transition_WaitingForInput_RecordingInput();
                    }
                    else
                    {
                        OnDrawDisallowed();
                    }
                }
                break;

            // TODO: unique state for capturing straightedge 2nd point rather than overload RecordingInput
            case LineCreationState.RecordingInput:
                if (m_LineEnabled)
                {
                    if (playbackPointersAvailable)
                    {
                        // Check straightedge gestures.
                        if (m_StraightEdgeEnabled)
                        {
                            CheckGestures();
                        }

                        // check to see if any pointer's line needs to end
                        // TODO: equivalent check during ProcessingStraightEdge
                        bool bStartNewLine = false;
                        for (int i = 0; i < m_NumActivePointers; ++i)
                        {
                            bStartNewLine = bStartNewLine || m_Pointers[i].m_Script.ShouldCurrentLineEnd();
                        }
                        if (bStartNewLine && !m_StraightEdgeEnabled)
                        {
                            //if it has, stop this line and start anew
                            FinalizeLine(isContinue: true);
                            InitiateLine(isContinue: true);
                        }
                    }
                    else if (!m_StraightEdgeEnabled)
                    {
                        OnDrawDisallowed();
                        Transition_RecordingInput_WaitingForInput();
                    }
                }
                else
                {
                    // Transition to either ProcessingStraightEdge or WaitingForInput
                    if (m_StraightEdgeProxyActive)
                    {
                        if (playbackPointersAvailable)
                        {
                            List <ControlPoint> cps = MainPointer.GetControlPoints();
                            FinalizeLine(discard: true);
                            Transition_RecordingInput_ProcessingStraightEdge(cps);
                        }
                        else
                        {
                            OnDrawDisallowed();
                            // cancel the straight edge
                            m_StraightEdgeProxyActive = false;
                            m_StraightEdgeGuide.HideGuide();
                            m_CurrentLineCreationState = LineCreationState.WaitingForInput;
                        }
                    }
                    else
                    {
                        m_StraightEdgeGuide.HideGuide();
                        var stencil = WidgetManager.m_Instance.ActiveStencil;
                        if (stencil != null)
                        {
                            stencil.AdjustLift(1);
                        }
                        Transition_RecordingInput_WaitingForInput();
                    }

                    // Eat up tool scale input for heavy grippers.
                    SketchControlsScript.m_Instance.EatToolScaleInput();
                }
                break;

            case LineCreationState.ProcessingStraightEdge:
                State_ProcessingStraightEdge(terminate: !playbackPointersAvailable);
                break;
            }
        }
示例#7
0
 private void Transition_RecordingInput_WaitingForInput()
 {
     // standard mode, just finalize our line and get ready for the next one
     FinalizeLine();
     m_CurrentLineCreationState = LineCreationState.WaitingForInput;
 }