Qt Quick 3D - 基于原则的材质示例
演示了“基于原理的材质”的使用方法。

本示例作为PrincipledMaterial 使用方法的交互式文档。PrincipledMaterial 的每个属性都附有使用说明,并提供了一种通过调整各属性进行实验的方法。
用法
本示例分为两个视图:左侧为交互式文档和控制面板,右侧为 3D 查看器。 3D 查看器具有交互性,允许相机围绕目标模型进行旋转。要将焦点重置到特定模型上,只需点击或单击该模型即可。通过拖动两个视图之间的分割条,可以调整两个视图之间的比例。
本示例分为多个部分,将PrincipledMaterial 的各项功能分组为易于管理的模块。点击说明区域顶部的标签页即可访问各部分。
SpecularGlossyMaterial
除了演示PrincipledMaterial 提供的金属度/粗糙度PBR工作流程外,还可以切换至使用SpecularGlossyMaterial 的镜面/光泽工作流程。此操作可在“基础”部分通过切换按钮完成。
资源加载器
本示例的复杂性也为演示ResourceLoader 组件的使用提供了机会。当模型在场景中不再可见时,Qt Quick 3D 将释放与该模型关联的所有资源(前提是场景中其他模型未使用这些资源)。 在此示例中,可以隐藏窗帘模型,这样一来,2 个网格和 2 张纹理将被从 GPU 内存中释放。 不过,下次将窗帘设为可见时,这些资源需要重新上传到 GPU。在某些硬件上,此上传过程可能会导致帧率短暂下降,因此为了缓解这一问题,在 BackgroundCurtain 组件内部使用了ResourceLoader 组件。
ResourceLoader {
meshSources: [
frame.source,
curtain.source
]
textures: [
tilePatternTexture,
curtainNormalTexture
]
}
Model {
id: frame
z: -1.95
source: "meshes/frame.mesh"
PrincipledMaterial {
id: frame_material
baseColor: "#ffcccccc"
metalness: 1
roughness: 0.259091
alphaMode: PrincipledMaterial.Opaque
}
materials: [
frame_material
]
}
Model {
id: curtain
y: 3.02413
z: 2.04922
source: "meshes/curtain.mesh"
PrincipledMaterial {
id: curtain_material
baseColorMap: Texture {
id: tilePatternTexture
source: "maps/tilepattern.png"
generateMipmaps: true
mipFilter: Texture.Linear
}
opacityChannel: Material.A
roughness: 0.5
normalMap: Texture {
id: curtainNormalTexture
source: "maps/curtain_normal.jpg"
generateMipmaps: true
mipFilter: Texture.Linear
}
cullMode: Material.NoCulling
alphaMode: PrincipledMaterial.Opaque
}
materials: [
curtain_material
]
}在此,网格文件和纹理均通过ResourceLoader 进行了注册。ResourceLoader 可确保所有已注册的资源始终在GPU内存中处于可用状态,因此无论BackgroundCurtain是否可见,其资源都将被保留。
ResourceLoaded 还可以用于预加载资源,如“Special”选项卡下的点和线网格所示。
ResourceLoader {
meshSources: [
"meshes/logo_lines.mesh",
"meshes/logo_points.mesh"
]
}此处直接列出了网格文件的QUrl 。资源无需与Model关联,即可被ResourceLoader 使用。
© 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.