void OnSceneGUI()
        {
            if (Asset == null) return;
            if (IconLoader == null) IconLoader = new IconLoader();

            float height = 32f * 13 + 30f;
            float width = 32f;

            bool disableVertexData = Asset.Mesh.vertices.Length >= MeshDisplay.MAX_VERTEX_COUNT;

            var rect = new Rect(Screen.width - width - 10, Screen.height/2 - height/2, width, height);

            GUILayout.BeginArea(rect);

            // Default Gizmo
            Asset.MeshDisplay.DisplayDefaultGizmo = GUILayout.Toggle(Asset.MeshDisplay.DisplayDefaultGizmo, IconLoader.Icons["defaultGizmo"], "button");
            GUILayout.Space(10);

            // Vertex Display
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayVertices = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertices, IconLoader.Icons["vertex"], "button");
            Asset.MeshDisplay.DisplayVertexNormal = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexNormal, IconLoader.Icons["vertexNormal"], "button");
            Asset.MeshDisplay.DisplayVertexTangent = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexTangent, IconLoader.Icons["vertexTangent"], "button");
            Asset.MeshDisplay.DisplayVertexIndex = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexIndex, IconLoader.Icons["vertexIndex"], "button");
            Asset.MeshDisplay.DisplayVertexPosition = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexPosition, IconLoader.Icons["vertexPosition"], "button");
            EditorGUI.EndDisabledGroup();
            GUILayout.Space(10);

            // Face Display
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayFaces = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaces, IconLoader.Icons["face"], "button");
            Asset.MeshDisplay.DisplayFaceOrder = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaceOrder, IconLoader.Icons["face"], "button");
            Asset.MeshDisplay.DisplayFaceNormal = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaceNormal, IconLoader.Icons["faceNormal"], "button");
            Asset.MeshDisplay.DisplayFaceIndex = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaceIndex, IconLoader.Icons["faceIndex"], "button");
            EditorGUI.EndDisabledGroup();
            GUILayout.Space(10);

            // Polygons
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayPolygons = GUILayout.Toggle(Asset.MeshDisplay.DisplayPolygons, IconLoader.Icons["polygon"], "button");
            Asset.MeshDisplay.DisplayPolygonIndex = GUILayout.Toggle(Asset.MeshDisplay.DisplayPolygonIndex, IconLoader.Icons["polygonIndex"], "button");
            EditorGUI.EndDisabledGroup();

            GUILayout.Space(10);

            // UV
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayUVs = GUILayout.Toggle(Asset.MeshDisplay.DisplayUVs, IconLoader.Icons["uv"], "button");
            EditorGUI.EndDisabledGroup();

            // origin
            Asset.MeshDisplay.DisplayOrigin = GUILayout.Toggle(Asset.MeshDisplay.DisplayOrigin, IconLoader.Icons["origin"], "button");

            GUILayout.EndArea();
        }
Beispiel #2
0
		void OnGUI() {
			// Initialize objects
			if (IconLoader == null) IconLoader = new IconLoader();
			if (BGTex == null) {
				BGTex = new Texture2D(1, 1);
				BGTex.hideFlags = HideFlags.HideAndDontSave;
				BGTex.SetPixel(0, 0, BGColor);
				BGTex.Apply();
			}
			if (VertexStyle == null) {
				VertexStyle = MakeStyle(Color.cyan, 0f);
				FaceStyle = MakeStyle(Color.red, 0f);
				ShadowStyle = MakeStyle(Color.black, 1f);
			}

			// Total canvas
			Canvas = new Rect(0f, 0f, position.width * 4 * Zoom, position.height * 4 * Zoom);

			// Scroll view
			Rect scrollViewRect = new Rect(0, 0, position.width, position.height);
			ScrollPoint = GUI.BeginScrollView(scrollViewRect, ScrollPoint, Canvas);
			bool needsRepaint = false;

			// Zoom with the mouse wheel
			if (Event.current.type == EventType.ScrollWheel) {
				Zoom += -Event.current.delta.y / 50;
				if (Zoom < 0.1f) Zoom = 0.1f;
				if (Zoom > 1f) Zoom = 1f;
				needsRepaint = true;
				Event.current.Use();
			}

			// Draw background
			GUI.DrawTexture(new Rect(ScrollPoint.x, ScrollPoint.y, scrollViewRect.width, scrollViewRect.height), BGTex);

			// Texture Inputs
			GameObject go = Selection.activeObject as GameObject;
			List<string> texInputsList = new List<string>();
			texInputsList.Add("-");
			Texture texPreview = null;
			if (go != null) {
				Renderer renderer = go.GetComponent<MeshRenderer>();
				if (renderer != null) {
					Material mat = renderer.sharedMaterial;
					if (mat != null) {
						for (int p = 0; p < ShaderUtil.GetPropertyCount(mat.shader); p++) {
							if (ShaderUtil.GetPropertyType(mat.shader, p) == ShaderUtil.ShaderPropertyType.TexEnv) {
								if (TexInput > 0 && TexInput == texInputsList.Count) {
									texPreview = mat.GetTexture(ShaderUtil.GetPropertyName(mat.shader, p));
								}
								texInputsList.Add(ShaderUtil.GetPropertyDescription(mat.shader, p));
							}
						}
					}
				}
			}

			// Draw UV Canvas
			Rect uvCanvas = new Rect(CanvasMargin, CanvasMarginTop, position.width * 4 * Zoom - CanvasMargin * 2, position.height * 4 * Zoom - (CanvasMarginTop + CanvasMargin));
			if (texPreview) {
				GUI.DrawTexture(uvCanvas, texPreview);
			} else {
				Handles.color = UVBorderColor;
				Handles.DrawPolyLine(new Vector3[] {
					new Vector3(uvCanvas.x, uvCanvas.y),
					new Vector3(uvCanvas.x + uvCanvas.width, uvCanvas.y),
					new Vector3(uvCanvas.x + uvCanvas.width, uvCanvas.y + uvCanvas.height),
					new Vector3(uvCanvas.x, uvCanvas.height + uvCanvas.y),
					new Vector3(uvCanvas.x, uvCanvas.y)
				});
			}

			// UI
			UVSet = EditorGUI.Popup(new Rect(10f, 12f, 100f, 30f), UVSet, new string[] { "uv0", "uv1" });
			DisplayVertices = GUI.Toggle(new Rect(120f, 10f, 30f, 20f), DisplayVertices, IconLoader.Icons["vertex"], "button");
			DisplayVertexIndices = GUI.Toggle(new Rect(155f, 10f, 30f, 20f), DisplayVertexIndices, IconLoader.Icons["vertexIndex"], "button");
			DisplayEdges = GUI.Toggle(new Rect(190f, 10f, 30f, 20f), DisplayEdges, IconLoader.Icons["face"], "button");
			DisplayFaces = GUI.Toggle(new Rect(225f, 10f, 30f, 20f), DisplayFaces, IconLoader.Icons["faceIndex"], "button");
			TexInput = EditorGUI.Popup(new Rect(260f, 12f, 100f, 30f), TexInput, texInputsList.ToArray());

			// Mesh data
			if (go != null) {
				var meshFilter = go.GetComponent<MeshFilter>();
				if (meshFilter != null) {

					Mesh mesh = meshFilter.sharedMesh;
					Vector2[] uvSet = UVSet == 0 ? mesh.uv : mesh.uv2;

					// Triangles
					for (int i = 0; i < mesh.triangles.Length; i += 3) {

						if (uvSet.Length == 0) {
							break;
						}

						Vector3[] verts = new Vector3[3];
						for (int n = 0; n < 3; n++) {
							verts[n] = new Vector3(
								uvCanvas.x + uvSet[mesh.triangles[i + n]].x * uvCanvas.width,
								uvCanvas.y + (1 - uvSet[mesh.triangles[i + n]].y) * uvCanvas.height,
								0f);
						}

						// Draw edges
						if (DisplayEdges) {
							Handles.color = Color.white;
							Handles.DrawPolyLine(new Vector3[] { verts[0], verts[1], verts[2], verts[0] });
						}

						// Draw face indices
						if (DisplayFaces) {
							Handles.color = Color.red;
							Vector3 mid = (verts[0] + verts[1] + verts[2]) / 3;
							mid.y -= 10f;
							DrawLabel(mid.x, mid.y, (i / 3).ToString(), FaceStyle);
						}
					}

					// Vertices
					for (int i = 0; i < uvSet.Length; i++) {
						Vector2 uv = uvSet[i];
						Vector3 point = new Vector3(uvCanvas.width * uv.x + uvCanvas.x, uvCanvas.height * (1 - uv.y) + uvCanvas.y, 0);

						// Draw vertex indices
						if (DisplayVertexIndices) {
							DrawLabel(point.x, point.y, i.ToString(), VertexStyle);
						}

						// Draw vertices
						if (DisplayVertices) {
							float thickness = 2f;
							Handles.color = Color.cyan;
							Handles.DrawSolidRectangleWithOutline(new Vector3[] {
								new Vector3(point.x - thickness, point.y - thickness, 0),
								new Vector3(point.x - thickness, point.y + thickness, 0),
								new Vector3(point.x + thickness, point.y + thickness, 0),
								new Vector3(point.x + thickness, point.y - thickness, 0)
							}, Color.white, Color.white);
						}
					}

				}
			}

			// Handle left mouse button events
			if (Event.current.button == 0) {

				// MouseDown
				if (Event.current.type == EventType.MouseDown && !_isDragging) {
					_isDragging = true;
				}

				// MouseDrag
				if (Event.current.type == EventType.MouseDrag && _isDragging) {
					if (Event.current.delta.magnitude > 0) {
						ScrollPoint.x += -Event.current.delta.x;
						ScrollPoint.y += -Event.current.delta.y;
						needsRepaint = true;
					}
				}

				// MouseUp
				if (Event.current.type == EventType.MouseUp) {
					_isDragging = false;
				}

			} // Left mouse down/drag/up

			// Right Click
			if (Event.current.button == 1 && Event.current.type == EventType.MouseUp) {
				var menu = new GenericMenu();
				menu.AddItem(new GUIContent("WIP"), false, MenuAction, null);
				menu.ShowAsContext();
			}


			if (needsRepaint) {
				Repaint();
			}

			GUI.EndScrollView();

		} // OnGUI
Beispiel #3
0
        void OnSceneGUI()
        {
            if (Asset == null)
            {
                return;
            }
            if (IconLoader == null)
            {
                IconLoader = new IconLoader();
            }

            float height = 32f * 13 + 30f;
            float width  = 32f;

            bool disableVertexData = Asset.Mesh.vertices.Length >= MeshDisplay.MAX_VERTEX_COUNT;

            var rect = new Rect(Screen.width - width - 10, Screen.height / 2 - height / 2, width, height);

            GUILayout.BeginArea(rect);

            // Default Gizmo
            Asset.MeshDisplay.DisplayDefaultGizmo = GUILayout.Toggle(Asset.MeshDisplay.DisplayDefaultGizmo, IconLoader.Icons["defaultGizmo"], "button");
            GUILayout.Space(10);

            // Vertex Display
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayVertices       = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertices, IconLoader.Icons["vertex"], "button");
            Asset.MeshDisplay.DisplayVertexNormal   = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexNormal, IconLoader.Icons["vertexNormal"], "button");
            Asset.MeshDisplay.DisplayVertexTangent  = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexTangent, IconLoader.Icons["vertexTangent"], "button");
            Asset.MeshDisplay.DisplayVertexIndex    = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexIndex, IconLoader.Icons["vertexIndex"], "button");
            Asset.MeshDisplay.DisplayVertexPosition = GUILayout.Toggle(Asset.MeshDisplay.DisplayVertexPosition, IconLoader.Icons["vertexPosition"], "button");
            EditorGUI.EndDisabledGroup();
            GUILayout.Space(10);

            // Face Display
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayFaces = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaces, IconLoader.Icons["face"], "button");
            //Asset.MeshDisplay.DisplayFaceOrder = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaceOrder, IconLoader.Icons["face"], "button");
            Asset.MeshDisplay.DisplayFaceNormal = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaceNormal, IconLoader.Icons["faceNormal"], "button");
            Asset.MeshDisplay.DisplayFaceIndex  = GUILayout.Toggle(Asset.MeshDisplay.DisplayFaceIndex, IconLoader.Icons["faceIndex"], "button");
            EditorGUI.EndDisabledGroup();
            GUILayout.Space(10);

            // Polygons
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayPolygons     = GUILayout.Toggle(Asset.MeshDisplay.DisplayPolygons, IconLoader.Icons["polygon"], "button");
            Asset.MeshDisplay.DisplayPolygonIndex = GUILayout.Toggle(Asset.MeshDisplay.DisplayPolygonIndex, IconLoader.Icons["polygonIndex"], "button");
            EditorGUI.EndDisabledGroup();

            GUILayout.Space(10);

            // UV
            EditorGUI.BeginDisabledGroup(disableVertexData);
            Asset.MeshDisplay.DisplayUVs = GUILayout.Toggle(Asset.MeshDisplay.DisplayUVs, IconLoader.Icons["uv"], "button");
            EditorGUI.EndDisabledGroup();

            // origin
            Asset.MeshDisplay.DisplayOrigin = GUILayout.Toggle(Asset.MeshDisplay.DisplayOrigin, IconLoader.Icons["origin"], "button");

            GUILayout.EndArea();
        }