PeriDyno 1.0.0
Loading...
Searching...
No Matches
RigidBodySystem.h
Go to the documentation of this file.
1
16#pragma once
17#include "Node.h"
18#include "RigidBodyShared.h"
19
20#include "Collision/Attribute.h"
22
23#include <vector>
24#include <iostream>
25namespace dyno
26{
32 template<typename TDataType>
33 class RigidBodySystem : virtual public Node
34 {
35 public:
36 typedef typename TDataType::Real Real;
37 typedef typename TDataType::Coord Coord;
38 typedef typename TDataType::Matrix Matrix;
39
42 typedef typename dyno::Quat<Real> TQuat;
43
45
46 typedef typename ::dyno::BallAndSocketJoint<Real> BallAndSocketJoint;
47 typedef typename ::dyno::SliderJoint<Real> SliderJoint;
48 typedef typename ::dyno::HingeJoint<Real> HingeJoint;
49 typedef typename ::dyno::FixedJoint<Real> FixedJoint;
50 typedef typename ::dyno::PointJoint<Real> PointJoint;
51
53 ~RigidBodySystem() override;
54
55 std::shared_ptr<PdActor> addBox(
56 const BoxInfo& box,
57 const RigidBodyInfo& bodyDef,
58 const Real density = Real(100));
59
60 std::shared_ptr<PdActor> addSphere(
61 const SphereInfo& sphere,
62 const RigidBodyInfo& bodyDef,
63 const Real density = Real(100));
64
65 std::shared_ptr<PdActor> addTet(
66 const TetInfo& tet,
67 const RigidBodyInfo& bodyDef,
68 const Real density = Real(100));
69
70 std::shared_ptr<PdActor> addCapsule(
71 const CapsuleInfo& capsule,
72 const RigidBodyInfo& bodyDef,
73 const Real density = Real(100));
74
75 std::shared_ptr<PdActor> createRigidBody(
76 const Coord& p,
77 const TQuat& q);
78
79 std::shared_ptr<PdActor> createRigidBody(
80 const RigidBodyInfo& bodyDef);
81
82 void bindBox(
83 const std::shared_ptr<PdActor> actor,
84 const BoxInfo& box,
85 const Real density = Real(100));
86
88 const std::shared_ptr<PdActor> actor,
89 const SphereInfo& sphere,
90 const Real density = Real(100));
91
93 const std::shared_ptr<PdActor> actor,
94 const CapsuleInfo& capsule,
95 const Real density = Real(100));
96
98 std::shared_ptr<PdActor> actor1,
99 std::shared_ptr<PdActor> actor2)
100 {
101 BallAndSocketJoint joint(actor1.get(), actor2.get());
103
105 }
106
108 std::shared_ptr<PdActor> actor1,
109 std::shared_ptr<PdActor> actor2)
110 {
111 SliderJoint joint(actor1.get(), actor2.get());
112 mHostJointsSlider.push_back(joint);
113
114 return mHostJointsSlider[mHostJointsSlider.size() - 1];
115 }
116
118 std::shared_ptr<PdActor> actor1,
119 std::shared_ptr<PdActor> actor2)
120 {
121 HingeJoint joint(actor1.get(), actor2.get());
122 mHostJointsHinge.push_back(joint);
123
124 return mHostJointsHinge[mHostJointsHinge.size() - 1];
125 }
126
128 std::shared_ptr<PdActor> actor1,
129 std::shared_ptr<PdActor> actor2)
130 {
131 FixedJoint joint(actor1.get(), actor2.get());
132 mHostJointsFixed.push_back(joint);
133
134 return mHostJointsFixed[mHostJointsFixed.size() - 1];
135 }
136
138 std::shared_ptr<PdActor> actor1)
139 {
140 FixedJoint joint(actor1.get());
141 mHostJointsFixed.push_back(joint);
142
143 return mHostJointsFixed[mHostJointsFixed.size() - 1];
144 }
145
147 std::shared_ptr<PdActor> actor1)
148 {
149 PointJoint joint(actor1.get());
150 mHostJointsPoint.push_back(joint);
151
152 return mHostJointsPoint[mHostJointsPoint.size() - 1];
153 }
154
156
157 std::string getNodeType() override { return "Rigid Bodies"; }
158
159 protected:
160 void resetStates() override;
161
162 void postUpdateStates() override;
163
165
166 public:
167 DEF_VAR(bool, FrictionEnabled, true, "A toggle to control the friction");
168
169 DEF_VAR(bool, GravityEnabled, true, "A toggle to control the gravity");
170
171 DEF_VAR(Real, GravityValue, 9.8, "");
172
173 DEF_VAR(Real, FrictionCoefficient, 200, "");
174
175 DEF_VAR(Real, Slop, 0.0001, "");
176
178
179 DEF_ARRAY_STATE(Real, FrictionCoefficients, DeviceType::GPU, "FrictionCoefficients of rigid bodies");
180
184 DEF_ARRAY_STATE(Real, Mass, DeviceType::GPU, "Mass of rigid bodies");
185
189 DEF_ARRAY_STATE(Coord, Center, DeviceType::GPU, "Center of rigid bodies");
190
194 DEF_ARRAY_STATE(Coord, Velocity, DeviceType::GPU, "Velocity of rigid bodies");
195
199 DEF_ARRAY_STATE(Coord, AngularVelocity, DeviceType::GPU, "Angular velocity of rigid bodies");
200
204 DEF_ARRAY_STATE(Matrix, RotationMatrix, DeviceType::GPU, "Rotation matrix of rigid bodies");
205
206 DEF_ARRAY_STATE(Matrix, Inertia, DeviceType::GPU, "Inertia matrix");
207
208 DEF_ARRAY_STATE(TQuat, Quaternion, DeviceType::GPU, "Quaternion");
209
210 DEF_ARRAY_STATE(CollisionMask, CollisionMask, DeviceType::GPU, "Collision mask for each rigid body");
211
212 DEF_ARRAY_STATE(Attribute, Attribute, DeviceType::GPU, "Rigid body attributes");
213
214 DEF_ARRAY_STATE(Matrix, InitialInertia, DeviceType::GPU, "Initial inertia matrix");
215
216 private:
218
219 std::vector<RigidBodyInfo> mHostRigidBodyStates;
220
221 std::vector<SphereInfo> mHostSpheres;
222 std::vector<BoxInfo> mHostBoxes;
223 std::vector<TetInfo> mHostTets;
224 std::vector<CapsuleInfo> mHostCapsules;
225
227
232
233 std::vector<BallAndSocketJoint> mHostJointsBallAndSocket;
234 std::vector<SliderJoint> mHostJointsSlider;
235 std::vector<HingeJoint> mHostJointsHinge;
236 std::vector<FixedJoint> mHostJointsFixed;
237 std::vector<PointJoint> mHostJointsPoint;
238
239 std::vector<Pair<uint, uint>> mHostShape2RigidBodyMapping;
240
241 public:
245
246 std::vector<Vec3f> samples;
247 std::vector<Vec3f> normals;
248
250
253 };
254}
particle attribute 0x00000000: [31-30]material; [29]motion; [28]Dynamic; [27-8]undefined yet,...
Definition Attribute.h:26
dyno::Quat< Real > TQuat
std::shared_ptr< PdActor > addBox(const BoxInfo &box, const RigidBodyInfo &bodyDef, const Real density=Real(100))
DArray2D< Vec3f > getNormals()
SliderJoint & createSliderJoint(std::shared_ptr< PdActor > actor1, std::shared_ptr< PdActor > actor2)
TDataType::Coord Coord
HingeJoint & createHingeJoint(std::shared_ptr< PdActor > actor1, std::shared_ptr< PdActor > actor2)
DEF_ARRAY_STATE(CollisionMask, CollisionMask, DeviceType::GPU, "Collision mask for each rigid body")
DEF_VAR(bool, FrictionEnabled, true, "A toggle to control the friction")
void resetStates() override
std::vector< BoxInfo > mHostBoxes
dyno::TSphere3D< Real > Sphere3D
std::shared_ptr< PdActor > createRigidBody(const RigidBodyInfo &bodyDef)
TDataType::Matrix Matrix
std::string getNodeType() override
DEF_VAR(Real, FrictionCoefficient, 200, "")
std::shared_ptr< PdActor > createRigidBody(const Coord &p, const TQuat &q)
Mat3f pointInertia(Coord v1)
void setupShape2RigidBodyMapping()
::dyno::PointJoint< Real > PointJoint
DArray< TetInfo > mDeviceTets
std::shared_ptr< PdActor > addTet(const TetInfo &tet, const RigidBodyInfo &bodyDef, const Real density=Real(100))
DArray< RigidBodyInfo > mDeviceRigidBodyStates
std::vector< HingeJoint > mHostJointsHinge
DEF_VAR(Real, Slop, 0.0001, "")
DEF_ARRAY_STATE(Attribute, Attribute, DeviceType::GPU, "Rigid body attributes")
FixedJoint & createFixedJoint(std::shared_ptr< PdActor > actor1, std::shared_ptr< PdActor > actor2)
std::vector< BallAndSocketJoint > mHostJointsBallAndSocket
FixedJoint & createUnilateralFixedJoint(std::shared_ptr< PdActor > actor1)
DEF_VAR(bool, GravityEnabled, true, "A toggle to control the gravity")
std::vector< RigidBodyInfo > mHostRigidBodyStates
void bindBox(const std::shared_ptr< PdActor > actor, const BoxInfo &box, const Real density=Real(100))
DArray2D< Vec3f > getSamples()
DArray2D< Vec3f > m_deviceNormals
DEF_ARRAY_STATE(TQuat, Quaternion, DeviceType::GPU, "Quaternion")
DEF_ARRAY_STATE(Coord, Velocity, DeviceType::GPU, "Velocity of rigid bodies")
Rigid Velocity.
dyno::TOrientedBox3D< Real > Box3D
DEF_ARRAY_STATE(Real, FrictionCoefficients, DeviceType::GPU, "FrictionCoefficients of rigid bodies")
DEF_ARRAY_STATE(Matrix, Inertia, DeviceType::GPU, "Inertia matrix")
std::shared_ptr< PdActor > addCapsule(const CapsuleInfo &capsule, const RigidBodyInfo &bodyDef, const Real density=Real(100))
DArray< CapsuleInfo > mDeviceCapsules
DEF_ARRAY_STATE(Coord, Center, DeviceType::GPU, "Center of rigid bodies")
Rigid Position.
DArray< BoxInfo > mDeviceBoxes
::dyno::BallAndSocketJoint< Real > BallAndSocketJoint
std::vector< CapsuleInfo > mHostCapsules
std::vector< SphereInfo > mHostSpheres
void bindCapsule(const std::shared_ptr< PdActor > actor, const CapsuleInfo &capsule, const Real density=Real(100))
std::vector< Pair< uint, uint > > mHostShape2RigidBodyMapping
DArray< SphereInfo > mDeviceSpheres
::dyno::SliderJoint< Real > SliderJoint
DEF_VAR(Real, GravityValue, 9.8, "")
void postUpdateStates() override
::dyno::HingeJoint< Real > HingeJoint
std::vector< FixedJoint > mHostJointsFixed
PointJoint & createPointJoint(std::shared_ptr< PdActor > actor1)
void bindSphere(const std::shared_ptr< PdActor > actor, const SphereInfo &sphere, const Real density=Real(100))
std::vector< Vec3f > samples
std::vector< Vec3f > normals
std::vector< SliderJoint > mHostJointsSlider
std::shared_ptr< PdActor > addSphere(const SphereInfo &sphere, const RigidBodyInfo &bodyDef, const Real density=Real(100))
std::vector< PointJoint > mHostJointsPoint
~RigidBodySystem() override
DEF_ARRAY_STATE(Real, Mass, DeviceType::GPU, "Mass of rigid bodies")
Rigid Mass.
DEF_INSTANCE_STATE(DiscreteElements< TDataType >, Topology, "Topology")
std::vector< TetInfo > mHostTets
DArray2D< Vec3f > m_deviceSamples
DEF_ARRAY_STATE(Matrix, RotationMatrix, DeviceType::GPU, "Rotation matrix of rigid bodies")
Rigid Rotation.
DEF_ARRAY_STATE(Matrix, InitialInertia, DeviceType::GPU, "Initial inertia matrix")
::dyno::FixedJoint< Real > FixedJoint
BallAndSocketJoint & createBallAndSocketJoint(std::shared_ptr< PdActor > actor1, std::shared_ptr< PdActor > actor2)
DEF_ARRAY_STATE(Coord, AngularVelocity, DeviceType::GPU, "Angular velocity of rigid bodies")
Rigid Angular Velocity.
dyno::TContactPair< Real > ContactPair
3D geometric primitives in three-dimensional space
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
int joint
Definition GltfFunc.h:19
SquareMatrix< float, 3 > Mat3f
Definition Matrix3x3.h:92
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
Array2D< T, DeviceType::GPU > DArray2D
Definition Array2D.inl:90