00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "bulletTriangleMeshShape.h"
00016 #include "bulletTriangleMesh.h"
00017
00018 #include "nodePathCollection.h"
00019 #include "geomNode.h"
00020 #include "geomVertexReader.h"
00021
00022 TypeHandle BulletTriangleMeshShape::_type_handle;
00023
00024
00025
00026
00027
00028
00029
00030 BulletTriangleMeshShape::
00031 BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, bool bvh) {
00032
00033
00034 if (!mesh) {
00035 bullet_cat.warning() << "mesh is NULL! creating new mesh." << endl;
00036 mesh = new BulletTriangleMesh();
00037 }
00038
00039
00040 if (mesh->get_num_triangles() == 0) {
00041 bullet_cat.warning() << "mesh has zero triangles! adding degenerated triangle." << endl;
00042 mesh->add_triangle(LPoint3::zero(), LPoint3::zero(), LPoint3::zero());
00043 }
00044
00045
00046 _mesh = mesh;
00047
00048
00049 if (dynamic) {
00050
00051 _gimpact_shape = new btGImpactMeshShape(mesh->ptr());
00052 _gimpact_shape->updateBound();
00053 _gimpact_shape->setUserPointer(this);
00054
00055 _bvh_shape = NULL;
00056 }
00057
00058
00059 else {
00060
00061 _bvh_shape = new btBvhTriangleMeshShape(mesh->ptr(), compress, bvh);
00062 _bvh_shape->setUserPointer(this);
00063
00064 _gimpact_shape = NULL;
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073 btCollisionShape *BulletTriangleMeshShape::
00074 ptr() const {
00075
00076 if (_bvh_shape) {
00077 return _bvh_shape;
00078 }
00079
00080 if (_gimpact_shape) {
00081 return _gimpact_shape;
00082 }
00083
00084 return NULL;
00085 }
00086
00087
00088
00089
00090
00091
00092 void BulletTriangleMeshShape::
00093 refit_tree(const LPoint3 &aabb_min, const LPoint3 &aabb_max) {
00094
00095 nassertv(!aabb_max.is_nan());
00096 nassertv(!aabb_max.is_nan());
00097
00098 nassertv(this->is_static());
00099
00100 _bvh_shape->refitTree(LVecBase3_to_btVector3(aabb_min),
00101 LVecBase3_to_btVector3(aabb_max));
00102 }
00103