Skip to content

Commit 32909b6

Browse files
committed
Improve Vertex to Indice functionality
1 parent 6222588 commit 32909b6

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

Assets/Plugins/MeshDebugger/Editor/MeshDebugger.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,17 @@ void OnSceneGUI(SceneView view)
163163
if (m_DebugBinormalVerts)
164164
m_Gizmo.AddRay(vert, m_cpu.m_Normals[2][i] * m_RaySize, red);
165165
if (m_DebugVertsToIndice)
166-
m_Gizmo.AddLine(vert, vert + m_cpu.m_VertToIndicesDir[i], cyan);
166+
{
167+
var refs = m_cpu.m_VertToIndicesDir[i];
168+
if (refs != null)
169+
for (int j = 0; j < refs.Count; j++)
170+
{
171+
int submesh, localidx;
172+
m_cpu.UnpackTriangleIdx(refs[j], out submesh, out localidx);
173+
localidx /= MeshInfo.m_TopologyDivision[m_cpu.m_IndiceTypes[submesh]];
174+
m_Gizmo.AddLine(vert, m_cpu.m_IndiceMedians[submesh][localidx], cyan);
175+
}
176+
}
167177
});
168178
}
169179

Assets/Plugins/MeshDebugger/Editor/MeshInfo.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class MeshInfo
2121
public List<Vector3> m_Verts;
2222
public List<int> m_VertUsedCounts;
2323
public Dictionary<Vector3, int> m_VertSimilars;
24-
public List<Vector3> m_VertToIndicesDir;
24+
public List<List<int>> m_VertToIndicesDir;
2525

2626
public List<int>[] m_Indices;
2727
public int[] m_IndiceOffsets;
@@ -173,11 +173,14 @@ public void Update()
173173
var indice = m_Indices[i];
174174
for (int j = 0; j < indice.Count; j++)
175175
{
176-
var idx = indice[j];
177-
m_VertToIndicesDir[idx] = (m_IndiceMedians[i][j / m_TopologyDivision[m_IndiceTypes[i]]] - m_Verts[idx]);
176+
var idx = indice[j]; // this is index of vertex, btw
178177
if (m_VertUsedCounts[idx] == 0)
178+
{
179179
m_VertOrphan--;
180-
m_VertUsedCountMax = Mathf.Max(m_VertUsedCountMax, ++m_VertUsedCounts[idx]);
180+
m_VertToIndicesDir[idx] = new List<int>();
181+
}
182+
m_VertToIndicesDir[idx].Add(m_IndiceOffsets[i] + j);
183+
m_VertUsedCountMax = Mathf.Max(m_VertUsedCountMax, ++m_VertUsedCounts[idx]);
181184
}
182185
}
183186
}
@@ -270,6 +273,20 @@ private static void Set<T>(ref List<T> list, T[] array)
270273
Reset<T>(ref list);
271274
list.AddRange(array);
272275
}
276+
277+
public void UnpackTriangleIdx(int src, out int submesh, out int localidx)
278+
{
279+
for (int i = m_MeshSubmeshCount; i --> 0;)
280+
{
281+
if (i > 0 && m_IndiceOffsets[i - 1] > src)
282+
continue;
283+
submesh = i;
284+
localidx = src - m_IndiceOffsets[i];
285+
return;
286+
}
287+
submesh = 0;
288+
localidx = src;
289+
}
273290
}
274291

275292
internal static class InternalMeshUtil

0 commit comments

Comments
 (0)