Jump to content

  • Log In with Google      Sign In   
  • Create Account


Determine Mesh Vertex Index Given Another Mesh Index


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 gretty   Members   -  Reputation: 211

Like
0Likes
Like

Posted 19 June 2014 - 11:51 PM

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, 20 June 2014 - 12:02 AM.


Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 3256

Like
0Likes
Like

Posted 20 June 2014 - 12:26 AM

uint aRow = A / nCols;    // 16 / 6 -> 2

uint aCol = A - (aRow * aCols);    // 16 - (2 * 6) -> 4






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS