# How selection triangle mesh of terrain?

Hello …
I’m new to jme3 and so far I’m amazed.
I am following the tutorials and are very clear …
now my question is - as I can select some triangles of the mesh of a terrain and then calculate its area?
Thank you

With a ray (see mousepicking example)
you should be albe to get the triangles,
with the triangles you can get their vertex positions, and then have the area in model space.

I can not find the way to get the triangles …

2 Likes

because it is indefinite use getTriangle within CollisionResults ?

``````    CollisionResults results = new CollisionResults();

Ray ray = new Ray(cam.getLocation(), cam.getDirection());

shootables.collideWith(ray, results);

for (int i = 0; i < results.size(); i++) {

//	int tt = results.getTriangleCount();

//	int j = results.getTriangleCount(i) ;

//results.getTriangle(i, l_vect1, l_vect2, l_vect3);

//System.out.println("index: " + i + ", v1: " + l_vect1 + ", v2: " + l_vect2 + ", v3: " + l_vect3);

//System.out.println("THE j: " + j);

float     dist = results.getCollision(i).getDistance();
Vector3f    pt = results.getCollision(i).getContactPoint();
String   party = results.getCollision(i).getGeometry().getName();
int        tri = results.getCollision(i).getTriangleIndex();

Triangle = results.getCollision(i).getTriangle( l_vect1, l_vect2, l_vect3);``````

Maybe there are some typos here… it should be

``````	   Triangle triangle = results.getCollision(i).getTriangle(null);
```

or

```
Triangle triangle=new Triangle()
results.getCollision(i).getTriangle(triangle);
`````````

thank…it is assumed that this is the triangle …

any suggestions of how to get the vertices?
thank

I’ll give you three guesses:

hi.
i used methods get # () to get the triangle, but do not quite understand because I change the vertex according to the shooting distance, and nearby triangle vertices have identical.

Triangle triangle=new Triangle();
results.getCollision(i).getTriangle(triangle).calculateNormal();
triangle.calculateNormal();
Vector3f vert1 = triangle.get1();
Vector3f vert2 =triangle.get2();
Vector3f vert3 =triangle.get3();