本页内容

AbstractRayCaster QML Type

用于3D场景中光线投射的抽象基类。更多...

Import Statement: import Qt3D.Render 2.12
In C++: QAbstractRayCaster
Status: Deprecated

此类型已弃用。我们强烈建议不要在新的代码中使用它。

属性

详细说明

AbstractRayCaster 是一个用于向 3D 场景中投射光线的抽象基类。 AbstractRayCaster 无法直接实例化,而必须通过其子类进行实例化。QAbstractRayCaster 规定了所有射线投射器的通用属性,例如运行模式和图层处理,而将实际的射线投射细节留给子类处理。

光线投射与拾取(使用ObjectPicker )的不同之处在于,它不需要鼠标事件来触发。

默认情况下,AbstractRayCaster 的实例处于禁用状态。启用后,系统将在每一帧对指定的光线进行测试,以检查是否与物体相交。即使未找到任何物体,AbstractRayCaster.hits 属性也会根据光线投射的结果进行更新。

可通过 Qt3D.Render::PickingSettings 控制光线投射,例如指定测试哪些基元以及结果的返回方式。

此外,还可以使用 Qt3D.Render::Layer 组件来控制实体或实体子图对光线投射的响应方式。

注意:从 AbstractRayCaster 派生的组件不应在多个实体之间共享。

另请参阅 Qt3D.Render::RayCaster 、Qt3D.Render::ScreenRayCaster 、Qt3D.Render::ObjectPicker 、Qt3D.Render::PickingSettings 以及Qt3D.Render::NoPicking 。

属性文档

filterMode : enumeration

存储用于指定在射线投射测试中要选择的实体的过滤模式。

默认值为AbstractRayCaster.AcceptMatchingLayers 。

常量描述
AcceptAnyMatchingLayers接受引用一个或多个已添加到此“AbstractRayCaster ”中的“Layer ”对象的实体。这是默认值
AcceptAllMatchingLayers接受引用已添加到此 中的所有Layer 对象的实体。这是默认值AbstractRayCaster
DiscardAnyMatchingLayers丢弃引用添加到此 中的一个或多个Layer 对象的实体简体中文(大陆)AbstractRayCaster
DiscardAllMatchingLayers丢弃引用了添加到此中的所有Layer 对象的实体AbstractRayCaster

hits : array [read-only]

将上次光线投射测试的结果作为 JavaScript 对象数组保存。这些对象上定义的字段如下所示。

{
    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)
}

请注意,即使连续的测试返回完全相同的结果(或空结果),每次测试都会触发一次变更通知。

runMode : enumeration

用于设置运行模式,控制光线投射测试的执行频率。

常量描述
Continuous只要该组件处于启用状态,就会在每一帧执行光线投射。
SingleShot仅执行一次光线投射,随后该组件会自动禁用。这是默认设置。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.