Scene2D QML Type

该类型可将 qml 渲染成纹理,然后用作 3D 场景的一部分。更多

Import Statement: import QtQuick.Scene2D 2.9
In C++: QScene2D
Status: Deprecated

属性

详细说明

该对象使用 RenderControl 将给定的 Item 渲染至屏幕外的表面,该表面与用户提供的纹理相连。这样,组件就可以直接渲染到纹理中,而无需中间复制,用户也可以自由指定纹理在三维场景中的使用方式。

使用 Scene2D 的实体可与该类型相关联,以实现与项目的交互;如果实体具有ObjectPicker 组件,则该拾取器的拾取事件会发送到 Scene2D,并转换为鼠标事件,最后发送到项目。

注意: 只支持鼠标事件。项目不支持键盘输入。

使用方法

Entity {
    id: sceneRoot

    // specify Scene2D inside the entity hierarchy
    Scene2D {
        // specify output
        output: RenderTargetOutput {
            attachmentPoint: RenderTargetOutput.Color0
            texture: Texture2D {
                id: textureId
                width: 1024
                height: 1024
                format: Texture.RGBA8_UNorm
            }
        }
        // specify entities
        entities: [entityId]

        // specify rendered content
        Rectangle {
            color: "red"
        }
    }

    Entity {
        id: entityId

        property Material material: TextureMaterial {
            texture: textureId
        }
        property ObjectPicker picker: ObjectPicker {
            hoverEnabled: true
            dragEnabled: true
        }
        ...

属性文档

entities : list<Entity>

保存与Scene2D 对象相关联的实体列表。如果实体有ObjectPicker ,则该实体的拾取事件将发送到Scene2D 并转换为鼠标事件。


item : Item

保存通过Scene2D 渲染到纹理的项目。


mouseEnabled : bool

显示渲染后的项目是否启用了鼠标事件。鼠标事件由添加到Scene2D 的实体的对象拾取事件生成。默认情况下鼠标事件已启用。

注: 由于后端正在进行对象拾取,发送到项目的事件会延迟一帧。


持有RenderTargetOutput ,它指定了Scene2D 的渲染位置。


renderPolicy : enumeration

持有该Scene2D 的呈现策略。

  • Continuous(连续)Scene2D 正在连续呈现。这是默认的呈现策略。
  • SingleShot(单次渲染)Scene2D 只渲染一次纹理,之后分配用于渲染的资源将被释放。

© 2025 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.