Beispiel #1
0
        private void TesselateGeometry(List <UIVertex> verts)
        {
            Vector2 tessellatedSize = settings.GetSize();

            /// Convert the list from triangles to quads to be used by the tesselation
            TrianglesToQuads(verts);

            //do not tesselate text verts. Text usually is small and has plenty of verts already.
            if (myText == null && !DoNotTesselate)
            {
                // Tesselate quads and apply transformation
                int startingVertexCount = verts.Count;
                for (int i = 0; i < startingVertexCount; i += 4)
                {
                    ModifyQuad(verts, i, tessellatedSize);
                }

                // Remove old quads
                verts.RemoveRange(0, startingVertexCount);
            }
        }
Beispiel #2
0
        private Mesh CreateSphereColliderMesh()
        {
            Mesh meshie = new Mesh();

            Vector3[] Corners = new Vector3[4];
            (canvas.transform as RectTransform).GetWorldCorners(Corners);

            List <Vector3> verts = new List <Vector3>(Corners);

            for (int i = 0; i < verts.Count; i++)
            {
                verts[i] = settings.transform.worldToLocalMatrix.MultiplyPoint3x4(verts[i]);
            }

            if (settings.Angle != 0)
            {
                // Tesselate quads and apply transformation
                int startingVertexCount = verts.Count;
                for (int i = 0; i < startingVertexCount; i += 4)
                {
                    ModifyQuad(verts, i, settings.GetSize(true));
                }

                // Remove old quads
                verts.RemoveRange(0, startingVertexCount);

                //curve verts
                float   vangle         = settings.VerticalAngle;
                float   cylinder_angle = settings.Angle;
                Vector2 canvasSize     = (canvas.transform as RectTransform).rect.size;
                float   radius         = settings.GetCyllinderRadiusInCanvasSpace();

                //caluclate vertical angle for aspect - consistent mapping
                vangle = settings.Angle * (canvasSize.y / canvasSize.x);

                //curve the vertices
                for (int i = 0; i < verts.Count; i++)
                {
                    float theta = (verts[i].x / canvasSize.x).Remap(-0.5f, 0.5f, (180 - cylinder_angle) / 2.0f - 90, 180 - (180 - cylinder_angle) / 2.0f - 90);
                    theta *= Mathf.Deg2Rad;
                    float gamma = (verts[i].y / canvasSize.y).Remap(-0.5f, 0.5f, (180 - vangle) / 2.0f, 180 - (180 - vangle) / 2.0f);
                    gamma *= Mathf.Deg2Rad;

                    verts[i] = new Vector3(Mathf.Sin(gamma) * Mathf.Sin(theta) * radius,
                                           -radius * Mathf.Cos(gamma),
                                           Mathf.Sin(gamma) * Mathf.Cos(theta) * radius + -radius);
                }
            }
            meshie.vertices = verts.ToArray();

            //create triangles from verts
            List <int> tris = new List <int>();

            for (int i = 0; i < verts.Count; i += 4)
            {
                tris.Add(i + 0);
                tris.Add(i + 1);
                tris.Add(i + 2);

                tris.Add(i + 3);
                tris.Add(i + 0);
                tris.Add(i + 2);
            }


            meshie.triangles = tris.ToArray();
            return(meshie);
        }