Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qabstractphysxnode.cpp
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qabstractphysxnode_p.h"
6
7
#
include
"qabstractphysicsnode_p.h"
8
#
include
"qphysicsmaterial_p.h"
9
#
include
"qstaticphysxobjects_p.h"
10
11
#
include
"PxPhysics.h"
12
#
include
"PxMaterial.h"
13
#
include
"PxShape.h"
14
15
#
define
PHYSX_RELEASE
(
x
)
16
if
(
x
!=
nullptr
)
{
17
x
->
release
(
)
;
18
x
=
nullptr
;
19
}
20
21
QT_BEGIN_NAMESPACE
22
23
QAbstractPhysXNode
::QAbstractPhysXNode(QAbstractPhysicsNode *node) :
frontendNode
(node)
24
{
25
Q_ASSERT(node->m_backendObject ==
nullptr
);
26
node->m_backendObject =
this
;
27
}
28
29
QAbstractPhysXNode
::~
QAbstractPhysXNode
() {
30
if
(!
frontendNode
) {
31
Q_ASSERT(
isRemoved
);
32
return
;
33
}
34
35
Q_ASSERT(
frontendNode
->m_backendObject ==
this
);
36
frontendNode
->m_backendObject =
nullptr
;
37
}
38
39
bool
QAbstractPhysXNode
::
cleanupIfRemoved
(
QPhysXWorld
*physX)
40
{
41
if
(
isRemoved
) {
42
cleanup
(
physX
)
;
43
delete
this
;
44
return
true
;
45
}
46
return
false
;
47
}
48
49
void
QAbstractPhysXNode
::
updateDefaultDensity
(
float
) { }
50
51
static
PhysicsMaterialProperties
propertiesFor
(
const
QPhysicsMaterial *qtMaterial)
52
{
53
if
(!qtMaterial) {
54
return
{ QPhysicsMaterial::defaultStaticFriction, QPhysicsMaterial::defaultDynamicFriction,
55
QPhysicsMaterial::defaultRestitution };
56
}
57
return
{ qtMaterial->staticFriction(), qtMaterial->dynamicFriction(),
58
qtMaterial->restitution() };
59
}
60
61
QPhysicsMaterial *
QAbstractPhysXNode
::
qtMaterial
()
const
62
{
63
return
nullptr
;
64
}
65
66
bool
QAbstractPhysXNode
::
updateMaterial
()
67
{
68
const
PhysicsMaterialProperties
properties =
propertiesFor
(
qtMaterial
(
)
)
;
69
if
(properties
==
materialProperties
)
70
return
false
;
71
72
physx
::PxMaterial *previousMaterial =
material
;
73
releaseMaterial
(
)
;
74
materialProperties
= properties;
75
76
auto
&s_physx =
StaticPhysXObjects
::
getReference
(
)
;
77
SharedPhysicsMaterial
&shared = s_physx.materials[properties];
78
if
(!shared
.
material
) {
79
shared
.
material
= s_physx
.
physics
->createMaterial(
80
properties
.
staticFriction
, properties
.
dynamicFriction
, properties
.
restitution
);
81
if
(!shared
.
material
) {
82
// PhysX allows at most 64K materials. Without a material the node gets no shapes,
83
// so it will not collide with anything.
84
qWarning() <<
"QtQuick3DPhysics: could not create physics material, the body will "
85
"not take part in collisions."
;
86
s_physx.materials.remove(properties);
87
return
material
!= previousMaterial;
88
}
89
}
90
91
++shared
.
nodeCount
;
92
material
= shared
.
material
;
93
return
material
!= previousMaterial;
94
}
95
96
void
QAbstractPhysXNode
::
releaseMaterial
()
97
{
98
if
(!
material
)
99
return
;
100
101
auto
&materials =
StaticPhysXObjects
::
getReference
(
)
.materials;
102
const
auto
it = materials.find(
materialProperties
);
103
if
(it != materials.end() && it->material ==
material
&& --it->nodeCount == 0) {
104
// Any shape still referencing the material keeps it alive until it is rebuilt
105
it->material->release();
106
materials.erase(it);
107
}
108
material
=
nullptr
;
109
materialProperties
=
PhysicsMaterialProperties
::
none
(
)
;
110
}
111
112
void
QAbstractPhysXNode
::
markDirtyShapes
() { }
113
114
void
QAbstractPhysXNode
::
rebuildDirtyShapes
(QPhysicsWorld *,
QPhysXWorld
*) { }
115
116
void
QAbstractPhysXNode
::
updateFilters
() { }
117
118
void
QAbstractPhysXNode
::
cleanup
(
QPhysXWorld
*)
119
{
120
for
(
auto
*shape : std::as_const(shapes))
121
PHYSX_RELEASE
(shape);
122
releaseMaterial
(
)
;
123
shapes.clear();
124
}
125
126
bool
QAbstractPhysXNode
::
debugGeometryCapability
()
127
{
128
return
false
;
129
}
130
131
physx
::
PxTransform
QAbstractPhysXNode
::
getGlobalPose
()
132
{
133
return
{};
134
}
135
136
bool
QAbstractPhysXNode
::
useTriggerFlag
()
137
{
138
return
false
;
139
}
140
141
DebugDrawBodyType
QAbstractPhysXNode
::
getDebugDrawBodyType
()
142
{
143
return
DebugDrawBodyType
::
Unknown
;
144
}
145
146
bool
QAbstractPhysXNode
::
shapesDirty
()
const
147
{
148
return
frontendNode
&&
frontendNode
->m_shapesDirty;
149
}
150
151
void
QAbstractPhysXNode
::
setShapesDirty
(
bool
dirty)
152
{
153
frontendNode
->m_shapesDirty = dirty;
154
}
155
156
bool
QAbstractPhysXNode
::
filtersDirty
()
const
157
{
158
return
frontendNode
&&
frontendNode
->m_filtersDirty;
159
}
160
161
void
QAbstractPhysXNode
::
setFiltersDirty
(
bool
dirty)
162
{
163
Q_ASSERT(
frontendNode
);
164
frontendNode
->m_filtersDirty = dirty;
165
}
166
167
void
QAbstractPhysXNode
::
detachFrontend
()
168
{
169
for
(
auto
*shape : std::as_const(shapes))
170
shape->userData =
nullptr
;
171
}
172
173
QT_END_NAMESPACE
QAbstractPhysXNode
Definition
qabstractphysxnode_p.h:58
QAbstractPhysXNode::updateDefaultDensity
virtual void updateDefaultDensity(float density)
Definition
qabstractphysxnode.cpp:49
QAbstractPhysXNode::frontendNode
QAbstractPhysicsNode * frontendNode
Definition
qabstractphysxnode_p.h:98
QAbstractPhysXNode::filtersDirty
bool filtersDirty() const
Definition
qabstractphysxnode.cpp:156
QAbstractPhysXNode::cleanup
virtual void cleanup(QPhysXWorld *)
Definition
qabstractphysxnode.cpp:118
QAbstractPhysXNode::material
physx::PxMaterial * material
Definition
qabstractphysxnode_p.h:95
QAbstractPhysXNode::rebuildDirtyShapes
virtual void rebuildDirtyShapes(QPhysicsWorld *, QPhysXWorld *)
Definition
qabstractphysxnode.cpp:114
QAbstractPhysXNode::shapesDirty
bool shapesDirty() const
Definition
qabstractphysxnode.cpp:146
QAbstractPhysXNode::materialProperties
PhysicsMaterialProperties materialProperties
Definition
qabstractphysxnode_p.h:97
QAbstractPhysXNode::setShapesDirty
void setShapesDirty(bool dirty)
Definition
qabstractphysxnode.cpp:151
QAbstractPhysXNode::debugGeometryCapability
virtual bool debugGeometryCapability()
Definition
qabstractphysxnode.cpp:126
QAbstractPhysXNode::updateFilters
virtual void updateFilters()
Definition
qabstractphysxnode.cpp:116
QAbstractPhysXNode::~QAbstractPhysXNode
virtual ~QAbstractPhysXNode()
Definition
qabstractphysxnode.cpp:29
QAbstractPhysXNode::getGlobalPose
virtual physx::PxTransform getGlobalPose()
Definition
qabstractphysxnode.cpp:131
QAbstractPhysXNode::updateMaterial
bool updateMaterial()
Definition
qabstractphysxnode.cpp:66
QAbstractPhysXNode::releaseMaterial
void releaseMaterial()
Definition
qabstractphysxnode.cpp:96
QAbstractPhysXNode::isRemoved
bool isRemoved
Definition
qabstractphysxnode_p.h:99
QAbstractPhysXNode::markDirtyShapes
virtual void markDirtyShapes()
Definition
qabstractphysxnode.cpp:112
QAbstractPhysXNode::getDebugDrawBodyType
virtual DebugDrawBodyType getDebugDrawBodyType()
Definition
qabstractphysxnode.cpp:141
QAbstractPhysXNode::qtMaterial
virtual QPhysicsMaterial * qtMaterial() const
Definition
qabstractphysxnode.cpp:61
QAbstractPhysXNode::setFiltersDirty
void setFiltersDirty(bool dirty)
Definition
qabstractphysxnode.cpp:161
QAbstractPhysXNode::detachFrontend
virtual void detachFrontend()
Definition
qabstractphysxnode.cpp:167
QAbstractPhysXNode::cleanupIfRemoved
bool cleanupIfRemoved(QPhysXWorld *physX)
Definition
qabstractphysxnode.cpp:39
QAbstractPhysXNode::useTriggerFlag
virtual bool useTriggerFlag()
Definition
qabstractphysxnode.cpp:136
QPhysXWorld
Definition
qphysxworld_p.h:33
physx
Definition
qphysxactorbody_p.h:22
physx::PxTransform
PxTransformT< float > PxTransform
Definition
qabstractphysicsnode_p.h:28
PHYSX_RELEASE
#define PHYSX_RELEASE(x)
Definition
qabstractphysxnode.cpp:15
propertiesFor
static PhysicsMaterialProperties propertiesFor(const QPhysicsMaterial *qtMaterial)
Definition
qabstractphysxnode.cpp:51
DebugDrawBodyType
DebugDrawBodyType
Definition
qabstractphysxnode_p.h:42
DebugDrawBodyType::Unknown
@ Unknown
Definition
qabstractphysxnode_p.h:48
QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
Definition
qtconfigmacros.h:161
QT_END_NAMESPACE
#define QT_END_NAMESPACE
Definition
qtconfigmacros.h:162
PhysicsMaterialProperties
Definition
qstaticphysxobjects_p.h:40
PhysicsMaterialProperties::dynamicFriction
float dynamicFriction
Definition
qstaticphysxobjects_p.h:42
PhysicsMaterialProperties::operator==
friend bool operator==(const PhysicsMaterialProperties &lhs, const PhysicsMaterialProperties &rhs) noexcept
Definition
qstaticphysxobjects_p.h:49
PhysicsMaterialProperties::staticFriction
float staticFriction
Definition
qstaticphysxobjects_p.h:41
PhysicsMaterialProperties::restitution
float restitution
Definition
qstaticphysxobjects_p.h:43
PhysicsMaterialProperties::none
static constexpr PhysicsMaterialProperties none()
Definition
qstaticphysxobjects_p.h:47
SharedPhysicsMaterial
Definition
qstaticphysxobjects_p.h:65
SharedPhysicsMaterial::nodeCount
int nodeCount
Definition
qstaticphysxobjects_p.h:67
SharedPhysicsMaterial::material
physx::PxMaterial * material
Definition
qstaticphysxobjects_p.h:66
StaticPhysXObjects
Definition
qstaticphysxobjects_p.h:71
StaticPhysXObjects::getReference
static StaticPhysXObjects & getReference()
Definition
qstaticphysxobjects.cpp:14
StaticPhysXObjects::physics
physx::PxPhysics * physics
Definition
qstaticphysxobjects_p.h:75
qtquick3dphysics
src
quick3dphysics
physxnode
qabstractphysxnode.cpp
Generated on
for Qt by
1.18.0