Ejemplo n.º 1
0
        /// <summary>
        /// Updates vertex normals and face planes.
        /// </summary>
        public void Invalidate(IProgressListener listener = null, InvalidateFlags invalidate = InvalidateFlags.All)
        {
            if (invalidate.HasFlag(InvalidateFlags.Faces))
            {
                if (listener != null)
                {
                    listener.OnStarted("Invalidating mesh faces");
                }

                foreach (var face in m_Faces)
                {
                    var v0 = m_Vertices[face[0]].Position;
                    var v1 = m_Vertices[face[1]].Position;
                    var v2 = m_Vertices[face[2]].Position;
                    face.Plane = new Plane(v0, v1, v2);
                }

                if (listener != null)
                {
                    listener.OnComplete("Invalidating mesh faces");
                }
            }

            if (invalidate.HasFlag(InvalidateFlags.Vertices))
            {
                if (listener != null)
                {
                    listener.OnStarted("Invalidating mesh vertices");
                }

                int i = 0;
                foreach (var vertex in m_Vertices)
                {
                    foreach (var face in m_Faces)
                    {
                        if (face.HasVertex(vertex.Key))
                        {
                            vertex.Value.Normal += face.Plane.Normal;
                        }
                    }
                    if (listener != null)
                    {
                        listener.OnStep(++i, m_Vertices.Count);
                    }
                    vertex.Value.Normal.Normalize();
                }
                if (listener != null)
                {
                    listener.OnComplete("Invalidating mesh vertices");
                }
            }
        }
Ejemplo n.º 2
0
        internal void InvalidateLines(InvalidateFlags flags = InvalidateFlags.None)
        {
            if (editor.Buffer == null)
            {
                return;
            }

            var startLine = 0;
            var endLine   = editor.Lines.Count;
            var forced    = (flags & InvalidateFlags.Force) == InvalidateFlags.Force;

            if (!editor.WordWrap)
            {
                if ((flags & InvalidateFlags.Atomic) == InvalidateFlags.Atomic)
                {
                    FastInvalidateLines();
                    return;
                }

                var maxHeight = 0;
                var maxWidth  = 0;
                var y         = 0;

                for (var i = startLine; i < endLine; i++)
                {
                    var ln = editor.Lines[i];

                    if (forced)
                    {
                        ln.ClearCuts();
                    }

                    if (!editor.Folding.IsLineVisible(i))
                    {
                        continue;
                    }

                    ln.Y = y;
                    var w = ln.GetTetras(editor.IndentSize) * editor.Info.CharWidth;
                    y += editor.Info.LineHeight;

                    if (w > maxWidth)
                    {
                        maxWidth = w;
                    }

                    maxHeight += editor.Info.LineHeight;
                }

                var xmax = maxWidth - editor.Info.TextWidth + editor.Info.CharWidth * 10;
                ScrollBounds = new Size(xmax < 0 ? 0 : xmax, maxHeight);
            }
            else
            {
                var maxHeight = 0;
                var twidth    = editor.WordWrapColumn > 0 ? editor.WordWrapColumn * editor.Info.CharWidth
                    : editor.Info.TextWidth;

                for (var i = startLine; i < endLine; i++)
                {
                    if (!editor.Folding.IsLineVisible(i))
                    {
                        continue;
                    }

                    var ln = editor.Lines[i];

                    if (!ln.Invalidated || forced)
                    {
                        ln.RecalculateCuts(twidth, editor.Info.CharWidth, editor.IndentSize, editor.EditorSettings.WrappingIndent);
                    }
                    ln.Y       = maxHeight;
                    maxHeight += ln.Stripes * editor.Info.LineHeight;
                }

                ScrollBounds = new Size(0, maxHeight);
                ResetFirstLast();
            }

            var ymax = ScrollBounds.Height - editor.Info.TextHeight + editor.Info.LineHeight * 5;

            ScrollBounds      = new Size(ScrollBounds.Width, ymax < 0 ? 0 : ymax);
            _firstVisibleLine = null;
            _lastVisibleLine  = null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates vertex normals and face planes.
        /// </summary>
        public void Invalidate(IProgressListener listener = null, InvalidateFlags invalidate = InvalidateFlags.All)
        {
            if (invalidate.HasFlag(InvalidateFlags.Faces))
            {
                if (listener != null)
                {
                    listener.OnStarted("Invalidating mesh faces");
                }

                foreach (var face in m_Faces)
                {
                    var v0 = m_Vertices[face[0]].Position;
                    var v1 = m_Vertices[face[1]].Position;
                    var v2 = m_Vertices[face[2]].Position;
                    face.Plane = new Plane(v0, v1, v2);

                }

                if (listener != null)
                {
                    listener.OnComplete("Invalidating mesh faces");
                }
            }

            if (invalidate.HasFlag(InvalidateFlags.Vertices))
            {
                if (listener != null)
                {
                    listener.OnStarted("Invalidating mesh vertices");
                }

                int i = 0;
                foreach (var vertex in m_Vertices)
                {
                    foreach (var face in m_Faces)
                    {
                        if (face.HasVertex(vertex.Key))
                        {
                            vertex.Value.Normal += face.Plane.Normal;
                        }
                    }
                    if (listener != null)
                    {
                        listener.OnStep(++i, m_Vertices.Count);
                    }
                    vertex.Value.Normal.Normalize();
                }
                if (listener != null)
                {
                    listener.OnComplete("Invalidating mesh vertices");
                }
            }
        }