Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtquick3dphysics-cooking.qdoc
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtquick3dphysics-cooking.html
6\title Qt Quick 3D Physics Cooking
7\brief An explanation of how Qt Quick 3D Physics handles meshes and cooking.
8
9When using a mesh as a collision shape it needs to be processed and converted into a data format for efficient collision detection.
10This is referred to as 'cooking'.
11There are three shape types that need to be cooked before they can be used, namely ConvexMeshShape, TriangleMeshShape and HeightFieldShape.
12The cooking happens automatically on the first frame of the simulation when using any of these shapes.
13This cooking can incur a noticeable performance cost so to enable faster loading times it is possible to precook the meshes and load them directly.
14There are two ways to do this, namely using a cache directory or the cooker tool.
15
16\section1 Cache directory
17
18To use the cache directory set the \c QT_PHYSICS_CACHE_PATH environment variable to a directory of choice.
19When the application runs for the first time all used meshes will be cooked and stored in this directory.
20The following times the application runs, the cooked meshes will be read from disk instead of being cooked.
21
22\warning The cache directory's files are not validated before being loaded. Loading a malformed
23or untrusted cache file may have security implications. Application developers should carefully
24consider these before pointing \c QT_PHYSICS_CACHE_PATH at a directory that is writable by other
25users or processes.
26
27\section1 Cooker tool
28
29The other way is to use the \c cooker tool. Build it, then simply call the tool with the mesh or heightfield image as the input argument:
30\code
31cooker input.mesh
32\endcode
33or
34\code
35cooker input.png
36\endcode
37
38If the input is a mesh it will generate two files:
39\list
40 \li \c input.cooked.tri
41 \li \c input.cooked.cvx
42\endlist
43
44One file is a cooked triangle mesh and the other a cooked convex mesh.
45These 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.
46Similiarily, if the input is an image file a heightfield is generated called \c input.cooked.hf which can then be loaded by referencing it in the HeightFieldShape::source property.
47
48
49*/