Qt Quick 3D 物理烹饪

将网格用作碰撞形状时,需要对其进行处理并转换为数据格式,以便高效地进行碰撞检测。这被称为 "烹饪"。有三种形状类型在使用前需要烹饪,即ConvexMeshShapeTriangleMeshShapeHeightFieldShape 。使用这些形状时,烹饪会在模拟的第一帧自动进行。这种烹调会产生明显的性能代价,因此为了加快加载时间,可以预先烹调网格并直接加载。有两种方法可以做到这一点,即使用缓存目录或烹饪工具。

缓存目录

要使用缓存目录,请将QT_PHYSICS_CACHE_PATH 环境变量设置为所选目录。程序首次运行时,所有使用过的网格都将被烹饪并存储在此目录中。以后程序运行时,将从磁盘读取熟化的网格而不是熟化。

制图工具

另一种方法是使用cooker 工具。先创建该工具,然后以网格或高度场图像作为输入参数调用该工具即可:

cooker input.mesh

cooker input.png

如果输入的是网格,它将生成两个文件:

  • input.cooked.tri
  • input.cooked.cvx

一个文件是熟化的三角形网格,另一个是熟化的凸形网格。这两个文件可以简单地用作TriangleMeshShape::sourceConvexMeshShape::source 的源文件,无需进行任何处理即可加载网格。同样,如果输入是图像文件,则会生成一个名为input.cooked.hf 的高度场,然后可以通过在HeightFieldShape::source 属性中引用该高度场来加载。

© 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.