Skip to content

Commit 8426548

Browse files
authored
Merge pull request #4 from Riskjockey/modifications
2 parents cb2cc97 + 8b06bdf commit 8426548

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

Assets/Plugins/MeshDebugger/Editor/MeshDebugger.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,20 @@ private void DrawGUILabels()
351351
{
352352
case DebugTriangle.Index:
353353
EachIndice((i, j, vert) =>
354-
DrawLabel(vert, m_cpu.m_IndiceNormals[i][j], (j + m_cpu.m_IndiceOffsets[i]))
354+
DrawLabel(vert, m_cpu.GetIndexNormalsSafely(i, j), (j + m_cpu.m_IndiceOffsets[i]))
355355
);
356356
break;
357357
case DebugTriangle.Area:
358358
EachIndice((i, j, vert) =>
359359
{
360360
var area = m_cpu.m_IndiceAreas[i][j];
361-
DrawLabel(vert, m_cpu.m_IndiceNormals[i][j], area.ToString(area < 1 ? "0.00" : "0.0"));
361+
DrawLabel(vert, m_cpu.GetIndexNormalsSafely(i, j), area.ToString(area < 1 ? "0.00" : "0.0"));
362362
}
363363
);
364364
break;
365365
case DebugTriangle.Submesh:
366366
EachIndice((i, j, vert) =>
367-
DrawLabel(vert, m_cpu.m_IndiceNormals[i][j], i)
367+
DrawLabel(vert, m_cpu.GetIndexNormalsSafely(i, j), i)
368368
);
369369
break;
370370
}
@@ -373,12 +373,12 @@ private void DrawGUILabels()
373373
{
374374
case DebugVertice.Index:
375375
EachVert((i, vert) =>
376-
DrawLabel(vert, m_cpu.m_Normals[0][i], i)
376+
DrawLabel(vert, m_cpu.GetNormalSafely(0, i), i)
377377
);
378378
break;
379379
case DebugVertice.Shared:
380380
EachVert((i, vert) =>
381-
DrawLabel(vert, m_cpu.m_Normals[0][i], m_cpu.m_VertUsedCounts[i])
381+
DrawLabel(vert, m_cpu.GetNormalSafely(0, i), m_cpu.m_VertUsedCounts[i])
382382
);
383383
break;
384384
case DebugVertice.Duplicates:

Assets/Plugins/MeshDebugger/Editor/MeshInfo.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,38 @@ public void UnpackTriangleIdx(int src, out int submesh, out int localidx)
318318
submesh = 0;
319319
localidx = src;
320320
}
321+
322+
/// <summary>
323+
/// If normal data for the specified vertex does not exist then this method will return Vector3.zero
324+
/// rather than throwing an IndexOutOfRangeException
325+
/// </summary>
326+
/// <param name="i1"></param>
327+
/// <param name="i2"></param>
328+
/// <returns></returns>
329+
public Vector3 GetNormalSafely(int i1, int i2)
330+
{
331+
if (i2 < m_Normals[i1].Count)
332+
{
333+
return m_Normals[i1][i2];
334+
}
335+
return Vector3.zero;
336+
}
337+
338+
/// <summary>
339+
/// If normal data for the specified index does not exist then this method will return Vector3.zero
340+
/// rather than throwing an IndexOutOfRangeException
341+
/// </summary>
342+
/// <param name="i1"></param>
343+
/// <param name="i2"></param>
344+
/// <returns></returns>
345+
public Vector3 GetIndexNormalsSafely(int i1, int i2)
346+
{
347+
if (i2 < m_IndiceNormals[i1].Count)
348+
{
349+
return m_IndiceNormals[i1][i2];
350+
}
351+
return Vector3.zero;
352+
}
321353
}
322354

323355
internal static class InternalMeshUtil

0 commit comments

Comments
 (0)