/// <summary>
        /// Constructs a tetrahedron draft
        /// </summary>
        public static MeshDraft Tetrahedron(float radius, bool generateUV = true)
        {
            const float tetrahedralAngle = -19.471220333f;

            var vertex0 = new Vector3(0, radius, 0);
            var vertex1 = Geometry.PointOnSphere(radius, 0, tetrahedralAngle);
            var vertex2 = Geometry.PointOnSphere(radius, 120, tetrahedralAngle);
            var vertex3 = Geometry.PointOnSphere(radius, 240, tetrahedralAngle);

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

            if (generateUV)
            {
                var uv0 = new Vector2(0, 0);
                var uv1 = new Vector2(0.5f, 1);
                var uv2 = new Vector2(1, 0);
                draft.AddTriangle(vertex2, vertex0, vertex1, true, uv0, uv1, uv2)
                .AddTriangle(vertex2, vertex1, vertex3, true, uv0, uv1, uv2)
                .AddTriangle(vertex3, vertex0, vertex2, true, uv0, uv1, uv2)
                .AddTriangle(vertex1, vertex0, vertex3, true, uv0, uv1, uv2);
            }
            else
            {
                draft.AddTriangle(vertex2, vertex0, vertex1, true)
                .AddTriangle(vertex2, vertex1, vertex3, true)
                .AddTriangle(vertex3, vertex0, vertex2, true)
                .AddTriangle(vertex1, vertex0, vertex3, true);
            }
            return(draft);
        }
Beispiel #2
0
        public static MeshDraft BaselessPyramid(Vector3 baseCenter, Vector3 apex, float radius, int segments,
                                                bool inverted = false)
        {
            float segmentAngle = 360f / segments * (inverted ? -1 : 1);
            float currentAngle = 0;

            var vertices = new Vector3[segments + 1];

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

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

            for (var i = 1; i < segments; i++)
            {
                draft.AddTriangle(vertices[0], vertices[i], vertices[i + 1]);
            }
            draft.AddTriangle(vertices[0], vertices[vertices.Length - 1], vertices[1]);
            return(draft);
        }
Beispiel #3
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.AddTriangle(apex, ring[i], ring[i + 1]);
            }
            draft.AddTriangle(apex, ring[ring.Count - 1], ring[0]);
            return(draft);
        }
Beispiel #4
0
        public static MeshDraft Triangle(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2)
        {
            var draft = new MeshDraft
            {
                name = "Triangle",
                uv   = new List <Vector2>(3)
                {
                    new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)
                },
            };

            draft.AddTriangle(vertex0, vertex1, vertex2);
            return(draft);
        }
Beispiel #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)
            {
                throw new ArgumentException("Array sizes must be greater than 2");
            }
            if (lowerRing.Count != upperRing.Count)
            {
                throw new ArgumentException("Array sizes must be equal");
            }

            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.AddTriangle(v0, v1, v2)
                .AddTriangle(v2, v1, v3);
            }

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

            return(draft);
        }