00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __BULLET_SOFT_BODY_NODE_H__
00016 #define __BULLET_SOFT_BODY_NODE_H__
00017
00018 #include "pandabase.h"
00019
00020 #include "bullet_includes.h"
00021 #include "bullet_utils.h"
00022 #include "bulletBodyNode.h"
00023
00024 #include "collideMask.h"
00025 #include "geom.h"
00026 #include "geomNode.h"
00027 #include "geomVertexFormat.h"
00028 #include "boundingBox.h"
00029 #include "nurbsCurveEvaluator.h"
00030 #include "nurbsSurfaceEvaluator.h"
00031 #include "pta_LVecBase3.h"
00032
00033 class BulletSoftBodyConfig;
00034 class BulletSoftBodyMaterial;
00035 class BulletSoftBodyWorldInfo;
00036
00037
00038
00039
00040
00041 class BulletSoftBodyNodeElement {
00042
00043 PUBLISHED:
00044 INLINE ~BulletSoftBodyNodeElement();
00045 INLINE static BulletSoftBodyNodeElement empty();
00046
00047 INLINE LPoint3 get_pos() const;
00048 INLINE LVector3 get_velocity() const;
00049 INLINE LVector3 get_normal() const;
00050 INLINE PN_stdfloat get_inv_mass() const;
00051 INLINE PN_stdfloat get_area() const;
00052 INLINE int is_attached() const;
00053
00054 public:
00055 BulletSoftBodyNodeElement(btSoftBody::Node &node);
00056
00057 private:
00058 btSoftBody::Node &_node;
00059 };
00060
00061
00062
00063
00064
00065 class EXPCL_PANDABULLET BulletSoftBodyNode : public BulletBodyNode {
00066
00067 public:
00068 BulletSoftBodyNode(btSoftBody *body, const char *name="softbody");
00069
00070 PUBLISHED:
00071 INLINE ~BulletSoftBodyNode();
00072
00073 BulletSoftBodyConfig get_cfg();
00074 BulletSoftBodyWorldInfo get_world_info();
00075
00076 void generate_bending_constraints(int distance, BulletSoftBodyMaterial *material=NULL);
00077 void randomize_constraints();
00078
00079
00080 void set_volume_mass(PN_stdfloat mass);
00081 void set_volume_density(PN_stdfloat density);
00082 void set_total_mass(PN_stdfloat mass, bool fromfaces=false);
00083 void set_total_density(PN_stdfloat density);
00084 void set_mass(int node, PN_stdfloat mass);
00085
00086 PN_stdfloat get_mass(int node) const;
00087 PN_stdfloat get_total_mass() const;
00088 PN_stdfloat get_volume() const;
00089
00090
00091 void add_force(const LVector3 &force);
00092 void add_force(const LVector3 &force, int node);
00093
00094 void set_velocity(const LVector3 &velocity);
00095 void add_velocity(const LVector3 &velocity);
00096 void add_velocity(const LVector3 &velocity, int node);
00097
00098 void set_pose(bool bvolume, bool bframe);
00099
00100 BoundingBox get_aabb() const;
00101
00102
00103 void generate_clusters(int k, int maxiterations=8192);
00104 void release_cluster(int index);
00105 void release_clusters();
00106 int get_num_clusters() const;
00107 LVecBase3 cluster_com(int cluster) const;
00108
00109
00110 void link_geom(Geom *geom);
00111 void unlink_geom();
00112
00113 void link_curve(NurbsCurveEvaluator *curve);
00114 void unlink_curve();
00115
00116 void link_surface(NurbsSurfaceEvaluator *surface);
00117 void unlink_surface();
00118
00119
00120 void append_anchor(int node, BulletRigidBodyNode *body,
00121 bool disable=false);
00122 void append_anchor(int node, BulletRigidBodyNode *body,
00123 const LVector3 &pivot,
00124 bool disable=false);
00125
00126
00127 int get_num_materials() const;
00128 BulletSoftBodyMaterial get_material(int idx) const;
00129 MAKE_SEQ(get_materials, get_num_materials, get_material);
00130
00131 BulletSoftBodyMaterial append_material();
00132
00133
00134 int get_num_nodes() const;
00135 BulletSoftBodyNodeElement get_node(int idx) const;
00136 MAKE_SEQ(get_nodes, get_num_nodes, get_node);
00137
00138 int get_closest_node_index(LVecBase3 point, bool local);
00139
00140
00141 static PT(BulletSoftBodyNode) make_rope(
00142 BulletSoftBodyWorldInfo &info,
00143 const LPoint3 &from,
00144 const LPoint3 &to,
00145 int res,
00146 int fixeds);
00147
00148 static PT(BulletSoftBodyNode) make_patch(
00149 BulletSoftBodyWorldInfo &info,
00150 const LPoint3 &corner00,
00151 const LPoint3 &corner10,
00152 const LPoint3 &corner01,
00153 const LPoint3 &corner11,
00154 int resx,
00155 int resy,
00156 int fixeds,
00157 bool gendiags);
00158
00159 static PT(BulletSoftBodyNode) make_ellipsoid(
00160 BulletSoftBodyWorldInfo &info,
00161 const LPoint3 ¢er,
00162 const LVecBase3 &radius,
00163 int res);
00164
00165 static PT(BulletSoftBodyNode) make_tri_mesh(
00166 BulletSoftBodyWorldInfo &info,
00167 const Geom *geom,
00168 bool randomizeConstraints=true);
00169
00170 static PT(BulletSoftBodyNode) make_tri_mesh(
00171 BulletSoftBodyWorldInfo &info,
00172 PTA_LVecBase3 points,
00173 PTA_int indices,
00174 bool randomizeConstraints=true);
00175
00176 static PT(BulletSoftBodyNode) make_tet_mesh(
00177 BulletSoftBodyWorldInfo &info,
00178 PTA_LVecBase3 points,
00179 PTA_int indices,
00180 bool tetralinks=true);
00181
00182 static PT(BulletSoftBodyNode) make_tet_mesh(
00183 BulletSoftBodyWorldInfo &info,
00184 const char *ele,
00185 const char *face,
00186 const char *node);
00187
00188 public:
00189 virtual btCollisionObject *get_object() const;
00190
00191 void sync_p2b();
00192 void sync_b2p();
00193
00194 protected:
00195 virtual void transform_changed();
00196
00197 private:
00198 btSoftBody *_soft;
00199
00200 CPT(TransformState) _sync;
00201 bool _sync_disable;
00202
00203 PT(Geom) _geom;
00204 PT(NurbsCurveEvaluator) _curve;
00205 PT(NurbsSurfaceEvaluator) _surface;
00206
00207 static int get_point_index(LVecBase3 p, PTA_LVecBase3 points);
00208 static int next_line(const char *buffer);
00209
00210
00211 public:
00212 static TypeHandle get_class_type() {
00213 return _type_handle;
00214 }
00215 static void init_type() {
00216 BulletBodyNode::init_type();
00217 register_type(_type_handle, "BulletSoftBodyNode",
00218 BulletBodyNode::get_class_type());
00219 }
00220 virtual TypeHandle get_type() const {
00221 return get_class_type();
00222 }
00223 virtual TypeHandle force_init_type() {
00224 init_type();
00225 return get_class_type();
00226 }
00227
00228 private:
00229 static TypeHandle _type_handle;
00230 };
00231
00232 #include "bulletSoftBodyNode.I"
00233
00234 #endif // __BULLET_SOFT_BODY_NODE_H__
00235