How selection triangle mesh of terrain?

Hello …
My English is very bad…
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 …

https://javadoc.jmonkeyengine.org/com/jme3/collision/CollisionResult.html#getTriangle(com.jme3.math.Triangle)

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:
https://javadoc.jmonkeyengine.org/com/jme3/math/Triangle.html

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();

thank for your time…

? any help

The sting is 12 inches long? Or maybe 25 inches?

Actually, I’m not even sure what the sentence means so it’s impossible to tell what’s going on.

Identical what?

You get no answers because your question doesn’t provide enough information and doesn’t really make any sense. You will likely continue to get no answers until you correct it.

Make a simple test case. Explain what you are trying to do. Explain what the test case is actually doing. Then you might get help.