Class RayPickSystem
java.lang.Object
com.marginallyclever.ro3.raypicking.RayPickSystem
RayPickSystem
is for finding the MeshInstance
s that collide with a Ray
. This is used for
ray picking and path tracing.
For path tracing, it is important to optimize the ray/mesh intersection tests as much as possible. This is done
by transforming each mesh into world space in a PathMesh
. For ray picking, the optimization is less
important, so the meshes are tested in their local space.
To use the RayPickSystem
, create an instance, call reset(optimize)
, and then
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindRayIntersections
(Ray ray) Traverse the scene and find all theMeshInstance
s that collide with the ray.getFirstHit
(Ray ray) Traverse the scene and find the nearestMeshInstance
that collides with the ray.static Material
getMaterial
(Node meshInstance) Find the nearestMaterial
in the scene graph, starting from the givenMeshInstance
.Guaranteed to return one valid result if there is at least one emissive triangle in the scene.void
reset
(boolean optimize) Reset the system and rebuild the list of scene elements.
-
Constructor Details
-
RayPickSystem
public RayPickSystem()
-
-
Method Details
-
reset
public void reset(boolean optimize) Reset the system and rebuild the list of scene elements. This should be called whenever the scene graph changes.- Parameters:
optimize
- true if extra steps should be taken to optimize, typically for path tracing. If false, the system will do less work and use less memory, but ray/mesh intersection tests will be slower.
-
getMaterial
Find the nearestMaterial
in the scene graph, starting from the givenMeshInstance
. The nearest material is the first one found in the given mesh instance or its parents.- Parameters:
meshInstance
- the mesh instance to start searching from.- Returns:
- the nearest
Material
, or null if none is found.
-
getFirstHit
Traverse the scene and find the nearestMeshInstance
that collides with the ray. This computes all intersections and then sorts them by distance, so it is a good idea to keep the ray length short.- Parameters:
ray
- the ray to test.- Returns:
- the nearest
Hit
by the ray, or null if no entity was hit.
-
findRayIntersections
Traverse the scene and find all theMeshInstance
s that collide with the ray.- Parameters:
ray
- the ray to test.- Returns:
- all
Hit
by the ray, sorted by distance.
-
getRandomEmissiveSurface
-