RuntimeLoader QML Type
在运行时导入一个 3D 资源。更多...
| Import Statement: | import QtQuick3D.AssetUtils |
| Since: | Qt 6.2 |
| Inherits: |
枚举
属性
- bounds : Bounds
- errorString : string
- instancing : Instancing
- source : url
- status : enumeration
方法
详细说明
RuntimeLoader 类型提供了一种在运行时直接从源文件加载 3D 资源的方法,无需先将其转换为QtQuick3D 的内部格式。
RuntimeLoader 支持 .obj 以及 glTF 2.0 版本的文件,包括文本格式(.gltf)和二进制格式(.glb)。
警告:RuntimeLoader 不会对资源内容进行沙箱隔离或验证。加载格式错误或不可信的资源可能会引发安全问题。详情请参阅source 。
枚举文档
QueryFilter
指定要查询的对象类型。
| 常量 | 描述 |
|---|---|
RuntimeLoader.Textures | 查询纹理对象 |
RuntimeLoader.Materials | 查询材质对象 |
RuntimeLoader.Nodes | 查询节点对象 |
RuntimeLoader.Cameras | 查询摄像机对象 |
RuntimeLoader.Lights | 查询光源对象 |
RuntimeLoader.Models | 查询模型对象 |
另请参阅 queryAll()。
属性文档
bounds : Bounds [read-only]
该属性描述了导入模型周围边界体积的范围。
注意: 在首次渲染之前,该 值可能不可用
errorString : string [read-only]
该属性包含一个易于理解的字符串,用于指示最新加载操作的状态。
instancing : Instancing
如果设置了此属性,导入的模型将不会按常规方式渲染。相反,系统将根据实例表中的定义渲染多个实例。
有关详细信息,请参阅“实例化渲染”概述文档。
source : url
该属性存储包含 3D 资源的源文件的位置。修改此属性将卸载当前资源,并尝试从给定的 URL 加载资源。
加载操作的成功或失败由status 指示。
警告: RuntimeLoader 不会对资源内容进行沙箱隔离或验证。加载格式错误或不可信的资源可能会引发安全问题。应用程序开发人员在允许加载不属于应用程序本身的用户提供的内容之前,应仔细考虑这些风险。
status : enumeration [read-only]
该属性保存了最近一次加载操作的状态。
| 常量 | 描述 |
|---|---|
RuntimeLoader.Empty | 未指定 URL。 |
RuntimeLoader.Success | 加载操作成功。 |
RuntimeLoader.Error | 加载操作失败。errorString 提供了可供人类阅读的错误消息。 |
方法文档
[since 6.12] Object3D query(string arg)
返回名称为给定名称的对象;如果不存在该名称的对象,则返回null 。
arg 参数是待查询对象的名称或查询字符串。例如,要查询名为“PaintMaterialX”的对象,请使用以下代码:
var object = runtimeLoader.query("PaintMaterial")假设源资源文件中的对象命名合理,上述代码将按预期运行。但是,如果存在多个同名对象,查询将返回第一个与给定名称匹配的对象。若要查询特定对象并避免歧义,请使用完整的对象路径。
var object = runtimeLoader.query("/House2/Wall001/Mirror/Material")注意:即使使用 路径, 如果源资源文件的结构不合理,仍 可能存在多个路径相同的对象,因为路径是由源资源文件中的对象名称构建而成的。
注意: 对象名称的 定义以源资源文件中的名称为准。
此方法于 Qt 6.12 中引入。
[since 6.12] List<Object3D> queryAll(QueryFilter filter)
返回一个包含所有符合给定筛选条件对象的列表。
filter 参数用于指定要查询的对象类型。例如,要查询所有材质,请使用以下代码:
var materials = runtimeLoader.queryAll(RuntimeLoader.Materials)上述代码将返回源资源文件中所有材质的一个列表。
此方法在 Qt 6.12 中引入。
© 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.