Hi, this is the way I use to get it:
First, using reflection, I get the PropertyInfo of the “Index" property. Then you get the value of that PropertyInfo referring to the vertex you want.
A few notes: This property isn’t available in the APi because it changes every time the surface is built or changed, so you need to be careful about that and prevent any changes to the surface while your code is running using the vertices indexes.
Also, beware that the vertices’ “Index”, which is an integer, may or may not be fully consecutive. I found this the hard way, trying to find a bug…
Here’s the code I’m using:
''' <summary>
''' Returns the PropertyInfo to use in GetIndex Extension Function (using reflection).
''' </summary>
''' <param name="vertex">The instance to which the method applies.</param>
''' <returns>The PropertyInfo corresponding to the Vertex Index.</returns>
<System.Runtime.CompilerServices.Extension()>
Public Function GetIndexPropertyInfo(vertex As TinSurfaceVertex) As PropertyInfo
Dim arrayPropertyInfo() As PropertyInfo = vertex.GetType().GetProperties(BindingFlags.NonPublic Or BindingFlags.Instance)
For Each prop As PropertyInfo In arrayPropertyInfo
If prop.Name.Equals("Index") Then
Return prop
End If
Next
Return Nothing
End Function
''' <summary>
''' Returns the vertex index in the surface (using reflection).
''' </summary>
''' <param name="vertex">The instance to which the method applies.</param>
''' <param name="IndexPropertyInfo">The PropertyInfo corresponding to the Vertex Index.</param>
''' <returns>The corresponding index.</returns>
<System.Runtime.CompilerServices.Extension()>
Public Function GetIndex(vertex As TinSurfaceVertex, IndexPropertyInfo As PropertyInfo) As Integer
Return IndexPropertyInfo.GetValue(vertex)
End Function
'SAMPLE USAGE
'get propertyinfo through reflection to gain access to the property index
Dim propIndex As Reflection.PropertyInfo = SourceVertex.GetIndexPropertyInfo
' If we can't get propertyinfo then we can't find the index of the Vertex
If propIndex.IsNull Then
Throw New Exception("TinSurfaceVertex Index PropertyInfo not found.")
End If
'get the indexes of the surface's vertices
For Each vertex As TinSurfaceVertex In Surface.Vertices
Dim index As Integer = vertex.GetIndex(propIndex)
Next