1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef ABSTRACTPHYSXNODE_H
5#define ABSTRACTPHYSXNODE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "foundation/PxTransform.h"
19#include "qtconfigmacros.h"
20
21#include <QVector>
22
23namespace physx {
24class PxMaterial;
25class PxShape;
26}
27
28QT_BEGIN_NAMESPACE
29
30class QAbstractPhysicsNode;
31class QMatrix4x4;
32class QQuick3DNode;
33class QPhysicsWorld;
34class QPhysicsMaterial;
35class QPhysXWorld;
36
37// Used for debug drawing
38enum class DebugDrawBodyType {
39 Static = 0,
40 DynamicAwake = 1,
41 DynamicSleeping = 2,
42 Trigger = 3,
43 Unknown = 4
44};
45
46/*
47 NOTE
48 The inheritance hierarchy is not ideal, since both controller and rigid body have materials,
49 but trigger doesn't. AND both trigger and rigid body have actors, but controller doesn't.
50
51 TODO: defaultMaterial isn't used for rigid bodies, since they always create their own
52 QPhysicsMaterial with default values. We should only have a qt material when set explicitly.
53*/
54
55class QAbstractPhysXNode
56{
57public:
58 QAbstractPhysXNode(QAbstractPhysicsNode *node);
59 virtual ~QAbstractPhysXNode();
60
61 bool cleanupIfRemoved(QPhysXWorld *physX); // TODO rename??
62
63 virtual void init(QPhysicsWorld *world, QPhysXWorld *physX) = 0;
64 virtual void updateDefaultDensity(float density);
65 virtual void createMaterial(QPhysXWorld *physX);
66 void createMaterialFromQtMaterial(QPhysXWorld *physX, QPhysicsMaterial *qtMaterial);
67 virtual void markDirtyShapes();
68 virtual void rebuildDirtyShapes(QPhysicsWorld *, QPhysXWorld *);
69
70 virtual void sync(float deltaTime, QHash<QQuick3DNode *, QMatrix4x4> &transformCache) = 0;
71 virtual void cleanup(QPhysXWorld *);
72 virtual bool debugGeometryCapability();
73 virtual physx::PxTransform getGlobalPose();
74
75 virtual bool useTriggerFlag();
76 virtual DebugDrawBodyType getDebugDrawBodyType();
77
78 bool shapesDirty() const;
79 void setShapesDirty(bool dirty);
80
81 QVector<physx::PxShape *> shapes;
82 physx::PxMaterial *material = nullptr;
83 QAbstractPhysicsNode *frontendNode = nullptr;
84 bool isRemoved = false;
85 static physx::PxMaterial *sDefaultMaterial;
86};
87
88QT_END_NAMESPACE
89
90#endif
91

source code of qtquick3dphysics/src/quick3dphysics/physxnode/qabstractphysxnode_p.h