internal static Mesh ExtractRegionAttachment (string name, RegionAttachment attachment, Mesh mesh = null, bool centered = true) { var bone = GetDummyBone(); if (centered) { bone.X = -attachment.X; bone.Y = -attachment.Y; } bone.UpdateWorldTransform(); Vector2[] uvs = ExtractUV(attachment.UVs); float[] floatVerts = new float[8]; attachment.ComputeWorldVertices(bone, floatVerts, 0); Vector3[] verts = ExtractVerts(floatVerts); //unrotate verts now that they're centered if (centered) { for (int i = 0; i < verts.Length; i++) verts[i] = Quaternion.Euler(0, 0, -attachment.Rotation) * verts[i]; } int[] triangles = { 1, 3, 0, 2, 3, 1 }; Color color = attachment.GetColor(); if (mesh == null) mesh = new Mesh(); mesh.triangles = new int[0]; mesh.vertices = verts; mesh.uv = uvs; mesh.triangles = triangles; mesh.colors = new [] { color, color, color, color }; mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.name = name; return mesh; }