Exemplo n.º 1
0
        protected static int ToPointsBuffer
        (
            Point point,
            out DB3D.VertexFormatBits vertexFormatBits,
            out DB3D.VertexBuffer vb, out int vertexCount,
            out DB3D.IndexBuffer ib
        )
        {
            int pointsCount = 0;

            if (point.Location.IsValid)
            {
                pointsCount = 1;
                vertexCount = 1;

                vertexFormatBits = DB3D.VertexFormatBits.Position;
                vb = new DB3D.VertexBuffer(pointsCount * DB3D.VertexPosition.GetSizeInFloats());
                vb.Map(pointsCount * DB3D.VertexPosition.GetSizeInFloats());
                using (var vstream = vb.GetVertexStreamPosition())
                {
                    vstream.AddVertex(new DB3D.VertexPosition(RawEncoder.AsXYZ(point.Location)));
                }
                vb.Unmap();

                ib = IndexPointsBuffer(pointsCount);
            }
            else
            {
                vertexFormatBits = 0;
                vb = null; vertexCount = 0;
                ib = null;
            }

            return(pointsCount);
        }
Exemplo n.º 2
0
        protected static int ToPolylineBuffer
        (
            Polyline polyline,
            out DB3D.VertexFormatBits vertexFormatBits,
            out DB3D.VertexBuffer vb, out int vertexCount,
            out DB3D.IndexBuffer ib
        )
        {
            int linesCount = 0;

            if (polyline.SegmentCount > 0)
            {
                linesCount  = polyline.SegmentCount;
                vertexCount = polyline.Count;

                vertexFormatBits = DB3D.VertexFormatBits.Position;
                vb = new DB3D.VertexBuffer(vertexCount * DB3D.VertexPosition.GetSizeInFloats());
                vb.Map(vertexCount * DB3D.VertexPosition.GetSizeInFloats());
                using (var vstream = vb.GetVertexStreamPosition())
                {
                    foreach (var v in polyline)
                    {
                        vstream.AddVertex(new DB3D.VertexPosition(RawEncoder.AsXYZ(v)));
                    }
                }
                vb.Unmap();

                ib = IndexLinesBuffer(vertexCount);
            }
            else
            {
                vertexFormatBits = 0;
                vb = null; vertexCount = 0;
                ib = null;
            }

            return(linesCount);
        }
Exemplo n.º 3
0
 public static bool HasVertexColors(DB3D.VertexFormatBits vertexFormatBits) => (((int)vertexFormatBits) & 4) != 0;
Exemplo n.º 4
0
 public static bool HasVertexNormals(DB3D.VertexFormatBits vertexFormatBits) => (((int)vertexFormatBits) & 2) != 0;
Exemplo n.º 5
0
        protected static int ToPointsBuffer
        (
            PointCloud pointCloud,
            Primitive.Part part,
            out DB3D.VertexFormatBits vertexFormatBits,
            out DB3D.VertexBuffer vb, out int vertexCount,
            out DB3D.IndexBuffer ib
        )
        {
            int pointsCount = part.VertexCount;
            int normalCount = pointCloud.ContainsNormals ? pointsCount : 0;
            int colorsCount = pointCloud.ContainsColors  ? pointsCount : 0;

            bool hasPoints  = pointsCount > 0;
            bool hasNormals = normalCount == pointsCount;
            bool hasColors  = colorsCount == pointsCount;

            if (hasPoints)
            {
                if (hasNormals)
                {
                    if (hasColors)
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.PositionNormalColored;
                        vb = new DB3D.VertexBuffer(pointsCount * DB3D.VertexPositionNormalColored.GetSizeInFloats());
                        vb.Map(pointsCount * DB3D.VertexPositionNormalColored.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionNormalColored())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                var c     = new DB.ColorWithTransparency(point.Color.R, point.Color.G, point.Color.B, 255u - point.Color.A);
                                vstream.AddVertex(new DB3D.VertexPositionNormalColored(RawEncoder.AsXYZ(point.Location), RawEncoder.AsXYZ(point.Normal), c));
                            }
                        }

                        vb.Unmap();
                    }
                    else
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.PositionNormal;
                        vb = new DB3D.VertexBuffer(pointsCount * DB3D.VertexPositionNormal.GetSizeInFloats());
                        vb.Map(pointsCount * DB3D.VertexPositionNormal.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionNormal())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                vstream.AddVertex(new DB3D.VertexPositionNormal(RawEncoder.AsXYZ(point.Location), RawEncoder.AsXYZ(point.Normal)));
                            }
                        }

                        vb.Unmap();
                    }
                }
                else
                {
                    if (hasColors)
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.PositionColored;
                        vb = new DB3D.VertexBuffer(pointsCount * DB3D.VertexPositionColored.GetSizeInFloats());
                        vb.Map(pointsCount * DB3D.VertexPositionColored.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionColored())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                var c     = new DB.ColorWithTransparency(point.Color.R, point.Color.G, point.Color.B, 255u - point.Color.A);
                                vstream.AddVertex(new DB3D.VertexPositionColored(RawEncoder.AsXYZ(point.Location), c));
                            }
                        }

                        vb.Unmap();
                    }
                    else
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.Position;
                        vb = new DB3D.VertexBuffer(pointsCount * DB3D.VertexPosition.GetSizeInFloats());
                        vb.Map(pointsCount * DB3D.VertexPosition.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPosition())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                vstream.AddVertex(new DB3D.VertexPosition(RawEncoder.AsXYZ(point.Location)));
                            }
                        }

                        vb.Unmap();
                    }
                }

                ib = IndexPointsBuffer(pointsCount);
            }
            else
            {
                vertexFormatBits = 0;
                vb = null;
                ib = null;
            }

            vertexCount = pointsCount;
            return(pointsCount);
        }
Exemplo n.º 6
0
        protected static DB3D.VertexBuffer ToVertexBuffer
        (
            Mesh mesh,
            Primitive.Part part,
            out DB3D.VertexFormatBits vertexFormatBits,
            System.Drawing.Color color = default
        )
        {
            int verticesCount = part.EndVertexIndex - part.StartVertexIndex;
            int normalCount   = mesh.Normals.Count == mesh.Vertices.Count ? verticesCount : 0;
            int colorsCount   = color.IsEmpty ? (mesh.VertexColors.Count == mesh.Vertices.Count ? verticesCount : 0) : verticesCount;

            bool hasVertices = verticesCount > 0;
            bool hasNormals  = normalCount > 0;
            bool hasColors   = colorsCount > 0;

            if (hasVertices)
            {
                var vertices = mesh.Vertices;
                if (hasNormals)
                {
                    var normals = mesh.Normals;
                    if (hasColors)
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.PositionNormalColored;
                        var colors = mesh.VertexColors;
                        var vb     = new DB3D.VertexBuffer(verticesCount * DB3D.VertexPositionNormalColored.GetSizeInFloats());
                        vb.Map(verticesCount * DB3D.VertexPositionNormalColored.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPositionNormalColored())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                var  c = !color.IsEmpty ? color : colors[v];
                                uint T = Math.Max(1, 255u - c.A);
                                stream.AddVertex(new DB3D.VertexPositionNormalColored(RawEncoder.AsXYZ(vertices[v]), RawEncoder.AsXYZ(normals[v]), new DB.ColorWithTransparency(c.R, c.G, c.B, T)));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                    else
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.PositionNormal;
                        var sizeInFloats = DB3D.VertexPositionNormal.GetSizeInFloats();
                        var vb           = new DB3D.VertexBuffer(verticesCount * sizeInFloats);
                        vb.Map(verticesCount * sizeInFloats);

                        using (var stream = vb.GetVertexStreamPositionNormal())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                stream.AddVertex(new DB3D.VertexPositionNormal(RawEncoder.AsXYZ(vertices[v]), RawEncoder.AsXYZ(normals[v])));
                            }
                        }

                        vb.Unmap();
                        return(vb);
                    }
                }
                else
                {
                    if (hasColors)
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.PositionColored;
                        var colors = mesh.VertexColors;
                        var vb     = new DB3D.VertexBuffer(verticesCount * DB3D.VertexPositionColored.GetSizeInFloats());
                        vb.Map(verticesCount * DB3D.VertexPositionColored.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPositionColored())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                var  c = !color.IsEmpty ? color : colors[v];
                                uint T = Math.Max(1, 255u - c.A);
                                stream.AddVertex(new DB3D.VertexPositionColored(RawEncoder.AsXYZ(vertices[v]), new DB.ColorWithTransparency(c.R, c.G, c.B, T)));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                    else
                    {
                        vertexFormatBits = DB3D.VertexFormatBits.Position;
                        var vb = new DB3D.VertexBuffer(verticesCount * DB3D.VertexPosition.GetSizeInFloats());
                        vb.Map(verticesCount * DB3D.VertexPosition.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPosition())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                stream.AddVertex(new DB3D.VertexPosition(RawEncoder.AsXYZ(vertices[v])));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                }
            }

            vertexFormatBits = 0;
            return(null);
        }