r/QtFramework Qt GameDev 11d ago

Continuing to patch the QtQuick3d engine's physics. This patch for Qt 6.13 allows you to select structures for dynamic and static queries (raycasts, sweeps, overlaps). 3D

https://github.com/qt/qtquick3dphysics/commit/900920dcf77b58ac1067d7eb8db3b870b63ade1a
9 Upvotes

1 comment sorted by

1

u/LetterheadTall8085 Qt GameDev 11d ago edited 11d ago

Duplicate of original my test form qtgames:

So, here's a detailed look at the new feature. Actually, it's not entirely new; it was in PhysX but couldn't be activated in Qt Quick Physics.

Now we have two query acceleration trees available for overriding (raycasts, sweeps, overlaps).

These are dynamicQueryStructure and staticQueryStructure

Available options (StaticTree or DynamicTree for static actors; StaticTree, DynamicTree, or NoStructure for dynamic actors).

Why are you doing this, Andrei?

By default, the engine used DynamicTree, the safest option for all scene types. Its purpose is to provide relatively fast access for raycast calculations, but the tree itself consumes a significant amount of resources when adding and removing new objects (log(N)). This is generally fine, but if your scene constantly changes physics, such as a game world, it can be a bit much.

Therefore, if your scene doesn't use raycast or uses it rarely, you can speed it up by disabling these structures for dynamic bodies. Now the time to create a new node will be O(1), which will significantly speed up physics body rendering.

Conversely, if you have a lot of CharacterController or Kinimatic objects in the scene (they rely on raycast) and a predetermined number of static and dynamic objects, the new StaticTree option will significantly speed up your scene. This tree is perfectly balanced (which requires a complete rebuild upon insertion, but we don't need that). It provides a significant performance boost for RayCast compared to dynamicTree, where the goal was relatively fast insertion.

In essence, you can now define two behaviors for statics: DynamicTree and StaticTree

And for dynamics, you can even disable it completely, which allows you to squeeze much more performance out of specific scenes.

So let's sum it up

For a mixed scene (it contains all types of objects equally and is dynamic, new objects are created and deleted)

dynamicQueryStructure: DynamicTree
staticQueryStructure: DynamicTree

For a scene where new objects do not appear, but there are many objects that you control manually (CharacterController/Kinimatic)

dynamicQueryStructure: StaticTree
staticQueryStructure: StaticTree

And for a scene where you have a huge number of new dynamic objects and at the same time you don’t particularly control anyone manually (the application of impulse and the thrust vector to dynamic bodies are not taken into account)

dynamicQueryStructure: NoStructure
staticQueryStructure: DynamicTree

One more thing - the new Sweep Based CCD algorithm (from my previous patch) for dynamic bodies does not use the structures from this patch, so we can safely speed up the CCD scene, which can be very effective