15 #include "bulletTriangleMesh.h" 18 #include "geomVertexData.h" 19 #include "geomVertexReader.h" 29 BulletTriangleMesh() {
31 _mesh =
new btTriangleMesh();
39 int BulletTriangleMesh::
40 get_num_triangles()
const {
42 return _mesh->getNumTriangles();
50 void BulletTriangleMesh::
51 preallocate(
int num_verts,
int num_indices) {
53 _mesh->preallocateVertices(num_verts);
54 _mesh->preallocateIndices(num_indices);
62 void BulletTriangleMesh::
63 add_triangle(
const LPoint3 &p0,
const LPoint3 &p1,
const LPoint3 &p2,
bool remove_duplicate_vertices) {
70 LVecBase3_to_btVector3(p0),
71 LVecBase3_to_btVector3(p1),
72 LVecBase3_to_btVector3(p2),
73 remove_duplicate_vertices);
81 void BulletTriangleMesh::
82 set_welding_distance(PN_stdfloat distance) {
84 _mesh->m_weldingThreshold = distance;
92 PN_stdfloat BulletTriangleMesh::
93 get_welding_distance()
const {
95 return _mesh->m_weldingThreshold;
103 void BulletTriangleMesh::
104 add_geom(
const Geom *geom,
bool remove_duplicate_vertices,
const TransformState *ts) {
122 btVector3 *vertices =
new btVector3[points.size()];
126 for (it=points.begin(); it!=points.end(); it++) {
128 vertices[i] = LVecBase3_to_btVector3(v);
133 for (
int k=0; k<geom->get_num_primitives(); k++) {
136 prim = prim->decompose();
138 for (
int l=0; l<prim->get_num_primitives(); l++) {
140 int s = prim->get_primitive_start(l);
141 int e = prim->get_primitive_end(l);
143 nassertv(e - s == 3);
145 btVector3 v0 = vertices[prim->get_vertex(s)];
146 btVector3 v1 = vertices[prim->get_vertex(s+1)];
147 btVector3 v2 = vertices[prim->get_vertex(s+2)];
149 _mesh->addTriangle(v0, v1, v2, remove_duplicate_vertices);
161 void BulletTriangleMesh::
162 add_array(
const PTA_LVecBase3 &points,
const PTA_int &indices,
bool remove_duplicate_vertices) {
165 btVector3 *vertices =
new btVector3[points.size()];
168 PTA_LVecBase3::const_iterator it;
169 for (it=points.begin(); it!=points.end(); it++) {
171 vertices[i] = LVecBase3_to_btVector3(v);
177 while (j+2 < (
int)indices.size()) {
179 btVector3 v0 = vertices[indices[j++]];
180 btVector3 v1 = vertices[indices[j++]];
181 btVector3 v2 = vertices[indices[j++]];
183 _mesh->addTriangle(v0, v1, v2, remove_duplicate_vertices);
194 void BulletTriangleMesh::
195 output(ostream &out)
const {
197 out << get_type() <<
", " << _mesh->getNumTriangles();
205 void BulletTriangleMesh::
206 write(ostream &out,
int indent_level)
const {
208 indent(out, indent_level) << get_type() <<
":" << endl;
210 IndexedMeshArray& array = _mesh->getIndexedMeshArray();
211 for (
int i=0; i < array.size(); i++) {
212 indent(out, indent_level + 2) <<
"IndexedMesh " << i <<
":" << endl;
213 btIndexedMesh meshPart = array.at(i);
215 indent(out, indent_level + 4) <<
"num triangles:" << meshPart.m_numTriangles << endl;
216 indent(out, indent_level + 4) <<
"num vertices:" << meshPart.m_numVertices << endl;
This is the base class for all three-component vectors and points.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
LVecBase3f xform_point(const LVecBase3f &v) const
The matrix transforms a 3-component point (including translation component) and returns the result...
This is a 4-by-4 transform matrix.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
const LVecBase3 & get_data3()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
bool is_at_end() const
Returns true if the reader is currently at the end of the list of vertices, false otherwise...
TypeHandle is the identifier used to differentiate C++ class types.