InstanceList QML Type
允许在 QML 中手动指定实例化。更多
Import Statement: | import QtQuick3D |
Inherits: |
属性
- instanceCount : int
(since 6.3)
- instances : List<QtQuick3D::InstanceListEntry>
详细说明
InstanceList 类型可以在 QML 中手动定义一个实例表。
下面的示例创建了一个有两个项的实例表:
InstanceList { id: manualInstancing instances: [ InstanceListEntry { position: Qt.vector3d(0, 0, -60) eulerRotation: Qt.vector3d(-10, 0, 30) color: "red" }, InstanceListEntry { position: Qt.vector3d(50, 10, 100) eulerRotation: Qt.vector3d(0, 180, 0) color: "green" } ] }
也可以通过向 InstanceList 添加子项来填充实例属性。下面的示例等同于前面的示例:
InstanceList { id: manualInstancing InstanceListEntry { position: Qt.vector3d(0, 0, -60) eulerRotation: Qt.vector3d(-10, 0, 30) color: "red" } InstanceListEntry { position: Qt.vector3d(50, 10, 100) eulerRotation: Qt.vector3d(0, 180, 0) color: "green" } }
每个InstanceListEntry 都是一个可以拥有属性绑定和动画的对象。这提供了极大的灵活性,但也会造成内存开销。因此,对于包含数千(或数百万)个实例的程序生成表,不建议使用 InstanceList。此外,对条目进行任何属性更改都会导致整个实例表重新计算并上载到 GPU。
另请参阅 RandomInstancing 和QQuick3DInstancing 。
属性文档
instanceCount : int |
此只读属性包含列表中实例的数量。
此属性在 Qt 6.3 中引入。
instances : List<QtQuick3D::InstanceListEntry> |
此属性包含实例定义列表。修改此列表或其任何元素都将导致实例表的更新。
© 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.