Qt Quick 3D Physics Cooking
Qt Quick 3D物理烘培
When using a mesh as a collision shape it needs to be processed and converted into a data format for efficient collision detection. This is referred to as 'cooking'. There are three shape types that need to be cooked before they can be used, namely ConvexMeshShape, TriangleMeshShape and HeightFieldShape. The cooking happens automatically on the first frame of the simulation when using any of these shapes. This cooking can incur a noticeable performance cost so to enable faster loading times it is possible to precook the meshes and load them directly. There are two ways to do this, namely using a cache directory or the cooker tool.
当使用网格作为碰撞形状时,需要对其进行处理并转换为数据格式,以实现高效的碰撞检测。这被称为“cooking”。有三种形状类型需要烘培才能使用,即凸网格形状、三角形网格形状和高场形状。当使用这些形状中的任何一个时,烘培会在模拟的第一帧自动发生。这种烘培可能会产生明显的性能成本,因此为了实现更快的加载时间,可以对网格进行预处理并直接加载。有两种方法可以做到这一点,即使用缓存目录或烘培工具。
Cache directory
缓存目录
To use the cache directory set the QT_PHYSICS_CACHE_PATH
environment variable to a directory of choice. When the application runs for the first time all used meshes will be cooked and stored in this directory. The following times the application runs, the cooked meshes will be read from disk instead of being cooked.
要使用缓存目录,请将QT_PHYSICS_CACHE_PATH
环境变量设置为所选目录。当应用程序首次运行时,所有使用过的网格都将被烘培并存储在此目录中。在应用程序运行的以下时间,将从磁盘读取已烹饪的网格,而不是对其进行烘培。
Cooker tool
烘培工具
The other way is to use the cooker
tool. Build it, then simply call the tool with the mesh or heightfield image as the input argument:
另一种方法是使用烘培工具。构建它,然后简单地使用网格或高度场图像作为输入参数调用该工具:
cooker input.mesh
or
cooker input.png
If the input is a mesh it will generate two files:
如果输入是网格,它将生成两个文件:
input.cooked.tri
input.cooked.cvx
One file is a cooked triangle mesh and the other a cooked convex mesh. These can then simply be used as the sources of TriangleMeshShape::source and ConvexMeshShape::source and the meshes will be loaded without any need for cooking. Similiarily, if the input is an image file a heightfield is generated called input.cooked.hf
which can then be loaded by referencing it in the HeightFieldShape::source property.
一个文件是烘培的三角形网格,另一个是煮熟的凸形网格。然后,这些可以简单地用作TriangleMassShape::source和ConverxMeshShape:source的源,网格将被加载,而不需要任何烘培。类似地,如果输入是一个图像文件,则会生成一个名为input.cooked.hf的高度字段,然后可以通过在HeightFieldShape::source属性中引用它来加载它。
UnitsAPI Changes from Tech Preview
© 2024 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.