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