Qt Quick 3D - 原则素材示例
演示如何使用 "原理材质"。
此示例可作为PrincipledMaterial 的交互式使用文档。PrincipledMaterial 的每个属性都附有使用说明,以及调整每个属性的实验方法。
使用方法
本示例分为两个视图,左侧为交互式文档和控件,右侧为 3D 查看器。3D 查看器是交互式的,允许摄像机围绕目标模型旋转。要重新设置特定模型的焦点,只需触摸或点击要聚焦的模型即可。两个视图之间的分割可通过在视图之间拖动条来调整大小。
该示例分为多个部分,将PrincipledMaterial 的各种功能分成易于管理的小块。点击解释区域顶部的选项卡可访问每个部分。
镜面光泽材料
除了演示PrincipledMaterial 提供的金属/粗糙度 PBR 工作流程外,还可以切换到使用SpecularGlossyMaterial 的镜面/光泽工作流程。这可以通过在基础部分进行切换来实现。
资源加载器
本例的复杂性也为演示ResourceLoader 组件的使用提供了机会。当一个模型在场景中不再可见时,与该模型相关的任何资源都将被Qt Quick 3D 释放(假设这些资源没有被场景中的其他模型使用)。在本例中,可以隐藏窗帘模型,这样就可以从 GPU 内存中释放 2 个网格和 2 个纹理。不过,当下次让窗帘可见时,这些资源就需要重新上传到 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 的可见性如何,其资源都将得到保留。
ResouceLoaded 也可用于预载资源,如 "特殊 "选项卡下的点网格和线网格所示。
ResourceLoader { meshSources: [ "meshes/logo_lines.mesh", "meshes/logo_points.mesh" ] }
这里直接列出了网格文件的QUrl's。ResourceLoader 使用的资源不必与模型关联。
© 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.