Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SoftBodySharedSettings.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
10
12
15class JPH_EXPORT SoftBodySharedSettings : public RefTarget<SoftBodySharedSettings>
16{
17public:
19
20
21 void CalculateEdgeLengths();
22
24 void CalculateVolumeConstraintVolumes();
25
28 {
29 public:
31 };
32
34 void Optimize(OptimizationResults &outResults);
35
37 void Optimize() { OptimizationResults results; Optimize(results); }
38
40 void SaveBinaryState(StreamOut &inStream) const;
41
43 void RestoreBinaryState(StreamIn &inStream);
44
49
51 void SaveWithMaterials(StreamOut &inStream, SharedSettingsToIDMap &ioSettingsMap, MaterialToIDMap &ioMaterialMap) const;
52
54
56 static SettingsResult sRestoreWithMaterials(StreamIn &inStream, IDToSharedSettingsMap &ioSettingsMap, IDToMaterialMap &ioMaterialMap);
57
60 {
62
63
64 Vertex() = default;
65 Vertex(const Float3 &inPosition, const Float3 &inVelocity = Float3(0, 0, 0), float inInvMass = 1.0f) : mPosition(inPosition), mVelocity(inVelocity), mInvMass(inInvMass) { }
66
67 Float3 mPosition { 0, 0, 0 };
68 Float3 mVelocity { 0, 0, 0 };
69 float mInvMass = 1.0f;
70 };
71
74 {
76
77
78 Face() = default;
79 Face(uint32 inVertex1, uint32 inVertex2, uint32 inVertex3, uint32 inMaterialIndex = 0) : mVertex { inVertex1, inVertex2, inVertex3 }, mMaterialIndex(inMaterialIndex) { }
80
82 bool IsDegenerate() const { return mVertex[0] == mVertex[1] || mVertex[0] == mVertex[2] || mVertex[1] == mVertex[2]; }
83
84 uint32 mVertex[3];
85 uint32 mMaterialIndex = 0;
86 };
87
90 {
92
93
94 Edge() = default;
95 Edge(uint32 inVertex1, uint32 inVertex2, float inCompliance = 0.0f) : mVertex { inVertex1, inVertex2 }, mCompliance(inCompliance) { }
96
97 uint32 mVertex[2];
98 float mRestLength = 1.0f;
99 float mCompliance = 0.0f;
100 };
101
104 {
106
107
108 Volume() = default;
109 Volume(uint32 inVertex1, uint32 inVertex2, uint32 inVertex3, uint32 inVertex4, float inCompliance = 0.0f) : mVertex { inVertex1, inVertex2, inVertex3, inVertex4 }, mCompliance(inCompliance) { }
110
111 uint32 mVertex[4];
112 float mSixRestVolume = 1.0f;
113 float mCompliance = 0.0f;
114 };
115
117 void AddFace(const Face &inFace) { JPH_ASSERT(!inFace.IsDegenerate()); mFaces.push_back(inFace); }
118
120 uint GetEdgeGroupSize(uint inGroupIdx) const { return inGroupIdx == 0? mEdgeGroupEndIndices[0] : mEdgeGroupEndIndices[inGroupIdx] - mEdgeGroupEndIndices[inGroupIdx - 1]; }
121
128};
129
#define JPH_EXPORT
Definition: Core.h:214
unsigned int uint
Definition: Core.h:426
#define JPH_NAMESPACE_END
Definition: Core.h:354
std::uint32_t uint32
Definition: Core.h:429
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:348
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
Array< RefConst< PhysicsMaterial > > PhysicsMaterialList
Definition: PhysicsMaterial.h:50
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition: SerializableObject.h:71
Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations.
Definition: Float3.h:13
static RefConst< PhysicsMaterial > sDefault
Default material that is used when a shape has no materials defined.
Definition: PhysicsMaterial.h:31
Definition: Reference.h:35
Helper class that either contains a valid result or an error.
Definition: Result.h:15
Information about the optimization of the soft body, the indices of certain elements may have changed...
Definition: SoftBodySharedSettings.h:28
Array< uint > mEdgeRemap
Maps old edge index to new edge index.
Definition: SoftBodySharedSettings.h:30
Definition: SoftBodySharedSettings.h:16
Array< Vertex > mVertices
The list of vertices or particles of the body.
Definition: SoftBodySharedSettings.h:122
StreamUtils::ObjectToIDMap< PhysicsMaterial > MaterialToIDMap
Definition: SoftBodySharedSettings.h:47
void Optimize()
Optimize the soft body settings without results.
Definition: SoftBodySharedSettings.h:37
StreamUtils::IDToObjectMap< SoftBodySharedSettings > IDToSharedSettingsMap
Definition: SoftBodySharedSettings.h:46
Array< Face > mFaces
The list of faces of the body.
Definition: SoftBodySharedSettings.h:123
uint GetEdgeGroupSize(uint inGroupIdx) const
Get the size of an edge group (edge groups can run in parallel)
Definition: SoftBodySharedSettings.h:120
Array< Volume > mVolumeConstraints
The list of volume constraints of the body that keep the volume of tetrahedra in the soft body consta...
Definition: SoftBodySharedSettings.h:126
StreamUtils::IDToObjectMap< PhysicsMaterial > IDToMaterialMap
Definition: SoftBodySharedSettings.h:48
Array< Edge > mEdgeConstraints
The list of edges or springs of the body.
Definition: SoftBodySharedSettings.h:124
void AddFace(const Face &inFace)
Add a face to this soft body.
Definition: SoftBodySharedSettings.h:117
Array< uint > mEdgeGroupEndIndices
The start index of each group of edges that can be solved in parallel.
Definition: SoftBodySharedSettings.h:125
StreamUtils::ObjectToIDMap< SoftBodySharedSettings > SharedSettingsToIDMap
Definition: SoftBodySharedSettings.h:45
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13
Array< Ref< Type > > IDToObjectMap
Definition: StreamUtils.h:21
UnorderedMap< const Type *, uint32 > ObjectToIDMap
Definition: StreamUtils.h:18
An edge keeps two vertices at a constant distance using a spring: |x1 - x2| = rest length.
Definition: SoftBodySharedSettings.h:90
A face defines the surface of the body.
Definition: SoftBodySharedSettings.h:74
bool IsDegenerate() const
Check if this is a degenerate face (a face which points to the same vertex twice)
Definition: SoftBodySharedSettings.h:82
A vertex is a particle, the data in this structure is only used during creation of the soft body and ...
Definition: SoftBodySharedSettings.h:60
Volume constraint, keeps the volume of a tetrahedron constant.
Definition: SoftBodySharedSettings.h:104