// Submits the geometry for rendering.
        public void RenderScene(Autodesk.Revit.DB.View view, DisplayStyle displayStyle)
        {
            try
            {
                // Populate geometry buffers if they are not initialized or need updating.
                if (UpdateAll ||
                    m_nonTransparentFaceBufferStorage == null || m_nonTransparentFaceBufferStorage.needsUpdate(displayStyle) ||
                    m_transparentFaceBufferStorage == null || m_transparentFaceBufferStorage.needsUpdate(displayStyle) ||
                    m_edgeBufferStorage == null || m_edgeBufferStorage.needsUpdate(displayStyle))
                {
                    Options         options  = new Options();
                    GeometryElement geomElem = m_element.get_Geometry(options);

                    CreateBufferStorageForElement(geomElem, displayStyle);
                }

                // Submit a subset of the geometry for drawing. Determine what geometry should be submitted based on
                // the type of the rendering pass (opaque or transparent) and DisplayStyle (wireframe or shaded).

                // If the server is requested to submit transparent geometry, DrawContext().IsTransparentPass()
                // will indicate that the current rendering pass is for transparent objects.
                RenderingPassBufferStorage faceBufferStorage = DrawContext.IsTransparentPass() ? m_transparentFaceBufferStorage : m_nonTransparentFaceBufferStorage;

                // Conditionally submit triangle primitives (for non-wireframe views).
                if (displayStyle != DisplayStyle.Wireframe &&
                    faceBufferStorage.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(faceBufferStorage.VertexBuffer,
                                            faceBufferStorage.VertexBufferCount,
                                            faceBufferStorage.IndexBuffer,
                                            faceBufferStorage.IndexBufferCount,
                                            faceBufferStorage.VertexFormat,
                                            faceBufferStorage.EffectInstance, PrimitiveType.TriangleList, 0,
                                            faceBufferStorage.PrimitiveCount);
                }

                // Conditionally submit line segment primitives.
                if (displayStyle != DisplayStyle.Shading &&
                    m_edgeBufferStorage.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(m_edgeBufferStorage.VertexBuffer,
                                            m_edgeBufferStorage.VertexBufferCount,
                                            m_edgeBufferStorage.IndexBuffer,
                                            m_edgeBufferStorage.IndexBufferCount,
                                            m_edgeBufferStorage.VertexFormat,
                                            m_edgeBufferStorage.EffectInstance, PrimitiveType.LineList, 0,
                                            m_edgeBufferStorage.PrimitiveCount);
                }

                UpdateAll = false;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Ejemplo n.º 2
0
        public static RenderData DrawEdges(List <Elements.Geometry.Line> edges)
        {
            var numVertices      = edges.Count * 2;
            var numPrimitives    = edges.Count;
            var pType            = PrimitiveType.LineList;
            var numIndices       = GetPrimitiveSize(pType) * numPrimitives;
            var vertexFormatBits = VertexFormatBits.Position;
            var vertexFormat     = new VertexFormat(vertexFormatBits);
            var vBuffer          = new VertexBuffer(GetVertexSize(vertexFormatBits) * numVertices);
            var iBuffer          = new IndexBuffer(numIndices);

            vBuffer.Map(GetVertexSize(vertexFormatBits) * numVertices);
            iBuffer.Map(numIndices);

            var vertices = new List <VertexPosition>();
            var lines    = new List <IndexLine>();

            var index = 0;

            foreach (var e in edges)
            {
                vertices.Add(new VertexPosition(e.Start.ToXYZFeet()));
                vertices.Add(new VertexPosition(e.End.ToXYZFeet()));
                lines.Add(new IndexLine(index, index + 1));
                index += 2;
            }
            var p = vBuffer.GetVertexStreamPosition();

            p.AddVertices(vertices);
            var iPos = iBuffer.GetIndexStreamLine();

            iPos.AddLines(lines);

            vBuffer.Unmap();
            iBuffer.Unmap();

            var effect = new EffectInstance(vertexFormatBits);

            var renderData = new RenderData()
            {
                VertexBuffer   = vBuffer,
                VertexCount    = numVertices,
                IndexBuffer    = iBuffer,
                IndexCount     = numIndices,
                VertexFormat   = vertexFormat,
                Effect         = effect,
                PrimitiveType  = pType,
                PrimitiveCount = numPrimitives
            };

            DrawContext.FlushBuffer(vBuffer, numVertices, iBuffer, numIndices, vertexFormat, effect, pType, 0, numPrimitives);

            return(renderData);
        }
Ejemplo n.º 3
0
        public void RenderScene(View dBView, DisplayStyle displayStyle)
        {
            if (!HyparHubApp.IsSyncing())
            {
                return;
            }

            if (HyparHubApp.CurrentWorkflows == null)
            {
                return;
            }

            // When the display style changes we need to redraw because
            // we'll use a different data layout.
            if (HyparHubApp.RequiresRedraw == false && _lastDisplayStyle == displayStyle)
            {
                // Draw what's in the cached buffers.
                foreach (var renderData in _renderDataCache.Values)
                {
                    DrawContext.FlushBuffer(renderData.VertexBuffer,
                                            renderData.VertexCount,
                                            renderData.IndexBuffer,
                                            renderData.IndexCount,
                                            renderData.VertexFormat,
                                            renderData.Effect,
                                            renderData.PrimitiveType,
                                            0,
                                            renderData.PrimitiveCount);
                }
                return;
            }

            _lastDisplayStyle = displayStyle;

            var executionsToDraw = HyparHubApp.CurrentWorkflows.Values.SelectMany(w => w.FunctionInstances.Where(fi => fi.SelectedOptionExecutionId != null).Select(fi => fi.Id)).ToList();

            if (executionsToDraw.Count == 0)
            {
                _logger.Debug("There were no executions to draw...");
                HyparHubApp.RequiresRedraw = false;
                return;
            }

            _outline = new Outline(new XYZ(), new XYZ());

            // TODO: This is doing way too much drawing!
            // We should be able to only update render data
            // for executions which are different.
            try
            {
                _renderDataCache.Clear();
                foreach (var workflow in HyparHubApp.CurrentWorkflows.Values)
                {
                    foreach (var id in executionsToDraw)
                    {
                        var renderDatas = DrawExecutionFromGlb(_logger, workflow.Id, id, _outline, displayStyle);
                        if (renderDatas != null && renderDatas.Count > 0)
                        {
                            for (var i = 0; i < renderDatas.Count; i++)
                            {
                                var renderData = renderDatas[i];
                                _renderDataCache.Add($"{id}_{i}", renderData);
                            }
                        }
                    }
                }

                HyparHubApp.RequiresRedraw = false;

                _logger.Debug("Render complete.");
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                _logger.Debug(ex.StackTrace);
            }
        }
Ejemplo n.º 4
0
        public static RenderData DrawMesh(Elements.Geometry.Mesh mesh, ref Outline outline, DisplayStyle displayStyle)
        {
            var min = new XYZ(double.MaxValue, double.MaxValue, double.MaxValue);
            var max = new XYZ(double.MinValue, double.MinValue, double.MinValue);

            var numVertices   = mesh.Triangles.Count * 3;
            var numPrimitives = mesh.Triangles.Count;
            var pType         = PrimitiveType.TriangleList;
            var numIndices    = GetPrimitiveSize(pType) * numPrimitives;
            VertexFormatBits vertexFormatBits;

            switch (displayStyle)
            {
            case DisplayStyle.HLR:
            case DisplayStyle.FlatColors:
                vertexFormatBits = VertexFormatBits.PositionColored;
                break;

            default:
                vertexFormatBits = VertexFormatBits.PositionNormalColored;
                break;
            }
            var vertexFormat = new VertexFormat(vertexFormatBits);

            var vBuffer = new VertexBuffer(GetVertexSize(vertexFormatBits) * numVertices);
            var iBuffer = new IndexBuffer(numIndices);

            vBuffer.Map(GetVertexSize(vertexFormatBits) * numVertices);
            iBuffer.Map(numIndices);

            var verticesFlat = new List <VertexPositionColored>();
            var vertices     = new List <VertexPositionNormalColored>();
            var triangles    = new List <IndexTriangle>();

            // We duplicate the vertices on each triangle so that
            // we can get the correct number of face normals.
            foreach (var t in mesh.Triangles)
            {
                foreach (var v in t.Vertices)
                {
                    var pos = v.Position.ToXYZFeet();

                    outline.AddPoint(pos);

                    switch (vertexFormatBits)
                    {
                    case VertexFormatBits.PositionColored:
                        var color = displayStyle == DisplayStyle.HLR ? new ColorWithTransparency(255, 255, 255, 0) : v.Color.ToColorWithTransparency();
                        verticesFlat.Add(new VertexPositionColored(pos, color));
                        break;

                    default:
                        vertices.Add(new VertexPositionNormalColored(pos, t.Normal.ToXYZ(), v.Color.ToColorWithTransparency()));
                        break;
                    }

                    if (pos.X < min.X && pos.Y < min.Y && pos.Z < min.Z)
                    {
                        min = pos;
                    }
                    if (pos.X > min.X && pos.Y > min.Y && pos.Z > min.Z)
                    {
                        max = pos;
                    }
                }

                triangles.Add(new IndexTriangle(t.Vertices[0].Index, t.Vertices[1].Index, t.Vertices[2].Index));
            }

            switch (displayStyle)
            {
            case DisplayStyle.HLR:
            case DisplayStyle.FlatColors:
                var pc = vBuffer.GetVertexStreamPositionColored();
                pc.AddVertices(verticesFlat);
                break;

            default:
                var pnc = vBuffer.GetVertexStreamPositionNormalColored();
                pnc.AddVertices(vertices);
                break;
            }

            var iPos = iBuffer.GetIndexStreamTriangle();

            iPos.AddTriangles(triangles);

            vBuffer.Unmap();
            iBuffer.Unmap();

            var effect = new EffectInstance(vertexFormatBits);
            // There is no reason why this should work.
            // In other situations, 255 is the 'full' component.
            // In the case of hidden line rendering, 0, 0, 0 makes white.
            // if (displayStyle == DisplayStyle.HLR)
            // {
            //     var color = new ColorWithTransparency(0, 0, 0, 0);
            //     effect.SetColor(color.GetColor());
            //     effect.SetAmbientColor(color.GetColor());
            //     effect.SetDiffuseColor(color.GetColor());
            // }

            // Create a render data for reuse
            // on non-update calls.
            var renderData = new RenderData()
            {
                VertexBuffer   = vBuffer,
                VertexCount    = numVertices,
                IndexBuffer    = iBuffer,
                IndexCount     = numIndices,
                VertexFormat   = vertexFormat,
                Effect         = effect,
                PrimitiveType  = pType,
                PrimitiveCount = numPrimitives
            };

            if (displayStyle != DisplayStyle.Wireframe && numPrimitives > 0)
            {
                DrawContext.FlushBuffer(vBuffer, numVertices, iBuffer, numIndices, vertexFormat, effect, pType, 0, numPrimitives);
            }

            return(renderData);
        }
Ejemplo n.º 5
0
        private static RenderData ProcessPrimitive(ILogger logger, glTFLoader.Schema.MeshPrimitive primitive, Gltf gltf, byte[][] buffers, DisplayStyle displayStyle, Outline outline, Transform transform)
        {
            if (primitive.Mode != MeshPrimitive.ModeEnum.TRIANGLES)
            {
                logger.Debug("The selected primitive mode is not supported.");
                return(null);
            }

            var indexAccessor    = gltf.Accessors[(int)primitive.Indices];
            var positionAccessor = gltf.Accessors[primitive.Attributes["POSITION"]];
            var normalAccessor   = gltf.Accessors[primitive.Attributes["NORMAL"]];
            var hasColor         = primitive.Attributes.ContainsKey("COLOR_0");

            var indexBufferView    = gltf.BufferViews[(int)indexAccessor.BufferView];
            var positionBufferView = gltf.BufferViews[(int)positionAccessor.BufferView];
            var normalBufferView   = gltf.BufferViews[(int)normalAccessor.BufferView];

            var indices = new List <int>();

            for (var i = indexBufferView.ByteOffset; i < indexBufferView.ByteOffset + indexBufferView.ByteLength; i += indexBufferView.ByteStride ?? sizeof(ushort))
            {
                var index = BitConverter.ToUInt16(buffers[indexBufferView.Buffer], i);
                indices.Add(index);
            }

            var floatSize = sizeof(float);
            var positions = new List <XYZ>();

            for (var i = positionBufferView.ByteOffset; i < positionBufferView.ByteOffset + positionBufferView.ByteLength; i += positionBufferView.ByteStride ?? (floatSize * 3))
            {
                // Read x, y, z values
                var x  = BitConverter.ToSingle(buffers[positionBufferView.Buffer], i);
                var y  = BitConverter.ToSingle(buffers[positionBufferView.Buffer], i + floatSize);
                var z  = BitConverter.ToSingle(buffers[positionBufferView.Buffer], i + floatSize * 2);
                var pt = new XYZ(Elements.Units.MetersToFeet(x), Elements.Units.MetersToFeet(y), Elements.Units.MetersToFeet(z));
                if (transform != null)
                {
                    pt = transform.OfPoint(pt);
                }
                outline.AddPoint(pt);
                positions.Add(pt);
            }

            var normals = new List <XYZ>();

            for (var i = normalBufferView.ByteOffset; i < normalBufferView.ByteOffset + normalBufferView.ByteLength; i += normalBufferView.ByteStride ?? (floatSize * 3))
            {
                // Read x, y, z values
                var x = BitConverter.ToSingle(buffers[normalBufferView.Buffer], i);
                var y = BitConverter.ToSingle(buffers[normalBufferView.Buffer], i + floatSize);
                var z = BitConverter.ToSingle(buffers[normalBufferView.Buffer], i + floatSize * 2);
                var n = new XYZ(x, y, z);
                if (transform != null)
                {
                    n = transform.OfVector(n);
                }
                normals.Add(n);
            }

            var colors = new List <ColorWithTransparency>();

            if (hasColor)
            {
                var colorAccessor   = gltf.Accessors[primitive.Attributes["COLOR_0"]];
                var colorBufferView = gltf.BufferViews[(int)colorAccessor.BufferView];
                for (var i = colorBufferView.ByteOffset; i < colorBufferView.ByteOffset + colorBufferView.ByteLength; i += colorBufferView.ByteStride ?? (floatSize * 3))
                {
                    // Read x, y, z values
                    var r = BitConverter.ToSingle(buffers[colorBufferView.Buffer], i);
                    var g = BitConverter.ToSingle(buffers[colorBufferView.Buffer], i + floatSize);
                    var b = BitConverter.ToSingle(buffers[colorBufferView.Buffer], i + floatSize * 2);
                    colors.Add(displayStyle == DisplayStyle.HLR ? new ColorWithTransparency(255, 255, 255, 0) : new ColorWithTransparency((uint)(r * 255), (uint)(g * 255), (uint)(b * 255), 0));
                }
            }

            // The number of vertices will be the same as the length of the indices
            // because we'll duplicate vertices at every position.
            var numVertices   = indices.Count;
            var pType         = PrimitiveType.TriangleList;
            var numPrimitives = indices.Count / 3;
            var numIndices    = GetPrimitiveSize(pType) * numPrimitives;

            VertexFormatBits vertexFormatBits;

            switch (displayStyle)
            {
            case DisplayStyle.HLR:
            case DisplayStyle.FlatColors:
                vertexFormatBits = VertexFormatBits.PositionColored;
                break;

            default:
                vertexFormatBits = VertexFormatBits.PositionNormalColored;
                break;
            }
            var vertexFormat = new VertexFormat(vertexFormatBits);

            var vBuffer = new VertexBuffer(GetVertexSize(vertexFormatBits) * numVertices);
            var iBuffer = new IndexBuffer(numIndices);

            vBuffer.Map(GetVertexSize(vertexFormatBits) * numVertices);
            iBuffer.Map(numIndices);

            var verticesFlat = new List <VertexPositionColored>();
            var vertices     = new List <VertexPositionNormalColored>();
            var triangles    = new List <IndexTriangle>();

            ColorWithTransparency color = null;

            if (displayStyle == DisplayStyle.HLR)
            {
                color = new ColorWithTransparency(255, 255, 255, 0);
            }
            else if (primitive.Material != null)
            {
                var material = gltf.Materials[(int)primitive.Material];
                var r        = (uint)(material.PbrMetallicRoughness.BaseColorFactor[0] * 255);
                var g        = (uint)(material.PbrMetallicRoughness.BaseColorFactor[1] * 255);
                var b        = (uint)(material.PbrMetallicRoughness.BaseColorFactor[2] * 255);
                var a        = (uint)(material.PbrMetallicRoughness.BaseColorFactor[3] * 255);
                color = new ColorWithTransparency(r, g, b, a);
            }

            for (var i = 0; i < indices.Count; i += 3)
            {
                var ia = indices[i];
                var ib = indices[i + 1];
                var ic = indices[i + 2];

                var a = positions[ia];
                var b = positions[ib];
                var c = positions[ic];

                var na = normals[ia];
                var nb = normals[ib];
                var nc = normals[ic];

                switch (vertexFormatBits)
                {
                case VertexFormatBits.PositionColored:
                    if (hasColor)
                    {
                        color = colors[ia];
                    }
                    verticesFlat.Add(new VertexPositionColored(a, hasColor ? colors[ia] : color));
                    verticesFlat.Add(new VertexPositionColored(b, hasColor ? colors[ib] : color));
                    verticesFlat.Add(new VertexPositionColored(c, hasColor ? colors[ic] : color));
                    break;

                default:
                    if (hasColor)
                    {
                        color = colors[ia];
                    }
                    vertices.Add(new VertexPositionNormalColored(a, na, hasColor ? colors[ia] : color));
                    vertices.Add(new VertexPositionNormalColored(b, nb, hasColor ? colors[ib] : color));
                    vertices.Add(new VertexPositionNormalColored(c, nc, hasColor ? colors[ic] : color));
                    break;
                }

                triangles.Add(new IndexTriangle(i, i + 1, i + 2));
            }

            switch (displayStyle)
            {
            case DisplayStyle.HLR:
            case DisplayStyle.FlatColors:
                var pc = vBuffer.GetVertexStreamPositionColored();
                pc.AddVertices(verticesFlat);
                break;

            default:
                var pnc = vBuffer.GetVertexStreamPositionNormalColored();
                pnc.AddVertices(vertices);
                break;
            }

            var iPos = iBuffer.GetIndexStreamTriangle();

            iPos.AddTriangles(triangles);

            vBuffer.Unmap();
            iBuffer.Unmap();

            var effect = new EffectInstance(vertexFormatBits);

            var renderData = new RenderData()
            {
                VertexBuffer   = vBuffer,
                VertexCount    = numVertices,
                IndexBuffer    = iBuffer,
                IndexCount     = numIndices,
                VertexFormat   = vertexFormat,
                Effect         = effect,
                PrimitiveType  = pType,
                PrimitiveCount = numPrimitives
            };

            if (displayStyle != DisplayStyle.Wireframe && numPrimitives > 0)
            {
                DrawContext.FlushBuffer(vBuffer, numVertices, iBuffer, numIndices, vertexFormat, effect, pType, 0, numPrimitives);
            }

            return(renderData);
        }
            public virtual void Draw(DisplayStyle displayStyle)
            {
                if (!Regen())
                {
                    return;
                }

                var vc = HasVertexColors(vertexFormatBits) && ShowsVertexColors(displayStyle);

                if (DrawContext.IsTransparentPass() != vc)
                {
                    if (vertexCount > 0)
                    {
                        var ei = EffectInstance(displayStyle, true);

                        if (triangleCount > 0)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                triangleBuffer, triangleCount * 3,
                                vertexFormat, ei,
                                PrimitiveType.TriangleList,
                                0, triangleCount
                            );
                        }
                        else if (linesBuffer != null)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                linesBuffer, vertexCount,
                                vertexFormat, ei,
                                PrimitiveType.PointList,
                                0, vertexCount
                            );
                        }
                    }
                }

                if (!DrawContext.IsTransparentPass())
                {
                    if (linesCount != 0)
                    {
                        if (triangleBuffer != null && !ShowsEdges(displayStyle))
                        {
                            return;
                        }

                        if (linesCount > 0)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                linesBuffer, linesCount * 2,
                                vertexFormat, EffectInstance(displayStyle, false),
                                PrimitiveType.LineList,
                                0, linesCount
                            );
                        }
                        else if (triangleCount == 0)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                linesBuffer, vertexCount,
                                vertexFormat, EffectInstance(displayStyle, false),
                                PrimitiveType.PointList,
                                0, vertexCount
                            );
                        }
                    }
                }
            }
Ejemplo n.º 7
0
        // Submits the geometry for rendering.
        public void RenderScene(Autodesk.Revit.DB.View view, DisplayStyle displayStyle)
        {
            try
            {
                //on request, process pre-stored graphic data
                //to get ready for submission for drawing.
                if (InputChanged)
                {
                    ProcessFaces(this.Inputs.NonTransFaceBuffer);
                    ProcessFaces(this.Inputs.TransFaceBuffer);
                    ProcessTriangles(this.Inputs.NonTransTriangleBuffer);
                    ProcessTriangles(this.Inputs.TransTriangleBuffer);
                    ProcessEdges(this.Inputs.EdgeBuffer);
                    ProcessPoints(this.Inputs.PointBuffer);
                }

                DrawContext.SetWorldTransform(this.WorldTransform);

                // Submit a subset of the geometry for drawing. Determine what geometry should be submitted based on
                // the type of the rendering pass (opaque or transparent) and DisplayStyle (wireframe or shaded).

                // If the server is requested to submit transparent geometry, DrawContext().IsTransparentPass()
                // will indicate that the current rendering pass is for transparent objects.
                RenderingPassBufferStorage faceBuffer =
                    DrawContext.IsTransparentPass()
                    ? this.Inputs.TransFaceBuffer
                    : this.Inputs.NonTransFaceBuffer;
                RenderingPassBufferStorage triangleBuffer =
                    DrawContext.IsTransparentPass()
                    ? this.Inputs.TransTriangleBuffer
                    : this.Inputs.NonTransTriangleBuffer;
                var edgeBuffer  = this.Inputs.EdgeBuffer;
                var pointBuffer = this.Inputs.PointBuffer;

                // Conditionally submit triangle primitives (for non-wireframe views).
                if (displayStyle != DisplayStyle.Wireframe &&
                    faceBuffer.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(faceBuffer.VertexBuffer,
                                            faceBuffer.VertexBufferCount,
                                            faceBuffer.IndexBuffer,
                                            faceBuffer.IndexBufferCount,
                                            faceBuffer.VertexFormat,
                                            faceBuffer.EffectInstance, PrimitiveType.TriangleList, 0,
                                            faceBuffer.PrimitiveCount);
                }

                if (displayStyle != DisplayStyle.Wireframe &&
                    triangleBuffer.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(triangleBuffer.VertexBuffer,
                                            triangleBuffer.VertexBufferCount,
                                            triangleBuffer.IndexBuffer,
                                            triangleBuffer.IndexBufferCount,
                                            triangleBuffer.VertexFormat,
                                            triangleBuffer.EffectInstance, PrimitiveType.TriangleList, 0,
                                            triangleBuffer.PrimitiveCount);
                }

                // Conditionally submit line segment primitives.
                if (displayStyle != DisplayStyle.Shading &&
                    edgeBuffer.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(edgeBuffer.VertexBuffer,
                                            edgeBuffer.VertexBufferCount,
                                            edgeBuffer.IndexBuffer,
                                            edgeBuffer.IndexBufferCount,
                                            edgeBuffer.VertexFormat,
                                            edgeBuffer.EffectInstance, PrimitiveType.LineList, 0,
                                            edgeBuffer.PrimitiveCount);
                }

                if (pointBuffer.PrimitiveCount > 0)
                {
                    DrawContext.FlushBuffer(pointBuffer.VertexBuffer,
                                            pointBuffer.VertexBufferCount,
                                            pointBuffer.IndexBuffer,
                                            pointBuffer.IndexBufferCount,
                                            pointBuffer.VertexFormat,
                                            pointBuffer.EffectInstance, PrimitiveType.PointList, 0,
                                            pointBuffer.PrimitiveCount);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                InputChanged = false;
            }
        }
            public virtual void Draw(DisplayStyle displayStyle)
            {
                if (!Regen())
                {
                    return;
                }

                if (DrawContext.IsTransparentPass())
                {
                    if (vertexCount > 0)
                    {
                        var ei = EffectInstance(displayStyle, true);

                        if (triangleCount > 0)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                triangleBuffer, triangleCount * 3,
                                vertexFormat, ei,
                                PrimitiveType.TriangleList,
                                0, triangleCount
                            );
                        }
                        else if (linesBuffer != null)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                linesBuffer, vertexCount,
                                vertexFormat, ei,
                                PrimitiveType.PointList,
                                0, vertexCount
                            );
                        }
                    }
                }
                else
                {
                    if (linesCount != 0)
                    {
                        if (triangleBuffer != null)
                        {
                            bool edges = displayStyle == DisplayStyle.Wireframe ||
                                         displayStyle == DisplayStyle.HLR ||
                                         displayStyle == DisplayStyle.ShadingWithEdges ||
                                         displayStyle == DisplayStyle.FlatColors ||
                                         displayStyle == DisplayStyle.RealisticWithEdges;

                            if (!edges)
                            {
                                return;
                            }
                        }

                        if (linesCount > 0)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                linesBuffer, linesCount * 2,
                                vertexFormat, EffectInstance(displayStyle, false),
                                PrimitiveType.LineList,
                                0, linesCount
                            );
                        }
                        else if (triangleCount == 0)
                        {
                            DrawContext.FlushBuffer
                            (
                                vertexBuffer, vertexCount,
                                linesBuffer, vertexCount,
                                vertexFormat, EffectInstance(displayStyle, false),
                                PrimitiveType.PointList,
                                0, vertexCount
                            );
                        }
                    }
                }
            }