1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  *   https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  *   Redistribution and use in source and binary forms, with or
10  *   without modification, are permitted provided that the following
11  *   conditions are met:
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *   * Redistributions in binary form must reproduce the above
15  *     copyright notice, this list of conditions and the following
16  *     disclaimer in the documentation and/or other materials provided
17  *     with the distribution.
18  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  *   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  *   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  *   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  *   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  *   AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  *   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  *   POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_DYNAMICS_DETAIL_SOFTBODYNODEASPECT_HPP_
34 #define DART_DYNAMICS_DETAIL_SOFTBODYNODEASPECT_HPP_
35 
36 #include "dart/common/RequiresAspect.hpp"
37 #include "dart/dynamics/BodyNode.hpp"
38 #include "dart/dynamics/PointMass.hpp"
39 
40 namespace dart {
41 namespace dynamics {
42 
43 const double DART_DEFAULT_VERTEX_STIFFNESS = 1.0;
44 const double DART_DEFAULT_EDGE_STIFNESS = 1.0;
45 const double DART_DEFAULT_DAMPING_COEFF = 0.01;
46 
47 class SoftBodyNode;
48 class SoftMeshShape;
49 
50 namespace detail {
51 
52 //==============================================================================
53 class SoftBodyAspect;
54 
55 //==============================================================================
56 struct SoftBodyNodeUniqueState
57 {
58   /// Array of States for PointMasses
59   std::vector<PointMass::State> mPointStates;
60 
61   virtual ~SoftBodyNodeUniqueState() = default;
62 };
63 
64 //==============================================================================
65 struct SoftBodyNodeUniqueProperties
66 {
67   /// Spring stiffness for vertex deformation restoring spring force of the
68   /// point masses
69   double mKv;
70 
71   /// Spring stiffness for edge deformation restoring spring force of the
72   /// point masses
73   double mKe;
74 
75   /// Damping coefficient
76   double mDampCoeff;
77 
78   /// Array of Properties for PointMasses
79   std::vector<PointMass::Properties> mPointProps;
80 
81   // TODO(JS): Let's remove this because this is rendering part
82   /// \brief Tri-mesh indexes for rendering.
83   std::vector<Eigen::Vector3i> mFaces;
84 
85   SoftBodyNodeUniqueProperties(
86       double _Kv = DART_DEFAULT_VERTEX_STIFFNESS,
87       double _Ke = DART_DEFAULT_EDGE_STIFNESS,
88       double _DampCoeff = DART_DEFAULT_DAMPING_COEFF,
89       const std::vector<PointMass::Properties>& _points
90       = std::vector<PointMass::Properties>(),
91       const std::vector<Eigen::Vector3i>& _faces
92       = std::vector<Eigen::Vector3i>());
93 
94   virtual ~SoftBodyNodeUniqueProperties() = default;
95 
96   /// Add a PointMass to this Properties struct
97   void addPointMass(const PointMass::Properties& _properties);
98 
99   /// Connect two PointMasses together in this Properties struct
100   bool connectPointMasses(std::size_t i1, std::size_t i2);
101 
102   /// Add a face to this Properties struct
103   void addFace(const Eigen::Vector3i& _newFace);
104 };
105 
106 //==============================================================================
107 struct SoftBodyNodeProperties : BodyNode::Properties,
108                                 SoftBodyNodeUniqueProperties
109 {
110   DART_DEFINE_ALIGNED_SHARED_OBJECT_CREATOR(SoftBodyNodeProperties)
111 
112   SoftBodyNodeProperties(
113       const BodyNode::Properties& _bodyProperties = BodyNode::Properties(),
114       const SoftBodyNodeUniqueProperties& _softProperties
115       = SoftBodyNodeUniqueProperties());
116 
117   virtual ~SoftBodyNodeProperties() = default;
118 };
119 
120 //==============================================================================
121 using SoftBodyNodeBase = common::EmbedStateAndPropertiesOnTopOf<
122     SoftBodyNode,
123     SoftBodyNodeUniqueState,
124     SoftBodyNodeUniqueProperties,
125     BodyNode>;
126 
127 } // namespace detail
128 } // namespace dynamics
129 } // namespace dart
130 
131 #endif // DART_DYNAMICS_DETAIL_SOFTBODYNODEASPECT_HPP_
132