Qt Quick 3D物理检测过程

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

​当使用网格作为碰撞形状时,需要对其进行处理并转换为数据格式,以便有效地进行碰撞检测。这被称为“烹饪”。有三种形状类型需要烹饪才能使用,即凸面网格形状、三角形网格形状和高度场形状。使用这些形状时,烹饪会在模拟的第一帧自动进行。这种烹饪可能会产生显著的性能成本,因此为了加快加载时间,可以预煮网格并直接加载网格。有两种方法可以做到这一点,即使用缓存目录或炊具工具。

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:

另一种方法是使用烹饪工具。构建它,然后只需使用网格或heightfield图像作为输入参数调用该工具:

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::meshSource and ConvexMeshShape::meshSource 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::heightMap property.

​一个文件是已烹饪的三角形网格,另一个是已烹饪的凸面网格。然后,这些网格可以简单地用作TriangleMeshShape::meshSource和ConvexMeshShape::meshResource的源,网格将被加载,而无需任何烹饪。类似地,如果输入是一个图像文件,则会生成一个称为input.cooked.hf的高度字段文件。然后可以通过在HeightFieldShape::heightMap属性中引用它来加载。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值