Beispiel #1
0
        protected override void DrawForSelection(GfxDrawForSelectionParams data)
        {
            if (DrawSubItemsForSelection)
            {
                var prev = vp.SuspendSetColorForSelection;
                vp.SuspendSetColorForSelection = false;

                // Draws the lines with the color-coding needed for visibility computation
                for (int index = 0; index < SelectedSubItems.Count; index++)
                {
                    Point3D p1 = Vertices[Lines[SelectedSubItems[index]].V1];
                    Point3D p2 = Vertices[Lines[SelectedSubItems[index]].V2];


                    vp.SetColorDrawForSelection(SelectedSubItems[index]);

                    IndexLine tri = Lines[SelectedSubItems[index]];
                    data.RenderContext.DrawLine(p1, p2);
                }

                vp.SuspendSetColorForSelection = prev;

                // reset the color to avoid issues with the entities drawn after this one
                data.RenderContext.SetColorWireframe(System.Drawing.Color.White);
            }

            else
            {
                data.RenderContext.DrawIndexLines(Lines, Vertices);
            }
        }
        protected static IndexBuffer ToWireframeBuffer(Rhino.Geometry.Mesh mesh, out int linesCount)
        {
            linesCount = (mesh.Faces.Count * 3) + mesh.Faces.QuadCount;
            if (linesCount > 0)
            {
                var ib = new IndexBuffer(linesCount * IndexLine.GetSizeInShortInts());
                ib.Map(linesCount * IndexLine.GetSizeInShortInts());

                using (var istream = ib.GetIndexStreamLine())
                {
                    foreach (var face in mesh.Faces)
                    {
                        istream.AddLine(new IndexLine(face.A, face.B));
                        istream.AddLine(new IndexLine(face.B, face.C));
                        istream.AddLine(new IndexLine(face.C, face.D));
                        if (face.IsQuad)
                        {
                            istream.AddLine(new IndexLine(face.D, face.A));
                        }
                    }
                }

                ib.Unmap();
                return(ib);
            }

            return(null);
        }
Beispiel #3
0
        protected override bool AllVerticesInScreenPolygon(ScreenPolygonParams data)
        {
            // Computes the lines that are completely enclosed to the screen polygon

            if (vp.processVisibleOnly && !Selected)
            {
                return(false);
            }

            SelectedSubItems = new List <int>();

            for (int i = 0; i < Lines.Length; i++)
            {
                IndexLine line = Lines[i];

                if (UtilityEx.AllVerticesInScreenPolygon(data, new List <Point3D>()
                {
                    Vertices[line.V1], Vertices[line.V2]
                }, 2))
                {
                    SelectedSubItems.Add(i);
                }
            }

            return(false);
        }
Beispiel #4
0
        // A helper function, analogous to ProcessFaces.
        private void ProcessEdges(RenderingPassBufferStorage bufferStorage)
        {
            List <IList <XYZ> > edges = bufferStorage.EdgeXYZs;

            if (edges.Count == 0)
            {
                return;
            }

            // Edges are encoded as line segment primitives whose vertices contain only position information.
            bufferStorage.FormatBits = VertexFormatBits.Position;

            int        edgeVertexBufferSizeInFloats = VertexPosition.GetSizeInFloats() * bufferStorage.VertexBufferCount;
            List <int> numVerticesInEdgesBefore     = new List <int>();

            numVerticesInEdgesBefore.Add(0);

            bufferStorage.VertexBuffer = new VertexBuffer(edgeVertexBufferSizeInFloats);
            bufferStorage.VertexBuffer.Map(edgeVertexBufferSizeInFloats);
            {
                VertexStreamPosition vertexStream = bufferStorage.VertexBuffer.GetVertexStreamPosition();
                foreach (IList <XYZ> xyzs in edges)
                {
                    foreach (XYZ vertex in xyzs)
                    {
                        vertexStream.AddVertex(new VertexPosition(vertex + m_offset));
                    }

                    numVerticesInEdgesBefore.Add(numVerticesInEdgesBefore.Last() + xyzs.Count);
                }
            }
            bufferStorage.VertexBuffer.Unmap();

            int edgeNumber = 0;

            bufferStorage.IndexBufferCount = bufferStorage.PrimitiveCount * IndexLine.GetSizeInShortInts();
            int indexBufferSizeInShortInts = 1 * bufferStorage.IndexBufferCount;

            bufferStorage.IndexBuffer = new IndexBuffer(indexBufferSizeInShortInts);
            bufferStorage.IndexBuffer.Map(indexBufferSizeInShortInts);
            {
                IndexStreamLine indexStream = bufferStorage.IndexBuffer.GetIndexStreamLine();
                foreach (IList <XYZ> xyzs in edges)
                {
                    int startIndex = numVerticesInEdgesBefore[edgeNumber];
                    for (int i = 1; i < xyzs.Count; i++)
                    {
                        // Add two indices that define a line segment.
                        indexStream.AddLine(new IndexLine((int)(startIndex + i - 1),
                                                          (int)(startIndex + i)));
                    }
                    edgeNumber++;
                }
            }
            bufferStorage.IndexBuffer.Unmap();


            bufferStorage.VertexFormat   = new VertexFormat(bufferStorage.FormatBits);
            bufferStorage.EffectInstance = new EffectInstance(bufferStorage.FormatBits);
        }
Beispiel #5
0
        private void LinearPathSpheres()
        {
            // creates the entities
            int          slices = 20;
            int          stacks = 10;
            MyLinearPath m2     = new MyLinearPath(model1, new LinearPath(Mesh.CreateSphere(10, slices, stacks).Vertices));

            //computes group of lines
            IndexLine[] edges = new IndexLine[slices * (stacks - 1)];
            for (int i = 0; i < (stacks - 1); i++)
            {
                for (int j = 0; j < (slices - 1); j++)
                {
                    int v1 = i * slices + j;
                    edges[v1] = new IndexLine(v1, v1 + 1);
                }
                edges[i * slices + (slices - 1)] = new IndexLine(i * slices + (slices - 1), i * slices);
            }
            m2.Lines = edges;

            MyLinearPath m1 = (MyLinearPath)m2.Clone();

            m2.Translate(25, 0, 0);
            m2.LineWeight = 4;

            model1.Entities.Add(m1, Color.FromArgb(255, Color.Green));
            model1.Entities.Add(m2, Color.FromArgb(155, Color.Red));
        }
        public static int GetPrimitiveSize(PrimitiveType primitive)
        {
            switch (primitive)
            {
            case PrimitiveType.LineList: return(IndexLine.GetSizeInShortInts());

            case PrimitiveType.PointList: return(IndexPoint.GetSizeInShortInts());

            case PrimitiveType.TriangleList: return(IndexTriangle.GetSizeInShortInts());

            default: break;
            }
            return(IndexTriangle.GetSizeInShortInts());
        }
Beispiel #7
0
        protected override bool InsideOrCrossingScreenPolygon(ScreenPolygonParams data)
        {
            // Computes the lines that are inside or crossing the screen polygon
            for (int i = 0; i < Lines.Length; i++)
            {
                Segment2D seg;

                IndexLine line = Lines[i];
                Point3D   pt1  = Vertices[line.V1];
                Point3D   pt2  = Vertices[line.V2];

                Point3D screenP1 = vp.Camera.WorldToScreen(pt1, data.ViewFrame);
                Point3D screenP2 = vp.Camera.WorldToScreen(pt2, data.ViewFrame);

                if (screenP1.Z > 1 || screenP2.Z > 1)
                {
                    return(false);  // for perspective
                }
                seg = new Segment2D(screenP1, screenP2);

                if (UtilityEx.PointInPolygon(screenP1, data.ScreenPolygon) ||
                    UtilityEx.PointInPolygon(screenP2, data.ScreenPolygon))

                {
                    SelectedSubItems.Add(i);
                    continue;
                }

                for (int j = 0; j < data.ScreenSegments.Count; j++)
                {
                    Point2D i0;
                    if (Segment2D.Intersection(data.ScreenSegments[j], seg, out i0))

                    {
                        SelectedSubItems.Add(i);
                        break;
                    }
                }
            }

            return(false);
        }
        static IndexBuffer IndexLinesBuffer(int pointsCount)
        {
            Debug.Assert(pointsCount <= VertexThreshold);

            if (indexLinesBuffer == null)
            {
                indexLinesBuffer = new IndexBuffer(VertexThreshold * IndexLine.GetSizeInShortInts());
                indexLinesBuffer.Map(VertexThreshold * IndexLine.GetSizeInShortInts());
                using (var istream = indexLinesBuffer.GetIndexStreamLine())
                {
                    for (int vi = 0; vi < VertexThreshold - 1; ++vi)
                    {
                        istream.AddLine(new IndexLine(vi, vi + 1));
                    }
                }
                indexLinesBuffer.Unmap();
            }

            Debug.Assert(indexLinesBuffer.IsValid());
            return(indexLinesBuffer);
        }
Beispiel #9
0
 public bool ContainsEdge(IndexLine edge, out bool polygonIsCCW)
 {
     for (int i = 0; i < _points.Count; ++i)
     {
         if (_points[i] == edge.Point0)
         {
             if (i + 1 < _points.Count && _points[i + 1] == edge.Point1)
             {
                 polygonIsCCW = true;
                 return(true);
             }
             else if (i - 1 >= 0 && _points[i - 1] == edge.Point1)
             {
                 polygonIsCCW = false;
                 return(true);
             }
         }
     }
     polygonIsCCW = true;
     return(false);
 }
Beispiel #10
0
        protected override bool AllVerticesInFrustum(FrustumParams data)
        {
            // Computes the lines that are completely enclosed to the selection rectangle

            if (vp.processVisibleOnly && !Selected)
            {
                return(false);
            }

            SelectedSubItems = new List <int>();

            for (int i = 0; i < Lines.Length; i++)
            {
                IndexLine line = Lines[i];

                if (Camera.IsInFrustum(Vertices[line.V1], data.Frustum) && Camera.IsInFrustum(Vertices[line.V2], data.Frustum))
                {
                    SelectedSubItems.Add(i);
                }
            }

            return(false);
        }
        protected static IndexBuffer ToEdgeBuffer
        (
            Rhino.Geometry.Mesh mesh,
            Primitive.Part part,
            out int linesCount
        )
        {
            if (part.VertexCount != mesh.Vertices.Count)
            {
                if (part.VertexCount > 0)
                {
                    linesCount = -part.VertexCount;
                    return(IndexPointsBuffer(part.VertexCount));
                }

                linesCount = 0;
            }
            else
            {
                var edgeIndices = new List <IndexPair>();
                if (mesh.Ngons.Count > 0)
                {
                    foreach (var ngon in mesh.Ngons)
                    {
                        var boundary = ngon.BoundaryVertexIndexList();
                        if ((boundary?.Length ?? 0) > 1)
                        {
                            for (int b = 0; b < boundary.Length - 1; ++b)
                            {
                                edgeIndices.Add(new IndexPair((int)boundary[b], (int)boundary[b + 1]));
                            }

                            edgeIndices.Add(new IndexPair((int)boundary[boundary.Length - 1], (int)boundary[0]));
                        }
                    }
                }
                else
                {
                    var vertices  = mesh.TopologyVertices;
                    var edges     = mesh.TopologyEdges;
                    var edgeCount = edges.Count;
                    for (int e = 0; e < edgeCount; ++e)
                    {
                        if (edges.IsEdgeUnwelded(e) || edges.GetConnectedFaces(e).Length < 2)
                        {
                            var pair = edges.GetTopologyVertices(e);
                            pair.I = vertices.MeshVertexIndices(pair.I)[0];
                            pair.J = vertices.MeshVertexIndices(pair.J)[0];
                            edgeIndices.Add(pair);
                        }
                    }
                }

                linesCount = edgeIndices.Count;
                if (linesCount > 0)
                {
                    var ib = new IndexBuffer(linesCount * IndexLine.GetSizeInShortInts());
                    ib.Map(linesCount * IndexLine.GetSizeInShortInts());
                    using (var istream = ib.GetIndexStreamLine())
                    {
                        foreach (var edge in edgeIndices)
                        {
                            Debug.Assert(0 <= edge.I && edge.I < part.VertexCount);
                            Debug.Assert(0 <= edge.J && edge.J < part.VertexCount);
                            istream.AddLine(new IndexLine(edge.I, edge.J));
                        }
                    }
                    ib.Unmap();

                    return(ib);
                }
            }

            return(null);
        }