Ejemplo n.º 1
0
        private void AddAdjacentPoint(MutableFace face, VertexPoint point, MutableSolid solid)
        {
            var s = point.MidpointStart.Position;
            var e = point.MidpointEnd.Position;

            foreach (var f in solid.Faces.Where(x => x != face))
            {
                var vertList = f.Vertices.ToList();

                foreach (var edge in f.GetEdges())
                {
                    if (edge.Start == s && edge.End == e)
                    {
                        var idx = vertList.FindIndex(x => x.Position.EquivalentTo(e));
                        f.Vertices.Insert(idx, new MutableVertex(point.Position));
                        return;
                    }
                    if (edge.Start == e && edge.End == s)
                    {
                        var idx = vertList.FindIndex(x => x.Position.EquivalentTo(s));
                        f.Vertices.Insert(idx, new MutableVertex(point.Position));
                        return;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void BevelFace(SolidFace solidFace, int num)
        {
            var face  = solidFace.Face;
            var solid = solidFace.Solid.Copy;

            // Remember the original positions
            var vertexPositions = face.Vertices.Select(x => x.Position).ToList();

            // Scale the face a bit and move it away by the bevel distance
            var origin = face.Origin;

            face.Transform(Matrix4x4.CreateScale(Vector3.One * 0.9f, origin));
            face.Transform(Matrix4x4.CreateTranslation(face.Plane.Normal * num));

            var vertList = face.Vertices.ToList();

            // Create a face for each new edge -> old edge
            foreach (var edge in face.GetEdges())
            {
                var startIndex = vertList.FindIndex(x => x.Position.EquivalentTo(edge.Start));
                var endIndex   = vertList.FindIndex(x => x.Position.EquivalentTo(edge.End));
                var verts      = new[] { vertexPositions[startIndex], vertexPositions[endIndex], edge.End, edge.Start };
                var f          = new MutableFace(verts, face.Texture.Clone());
                solid.Faces.Add(f);
            }
        }
Ejemplo n.º 3
0
        private void PokeFace(SolidFace solidFace, int num)
        {
            var face  = solidFace.Face;
            var solid = solidFace.Solid.Copy;

            // Remove the face
            solid.Faces.Remove(face);

            var center = face.Origin + face.Plane.Normal * num;

            foreach (var edge in face.GetEdges())
            {
                var v1    = face.Vertices.First(x => x.Position.EquivalentTo(edge.Start));
                var v2    = face.Vertices.First(x => x.Position.EquivalentTo(edge.End));
                var verts = new[] { v1.Position, v2.Position, center };
                var f     = new MutableFace(verts, face.Texture.Clone());
                solid.Faces.Add(f);
            }
        }
Ejemplo n.º 4
0
 public SolidFace(VertexSolid solid, MutableFace face)
 {
     Solid = solid;
     Face  = face;
 }
Ejemplo n.º 5
0
 private Vector3?GetIntersectionPoint(MutableFace face, Line line)
 {
     return(new Polygon(face.Vertices.Select(x => x.Position)).GetIntersectionPoint(line));
 }
Ejemplo n.º 6
0
 private static bool IsConvex(MutableFace face)
 {
     return(face.Vertices.Count > 2 && new Polygon(face.Vertices.Select(x => x.Position)).IsConvex());
 }