Пример #1
0
        private static void CreatePlaneTessellation(IRenderPackage package, Plane plane)
        {
            package.RequiresPerVertexColoration = true;

            var s = 2.5;

            var cs = CoordinateSystem.ByPlane(plane);
            var a  = Point.ByCartesianCoordinates(cs, s, s, 0);
            var b  = Point.ByCartesianCoordinates(cs, -s, s, 0);
            var c  = Point.ByCartesianCoordinates(cs, -s, -s, 0);
            var d  = Point.ByCartesianCoordinates(cs, s, -s, 0);

            //Add two triangles to represent the plane
            package.AddTriangleVertex(a.X, a.Y, a.Z);
            package.AddTriangleVertex(b.X, b.Y, b.Z);
            package.AddTriangleVertex(c.X, c.Y, c.Z);

            package.AddTriangleVertex(c.X, c.Y, c.Z);
            package.AddTriangleVertex(d.X, d.Y, d.Z);
            package.AddTriangleVertex(a.X, a.Y, a.Z);

            //Add the mesh vertex UV, normal, and color data for the 6 triangle vertices
            for (var i = 0; i < 6; i++)
            {
                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexNormal(plane.Normal.X, plane.Normal.Y, plane.Normal.Z);
                package.AddTriangleVertexColor(0, 0, 0, 10);
            }

            // Draw plane edges
            package.AddLineStripVertex(a.X, a.Y, a.Z);
            package.AddLineStripVertex(b.X, b.Y, b.Z);
            package.AddLineStripVertex(b.X, b.Y, b.Z);
            package.AddLineStripVertex(c.X, c.Y, c.Z);
            package.AddLineStripVertex(c.X, c.Y, c.Z);
            package.AddLineStripVertex(d.X, d.Y, d.Z);
            package.AddLineStripVertex(d.X, d.Y, d.Z);
            package.AddLineStripVertex(a.X, a.Y, a.Z);

            // Draw normal
            package.AddLineStripVertex(plane.Origin.X, plane.Origin.Y, plane.Origin.Z);
            var nEnd = plane.Origin.Add(plane.Normal.Scale(2.5));

            package.AddLineStripVertex(nEnd.X, nEnd.Y, nEnd.Z);

            //Add the line vertex data for the plane line geometry (4 plane edges and 1 normal).
            for (var i = 0; i < 5; i++)
            {
                package.AddLineStripVertexCount(2);
                package.AddLineStripVertexColor(MidTone, MidTone, MidTone, 255);
                package.AddLineStripVertexColor(MidTone, MidTone, MidTone, 255);
            }

            //dispose helper geometry
            a.Dispose();
            b.Dispose();
            c.Dispose();
            d.Dispose();
            cs.Dispose();
        }
Пример #2
0
        internal static void RenderNetworkFrame(CompasNetwork network, double[][] vertices, IRenderPackage package, TessellationParameters parameters)
        {
            // Vertices
            foreach (double[] p in vertices)
            {
                package.AddPointVertex(p[0], p[1], p[2]);
                package.AddPointVertexColor(255, 0, 0, 255);
            }

            if (network.edgesInt != null)
            {
                foreach (int[] ids in network.edgesInt)
                {
                    double[] p0 = vertices[ids[0]];
                    double[] p1 = vertices[ids[1]];

                    package.AddLineStripVertexColor(0, 255, 0, 255);
                    package.AddLineStripVertex(p0[0], p0[1], p0[2]);

                    package.AddLineStripVertexColor(0, 0, 255, 255);
                    package.AddLineStripVertex(p1[0], p1[1], p1[2]);

                    package.AddLineStripVertexCount(2);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Draws plane at half the scale.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="plane"></param>
        /// <param name="name"></param>
        private void DrawPlane(ref IRenderPackage package, Plane plane, Planes name)
        {
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorPlane, Name, name);
            using (var vec1 = plane.XAxis.Scale(scale / 3))
                using (var vec2 = plane.YAxis.Scale(scale / 3))
                    using (var vec3 = plane.YAxis.Scale(scale / 3))
                    {
                        using (var p1 = Origin.Add(vec1))
                            using (var p2 = p1.Add(vec2))
                                using (var p3 = Origin.Add(vec3))
                                {
                                    var axis  = plane.Normal;
                                    var color = GetAxisColor(GetAlignedAxis(axis));

                                    package.AddLineStripVertexCount(3);
                                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                                    package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

                                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                                    package.AddLineStripVertex(p2.X, p2.Y, p2.Z);

                                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                                    package.AddLineStripVertex(p3.X, p3.Y, p3.Z);
                                }
                    }
        }
Пример #4
0
 public static void DrawLine(IRenderPackage package, Triple start, Triple end, Color color)
 {
     package.AddLineStripVertexCount(2);
     package.AddLineStripVertex(start.X, start.Y, start.Z);
     package.AddLineStripVertex(end.X, end.Y, end.Z);
     package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
     package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
 }
Пример #5
0
        internal static void AddColouredEdge(IRenderPackage package, gEdge edge, DSCore.Color color)
        {
            package.AddLineStripVertex(edge.StartVertex.X, edge.StartVertex.Y, edge.StartVertex.Z);
            package.AddLineStripVertex(edge.EndVertex.X, edge.EndVertex.Y, edge.EndVertex.Z);

            package.AddLineStripVertexColor(color.Red, color.Green, color.Blue, color.Alpha);
            package.AddLineStripVertexColor(color.Red, color.Green, color.Blue, color.Alpha);

            package.AddLineStripVertexCount(2);
        }
Пример #6
0
 /// <summary>
 /// Draws axis line
 /// </summary>
 /// <param name="package"></param>
 /// <param name="axis"></param>
 /// <param name="name"></param>
 private void DrawAxisLine(ref IRenderPackage package, Vector axis, string name)
 {
     package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.AxisLine, Name, name);
     using (var line = RayExtensions.ToOriginCenteredLine(Origin, axis))
     {
         var color = GetAxisColor(GetAlignedAxis(axis));
         package.AddLineStripVertexCount(2);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
         package.AddLineStripVertex(line.StartPoint.X, line.StartPoint.Y, line.StartPoint.Z);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
         package.AddLineStripVertex(line.EndPoint.X, line.EndPoint.Y, line.EndPoint.Z);
     }
 }
Пример #7
0
        private static void AddColoredLineToPackage(IRenderPackage package)
        {
            package.AddLineStripVertex(0,0,0);
            package.AddLineStripVertex(5,5,5);

            package.AddLineStripVertexColor(255,0,0,255);
            package.AddLineStripVertexColor(255,0,0,255);

            // Specify line segments by adding a line vertex count.
            // Ex. The above line has two vertices, so we add a line
            // vertex count of 2. If we had tessellated a curve with n
            // vertices, we would add a line vertex count of n.
            package.AddLineStripVertexCount(2);
        }
Пример #8
0
        private static void AddColoredLineToPackage(IRenderPackage package)
        {
            package.AddLineStripVertex(0, 0, 0);
            package.AddLineStripVertex(5, 5, 5);

            package.AddLineStripVertexColor(255, 0, 0, 255);
            package.AddLineStripVertexColor(255, 0, 0, 255);

            // Specify line segments by adding a line vertex count.
            // Ex. The above line has two vertices, so we add a line
            // vertex count of 2. If we had tessellated a curve with n
            // vertices, we would add a line vertex count of n.
            package.AddLineStripVertexCount(2);
        }
Пример #9
0
        private void DrawVector(Tuple <Vector, Point> data, IRenderPackage package)
        {
            var p = data.Item2;
            var v = data.Item1;

            package.AddLineStripVertex(p.X, p.Y, p.Z);
            package.AddLineStripVertexColor(VectorColor, VectorColor, VectorColor, 255);

            var o = p.Add(v);

            package.AddLineStripVertex(o.X, o.Y, o.Z);
            package.AddLineStripVertexColor(VectorColor, VectorColor, VectorColor, 255);

            package.AddLineStripVertexCount(2);
        }
Пример #10
0
        /// <summary>
        /// Draws axis as 3D arrow based on scale factor.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="axis"></param>
        private void DrawAxis(ref IRenderPackage package, Vector axis)
        {
            var axisType = GetAlignedAxis(axis);

            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorAxis, Name, axisType);

            using (var axisEnd = Origin.Add(axis.Scale(scale)))
            {
                var color = GetAxisColor(axisType);
                package.AddLineStripVertexCount(2);
                package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                package.AddLineStripVertex(Origin.X, Origin.Y, Origin.Z);
                package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                package.AddLineStripVertex(axisEnd.X, axisEnd.Y, axisEnd.Z);
            }
        }
Пример #11
0
        /// <summary>
        /// Draws plane at half the scale.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="plane"></param>
        /// <param name="name"></param>
        private void DrawPlane(ref IRenderPackage package, Plane plane, Planes name)
        {
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorPlane, Name, name);
            var p1 = Origin.Add(plane.XAxis.Scale(scale / 2));
            var p2 = p1.Add(plane.YAxis.Scale(scale / 2));
            var p3 = Origin.Add(plane.YAxis.Scale(scale / 2));

            package.AddLineStripVertexCount(3);
            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p2.X, p2.Y, p2.Z);

            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p3.X, p3.Y, p3.Z);
        }
Пример #12
0
        internal static void DrawColoredLine(IRenderPackage package, CompasNetworkWrapper network, Point p0, Point p1)
        {
            package.AddLineStripVertex(p0.X, p0.Y, p0.Z);
            package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

            byte blue0 = (byte)Math.Round(255 * ((p0.Z - network.minZ) / network.dz));
            byte blue1 = (byte)Math.Round(255 * ((p1.Z - network.minZ) / network.dz));

            package.AddLineStripVertexColor(0, 0, blue0, 255);
            package.AddLineStripVertexColor(0, 0, blue1, 255);

            // Specify line segments by adding a line vertex count.
            // Ex. The above line has two vertices, so we add a line
            // vertex count of 2. If we had tessellated a curve with n
            // vertices, we would add a line vertex count of n.
            package.AddLineStripVertexCount(2);
        }
Пример #13
0
 public static void DrawPolyline(IRenderPackage package, List <Triple> vertices, Color color)
 {
     package.AddLineStripVertexCount(vertices.Count);
     for (int i = 0; i < vertices.Count; i++)
     {
         package.AddLineStripVertex(vertices[i].X, vertices[i].Y, vertices[i].Z);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
     }
 }
Пример #14
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            var el = InternalElement as EdificeCore.Grid;

            if (el == null)
            {
                return;
            }

            // draw the grid
            package.AddTriangleVertex(el.Start.X, el.Start.Y, el.Start.Z);
            package.AddTriangleVertex(el.End.X, el.End.Y, el.End.Z);
            package.AddTriangleVertex(el.Start.X, el.Start.Y, el.End.Z);
            //package.


            package.AddLineStripVertex(el.Start.X, el.Start.Y, el.Start.Z);
            package.AddLineStripVertex(el.End.X, el.End.Y, el.End.Z);
            package.AddLineStripVertexCount(2);
            package.AddLineStripVertexColor(100, 100, 100, 255);
            package.AddLineStripVertexColor(100, 100, 100, 255);
        }
Пример #15
0
        private static void LegacyPackageEnsureColorExistsPerVertex(IRenderPackage pkg, int previousPointVertexCount, int previousLineVertexCount, int previousMeshVertexCount)
        {
            // We sequence the if statements here to avoid calling Count on PointVertexColors if we don't have to.
            // For Helix IRenderPackage implementation we have to regenerate a new IEnumerable each time we access PointVertexColors.
            // The data is stored in a Helix specific data structure for efficient transfer to the view later.
            // The same applies for line and mesh

            if (pkg.PointVertexCount > previousPointVertexCount)
            {
                var colorCount = pkg.PointVertexColors.Count() / 4;
                if (colorCount < pkg.PointVertexCount)
                {
                    for (var i = colorCount; i < pkg.PointVertexCount; i++)
                    {
                        pkg.AddPointVertexColor(DefR, DefG, DefB, DefA);
                    }
                }
            }

            if (pkg.LineVertexCount > previousLineVertexCount)
            {
                var colorCount = pkg.LineStripVertexColors.Count() / 4;
                if (colorCount < pkg.LineVertexCount)
                {
                    for (var i = colorCount; i < pkg.LineVertexCount; i++)
                    {
                        pkg.AddLineStripVertexColor(DefR, DefG, DefB, DefA);
                    }
                }
            }

            if (pkg.MeshVertexCount > previousMeshVertexCount)
            {
                var colorCount = pkg.MeshVertexColors.Count() / 4;
                if (colorCount < pkg.MeshVertexCount)
                {
                    for (var i = colorCount; i < pkg.MeshVertexCount; i++)
                    {
                        pkg.AddTriangleVertexColor(DefR, DefG, DefB, DefA);
                    }
                }
            }
        }
Пример #16
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            package.RequiresPerVertexColoration = true;

            Geo.Point OP1 = this._webAxis.StartPoint;
            Geo.Point OP2 = this._webAxis.EndPoint;

            Geo.Vector webAxis = Geo.Vector.ByTwoPoints(OP1, OP2);
            Geo.Vector normal  = _webNormal;
            Geo.Vector lateral = webAxis.Cross(normal);
            lateral = lateral.Normalized();
            lateral = lateral.Scale(1.75);
            normal  = normal.Normalized();
            normal  = normal.Scale(1.5);
            Geo.Vector lateralR = Geo.Vector.ByCoordinates(lateral.X * -1, lateral.Y * -1, lateral.Z * -1);
            Geo.Vector webAxisR = Geo.Vector.ByCoordinates(webAxis.X * -1, webAxis.Y * -1, webAxis.Z * -1);
            Geo.Vector normalR  = Geo.Vector.ByCoordinates(normal.X * -1, normal.Y * -1, normal.Z * -1);

            Geo.Point p0 = OP1.Add(normal.Add(lateral));
            Geo.Point p1 = OP2.Add(normal.Add(lateral));
            Geo.Point p2 = OP1.Add(lateral);
            Geo.Point p3 = OP2.Add(lateral);
            Geo.Point p6 = OP1.Add(normal.Add(lateralR));
            Geo.Point p7 = OP2.Add(normal.Add(lateralR));
            Geo.Point p4 = OP1.Add(lateralR);
            Geo.Point p5 = OP2.Add(lateralR);
            lateral  = lateral.Normalized().Scale(1.25);
            lateralR = lateralR.Normalized().Scale(1.25);
            Geo.Point p8  = OP1.Add(lateralR).Add(normal);
            Geo.Point p9  = OP2.Add(lateralR).Add(normal);
            Geo.Point p10 = OP1.Add(lateral).Add(normal);
            Geo.Point p11 = OP2.Add(lateral).Add(normal);
            ////////////        //          //          //          //          //          //          //           //            //          //
            Geo.Point[]  pts     = { p0, p1, p2, p1, p2, p3, p2, p3, p4, p3, p4, p5, p4, p5, p6, p5, p6, p7, p0, p1, p10, p1, p10, p11, p6, p7, p8, p7, p8, p9 };
            Geo.Vector[] vectors = { lateral, normal, lateral.Reverse(), normal.Reverse(), normal.Reverse() };
            byte[]       colors  = { 100, 100, 100, 100, 110, 110, 110, 110, 110, 110 };

            var faces = new List <List <int> >
            {
                new List <int> {
                    0, 1, 2
                },
                new List <int> {
                    3, 4, 5
                },
                new List <int> {
                    6, 7, 8
                },
                new List <int> {
                    9, 10, 11
                },
                new List <int> {
                    12, 13, 14
                },
                new List <int> {
                    15, 16, 17
                },
                new List <int> {
                    18, 19, 20
                },
                new List <int> {
                    21, 22, 23
                },
                new List <int> {
                    24, 25, 26
                },
                new List <int> {
                    27, 28, 29
                }
            };

            for (int i = 0; i < faces.Count; i++)
            {
                package.AddTriangleVertex(pts[faces[i][0]].X, pts[faces[i][0]].Y, pts[faces[i][0]].Z);
                package.AddTriangleVertex(pts[faces[i][1]].X, pts[faces[i][1]].Y, pts[faces[i][1]].Z);
                package.AddTriangleVertex(pts[faces[i][2]].X, pts[faces[i][2]].Y, pts[faces[i][2]].Z);
                package.AddTriangleVertexColor(colors[i], colors[i], colors[i], 255);
                package.AddTriangleVertexColor(colors[i], colors[i], colors[i], 255);
                package.AddTriangleVertexColor(colors[i], colors[i], colors[i], 255);
                package.AddTriangleVertexNormal(vectors[i / 2].X, vectors[i / 2].Y, vectors[i / 2].Z);
                package.AddTriangleVertexNormal(vectors[i / 2].X, vectors[i / 2].Y, vectors[i / 2].Z);
                package.AddTriangleVertexNormal(vectors[i / 2].X, vectors[i / 2].Y, vectors[i / 2].Z);
                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexUV(0, 0);
            }

            foreach (hOperation op in operations)
            {
                Geo.Point opPoint = this._webAxis.PointAtParameter(op._loc / this._webAxis.Length);
                byte      r       = 255;
                byte      g       = 66;
                byte      b       = 57;
                byte      a       = 255;
                switch (op._type)
                {
                case Operation.WEB:
                    package.AddPointVertex(opPoint.X, opPoint.Y, opPoint.Z);
                    package.AddPointVertexColor(r, g, b, a);

                    lateral  = lateral.Normalized().Scale(15.0 / 16.0);
                    lateralR = lateralR.Normalized().Scale(15.0 / 16.0);

                    package.AddPointVertex(opPoint.Add(lateral).X, opPoint.Add(lateral).Y, opPoint.Add(lateral).Z);
                    package.AddPointVertexColor(r, g, b, a);
                    package.AddPointVertex(opPoint.Add(lateralR).X, opPoint.Add(lateralR).Y, opPoint.Add(lateralR).Z);
                    package.AddPointVertexColor(r, g, b, a);
                    break;

                case Operation.DIMPLE:
                    lateral  = lateral.Normalized().Scale(1.0);
                    lateralR = lateralR.Normalized().Scale(1.0);
                    normal   = normal.Normalized().Scale(0.75);

                    package.AddLineStripVertex(opPoint.Add(lateral.Add(normal)).X, opPoint.Add(lateral.Add(normal)).Y, opPoint.Add(lateral.Add(normal)).Z);
                    lateral = lateral.Normalized().Scale(2.5);
                    package.AddLineStripVertex(opPoint.Add(lateral.Add(normal)).X, opPoint.Add(lateral.Add(normal)).Y, opPoint.Add(lateral.Add(normal)).Z);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexCount(2);

                    lateral = lateral.Normalized().Scale(1.75);
                    package.AddPointVertex(opPoint.Add(lateral.Add(normal)).X, opPoint.Add(lateral.Add(normal)).Y, opPoint.Add(lateral.Add(normal)).Z);
                    package.AddPointVertexColor(r, g, b, a);

                    package.AddLineStripVertex(opPoint.Add(lateralR.Add(normal)).X, opPoint.Add(lateralR.Add(normal)).Y, opPoint.Add(lateralR.Add(normal)).Z);
                    lateralR = lateralR.Normalized().Scale(2.5);
                    package.AddLineStripVertex(opPoint.Add(lateralR.Add(normal)).X, opPoint.Add(lateralR.Add(normal)).Y, opPoint.Add(lateralR.Add(normal)).Z);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexCount(2);

                    lateralR = lateralR.Normalized().Scale(1.75);
                    package.AddPointVertex(opPoint.Add(lateralR.Add(normal)).X, opPoint.Add(lateralR.Add(normal)).Y, opPoint.Add(lateralR.Add(normal)).Z);
                    package.AddPointVertexColor(r, g, b, a);
                    break;

                case Operation.SWAGE:
                    lateral  = lateral.Normalized().Scale(1.25);
                    lateralR = lateralR.Normalized().Scale(1.25);
                    webAxis  = webAxis.Normalized().Scale(.875);
                    webAxisR = webAxisR.Normalized().Scale(.875);

                    package.AddLineStripVertex(opPoint.Add(lateral.Add(webAxis)).X, opPoint.Add(lateral.Add(webAxis)).Y, opPoint.Add(lateral.Add(webAxis)).Z);
                    package.AddLineStripVertex(opPoint.Add(lateral.Add(webAxisR)).X, opPoint.Add(lateral.Add(webAxisR)).Y, opPoint.Add(lateral.Add(webAxisR)).Z);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexCount(2);

                    package.AddLineStripVertex(opPoint.Add(lateralR.Add(webAxis)).X, opPoint.Add(lateralR.Add(webAxis)).Y, opPoint.Add(lateralR.Add(webAxis)).Z);
                    package.AddLineStripVertex(opPoint.Add(lateralR.Add(webAxisR)).X, opPoint.Add(lateralR.Add(webAxisR)).Y, opPoint.Add(lateralR.Add(webAxisR)).Z);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexColor(r, g, b, a);
                    package.AddLineStripVertexCount(2);
                    break;

                case Operation.BOLT:
                    lateral  = lateral.Normalized().Scale(0.25);
                    lateralR = lateralR.Normalized().Scale(0.25);
                    webAxis  = webAxis.Normalized().Scale(0.25);
                    webAxisR = webAxisR.Normalized().Scale(0.25);
                    normal   = normal.Normalized().Scale(0.01);
                    normalR  = normalR.Normalized().Scale(0.01);

                    Geo.Point[] boltPts = { opPoint.Add(lateral.Add(webAxis.Add(normal))), opPoint.Add(lateral.Add(webAxisR.Add(normal))), opPoint.Add(lateralR.Add(webAxisR.Add(normal))), opPoint.Add(lateralR.Add(webAxis.Add(normal))) };
                    package.AddTriangleVertex(boltPts[0].X, boltPts[0].Y, boltPts[0].Z);
                    package.AddTriangleVertex(boltPts[1].X, boltPts[1].Y, boltPts[1].Z);
                    package.AddTriangleVertex(boltPts[2].X, boltPts[2].Y, boltPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(boltPts[0].X, boltPts[0].Y, boltPts[0].Z);
                    package.AddTriangleVertex(boltPts[2].X, boltPts[2].Y, boltPts[2].Z);
                    package.AddTriangleVertex(boltPts[3].X, boltPts[3].Y, boltPts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    boltPts = new Geo.Point[] { opPoint.Add(lateral.Add(webAxis.Add(normalR))), opPoint.Add(lateral.Add(webAxisR.Add(normalR))), opPoint.Add(lateralR.Add(webAxisR.Add(normalR))), opPoint.Add(lateralR.Add(webAxis.Add(normalR))) };
                    package.AddTriangleVertex(boltPts[0].X, boltPts[0].Y, boltPts[0].Z);
                    package.AddTriangleVertex(boltPts[1].X, boltPts[1].Y, boltPts[1].Z);
                    package.AddTriangleVertex(boltPts[2].X, boltPts[2].Y, boltPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(boltPts[0].X, boltPts[0].Y, boltPts[0].Z);
                    package.AddTriangleVertex(boltPts[2].X, boltPts[2].Y, boltPts[2].Z);
                    package.AddTriangleVertex(boltPts[3].X, boltPts[3].Y, boltPts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    break;

                case Operation.SERVICE_HOLE:
                    lateral  = lateral.Normalized().Scale(0.5);
                    lateralR = lateralR.Normalized().Scale(0.5);
                    webAxis  = webAxis.Normalized().Scale(0.5);
                    webAxisR = webAxisR.Normalized().Scale(0.5);
                    normal   = normal.Normalized().Scale(0.01);
                    normalR  = normalR.Normalized().Scale(0.01);

                    Geo.Point[] servicePts = new Geo.Point[] { opPoint.Add(lateral.Add(webAxis.Add(normal))), opPoint.Add(lateral.Add(webAxisR.Add(normal))), opPoint.Add(lateralR.Add(webAxisR.Add(normal))), opPoint.Add(lateralR.Add(webAxis.Add(normal))) };
                    package.AddTriangleVertex(servicePts[0].X, servicePts[0].Y, servicePts[0].Z);
                    package.AddTriangleVertex(servicePts[1].X, servicePts[1].Y, servicePts[1].Z);
                    package.AddTriangleVertex(servicePts[2].X, servicePts[2].Y, servicePts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(servicePts[0].X, servicePts[0].Y, servicePts[0].Z);
                    package.AddTriangleVertex(servicePts[2].X, servicePts[2].Y, servicePts[2].Z);
                    package.AddTriangleVertex(servicePts[3].X, servicePts[3].Y, servicePts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    servicePts = new Geo.Point[] { opPoint.Add(lateral.Add(webAxis.Add(normalR))), opPoint.Add(lateral.Add(webAxisR.Add(normalR))), opPoint.Add(lateralR.Add(webAxisR.Add(normalR))), opPoint.Add(lateralR.Add(webAxis.Add(normalR))) };
                    package.AddTriangleVertex(servicePts[0].X, servicePts[0].Y, servicePts[0].Z);
                    package.AddTriangleVertex(servicePts[1].X, servicePts[1].Y, servicePts[1].Z);
                    package.AddTriangleVertex(servicePts[2].X, servicePts[2].Y, servicePts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(servicePts[0].X, servicePts[0].Y, servicePts[0].Z);
                    package.AddTriangleVertex(servicePts[2].X, servicePts[2].Y, servicePts[2].Z);
                    package.AddTriangleVertex(servicePts[3].X, servicePts[3].Y, servicePts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    break;


                case Operation.NOTCH:
                    lateral  = lateral.Normalized().Scale(1.75);
                    lateralR = lateralR.Normalized().Scale(1.75);
                    webAxis  = webAxis.Normalized().Scale(0.875);
                    webAxisR = webAxisR.Normalized().Scale(0.875);
                    normal   = normal.Normalized().Scale(0.01);
                    normalR  = normalR.Normalized().Scale(0.01);

                    Geo.Point[] notchPts = { opPoint.Add(lateral.Add(webAxis.Add(normal))), opPoint.Add(lateral.Add(webAxisR.Add(normal))), opPoint.Add(lateralR.Add(webAxisR.Add(normal))), opPoint.Add(lateralR.Add(webAxis.Add(normal))) };
                    package.AddTriangleVertex(notchPts[0].X, notchPts[0].Y, notchPts[0].Z);
                    package.AddTriangleVertex(notchPts[1].X, notchPts[1].Y, notchPts[1].Z);
                    package.AddTriangleVertex(notchPts[2].X, notchPts[2].Y, notchPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(notchPts[0].X, notchPts[0].Y, notchPts[0].Z);
                    package.AddTriangleVertex(notchPts[2].X, notchPts[2].Y, notchPts[2].Z);
                    package.AddTriangleVertex(notchPts[3].X, notchPts[3].Y, notchPts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);


                    notchPts = new Geo.Point[] { opPoint.Add(lateral.Add(webAxis.Add(normalR))), opPoint.Add(lateral.Add(webAxisR.Add(normalR))), opPoint.Add(lateralR.Add(webAxisR.Add(normalR))), opPoint.Add(lateralR.Add(webAxis.Add(normalR))) };
                    package.AddTriangleVertex(notchPts[0].X, notchPts[0].Y, notchPts[0].Z);
                    package.AddTriangleVertex(notchPts[1].X, notchPts[1].Y, notchPts[1].Z);
                    package.AddTriangleVertex(notchPts[2].X, notchPts[2].Y, notchPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(notchPts[0].X, notchPts[0].Y, notchPts[0].Z);
                    package.AddTriangleVertex(notchPts[2].X, notchPts[2].Y, notchPts[2].Z);
                    package.AddTriangleVertex(notchPts[3].X, notchPts[3].Y, notchPts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    break;

                case Operation.LIP_CUT:
                    lateral  = lateral.Normalized().Scale(1.75);
                    lateralR = lateralR.Normalized().Scale(1.75);
                    webAxis  = webAxis.Normalized().Scale(0.875);
                    webAxisR = webAxisR.Normalized().Scale(0.875);
                    normal   = normal.Normalized().Scale(1.51);
                    normalR  = normalR.Normalized().Scale(0.01);
                    Geo.Vector lateral2  = lateral.Normalized().Scale(1.25);
                    Geo.Vector lateral2R = lateralR.Normalized().Scale(1.25);

                    Geo.Point[] lipPts = { opPoint.Add(webAxis).Add(lateral).Add(normal), opPoint.Add(webAxisR).Add(lateral).Add(normal), opPoint.Add(webAxis).Add(lateral2).Add(normal), opPoint.Add(webAxisR).Add(lateral2).Add(normal) };
                    package.AddTriangleVertex(lipPts[0].X, lipPts[0].Y, lipPts[0].Z);
                    package.AddTriangleVertex(lipPts[1].X, lipPts[1].Y, lipPts[1].Z);
                    package.AddTriangleVertex(lipPts[2].X, lipPts[2].Y, lipPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(lipPts[1].X, lipPts[1].Y, lipPts[1].Z);
                    package.AddTriangleVertex(lipPts[2].X, lipPts[2].Y, lipPts[2].Z);
                    package.AddTriangleVertex(lipPts[3].X, lipPts[3].Y, lipPts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);


                    lipPts = new Geo.Point[] { opPoint.Add(webAxis).Add(lateralR).Add(normal), opPoint.Add(webAxisR).Add(lateralR).Add(normal), opPoint.Add(webAxis).Add(lateral2R).Add(normal), opPoint.Add(webAxisR).Add(lateral2R).Add(normal) };
                    package.AddTriangleVertex(lipPts[0].X, lipPts[0].Y, lipPts[0].Z);
                    package.AddTriangleVertex(lipPts[1].X, lipPts[1].Y, lipPts[1].Z);
                    package.AddTriangleVertex(lipPts[2].X, lipPts[2].Y, lipPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    package.AddTriangleVertex(lipPts[1].X, lipPts[1].Y, lipPts[1].Z);
                    package.AddTriangleVertex(lipPts[2].X, lipPts[2].Y, lipPts[2].Z);
                    package.AddTriangleVertex(lipPts[3].X, lipPts[3].Y, lipPts[3].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexNormal(normal.X, normal.Y, normal.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    break;


                case Operation.END_TRUSS:
                    lateral  = lateral.Normalized().Scale(1.76);
                    lateralR = lateralR.Normalized().Scale(1.76);
                    if (opPoint.DistanceTo(this._webAxis.StartPoint) < opPoint.DistanceTo(this._webAxis.EndPoint))
                    {
                        webAxis = webAxis.Normalized().Scale(0.5);
                    }
                    else
                    {
                        webAxis = webAxisR.Normalized().Scale(0.5);
                    }

                    normal = normal.Normalized().Scale(1.50);
                    Geo.Vector normal2 = normal.Normalized().Scale(1.0);
                    Geo.Vector normal3 = normal.Normalized().Scale(0.5);
                    normalR   = normalR.Normalized().Scale(0.01);
                    lateral2  = lateral.Normalized().Scale(1.25);
                    lateral2R = lateralR.Normalized().Scale(1.25);

                    Geo.Point[] endTrussPts = { opPoint.Add(lateral).Add(normal2), opPoint.Add(lateral).Add(normal).Add(webAxis), opPoint.Add(lateral).Add(normal) };
                    package.AddTriangleVertex(endTrussPts[0].X, endTrussPts[0].Y, endTrussPts[0].Z);
                    package.AddTriangleVertex(endTrussPts[1].X, endTrussPts[1].Y, endTrussPts[1].Z);
                    package.AddTriangleVertex(endTrussPts[2].X, endTrussPts[2].Y, endTrussPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(lateral.X, lateral.Y, lateral.Z);
                    package.AddTriangleVertexNormal(lateral.X, lateral.Y, lateral.Z);
                    package.AddTriangleVertexNormal(lateral.X, lateral.Y, lateral.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    endTrussPts = new Geo.Point[] { opPoint.Add(lateral).Add(normal3), opPoint.Add(lateral).Add(webAxis), opPoint.Add(lateral) };
                    package.AddTriangleVertex(endTrussPts[0].X, endTrussPts[0].Y, endTrussPts[0].Z);
                    package.AddTriangleVertex(endTrussPts[1].X, endTrussPts[1].Y, endTrussPts[1].Z);
                    package.AddTriangleVertex(endTrussPts[2].X, endTrussPts[2].Y, endTrussPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(lateral.X, lateral.Y, lateral.Z);
                    package.AddTriangleVertexNormal(lateral.X, lateral.Y, lateral.Z);
                    package.AddTriangleVertexNormal(lateral.X, lateral.Y, lateral.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    endTrussPts = new Geo.Point[] { opPoint.Add(lateralR).Add(normal2), opPoint.Add(lateralR).Add(normal).Add(webAxis), opPoint.Add(lateralR).Add(normal) };
                    package.AddTriangleVertex(endTrussPts[0].X, endTrussPts[0].Y, endTrussPts[0].Z);
                    package.AddTriangleVertex(endTrussPts[1].X, endTrussPts[1].Y, endTrussPts[1].Z);
                    package.AddTriangleVertex(endTrussPts[2].X, endTrussPts[2].Y, endTrussPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(lateralR.X, lateralR.Y, lateralR.Z);
                    package.AddTriangleVertexNormal(lateralR.X, lateralR.Y, lateralR.Z);
                    package.AddTriangleVertexNormal(lateralR.X, lateralR.Y, lateralR.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);

                    endTrussPts = new Geo.Point[] { opPoint.Add(lateralR).Add(normal3), opPoint.Add(lateralR).Add(webAxis), opPoint.Add(lateralR) };
                    package.AddTriangleVertex(endTrussPts[0].X, endTrussPts[0].Y, endTrussPts[0].Z);
                    package.AddTriangleVertex(endTrussPts[1].X, endTrussPts[1].Y, endTrussPts[1].Z);
                    package.AddTriangleVertex(endTrussPts[2].X, endTrussPts[2].Y, endTrussPts[2].Z);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexColor(r, g, b, a);
                    package.AddTriangleVertexNormal(lateralR.X, lateralR.Y, lateralR.Z);
                    package.AddTriangleVertexNormal(lateralR.X, lateralR.Y, lateralR.Z);
                    package.AddTriangleVertexNormal(lateralR.X, lateralR.Y, lateralR.Z);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    package.AddTriangleVertexUV(0, 0);
                    break;

                default:
                    package.AddPointVertex(opPoint.X, opPoint.Y, opPoint.Z);
                    package.AddPointVertexColor(r, g, b, a);
                    break;
                }
            }
        }
Пример #17
0
        /// <summary>
        /// This method uses the MIConvexHull Delaunay triangulator to create a
        /// Delaunay tessellation of a given u and v distribution on the surface.
        /// It adds to this tessellation all the points on the surface's trim
        /// curves. Triangles are then deleted from the tessellation based on whether
        /// the sum of their vertices' distances from the surface are greater than a
        /// threshold.
        /// </summary>
        /// <param name="surface">The surface on which to apply the tessellation.</param>
        /// <param name="package">The IRenderPackage object into which the graphics data will be pushed.</param>
        /// <param name="uDiv">The number of divisions of the grid on the surface in the U direction.</param>
        /// <param name="vDiv">The number of divisions of the grid on the surface in the V direction.</param>
        private static void DelaunayTesselate(Surface surface, IRenderPackage package, int uDiv, int vDiv, IEnumerable <UV> additionalUVs)
        {
            var uvs = new List <UV>();

            for (var i = 0; i <= uDiv; i += 1)
            {
                for (var j = 0; j <= vDiv; j += 1)
                {
                    var u  = (double)i / uDiv;
                    var v  = (double)j / vDiv;
                    var uv = UV.ByCoordinates(u, v);
                    uvs.Add(uv);
                }
            }

            uvs.AddRange(additionalUVs);

            var curves = surface.PerimeterCurves();
            var coords = GetEdgeCoordinates(curves, 100, surface);

            curves.ForEach(c => c.Dispose());

            var verts  = uvs.Select(Vertex2.FromUV).Concat(coords.Select(Vertex2.FromUV)).ToList();
            var config = new TriangulationComputationConfig
            {
                PointTranslationType   = PointTranslationType.TranslateInternal,
                PlaneDistanceTolerance = 0.000001,
                // the translation radius should be lower than PlaneDistanceTolerance / 2
                PointTranslationGenerator = TriangulationComputationConfig.RandomShiftByRadius(0.0000001, 0)
            };

            var triangulation = DelaunayTriangulation <Vertex2, Cell2> .Create(verts, config);

            foreach (var cell in triangulation.Cells)
            {
                var v1  = cell.Vertices[0].AsVector();
                var pt1 = surface.PointAtParameter(v1.X, v1.Y);
                var n1  = surface.NormalAtParameter(v1.X, v1.Y);

                var v2  = cell.Vertices[1].AsVector();
                var pt2 = surface.PointAtParameter(v2.X, v2.Y);
                var n2  = surface.NormalAtParameter(v2.X, v2.Y);

                var v3  = cell.Vertices[2].AsVector();
                var pt3 = surface.PointAtParameter(v3.X, v3.Y);
                var n3  = surface.NormalAtParameter(v3.X, v3.Y);

                // Calculate the aggregate distance of all vertex
                // locations from the surface. Triangles not on the surface
                // will have a higher aggregate value.
                var sumDist = pt1.DistanceTo(surface) + pt2.DistanceTo(surface) + pt3.DistanceTo(surface);
                if (sumDist > 0.05)
                {
                    continue;
                }

                package.AddTriangleVertex(pt1.X, pt1.Y, pt1.Z);
                package.AddTriangleVertexNormal(n1.X, n1.Y, n1.Z);
                package.AddTriangleVertexUV(v1.X, v1.Y);
                package.AddTriangleVertexColor(0, 0, 0, 255);

                package.AddTriangleVertex(pt2.X, pt2.Y, pt2.Z);
                package.AddTriangleVertexNormal(n2.X, n2.Y, n2.Z);
                package.AddTriangleVertexUV(v2.X, v2.Y);
                package.AddTriangleVertexColor(0, 0, 0, 255);

                package.AddTriangleVertex(pt3.X, pt3.Y, pt3.Z);
                package.AddTriangleVertexNormal(n3.X, n3.Y, n3.Z);
                package.AddTriangleVertexUV(v3.X, v3.Y);
                package.AddTriangleVertexColor(0, 0, 0, 255);

                package.AddLineStripVertex(pt1.X, pt1.Y, pt1.Z);
                package.AddLineStripVertex(pt2.X, pt2.Y, pt2.Z);
                package.AddLineStripVertexColor(100, 100, 100, 255);
                package.AddLineStripVertexColor(100, 100, 100, 255);
                package.AddLineStripVertexCount(2);

                package.AddLineStripVertex(pt2.X, pt2.Y, pt2.Z);
                package.AddLineStripVertex(pt3.X, pt3.Y, pt3.Z);
                package.AddLineStripVertexColor(100, 100, 100, 255);
                package.AddLineStripVertexColor(100, 100, 100, 255);
                package.AddLineStripVertexCount(2);

                package.AddLineStripVertex(pt3.X, pt3.Y, pt3.Z);
                package.AddLineStripVertex(pt1.X, pt1.Y, pt1.Z);
                package.AddLineStripVertexColor(100, 100, 100, 255);
                package.AddLineStripVertexColor(100, 100, 100, 255);
                package.AddLineStripVertexCount(2);

                v1.Dispose(); v2.Dispose(); v3.Dispose();
                pt1.Dispose(); pt2.Dispose(); pt3.Dispose();
                n1.Dispose(); n2.Dispose(); n3.Dispose();
            }
        }
Пример #18
0
        /// <summary>
        /// Draws axis as 3D arrow based on scale factor.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="axis"></param>
        private void DrawAxis(ref IRenderPackage package, Vector axis)
        {
            var axisType = GetAlignedAxis(axis);
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorAxis, Name, axisType.ToString());

            using (var axisEnd = Origin.Add(axis.Scale(scale)))
            {
                var color = GetAxisColor(axisType);
                package.AddLineStripVertexCount(2);
                package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                package.AddLineStripVertex(Origin.X, Origin.Y, Origin.Z);
                package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                package.AddLineStripVertex(axisEnd.X, axisEnd.Y, axisEnd.Z);
            }
        }
Пример #19
0
        /// <summary>
        /// Draws plane at half the scale.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="plane"></param>
        /// <param name="name"></param>
        private void DrawPlane(ref IRenderPackage package, Plane plane, Planes name)
        {
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorPlane, Name, name.ToString()); 
            var p1 = Origin.Add(plane.XAxis.Scale(scale/2));
            var p2 = p1.Add(plane.YAxis.Scale(scale/2));
            var p3 = Origin.Add(plane.YAxis.Scale(scale/2));
            
            package.AddLineStripVertexCount(3);
            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p2.X, p2.Y, p2.Z);

            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p3.X, p3.Y, p3.Z);
        }
Пример #20
0
 /// <summary>
 /// Draws axis line
 /// </summary>
 /// <param name="package"></param>
 /// <param name="axis"></param>
 /// <param name="name"></param>
 private void DrawAxisLine(ref IRenderPackage package, Vector axis, string name)
 {
     package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.AxisLine, Name, name);
     using (var line = RayExtensions.ToOriginCenteredLine(Origin, axis))
     {
         var color = GetAxisColor(GetAlignedAxis(axis));
         package.AddLineStripVertexCount(2);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
         package.AddLineStripVertex(line.StartPoint.X, line.StartPoint.Y, line.StartPoint.Z);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
         package.AddLineStripVertex(line.EndPoint.X, line.EndPoint.Y, line.EndPoint.Z);
     }
 }
Пример #21
0
        /// <summary>
        /// Draws plane at half the scale.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="plane"></param>
        /// <param name="name"></param>
        private void DrawPlane(ref IRenderPackage package, Plane plane, Planes name)
        {
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorPlane, Name, name);
            using (var vec1 = plane.XAxis.Scale(scale/3))
            using (var vec2 = plane.YAxis.Scale(scale/3))
            using (var vec3 = plane.YAxis.Scale(scale/3))
            {
                using (var p1 = Origin.Add(vec1))
                using (var p2 = p1.Add(vec2))
                using (var p3 = Origin.Add(vec3))
                {
                    var axis = plane.Normal;
                    var color = GetAxisColor(GetAlignedAxis(axis));

                    package.AddLineStripVertexCount(3);
                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                    package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                    package.AddLineStripVertex(p2.X, p2.Y, p2.Z);

                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                    package.AddLineStripVertex(p3.X, p3.Y, p3.Z);
                    
                }
            }
        }
Пример #22
0
        private void AddColoredQuadToPackage(IRenderPackage package)
        {
            // For each quad
            for (int i = 0; i < vertices.Count; i += 6)
            {
                // Meshes

                // Triangle 1
                package.AddTriangleVertex(vertices[i].X, vertices[i].Y, vertices[i].Z);
                package.AddTriangleVertex(vertices[i + 1].X, vertices[i + 1].Y, vertices[i + 1].Z);
                package.AddTriangleVertex(vertices[i + 2].X, vertices[i + 2].Y, vertices[i + 2].Z);

                package.AddTriangleVertexColor(32, 178, 170, 255);
                package.AddTriangleVertexColor(32, 178, 170, 255);
                package.AddTriangleVertexColor(32, 178, 170, 255);

                package.AddTriangleVertexNormal(0, 0, 1);
                package.AddTriangleVertexNormal(0, 0, 1);
                package.AddTriangleVertexNormal(0, 0, 1);

                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexUV(0, 0);

                // Triangle 2
                package.AddTriangleVertex(vertices[i + 3].X, vertices[i + 3].Y, vertices[i + 3].Z);
                package.AddTriangleVertex(vertices[i + 4].X, vertices[i + 4].Y, vertices[i + 4].Z);
                package.AddTriangleVertex(vertices[i + 5].X, vertices[i + 5].Y, vertices[i + 5].Z);

                package.AddTriangleVertexColor(32, 178, 170, 255);
                package.AddTriangleVertexColor(32, 178, 170, 255);
                package.AddTriangleVertexColor(32, 178, 170, 255);

                package.AddTriangleVertexNormal(0, 0, 1);
                package.AddTriangleVertexNormal(0, 0, 1);
                package.AddTriangleVertexNormal(0, 0, 1);

                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexUV(0, 0);
                package.AddTriangleVertexUV(0, 0);

                // Edges
                // NOTE: this could be reduced to less than 6 vertices
                // but for the purposes of this example it is more clear

                // Triangle 1
                package.AddLineStripVertex(vertices[i].X, vertices[i].Y, vertices[i].Z);
                package.AddLineStripVertex(vertices[i + 1].X, vertices[i + 1].Y, vertices[i + 1].Z);
                package.AddLineStripVertex(vertices[i + 2].X, vertices[i + 2].Y, vertices[i + 2].Z);
                // Triangle 2
                package.AddLineStripVertex(vertices[i + 3].X, vertices[i + 3].Y, vertices[i + 3].Z);
                package.AddLineStripVertex(vertices[i + 4].X, vertices[i + 4].Y, vertices[i + 4].Z);
                package.AddLineStripVertex(vertices[i + 5].X, vertices[i + 5].Y, vertices[i + 5].Z);

                package.AddLineStripVertexColor(0, 0, 0, 255);
                package.AddLineStripVertexColor(0, 0, 0, 255);
                package.AddLineStripVertexColor(0, 0, 0, 255);
                package.AddLineStripVertexColor(0, 0, 0, 255);
                package.AddLineStripVertexColor(0, 0, 0, 255);
                package.AddLineStripVertexColor(0, 0, 0, 255);

                package.AddLineStripVertexCount(6);
            }
        }