12 private GameObject targetGameObject;
13 private MeshFilter targetMeshFilter;
14 private Texture2D tex;
16 [MenuItem(
"Window/InkPainter/UVChecker")]
17 private static void Open()
19 GetWindow<UVChecker>();
24 targetGameObject = EditorGUILayout.ObjectField(
"TargetMesh", targetGameObject, typeof(GameObject),
true) as GameObject;
25 if(GUILayout.Button(
"Execute"))
27 targetMeshFilter = targetGameObject.GetComponent<MeshFilter>();
28 tex =
new Texture2D(256, 256);
29 var mesh = targetMeshFilter.sharedMesh;
34 EditorGUI.DrawPreviewTexture(
new Rect(10, 50, tex.width, tex.height), tex);
38 private void DrawUV(Mesh mesh)
41 var tri = mesh.triangles;
43 for(
int i_base = 0; i_base < tri.Length; i_base += 3)
49 Vector2 uv1 = uvs[tri[i_1]];
50 Vector2 uv2 = uvs[tri[i_2]];
51 Vector2 uv3 = uvs[tri[i_3]];
63 private void UVLog(Vector2[] uvs)
65 StringBuilder sb =
new StringBuilder();
66 foreach(var uv
in uvs)
68 sb.AppendLine(uv.ToString());
71 Debug.Log(sb.ToString());
74 private void DrawLine(Vector2 from, Vector2 to)
76 int x0 = Mathf.RoundToInt(from.x * tex.width);
77 int y0 = Mathf.RoundToInt(from.y * tex.height);
78 int x1 = Mathf.RoundToInt(to.x * tex.width);
79 int y1 = Mathf.RoundToInt(to.y * tex.height);
84 private void DrawLine(
int x0,
int y0,
int x1,
int y1,
Color col)
91 { dy = -dy; stepy = -1; }
95 { dx = -dx; stepx = -1; }
103 tex.SetPixel(x0, y0, col);
106 fraction = dy - (dx >> 1);
107 while(Mathf.Abs(x0 - x1) > 1)
116 tex.SetPixel(x0, y0, col);
121 fraction = dx - (dy >> 1);
122 while(Mathf.Abs(y0 - y1) > 1)
131 tex.SetPixel(x0, y0, col);
Editor window to check UV.