AbstractRayCaster QML Type | Qt 3D 5.12.5

Qt 5.12 | Qt 3D | QML Types | AbstractRayCaster QML Type

Qt 5.12.5 Reference Documentation

# AbstractRayCaster QML Type

An abstract base class for ray casting in 3d scenes. More...

Import Statement: | import Qt3D.Render 2.12
Since: | Qt 5.11
Instantiates: | QAbstractRayCaster

- List of all members, including inherited members

## Properties

- filterMode : enumeration
- hits : array
- runMode : enumeration

## Detailed Description

AbstractRayCaster is an abstract base class for casting rays into a 3d scene. AbstractRayCaster can not be directly instantiated, but rather through its subclasses. QAbstractRayCaster specifies common properties for all ray casters, such as run mode and layer handling, while leaving the actual ray casting details to the subclasses.

Ray castings differs from picking (using ObjectPicker) in that it does not require mouse events to trigger.

By default, the instances of AbstractRayCaster are disabled. When enabled, the specified ray will be tested for intersecting objects at every frame. The AbstractRayCaster.hits property will be updated with the results of the ray casting, even if no objects are found.

The Qt3D.Render::PickingSettings can be used to control the ray casting, such as which primitives are tested and how the results are returned.

Furthermore, Qt3D.Render::Layer components can be used to control how entities, or entity sub-graphs, react to ray casting.

Note: components derived from AbstractRayCaster should not be shared amount multiple entities.

See also Qt3D.Render::RayCaster, Qt3D.Render::ScreenRayCaster, Qt3D.Render::ObjectPicker, and Qt3D.Render::PickingSettings.

## Property Documentation

filterMode : enumeration

Holds the filter mode specifying the entities to select for ray casting tests.

The default value is `AbstractRayCaster.AcceptMatchingLayers`.

Constant | Description
--- | ---
`AcceptAnyMatchingLayers` | Accept entities that reference one or more Layer objects added to this AbstractRayCaster. This is the default
`AcceptAllMatchingLayers` | Accept entities that reference all the Layer objects added to this AbstractRayCaster
`DiscardAnyMatchingLayers` | Discard entities that reference one or more Layer objects added to this AbstractRayCaster
`DiscardAllMatchingLayers` | Discard entities that reference all Layer objects added to this AbstractRayCaster

hits : array

Holds the results of last ray casting test as an array of javascript objects. The fields defined on the objects are defined below.

      {
          type // enum value of RayCasterHit.HitType
          entity // entity that was intersected
          distance // distance from ray origin to intersection
          localIntersection.x: // coordinate of intersection in the entity's coordinate system
          localIntersection.y
          localIntersection.z
          worldIntersection.x // coordinate of intersection in the model's coordinate system
          worldIntersection.y
          worldIntersection.z
          primitiveIndex // index of the primitive (triangle, line, point) that was intersected;
                         // (undefined if the picking mode is set to bounding volume)
          vertex1Index // index of the first point of the triangle or line that was intersected
                       // (undefined if the picking mode is set to bounding volume or points)
          vertex2Index // index of the second point of the triangle or line that was intersected
                       // (undefined if the picking mode is set to bounding volume or points)
          vertex3Index // index of the second point of the triangle that was intersected
                       // (undefined if the picking mode is set to bounding volume, points or lines)
      }

Note that even if successive tests return the exact same results (or empty results), a change notification will be emitted at every test.

runMode : enumeration

Holds the run mode controlling how often ray casting tests are performed.

Constant | Description
--- | ---
`Continuous` | Ray casting is performed at every frame as long as the component is enabled.
`SingleShot` | Ray casting is done once then the component disables itself. This is the default