예제 #1
0
        /// Bulk control point addition
        public void UpdateLineFromStroke(Stroke stroke)
        {
            RdpStrokeSimplifier simplifier = App.Instance.IsLoading()
        ? QualityControls.m_Instance.StrokeSimplifier
        : QualityControls.m_Instance.UserStrokeSimplifier;

            if (simplifier.Level > 0.0f)
            {
                simplifier.CalculatePointsToDrop(stroke, CurrentBrushScript);
            }
            float scale = m_CurrentLine.StrokeScale;

            foreach (var cp in stroke.m_ControlPoints.Where((x, i) => !stroke.m_ControlPointsToDrop[i]))
            {
                m_CurrentLine.UpdatePosition_LS(TrTransform.TRS(cp.m_Pos, cp.m_Orient, scale), cp.m_Pressure);
            }
        }
예제 #2
0
        /// Counts the number of control points in a sketch and estimates a simplification level in an
        /// attempt to keep the framerate high.
        public void AutoAdjustSimplifierLevel(List <Stroke> strokes, Guid[] brushes)
        {
            if (App.UserConfig.Profiling.HasStrokeSimplification)
            {
                Debug.LogFormat("Simplification overridden to be: {0}.",
                                App.UserConfig.Profiling.StrokeSimplification);
                return;
            }

            Dictionary <Guid, int> controlPointCount = brushes.Distinct().ToDictionary(x => x, x => 0);

            foreach (var stroke in strokes)
            {
                controlPointCount[stroke.m_BrushGuid] += stroke.m_ControlPoints.Length;
            }
            float total = 0;

            foreach (var pair in controlPointCount)
            {
                total += pair.Value * AppQualityLevels.GetWeightForBrush(pair.Key);
            }
            if (total < m_targetMaxControlPoints)
            {
                Debug.LogFormat("Complexity ({0}) is less than {1}. No extra simplification required.",
                                total, m_targetMaxControlPoints);
                return;
            }
            float reduction = m_targetMaxControlPoints / total;
            float level     = Mathf.Max(Mathf.Min(RdpStrokeSimplifier.CalculateLevelForReduction(reduction),
                                                  m_maxLoadingSimplification), StrokeSimplifier.Level);

            if (AutosimplifyEnabled)
            {
                Debug.LogFormat(
                    "Complexity ({0}) is greater than {1}. Reduction of {2} using level {3} simplification.",
                    total, m_targetMaxControlPoints, reduction, level);
                SimplificationLevel = level;
            }
        }
예제 #3
0
        // Continue drawing stroke for this frame.
        public void Update()
        {
            if (m_isDone)
            {
                return;
            }

            var rPointerScript = m_pointer;
            var rPointerObject = m_pointer.gameObject;

            bool needMeshUpdate    = false;
            bool needPointerUpdate = false;
            bool strokeFinished    = false;
            var  lastCp            = new PointerManager.ControlPoint();

            OverlayManager.m_Instance.UpdateProgress(SketchMemoryScript.m_Instance.GetDrawnPercent());

            RdpStrokeSimplifier simplifier = QualityControls.m_Instance.StrokeSimplifier;

            if (simplifier.Level > 0.0f)
            {
                simplifier.CalculatePointsToDrop(m_stroke, m_pointer.CurrentBrushScript);
            }

            while (true)
            {
                if (m_nextControlPoint >= m_stroke.m_ControlPoints.Length)
                {
                    needMeshUpdate = true; // Is this really necessary?
                    strokeFinished = true;
                    break;
                }
                var cp = m_stroke.m_ControlPoints[m_nextControlPoint];
                if (!IsControlPointReady(cp))
                {
                    break;
                }

                if (!m_stroke.m_ControlPointsToDrop[m_nextControlPoint])
                {
                    rPointerScript.UpdateLineFromControlPoint(cp);
                    needMeshUpdate    = true;
                    lastCp            = cp;
                    needPointerUpdate = true;
                }
                ++m_nextControlPoint;
            }

            if (needMeshUpdate)
            {
                rPointerScript.UpdateLineVisuals();
            }
            if (needPointerUpdate)
            {
                // This is only really done for visual reasons
                var xf_GS = Coords.CanvasPose * TrTransform.TR(lastCp.m_Pos, lastCp.m_Orient);
                xf_GS.scale = rPointerObject.transform.GetUniformScale();
                Coords.AsGlobal[rPointerObject.transform] = xf_GS;
                rPointerScript.SetPressure(lastCp.m_Pressure);
            }

            if (strokeFinished)
            {
                rPointerScript.EndLineFromMemory(m_stroke);
                m_isDone = true;
            }
        }