# Triangles, a lot of questions about them

First of all I hope I posted this under the right topic as I ran into these question while working on graphics but I’m not quite sure it belongs here. Anywho…

Triangles, a lot of question about them, and to be clear, I don’t mean the literal triangle class, though that may be used to answer my question. I’m going to be asking about the triangle polys within a mesh. So a mesh’s data-structure is a one dimensional array that lists all the polys in the mesh, each poly taking up 3 slots in that array at a time. This is assuming you don’t share any elements between the polys, aka the polys are completely Independent of each other, which is the system I use out of necessity. All of my following questions are about finding the indexes of particular polys within that array.

1.) Is there a method for returning all the indexes of all the polys within a given volume, say a cube or a cone? And that is without searching through the entire mesh’s array. I know this could be achieved by doing so but it’d also be potentially scanning though a very large amount of data…

2.) Is there a method for returning all the indexes of all the polys adjacent to a given poly, aka it returns the indexes of all polys that share a side with a particular poly. Again I thought up a way to do this but it requires creating another entire data-structure in addition to the mesh and I was just wondering if the engine comes with a method already available to do this. No point in reinventing the wheel after all.

3.) Is there a method for taking a particular poly in a mesh and finding out if it collides or intersects with any other poly from that mesh or possibly any poly from another mesh, and if so return the indexes of all the polys it intersects? This one has me scratching my head. Also, if you can obtain these polys, can you obtain extra data about the intersection, for example can you get the two endpoints that would define the line of intersection?

Thank you for your time ^.^

magister said:
1.) Is there a method for returning all the indexes of all the polys within a given volume, say a cube or a cone? And that is without searching through the entire mesh's array. I know this could be achieved by doing so but it'd also be potentially scanning though a very large amount of data...

I think Mesh.getIndexBuffer() is what you're looking for. For triangle meshes, it will give you 3 indices per triangle which are the indices for each vertex.

magister said:
2.) Is there a method for returning all the indexes of all the polys adjacent to a given poly, aka it returns the indexes of all polys that share a side with a particular poly. Again I thought up a way to do this but it requires creating another entire data-structure in addition to the mesh and I was just wondering if the engine comes with a method already available to do this. No point in reinventing the wheel after all.

No. You will probably need to use the data structure, which I presume is a HashMap where the key is the vertex position and the value is the adjacent triangles.

magister said:
3.) Is there a method for taking a particular poly in a mesh and finding out if it collides or intersects with any other poly from that mesh or possibly any poly from another mesh, and if so return the indexes of all the polys it intersects? This one has me scratching my head. Also, if you can obtain these polys, can you obtain extra data about the intersection, for example can you get the two endpoints that would define the line of intersection?

In jME2 there was a complex algorithm for finding all triangle collisions between two meshes. Because the operation is so expensive, we decided not to include it in jME3.
1 Like

Thank you for the response ^.^

1.) I shall look into this method. Thank you.

2.) No such thing huh? : ( I guess my data structure would be a hash map of sorts. The idea was each vertex would store a list of the indexes of all the polys it is used in. You could then search the lists of the 3 vertices of a given poly for any duplicate indexes, thus giving you a poly that shares 2 vertices with the first poly and therefore is adjacent to it. Hmm implementing ‘sets’ would be perfect for this.

3.) Removing a feature?!?! BLEH!!! Step in the wrong direction. I kid though, I understand the reasoning behind it. Well, given the sheer complication that such an algorithm would pose I’ll be changing my approach to no longer need this operation anyway. Hopefully it’ll still work XD