Ejemplo n.º 1
0
        public static MeshDraft BaselessPyramid(Vector3 baseCenter, Vector3 apex, float radius, int segments,
                                                bool inverted = false)
        {
            float segmentAngle = Mathf.PI * 2 / segments * (inverted ? -1 : 1);
            float currentAngle = 0f;

            var vertices = new Vector3[segments + 1];

            vertices[0] = apex;
            for (var i = 1; i <= segments; i++)
            {
                vertices[i]   = PTUtils.PointOnCircle3(radius, currentAngle) + baseCenter;
                currentAngle += segmentAngle;
            }

            var draft = new MeshDraft {
                name = "BaselessPyramid"
            };

            for (var i = 1; i < segments; i++)
            {
                draft.Add(Triangle(vertices[0], vertices[i], vertices[i + 1]));
            }
            draft.Add(Triangle(vertices[0], vertices[vertices.Length - 1], vertices[1]));
            return(draft);
        }
Ejemplo n.º 2
0
        public static MeshDraft BaselessPyramid(Vector3 apex, List <Vector3> ring)
        {
            var draft = new MeshDraft {
                name = "BaselessPyramid"
            };

            for (var i = 0; i < ring.Count - 1; i++)
            {
                draft.Add(Triangle(apex, ring[i], ring[i + 1]));
            }
            draft.Add(Triangle(apex, ring[ring.Count - 1], ring[0]));
            return(draft);
        }
Ejemplo n.º 3
0
        public static MeshDraft FlatSphere(float radius, int longitudeSegments, int latitudeSegments)
        {
            float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments;
            float latitudeSegmentAngle  = Mathf.PI / latitudeSegments;

            float currentLatitude = -Mathf.PI / 2;
            var   rings           = new List <List <Vector3> >(latitudeSegments);

            for (var i = 0; i <= latitudeSegments; i++)
            {
                var currentLongitude = 0f;
                var ring             = new List <Vector3>(longitudeSegments);
                for (int j = 0; j < longitudeSegments; j++)
                {
                    ring.Add(PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude));
                    currentLongitude -= longitudeSegmentAngle;
                }
                rings.Add(ring);
                currentLatitude += latitudeSegmentAngle;
            }

            var draft = new MeshDraft {
                name = "Flat sphere"
            };

            for (int i = 0; i < rings.Count - 1; i++)
            {
                draft.Add(FlatBand(rings[i], rings[i + 1]));
            }
            return(draft);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructs partial hexahedron aka cube with specified faces
        /// </summary>
        public static MeshDraft Hexahedron(Vector3 width, Vector3 length, Vector3 height, Directions parts)
        {
            Vector3 corner0 = -width / 2 - length / 2 - height / 2;
            Vector3 corner1 = width / 2 + length / 2 + height / 2;

            var draft = new MeshDraft {
                name = "Hexahedron"
            };

            if ((parts & Directions.Left) == Directions.Left)
            {
                draft.Add(Quad(corner0, height, length));
            }
            if ((parts & Directions.Right) == Directions.Right)
            {
                draft.Add(Quad(corner1, -length, -height));
            }
            if ((parts & Directions.Down) == Directions.Down)
            {
                draft.Add(Quad(corner0, length, width));
            }
            if ((parts & Directions.Up) == Directions.Up)
            {
                draft.Add(Quad(corner1, -width, -length));
            }
            if ((parts & Directions.Back) == Directions.Back)
            {
                draft.Add(Quad(corner0, width, height));
            }
            if ((parts & Directions.Forward) == Directions.Forward)
            {
                draft.Add(Quad(corner1, -height, -width));
            }
            return(draft);
        }
Ejemplo n.º 5
0
        public static MeshDraft FlatBand(List <Vector3> lowerRing, List <Vector3> upperRing)
        {
            var draft = new MeshDraft {
                name = "Flat band"
            };

            if (lowerRing.Count < 3 || upperRing.Count < 3)
            {
                Debug.LogError("Array sizes must be greater than 2");
                return(draft);
            }
            if (lowerRing.Count != upperRing.Count)
            {
                Debug.LogError("Array sizes must be equal");
                return(draft);
            }

            Vector3 v0, v1, v2, v3;

            for (int i = 0; i < lowerRing.Count - 1; i++)
            {
                v0 = lowerRing[i];
                v1 = upperRing[i];
                v2 = lowerRing[i + 1];
                v3 = upperRing[i + 1];
                draft.Add(Triangle(v0, v1, v2));
                draft.Add(Triangle(v2, v1, v3));
            }

            v0 = lowerRing[lowerRing.Count - 1];
            v1 = upperRing[upperRing.Count - 1];
            v2 = lowerRing[0];
            v3 = upperRing[0];
            draft.Add(Triangle(v0, v1, v2));
            draft.Add(Triangle(v2, v1, v3));

            return(draft);
        }
Ejemplo n.º 6
0
        public static MeshDraft FlatRevolutionSurface(
            Func <float, float, float, float, Vector3> surfaceFunction,
            float radius,
            float height,
            int horizontalSegments,
            int verticalSegments)
        {
            float horizontalSegmentAngle = 360f / horizontalSegments;
            float verticalSegmentAngle   = 180f / verticalSegments;
            float currentVerticalAngle   = -90;

            var rings = new List <List <Vector3> >(verticalSegments);

            for (int i = 0; i <= verticalSegments; i++)
            {
                float currentHorizontalAngle = 0f;
                var   ring = new List <Vector3>(horizontalSegments);
                for (int j = 0; j < horizontalSegments; j++)
                {
                    ring.Add(surfaceFunction(radius, height, currentHorizontalAngle, currentVerticalAngle));
                    currentHorizontalAngle -= horizontalSegmentAngle;
                }
                rings.Add(ring);
                currentVerticalAngle += verticalSegmentAngle;
            }

            var draft = new MeshDraft {
                name = "Flat revolution surface"
            };

            for (int i = 0; i < rings.Count - 1; i++)
            {
                draft.Add(FlatBand(rings[i], rings[i + 1]));
            }
            return(draft);
        }
Ejemplo n.º 7
0
        public static MeshDraft FlatRevolutionSurface(
            Func <float, float, float, float, Vector3> surfaceFunction,
            float radius,
            float height,
            int longitudeSegments,
            int latitudeSegments)
        {
            float longitudeSegmentAngle = 360f / longitudeSegments;
            float latitudeSegmentAngle  = 180f / latitudeSegments;
            float currentLatitude       = -90;

            var rings = new List <List <Vector3> >(latitudeSegments);

            for (int i = 0; i <= latitudeSegments; i++)
            {
                var currentLongitude = 0f;
                var ring             = new List <Vector3>(longitudeSegments);
                for (int j = 0; j < longitudeSegments; j++)
                {
                    ring.Add(surfaceFunction(radius, height, currentLongitude, currentLatitude));
                    currentLongitude -= longitudeSegmentAngle;
                }
                rings.Add(ring);
                currentLatitude += latitudeSegmentAngle;
            }

            var draft = new MeshDraft {
                name = "Flat revolution surface"
            };

            for (int i = 0; i < rings.Count - 1; i++)
            {
                draft.Add(FlatBand(rings[i], rings[i + 1]));
            }
            return(draft);
        }
Ejemplo n.º 8
0
        public static MeshDraft BaselessPyramid(Vector3 baseCenter, Vector3 apex, float radius, int segments,
            bool inverted = false)
        {
            float segmentAngle = Mathf.PI*2/segments*(inverted ? -1 : 1);
            float currentAngle = 0f;

            var vertices = new Vector3[segments + 1];
            vertices[0] = apex;
            for (var i = 1; i <= segments; i++)
            {
                vertices[i] = PTUtils.PointOnCircle3(radius, currentAngle) + baseCenter;
                currentAngle += segmentAngle;
            }

            var draft = new MeshDraft {name = "BaselessPyramid"};
            for (var i = 1; i < segments; i++)
            {
                draft.Add(Triangle(vertices[0], vertices[i], vertices[i + 1]));
            }
            draft.Add(Triangle(vertices[0], vertices[vertices.Length - 1], vertices[1]));
            return draft;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Constructs partial hexahedron aka cube with specified faces
        /// </summary>
        public static MeshDraft Hexahedron(Vector3 width, Vector3 length, Vector3 height, Directions parts)
        {
            Vector3 corner0 = -width/2 - length/2 - height/2;
            Vector3 corner1 = width/2 + length/2 + height/2;

            var draft = new MeshDraft {name = "Hexahedron"};
            if ((parts & Directions.Left) == Directions.Left)
            {
                draft.Add(Quad(corner0, height, length));
            }
            if ((parts & Directions.Right) == Directions.Right)
            {
                draft.Add(Quad(corner1, -length, -height));
            }
            if ((parts & Directions.Down) == Directions.Down)
            {
                draft.Add(Quad(corner0, length, width));
            }
            if ((parts & Directions.Up) == Directions.Up)
            {
                draft.Add(Quad(corner1, -width, -length));
            }
            if ((parts & Directions.Back) == Directions.Back)
            {
                draft.Add(Quad(corner0, width, height));
            }
            if ((parts & Directions.Forward) == Directions.Forward)
            {
                draft.Add(Quad(corner1, -height, -width));
            }
            return draft;
        }
Ejemplo n.º 10
0
        public static MeshDraft FlatSphere(float radius, int longitudeSegments, int latitudeSegments)
        {
            float longitudeSegmentAngle = Mathf.PI*2/longitudeSegments;
            float latitudeSegmentAngle = Mathf.PI/latitudeSegments;

            float currentLatitude = -Mathf.PI/2;
            var rings = new List<List<Vector3>>(latitudeSegments);
            for (var i = 0; i <= latitudeSegments; i++)
            {
                var currentLongitude = 0f;
                var ring = new List<Vector3>(longitudeSegments);
                for (int j = 0; j < longitudeSegments; j++)
                {
                    ring.Add(PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude));
                    currentLongitude -= longitudeSegmentAngle;
                }
                rings.Add(ring);
                currentLatitude += latitudeSegmentAngle;
            }

            var draft = new MeshDraft {name = "Flat sphere"};
            for (int i = 0; i < rings.Count - 1; i++)
            {
                draft.Add(FlatBand(rings[i], rings[i + 1]));
            }
            return draft;
        }
Ejemplo n.º 11
0
        public static MeshDraft FlatBand(List<Vector3> lowerRing, List<Vector3> upperRing)
        {
            var draft = new MeshDraft {name = "Flat band"};
            if (lowerRing.Count < 3 || upperRing.Count < 3)
            {
                Debug.LogError("Array sizes must be greater than 2");
                return draft;
            }
            if (lowerRing.Count != upperRing.Count)
            {
                Debug.LogError("Array sizes must be equal");
                return draft;
            }

            Vector3 v0, v1, v2, v3;
            for (int i = 0; i < lowerRing.Count - 1; i++)
            {
                v0 = lowerRing[i];
                v1 = upperRing[i];
                v2 = lowerRing[i + 1];
                v3 = upperRing[i + 1];
                draft.Add(Triangle(v0, v1, v2));
                draft.Add(Triangle(v2, v1, v3));
            }

            v0 = lowerRing[lowerRing.Count - 1];
            v1 = upperRing[upperRing.Count - 1];
            v2 = lowerRing[0];
            v3 = upperRing[0];
            draft.Add(Triangle(v0, v1, v2));
            draft.Add(Triangle(v2, v1, v3));

            return draft;
        }
Ejemplo n.º 12
0
 public static MeshDraft BaselessPyramid(Vector3 apex, List<Vector3> ring)
 {
     var draft = new MeshDraft {name = "BaselessPyramid"};
     for (var i = 0; i < ring.Count - 1; i++)
     {
         draft.Add(Triangle(apex, ring[i], ring[i + 1]));
     }
     draft.Add(Triangle(apex, ring[ring.Count - 1], ring[0]));
     return draft;
 }