Sign in to follow this  
gretty

Unity Determine Mesh Vertex Index Given Another Mesh Index

Recommended Posts

Hello

 

Please bare with me as I explain what I am trying to accomplish tongue.png

 

Each 'X' below represents a mesh vertex:

 

 

X---X---X---X---X---X

|      |      |     |     |      |

X---X---X---X---X---X

|      |      |     |     |      |

X---X---X---X---X---X

|      |      |     |     |      |

X---X---X---X---X---X

 

For my Unity3d GameObject (G1); the mesh vertices are stored in a C# List<Vector3> object in the following order. *Note the mesh index 'A'. This is a value I know - in this case A=16 (mesh index 16).

 

0---1---2---3---4---5

|      |      |     |     |      |

6---7---8---9--10--11

|      |      |     |     |      |

X---X---X---X---A---X

|      |      |     |     |      |

X---X---X---X---X---N

 

 

I have another GameObject (G2) whose shape is the same (a simple rectangle) but the mesh vertices are ordered differently.*Note the mesh index 'B'. This is a value I dont know and I want to find this value (mesh index) - in this case B=17 (mesh index 17).

 

3---7---11--X---X---N

|      |      |     |     |      |

2---6---10--X---X---X

|      |      |     |     |      |

1---5---9---X---B---X

|      |      |     |     |      |

0---4---8---X---X---X

 

 

As you can see the mesh arrangement is pretty much the same except rotated 90 degrees. If I know the 'mesh vertex index' of A how can I find the 'mesh vertex index' of B?

 

Whats an algorithm that can calculate the mesh index of B? My attempt is not working at all:

uint A     = 16;
uint nCols = 6;
uint nRows = 4;

// Technically both B and A sit on Row 3, Column 5 so if I can find A's row and column maybe I am there?
uint aCol = 16 / nCols;        // nup not right
uint aRow = (16 % nCols) - 1;  // gives 3

// Once I've calculated aCol and aRow its easy
uint B    = (aRow * nRows) + aCol;  // ie, (3 * 4) + 5 = 17
Edited by gretty

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this