[QML] QML performance optimization | 3D scene optimization


Using QML for 3D application development, optimizing 3D scenes and optimizing design will have a significant performance impact on 3D applications. This article describes several rules and methods for optimizing 3D scenes. Most of the content and opinions in this article are referred to official documents, and combined with their own actual use.

1. Four 3D scene design methods

There are many different ways to create and combine 3D scenes. For example: Advanced Scene, Low Level Scene, Mixed Scene, and Vertex Color Scene. Advanced scenes contain more objects than other versions of the scene. Low-Level, Hybrid and Vertex scenes contain relatively fewer objects because they have been optimized by incorporating geometry and baked materials into textures. The following figure shows the components in each scene in the Navigator view, which is used to compare and illustrate the structural differences between scenes:

(1-1) Low-level scene


As shown in the image above, the low-level scene contains a total of 12 objects. Each model (such as cabinets, lamps, plates and sinks) is a separate mesh.

(1-2) Advanced scenarios


As shown in the image above, the tall scene contains a total of 27 objects. This scene is otherwise similar to the low-level scene, but with more details and animated components (such as openable cabinet doors and oven latches)

(1-2) Mixed scene

A hybrid scene combines all meshes into a single object, with all materials baked into a single texture.

(1-3) Vertex color scene

The scene combines all the meshes into a single object, the color of the mesh .meshis described by the vertex data of the file, which includes materials, no textures.

In this section, the four scenes of high-level scene, low-level scene, mixed scene and Vertex color scene are essentially a method of organizing 3D scenes. In advanced scenes, there are a lot of 3D objects. Why do you need to include so many 3D objects? In most cases, it is to separate small objects for 动画效果summing 动画控制. If there is no animation requirement in a scene, the method of mixing scenes and Vertex color scenes can be used to design 3D scenes, which also improves the application rendering performance.

2. 3D scene optimization rules

In order to optimize the graphics rendering performance of the 3D scene, you should first consider whether you need to add animation to the 3D objects, lights, cameras or components in the scene, if not, simplify the scene structure as much as possible, for example: you can combine geometry and baking materials into the texture. Ideally, pre-rendering 3D images into 2D images is fine. Check the scene for multiple instances of the same mesh, and if so, import only one instance of the mesh, then duplicate it in the scene, and use the same material for each copy.

(2-1)Scene Graph

In Qt Design Studio, the scene graph is represented by a tree view Navigatorin . At the same time, we can also view the node hierarchy in the Code view. By minimizing the scene graph, you can reduce the work required to run the scene. Because deep hierarchical nesting with complex functions will increase the performance cost, in order to optimize the scene graph, unnecessary groups and complex hierarchies should be avoided as much as possible.

(2-2) Resource file optimization

Reduce the use and loading of resource files as much as possible to improve rendering performance (in the actual 3D application development process, due to various factors, there are often a lot of resource files in the design process. The general practice is: optimize resource files while developing) .

When designing a 3D material model, try to use as few triangles or vertices as possible to achieve the desired modeling effect . Because when rendering 3D scenes, fewer graphics can reduce memory requirements and help fast rendering.

(2-3) CPU performance optimization

Displaying 3D objects requires a lot of CPU or GPU processing. Processing each 3D component consumes resources, so reducing the number of visible objects reduces CPU workload. The optimization suggestions are as follows:

(1) Merge objects that are adjacent and share textures.

Note: Merging objects that do not share textures will not improve CPU performance when running the scene.

(2) Combine different textures into one texture atlas to reduce material usage.

(3) Avoid rendering objects multiple times.

(2-4) Optimizing the geometry of the model

(1) Reduce the number of triangles used in the model.

(2) Reduce the number of UV-mapped seams and hard edges created with doubled vertices.

3. Summary

The following table summarizes best practices related to optimizing 3D scenes:

serial number 3D behavior best practice advice
1 Get the best performance out of 3D scenes If animation is not required, the 3D scene can be pre-rendered into a 2D image.
2 Animation of objects in the scene All static objects are merged and only one of each animated component is exported.
3 camera animation While using 2D images is not advisable in this case, all geometry, baked lighting and materials should be combined into a single material
4 lighting animation The optimization method is the same as "camera animation"
5 Best performance in mesh-separated 3D scenes Use the same material for every instance of the same mesh
6 Disable mesh rendering at runtime Keep specific meshes separate and incorporate other components.
7 Use low-memory baked textures Bake mesh colors into vertex colors

For modern software, 3D development is a more advanced development (except for games, haha). The basic components of 3D development provided by Qt Quick are also very powerful. Higher versions of Qt have optimized 3D performance more, and 3D Development, as one of Quick's future development directions, has also received a lot of official optimization and maintenance.

The following is a demo of the vehicle central control terminal software provided by the official, which incorporates 3D elements into the software, which is intuitive and cool.

Qt3D scene-vehicle terminal-demo effect

Guess you like

Origin blog.csdn.net/iriczhao/article/details/126897637