Пример #1
0
        /// Like BeginLineFromMemory + EndLineFromMemory
        /// To help catch bugs in higher-level stroke code, it is considered
        /// an error unless the stroke is in state NotCreated.
        public void RecreateLineFromMemory(Stroke stroke)
        {
            if (stroke.m_Type != Stroke.Type.NotCreated)
            {
                throw new InvalidOperationException();
            }
            if (BeginLineFromMemory(stroke, stroke.Canvas) == null)
            {
                // Unclear why it would have failed, but okay.
                // I guess we keep the old version?
                Debug.LogError("Unexpected error recreating line");
                return;
            }

            UpdateLineFromStroke(stroke);

            // It's kind of warty that this needs to happen; brushes should probably track
            // the mesh-dirty state and flush it in Finalize().
            // TODO: Check if this is still necessary now that QuadStripBrushStretchUV
            // flushes pending geometry changes in Finalize*Brush()
            m_CurrentLine.ApplyChangesToVisuals();

            // Copy in new contents

            if (App.Config.m_UseBatchedBrushes && m_CurrentLine.m_bCanBatch)
            {
                var subset = m_CurrentLine.FinalizeBatchedBrush();

                stroke.m_Type           = Stroke.Type.BatchedBrushStroke;
                stroke.m_IntendedCanvas = null;
                Debug.Assert(stroke.m_Object == null);
                stroke.m_BatchSubset          = subset;
                stroke.m_BatchSubset.m_Stroke = stroke;

                m_CurrentLine.DestroyMesh();
                Destroy(m_CurrentLine.gameObject);
            }
            else
            {
                m_CurrentLine.FinalizeSolitaryBrush();

                stroke.m_Type           = Stroke.Type.BrushStroke;
                stroke.m_IntendedCanvas = null;
                Debug.Assert(stroke.m_BatchSubset == null);
                stroke.m_Object = m_CurrentLine.gameObject;
                stroke.m_Object.GetComponent <BaseBrushScript>().Stroke = stroke;
            }

            m_CurrentLine = null;
        }
Пример #2
0
        /// Creates and returns a BatchSubset in the passed Canvas.
        /// If stroke contains too many CPs to fit, it will be cut short.
        /// This differs from what TB does, which is to create multiple subsets.
        public static BatchSubset CreateSubsetFromStroke(CanvasScript canvas, Stroke stroke)
        {
            // See PointerScript.RecreateLineFromMemory

            BrushDescriptor desc = BrushCatalog.m_Instance.GetBrush(stroke.m_BrushGuid);

            var             cp0 = stroke.m_ControlPoints[0];
            var             xf0 = TrTransform.TRS(cp0.m_Pos, cp0.m_Orient, stroke.m_BrushScale);
            BaseBrushScript bbs = BaseBrushScript.Create(
                canvas.transform, xf0, desc, stroke.m_Color, stroke.m_BrushSize);

            try {
                bbs.SetIsLoading();
                Assert.True(bbs.Canvas != null);

                foreach (var cp in stroke.m_ControlPoints)
                {
                    bbs.UpdatePosition_LS(
                        TrTransform.TRS(cp.m_Pos, cp.m_Orient, stroke.m_BrushScale), cp.m_Pressure);
                }
                return(bbs.FinalizeBatchedBrush());
            } finally {
                UnityEngine.Object.DestroyImmediate(bbs.gameObject);
            }
        }