Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/DecoratedShape.cpp

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #include <Jolt/Jolt.h>
6
7 #include <Jolt/Physics/Collision/Shape/DecoratedShape.h>
8 #include <Jolt/ObjectStream/TypeDeclarations.h>
9
10 JPH_NAMESPACE_BEGIN
11
12 JPH_IMPLEMENT_SERIALIZABLE_ABSTRACT(DecoratedShapeSettings)
13 {
14 JPH_ADD_BASE_CLASS(DecoratedShapeSettings, ShapeSettings)
15
16 JPH_ADD_ATTRIBUTE(DecoratedShapeSettings, mInnerShape)
17 }
18
19 DecoratedShape::DecoratedShape(EShapeSubType inSubType, const DecoratedShapeSettings &inSettings, ShapeResult &outResult) :
20 Shape(EShapeType::Decorated, inSubType, inSettings, outResult)
21 {
22 // Check that there's a shape
23 if (inSettings.mInnerShape == nullptr && inSettings.mInnerShapePtr == nullptr)
24 {
25 outResult.SetError("Inner shape is null!");
26 return;
27 }
28
29 if (inSettings.mInnerShapePtr != nullptr)
30 {
31 // Use provided shape
32 mInnerShape = inSettings.mInnerShapePtr;
33 }
34 else
35 {
36 // Create child shape
37 ShapeResult child_result = inSettings.mInnerShape->Create();
38 if (!child_result.IsValid())
39 {
40 outResult = child_result;
41 return;
42 }
43 mInnerShape = child_result.Get();
44 }
45 }
46
47 const PhysicsMaterial *DecoratedShape::GetMaterial(const SubShapeID &inSubShapeID) const
48 {
49 return mInnerShape->GetMaterial(inSubShapeID);
50 }
51
52 void DecoratedShape::GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const
53 {
54 mInnerShape->GetSupportingFace(inSubShapeID, inDirection, inScale, inCenterOfMassTransform, outVertices);
55 }
56
57 uint64 DecoratedShape::GetSubShapeUserData(const SubShapeID &inSubShapeID) const
58 {
59 return mInnerShape->GetSubShapeUserData(inSubShapeID);
60 }
61
62 void DecoratedShape::SaveSubShapeState(ShapeList &outSubShapes) const
63 {
64 outSubShapes.clear();
65 outSubShapes.push_back(mInnerShape);
66 }
67
68 void DecoratedShape::RestoreSubShapeState(const ShapeRefC *inSubShapes, uint inNumShapes)
69 {
70 JPH_ASSERT(inNumShapes == 1);
71 mInnerShape = inSubShapes[0];
72 }
73
74 Shape::Stats DecoratedShape::GetStatsRecursive(VisitedShapes &ioVisitedShapes) const
75 {
76 // Get own stats
77 Stats stats = Shape::GetStatsRecursive(ioVisitedShapes);
78
79 // Add child stats
80 Stats child_stats = mInnerShape->GetStatsRecursive(ioVisitedShapes);
81 stats.mSizeBytes += child_stats.mSizeBytes;
82 stats.mNumTriangles += child_stats.mNumTriangles;
83
84 return stats;
85 }
86
87 JPH_NAMESPACE_END