Skip to content

Commit

Permalink
Making adding of the stream component more conservative
Browse files Browse the repository at this point in the history
Note, this changes the workflow ever so slightly. The issue, is that in
some cases (when brush influence was on, etc), the VertexInstanceStream
component would get added to objects which were not being painted on.
Now these are only added when absolutely necessary, but the downside is
that you can no longer use ‘Show Vertex Data’ without the tool being
active and the stream being already added.

This means that you have to paint before you’ll see the vertex data,
which is not very nice. So, to at least make this better, there’s now
an “Add Stream” button next to the preview toggle. Clicking it will add
the stream and start showing the vertex data if preview mode is on.
While I was there, I also added a “Remove Unused” if none of the
streams have data. This makes it a bit easier to cleanup as well.
  • Loading branch information
slipster216 committed Oct 20, 2016
1 parent e8cb2b6 commit e0b91b8
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 109 deletions.
175 changes: 107 additions & 68 deletions Editor/VertexPainterWindow_GUI.cs
Expand Up @@ -153,13 +153,33 @@ void DrawChannelGUI()
if (enabled != oldEnabled)
{
InitMeshes();
UpdateDisplayMode();
}
var oldShow = showVertexShader;
EditorGUILayout.BeginHorizontal();
showVertexShader = GUILayout.Toggle(showVertexShader, "Show Vertex Data (ctrl-V)");
if (oldShow != showVertexShader)
{
UpdateDisplayMode();
}
bool emptyStreams = false;
for (int i = 0; i < jobs.Length; ++i)
{
if (!jobs[i].HasStream())
emptyStreams = true;
}
if (emptyStreams)
{
if (GUILayout.Button("Add Streams"))
{
for (int i = 0; i < jobs.Length; ++i)
{
jobs[i].EnforceStream();
}
UpdateDisplayMode();
}
}
EditorGUILayout.EndHorizontal();

brushVisualization = (BrushVisualization)EditorGUILayout.EnumPopup("Brush Visualization", brushVisualization);

Expand All @@ -184,14 +204,14 @@ void DrawChannelGUI()
bool hasUV3 = false;
bool hasPositions = false;
bool hasNormals = false;

bool hasStream = false;
for (int i = 0; i < jobs.Length; ++i)
{
var stream = jobs[i]._stream;
if (stream != null)
{
int vertexCount = jobs[i].verts.Length;

hasStream = true;
hasColors = (stream.colors != null && stream.colors.Length == vertexCount);
hasUV0 = (stream.uv0 != null && stream.uv0.Count == vertexCount);
hasUV1 = (stream.uv1 != null && stream.uv1.Count == vertexCount);
Expand All @@ -201,90 +221,109 @@ void DrawChannelGUI()
hasNormals = (stream.normals != null && stream.normals.Length == vertexCount);
}
}

EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Clear Channel:");
if (hasColors && DrawClearButton("Colors"))

if (hasStream && (hasColors || hasUV0 || hasUV1 || hasUV2 || hasUV3 || hasPositions || hasNormals))
{
for (int i = 0; i < jobs.Length; ++i)
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Clear Channel:");
if (hasColors && DrawClearButton("Colors"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.colors = null;
stream.Apply();
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.colors = null;
stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
if (hasUV0 && DrawClearButton("UV0"))
{
for (int i = 0; i < jobs.Length; ++i)
if (hasUV0 && DrawClearButton("UV0"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv0 = null;
stream.Apply();
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv0 = null;
stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
if (hasUV1 && DrawClearButton("UV1"))
{
for (int i = 0; i < jobs.Length; ++i)
if (hasUV1 && DrawClearButton("UV1"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv1 = null;
stream.Apply();
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv1 = null;
stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
if (hasUV2 && DrawClearButton("UV2"))
{
for (int i = 0; i < jobs.Length; ++i)
if (hasUV2 && DrawClearButton("UV2"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv2 = null;
stream.Apply();
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv2 = null;
stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
if (hasUV3 && DrawClearButton("UV3"))
{
for (int i = 0; i < jobs.Length; ++i)
if (hasUV3 && DrawClearButton("UV3"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv3 = null;
stream.Apply();
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
var stream = jobs[i].stream;
stream.uv3 = null;
stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
if (hasPositions && DrawClearButton("Pos"))
{
for (int i = 0; i < jobs.Length; ++i)
if (hasPositions && DrawClearButton("Pos"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
jobs[i].stream.positions = null;
Mesh m = jobs[i].stream.GetModifierMesh();
if (m != null)
m.vertices = jobs[i].meshFilter.sharedMesh.vertices;
jobs[i].stream.Apply();
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
jobs[i].stream.positions = null;
Mesh m = jobs[i].stream.GetModifierMesh();
if (m != null)
m.vertices = jobs[i].meshFilter.sharedMesh.vertices;
jobs[i].stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
if (hasNormals && DrawClearButton("Norm"))
{
for (int i = 0; i < jobs.Length; ++i)
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
jobs[i].stream.normals = null;
jobs[i].stream.tangents = null;
jobs[i].stream.Apply();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}

EditorGUILayout.EndHorizontal();
}
if (hasNormals && DrawClearButton("Norm"))
else if (hasStream)
{
for (int i = 0; i < jobs.Length; ++i)
if (GUILayout.Button("Remove Unused Stream Components"))
{
Undo.RecordObject(jobs[i].stream, "Vertex Painter Clear");
jobs[i].stream.normals = null;
jobs[i].stream.tangents = null;
jobs[i].stream.Apply();
RevertMat();
for (int i = 0; i < jobs.Length; ++i)
{
if (jobs[i].HasStream())
{
DestroyImmediate(jobs[i].stream);
}
}
UpdateDisplayMode();
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}

EditorGUILayout.EndHorizontal();


EditorGUILayout.Separator();
GUILayout.Box("", new GUILayoutOption[]{GUILayout.ExpandWidth(true), GUILayout.Height(1)});
Expand Down

0 comments on commit e0b91b8

Please sign in to comment.