Share physics materials between bodies with equal properties
Every PhysicsBody creates a QPhysicsMaterial with default values in its
constructor, and the backend created a PxMaterial of its own for every
node. PhysX allows at most 64K materials, so a scene with many bodies
would hit
invalid parameter : PxPhysics::createMaterial: limit of 64K materials
reached
after which createMaterial() returns null and the affected bodies get no
shapes at all, and so stop colliding. Duplicating identical material
state for thousands of bodies is also wasteful in itself.
Keep the materials in a cache in StaticPhysXObjects instead, keyed on
the material properties and counting the nodes using each, so that all
nodes needing the same properties share one PxMaterial. A scene with
200 bodies, each with its own default-valued PhysicsMaterial, now uses a
single material instead of 200.
Since the materials are shared they have to be treated as immutable, so
a node whose properties change is moved to the material with the new
properties, and the shapes of the node are pointed at it. This replaces
writing the new values into the material of the node.
Pick-to: 6.12 6.11 6.8
Change-Id: I711f5832346779f6e9a3be659d2a09ce4da8fb6c
Reviewed-by: Kristoffer Skau <kristoffer.skau@qt.io>