private void DrawActions() { GUILayout.BeginHorizontal(); if (!_brushMode) { if (GUILayout.Button(new GUIContent(_config.BrushInactiveIcon), GUILayout.Width(75), GUILayout.Height(70))) { HideGizmos(); _brushMode = true; } } else { if (GUILayout.Button(new GUIContent(_config.BrushActiveIcon), GUILayout.Width(75), GUILayout.Height(70))) { ShowGizmos(); _brushMode = false; } } if (GUILayout.Button(new GUIContent(_config.FillColorIcon), GUILayout.Width(70), GUILayout.Height(70))) { _activeObject = Selection.activeGameObject = ((Component)target).gameObject; //Here! Manually assign the selection to be your object _activeVPTMesh = _activeObject.GetComponent <VPTMesh>(); PaintVertexFill(_activeVPTMesh); } GUILayout.EndHorizontal(); }
private void PaintVertexFill(VPTMesh target) { Vector3[] vertices = target.Mesh.vertices; Color[] colors = target.Mesh.colors; if (vertices.Length != colors.Length) //if the mesh doesn't have vertex color we create them. { colors = new Color[vertices.Length]; } for (int i = 0; i < vertices.Length; i++) { colors[i] = _selectedColor; } target.Mesh.SetColors(colors); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); }
private void OnSceneGUI() { UpdateSkin(); Rect windowRect = new Rect(20, 40, 80, 0); GUILayout.Window(0, windowRect, WindowVPTools, "Vertex Paint Tools"); if (_brushMode) { HideGizmos(); if (_activeObject != ((Component)target).gameObject) { _activeObject = Selection.activeGameObject = ((Component)target).gameObject; _activeVPTMesh = _activeObject.GetComponent <VPTMesh>(); _objectLayer = _activeObject.layer; _activeObject.layer = _paintingLayer = LayerMask.NameToLayer(CreateLayer("PaintingLayer")); } Rect rect = new Rect(195, 40, 150, 0); GUILayout.Window(1, rect, WindowBrushSettings, "Brush Settings"); if (_brush == null) { _brush = Instantiate(_config.VPT_Brush, Vector3.zero, Quaternion.identity); } else { if (!BrushPlacementOnSelectedMesh(_activeObject, Event.current.mousePosition)) { _brush.SetActive(false); } else { _brush.SetActive(true); if (Event.current.type == EventType.MouseDrag && Event.current.button == 0) { PaintVertex(_activeVPTMesh); } } } } }
private void PaintVertex(VPTMesh target) { Vector3[] vertices = target.Mesh.vertices; Color[] colors = target.Mesh.colors; if (vertices.Length != colors.Length) { colors = new Color[vertices.Length]; } for (int i = 0; i < vertices.Length; i++) { vertices[i] = target.transform.TransformPoint(vertices[i]); var distance = Vector3.Distance(vertices[i], _brush.transform.position); var color = Color.white; colors[i] = GetColor(colors[i], distance); } target.Mesh.SetColors(colors); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); }