We have just improved our selection algorithm.
Before we did:
- project all the triangles on screen
- check for pickbox intersection with 2D triangles and for mutual vertex inside (pickbox vertex inside the triangle and triangle vertex inside the pickbox)
In perspective mode, triangles with a vertex behind the viewer got weird 2D coordinates invalidanting the complete selection operation.
- Get a 3D frustum composed by 6 planes
- Check first if the object bounding sphere intersects the frustum
- In case of intersection, loop over object’s triangles to check if the triangles sides cross the frustum
- If no intersection is found, check for ray-triangle intersection for all 4 frustum sides (near to far)
Speed. The new algorithm is accurate but slow. Intersection checks for triangles sides and furstum planes and ray-triangle intersections are slow processing a mesh of 50.000 triangles.
Is there any way to speed up the new algorithm?