- Qt 6.8
- Qt Quick 3D Physics
- Qt Quick 3D Physics Cooking
- Qt Quick 3D Physics | Commercial or GPLv3

# Qt Quick 3D Physics Cooking

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.

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

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