コード例 #1
0
ファイル: JohnsonPoly.cs プロジェクト: IxxyXR/polyhydra-upm
        public static ConwayPoly ElongatedBicupola(int sides, bool gyro)
        {
            ConwayPoly poly        = ElongatedCupola(sides);
            Face       bottom      = poly.Faces[sides * 2];
            int        i           = 0;
            var        middleVerts = bottom.GetVertices();

            poly.Faces.Remove(bottom);
            poly.FaceRoles.RemoveAt(poly.FaceRoles.Count - 1);
            poly.FaceTags.RemoveAt(poly.FaceRoles.Count - 1);

            float      baseOffset  = -(_CalcSideLength(sides * 2) + _CalcCupolaHeight(sides));
            float      angleOffset = gyro ? 0.75f : 0.25f;
            ConwayPoly cap2        = _MakePolygon(sides, false, angleOffset, baseOffset, _CalcCupolaCapRadius(sides));

            poly.Append(cap2);
            var edge2 = poly.Faces.Last().Halfedge.Prev;

            int edgeOffset = gyro ? 0 : 1;

            while (true)
            {
                var side1 = new List <Vertex>
                {
                    middleVerts[PolyUtils.ActualMod(i * 2 - 1 - edgeOffset, sides * 2)],
                    middleVerts[PolyUtils.ActualMod(i * 2 - edgeOffset, sides * 2)],
                    edge2.Vertex
                };
                poly.Faces.Add(side1);
                poly.FaceRoles.Add(ConwayPoly.Roles.New);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                var side2 = new List <Vertex>
                {
                    middleVerts[PolyUtils.ActualMod(i * 2 - edgeOffset, sides * 2)],
                    middleVerts[PolyUtils.ActualMod(i * 2 + 1 - edgeOffset, sides * 2)],
                    edge2.Next.Vertex,
                    edge2.Vertex,
                };
                poly.Faces.Add(side2);
                poly.FaceRoles.Add(ConwayPoly.Roles.NewAlt);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                i++;
                edge2 = edge2.Next;

                if (i == sides)
                {
                    break;
                }
            }
            poly.Halfedges.MatchPairs();
            return(poly);
        }
コード例 #2
0
ファイル: JohnsonPoly.cs プロジェクト: IxxyXR/polyhydra-upm
        public static ConwayPoly GyroelongatedCupola(int sides)
        {
            ConwayPoly poly    = Antiprism(sides * 2);
            Face       topFace = poly.Faces[1];
            ConwayPoly cap1    = _MakePolygon(sides, true, 0f, _CalcCupolaHeight(sides) + _CalcAntiprismHeight(sides * 2), _CalcCupolaCapRadius(sides));

            poly.Append(cap1);

            int i           = 0;
            var middleVerts = topFace.GetVertices();

            poly.Faces.Remove(topFace);
            poly.FaceRoles.RemoveAt(1);
            poly.FaceTags.RemoveAt(1);

            var edge2 = poly.Faces.Last().Halfedge.Prev;

            while (true)
            {
                var side1 = new List <Vertex>
                {
                    middleVerts[PolyUtils.ActualMod(i * 2 - 1, sides * 2)],
                    middleVerts[PolyUtils.ActualMod(i * 2, sides * 2)],
                    edge2.Vertex
                };
                poly.Faces.Add(side1);
                poly.FaceRoles.Add(ConwayPoly.Roles.New);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                var side2 = new List <Vertex>
                {
                    middleVerts[PolyUtils.ActualMod(i * 2, sides * 2)],
                    middleVerts[PolyUtils.ActualMod(i * 2 + 1, sides * 2)],
                    edge2.Next.Vertex,
                    edge2.Vertex,
                };
                poly.Faces.Add(side2);
                poly.FaceRoles.Add(ConwayPoly.Roles.NewAlt);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                i++;
                edge2 = edge2.Next;
                if (i == sides)
                {
                    break;
                }
            }

            poly.Halfedges.MatchPairs();
            return(poly);
        }
コード例 #3
0
    private static int CalcDirectionIndex(Face face, int range)
    {
        var angles = new []
        {
            Vector3.Angle(face.Normal, Vector3.up),
            Vector3.Angle(face.Normal, Vector3.down),
            Vector3.Angle(face.Normal, Vector3.left),
            Vector3.Angle(face.Normal, Vector3.right),
            Vector3.Angle(face.Normal, Vector3.forward),
            Vector3.Angle(face.Normal, Vector3.back),
        };
        float angle = angles.Min();

        return(Mathf.FloorToInt((angle / 90f) * range));
    }
コード例 #4
0
ファイル: JohnsonPoly.cs プロジェクト: IxxyXR/polyhydra-upm
        // Work in progress. Not working at the moment
        private static ConwayPoly _MakeRotunda(int sides, float height, bool bi = false)
        {
            sides = Mathf.Clamp(sides, 3, 64);

            ConwayPoly poly   = _MakePolygon(sides);
            Face       bottom = poly.Faces[0];
            ConwayPoly cap1   = _MakePolygon(sides, true, 0.25f, height, _CalcCupolaCapRadius(sides));

            poly.Append(cap1);

            int i = 0;
//            var upperTriFaces = new List<Face>();
//            var LowerTriFaces = new List<Face>();
//            var SidePentFaces = new List<Face>();

            var edge1 = poly.Halfedges[0];
            var edge2 = poly.Halfedges[sides * 2];

            while (true)
            {
                poly.Vertices.Add(new Vertex(Vector3.Lerp(edge1.Vector, edge2.Vector, _CalcCupolaCapRadius(sides))));
                var newV1 = poly.Vertices.Last();
                poly.Vertices.Add(new Vertex(Vector3.Lerp(edge1.Prev.Vector, edge2.Next.Vector, 0.5f)));
                var newV2 = poly.Vertices.Last();

                var pentFace = new List <Vertex>
                {
                    edge1.Next.Vertex,
                    edge1.Vertex,
                    newV1,
                };
                poly.Faces.Add(pentFace);
                poly.FaceRoles.Add(ConwayPoly.Roles.New);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                i++;
                edge1 = edge1.Next.Next;
                edge2 = edge2.Prev;
                if (i == sides)
                {
                    break;
                }
            }

            poly.Halfedges.MatchPairs();
            return(poly);
        }
コード例 #5
0
 public Halfedge(Vertex vertex, Halfedge next, Halfedge prev, Face face, Halfedge pair)  : this(vertex, next, prev, face)
 {
     Pair = pair;
 }
コード例 #6
0
 public Halfedge(Vertex vertex, Halfedge next, Halfedge prev, Face face) : this(vertex) {
     Next = next;
     Prev = prev;
     Face = face;
 }
コード例 #7
0
ファイル: JohnsonPoly.cs プロジェクト: IxxyXR/polyhydra-upm
        private static ConwayPoly _MakeCupola(int sides, float height, bool bi = false, bool gyro = true)
        {
            sides = Mathf.Clamp(sides, 3, 64);

            ConwayPoly poly   = _MakePolygon(sides * 2);
            Face       bottom = poly.Faces[0];
            ConwayPoly cap1   = _MakePolygon(sides, true, 0.25f, height, _CalcCupolaCapRadius(sides));

            poly.Append(cap1);

            int i = 0;
            var squareSideFaces = new List <Face>();
            var edge1           = poly.Halfedges[0];
            var edge2           = poly.Halfedges[sides * 2];

            while (true)
            {
                var side1 = new List <Vertex>
                {
                    edge1.Next.Vertex,
                    edge1.Vertex,
                    edge2.Prev.Vertex
                };
                poly.Faces.Add(side1);
                poly.FaceRoles.Add(ConwayPoly.Roles.New);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                var side2 = new List <Vertex>
                {
                    edge1.Vertex,
                    edge1.Prev.Vertex,
                    edge2.Vertex,
                    edge2.Prev.Vertex
                };
                poly.Faces.Add(side2);
                squareSideFaces.Add(poly.Faces.Last());
                poly.FaceRoles.Add(ConwayPoly.Roles.NewAlt);
                poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                i++;
                edge1 = edge1.Next.Next;
                edge2 = edge2.Prev;
                if (i == sides)
                {
                    break;
                }
            }

            if (bi)
            {
                float      angleOffset = gyro ? 0.75f : 0.25f;
                ConwayPoly cap2        = _MakePolygon(sides, false, angleOffset, -height, _CalcCupolaCapRadius(sides));
                poly.Append(cap2);

                i = 0;
                var middleVerts = bottom.GetVertices();

                poly.Faces.Remove(bottom);
                poly.FaceRoles.RemoveAt(0);

                edge2 = poly.Faces.Last().Halfedge.Prev;
                int indexOffset = gyro ? 0 : -1;
                while (true)
                {
                    var side1 = new List <Vertex>
                    {
                        middleVerts[PolyUtils.ActualMod(i * 2 - 1 + indexOffset, sides * 2)],
                        middleVerts[PolyUtils.ActualMod(i * 2 + indexOffset, sides * 2)],
                        edge2.Vertex
                    };
                    poly.Faces.Add(side1);
                    poly.FaceRoles.Add(ConwayPoly.Roles.New);
                    poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                    var side2 = new List <Vertex>
                    {
                        middleVerts[PolyUtils.ActualMod(i * 2 + indexOffset, sides * 2)],
                        middleVerts[PolyUtils.ActualMod(i * 2 + 1 + indexOffset, sides * 2)],
                        edge2.Next.Vertex,
                        edge2.Vertex,
                    };
                    poly.Faces.Add(side2);
                    poly.FaceRoles.Add(ConwayPoly.Roles.NewAlt);
                    poly.FaceTags.Add(new HashSet <Tuple <string, ConwayPoly.TagType> >());

                    i++;
                    edge2 = edge2.Next;

                    if (i == sides)
                    {
                        break;
                    }
                }
            }

            poly.Halfedges.MatchPairs();
            return(poly);
        }