Panda3D
 All Classes Functions Variables Enumerations
bulletSoftBodyNode.h
1 // Filename: bulletSoftBodyNode.h
2 // Created by: enn0x (27Dec10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef __BULLET_SOFT_BODY_NODE_H__
16 #define __BULLET_SOFT_BODY_NODE_H__
17 
18 #include "pandabase.h"
19 
20 #include "bullet_includes.h"
21 #include "bullet_utils.h"
22 #include "bulletBodyNode.h"
23 
24 #include "collideMask.h"
25 #include "geom.h"
26 #include "geomNode.h"
27 #include "geomVertexFormat.h"
28 #include "boundingBox.h"
29 #include "nurbsCurveEvaluator.h"
30 #include "nurbsSurfaceEvaluator.h"
31 #include "pta_LVecBase3.h"
32 
37 
38 ////////////////////////////////////////////////////////////////////
39 // Class : BulletSoftBodyNodeElement
40 // Description :
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_PANDABULLET BulletSoftBodyNodeElement {
43 
44 PUBLISHED:
45  INLINE ~BulletSoftBodyNodeElement();
46  INLINE static BulletSoftBodyNodeElement empty();
47 
48  INLINE LPoint3 get_pos() const;
49  INLINE LVector3 get_velocity() const;
50  INLINE LVector3 get_normal() const;
51  INLINE PN_stdfloat get_inv_mass() const;
52  INLINE PN_stdfloat get_area() const;
53  INLINE int is_attached() const;
54 
55 public:
56  BulletSoftBodyNodeElement(btSoftBody::Node &node);
57 
58 private:
59  btSoftBody::Node &_node;
60 };
61 
62 ////////////////////////////////////////////////////////////////////
63 // Class : BulletSoftBodyNode
64 // Description :
65 ////////////////////////////////////////////////////////////////////
66 class EXPCL_PANDABULLET BulletSoftBodyNode : public BulletBodyNode {
67 
68 public:
69  BulletSoftBodyNode(btSoftBody *body, const char *name="softbody");
70 
71 PUBLISHED:
72  INLINE ~BulletSoftBodyNode();
73 
74  BulletSoftBodyConfig get_cfg();
75  BulletSoftBodyWorldInfo get_world_info();
76 
77  void generate_bending_constraints(int distance, BulletSoftBodyMaterial *material=NULL);
78  void randomize_constraints();
79 
80  // Mass, volume, density
81  void set_volume_mass(PN_stdfloat mass);
82  void set_volume_density(PN_stdfloat density);
83  void set_total_mass(PN_stdfloat mass, bool fromfaces=false);
84  void set_total_density(PN_stdfloat density);
85  void set_mass(int node, PN_stdfloat mass);
86 
87  PN_stdfloat get_mass(int node) const;
88  PN_stdfloat get_total_mass() const;
89  PN_stdfloat get_volume() const;
90 
91  // Force
92  void add_force(const LVector3 &force);
93  void add_force(const LVector3 &force, int node);
94 
95  void set_velocity(const LVector3 &velocity);
96  void add_velocity(const LVector3 &velocity);
97  void add_velocity(const LVector3 &velocity, int node);
98 
99  void set_wind_velocity(const LVector3 &velocity);
100  LVector3 get_wind_velocity() const;
101 
102  void set_pose(bool bvolume, bool bframe);
103 
104  BoundingBox get_aabb() const;
105 
106  // Cluster
107  void generate_clusters(int k, int maxiterations=8192);
108  void release_cluster(int index);
109  void release_clusters();
110  int get_num_clusters() const;
111  LVecBase3 cluster_com(int cluster) const;
112 
113  // Rendering
114  void link_geom(Geom *geom);
115  void unlink_geom();
116 
117  void link_curve(NurbsCurveEvaluator *curve);
118  void unlink_curve();
119 
120  void link_surface(NurbsSurfaceEvaluator *surface);
121  void unlink_surface();
122 
123  // Anchors
124  void append_anchor(int node, BulletRigidBodyNode *body,
125  bool disable=false);
126  void append_anchor(int node, BulletRigidBodyNode *body,
127  const LVector3 &pivot,
128  bool disable=false);
129 
130  // Links
131  void append_linear_joint(BulletBodyNode *body, int cluster,
132  PN_stdfloat erp=1.0,
133  PN_stdfloat cfm=1.0,
134  PN_stdfloat split=1.0);
135 
136  void append_linear_joint(BulletBodyNode *body, const LPoint3 &pos,
137  PN_stdfloat erp=1.0,
138  PN_stdfloat cfm=1.0,
139  PN_stdfloat split=1.0);
140 
141  void append_angular_joint(BulletBodyNode *body, const LVector3 &axis,
142  PN_stdfloat erp=1.0,
143  PN_stdfloat cfm=1.0,
144  PN_stdfloat split=1.0,
145  BulletSoftBodyControl *control=NULL);
146 
147  // Materials
148  int get_num_materials() const;
149  BulletSoftBodyMaterial get_material(int idx) const;
150  MAKE_SEQ(get_materials, get_num_materials, get_material);
151 
152  BulletSoftBodyMaterial append_material();
153 
154  // Nodes
155  int get_num_nodes() const;
156  BulletSoftBodyNodeElement get_node(int idx) const;
157  MAKE_SEQ(get_nodes, get_num_nodes, get_node);
158 
159  int get_closest_node_index(LVecBase3 point, bool local);
160 
161  // Factory
162  static PT(BulletSoftBodyNode) make_rope(
164  const LPoint3 &from,
165  const LPoint3 &to,
166  int res,
167  int fixeds);
168 
169  static PT(BulletSoftBodyNode) make_patch(
171  const LPoint3 &corner00,
172  const LPoint3 &corner10,
173  const LPoint3 &corner01,
174  const LPoint3 &corner11,
175  int resx,
176  int resy,
177  int fixeds,
178  bool gendiags);
179 
180  static PT(BulletSoftBodyNode) make_ellipsoid(
182  const LPoint3 &center,
183  const LVecBase3 &radius,
184  int res);
185 
186  static PT(BulletSoftBodyNode) make_tri_mesh(
188  const Geom *geom,
189  bool randomizeConstraints=true);
190 
191  static PT(BulletSoftBodyNode) make_tri_mesh(
193  PTA_LVecBase3 points,
194  PTA_int indices,
195  bool randomizeConstraints=true);
196 
197  static PT(BulletSoftBodyNode) make_tet_mesh(
199  PTA_LVecBase3 points,
200  PTA_int indices,
201  bool tetralinks=true);
202 
203  static PT(BulletSoftBodyNode) make_tet_mesh(
205  const char *ele,
206  const char *face,
207  const char *node);
208 
209 public:
210  virtual btCollisionObject *get_object() const;
211 
212  void sync_p2b();
213  void sync_b2p();
214 
215 protected:
216  virtual void transform_changed();
217 
218 private:
219  btSoftBody *_soft;
220 
221  CPT(TransformState) _sync;
222  bool _sync_disable;
223 
224  PT(Geom) _geom;
225  PT(NurbsCurveEvaluator) _curve;
226  PT(NurbsSurfaceEvaluator) _surface;
227 
228  static int get_point_index(LVecBase3 p, PTA_LVecBase3 points);
229  static int next_line(const char *buffer);
230 
231 ////////////////////////////////////////////////////////////////////
232 public:
233  static TypeHandle get_class_type() {
234  return _type_handle;
235  }
236  static void init_type() {
237  BulletBodyNode::init_type();
238  register_type(_type_handle, "BulletSoftBodyNode",
239  BulletBodyNode::get_class_type());
240  }
241  virtual TypeHandle get_type() const {
242  return get_class_type();
243  }
244  virtual TypeHandle force_init_type() {
245  init_type();
246  return get_class_type();
247  }
248 
249 private:
250  static TypeHandle _type_handle;
251 };
252 
253 #include "bulletSoftBodyNode.I"
254 
255 #endif // __BULLET_SOFT_BODY_NODE_H__
256 
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
Definition: boundingBox.h:31
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This class is an abstraction for evaluating NURBS curves.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This class is an abstraction for evaluating NURBS surfaces.
A container for geometry primitives.
Definition: geom.h:58
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85