本页内容

FileInstancing QML Type

允许从文件中读取实例表。更多...

Import Statement: import QtQuick3D
Since: Qt 6.2
Inherits:

Instancing

属性

详细说明

FileInstancing 类型允许从文件中读取实例表。

支持两种文件格式:XML 以及 Qt 专有的二进制格式。二进制文件格式的布局与上传到 GPU 的表布局相同,因此可以直接映射到内存中。实例化工具会将XML 转换为二进制格式。

以下是 XML 文件格式的示例:

<?xml version="1.0" encoding="UTF-8" ?>
<InstanceTable>
  <Instance position="0 200 0"  scale="0.75 0.75 0.75" custom="20 20" color="#ffcf7f"/>
  <Instance position="0 -100 0" scale="0.5 0.5 0.5" color="red"/>
  <Instance position="0 -200 0" eulerRotation="0 0 60" color="darkred" custom="10 40 0 0"/>
</InstanceTable>

为了确保有效,XML 文件必须包含顶级InstanceTable 元素。每个实例由InstanceTable 内的Instance 元素表示。未知元素将被无提示地忽略。

一个Instance 元素可以具有多个属性。color 属性通过常规的Qt SVG 颜色名称或十六进制表示法指定。vector3d 和{vector4d}属性通过空格分隔的数字字符串指定,其中缺失的尾部数字表示零。支持以下属性:

名称type
positionvector3d
scalevector3d
eulerRotationvector3d
quaternionvector4d
customvector4d
colorcolor

未知属性将被静默忽略。

属性文档

instanceCount : int [since 6.3]

此只读属性包含实例表中的实例数量。

该属性自 Qt 6.3 起引入。

source : url

该属性存储包含实例数据的 XML 或二进制文件的位置。

如果文件名带有“.bin”扩展名,则认为其指代二进制文件;否则,则认为其指代 XML 文件。如果指定了 XML 文件foo.xml,且文件foo.xml.bin存在,则将加载二进制文件foo.xml.bin代替。

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