bullet: add interface to access BulletTriangleMesh vertices/triangles

This commit is contained in:
rdb 2017-10-20 19:53:02 +02:00
parent 8a35f360bd
commit 407c8e8712
3 changed files with 40 additions and 3 deletions

View File

@ -19,6 +19,34 @@ ptr() const {
return (btStridingMeshInterface *)&_mesh;
}
/**
* Returns the number of vertices in this triangle mesh.
*/
INLINE size_t BulletTriangleMesh::
get_num_vertices() const {
return _vertices.size();
}
/**
* Returns the vertex at the given vertex index.
*/
INLINE LPoint3 BulletTriangleMesh::
get_vertex(size_t index) const {
nassertr(index < _vertices.size(), LPoint3::zero());
const btVector3 &vertex = _vertices[index];
return LPoint3(vertex[0], vertex[1], vertex[2]);
}
/**
* Returns the vertex indices making up the given triangle index.
*/
INLINE LVecBase3i BulletTriangleMesh::
get_triangle(size_t index) const {
index *= 3;
nassertr(index + 2 < _indices.size(), LVecBase3i::zero());
return LVecBase3i(_indices[index], _indices[index + 1], _indices[index + 2]);
}
/**
*
*/

View File

@ -39,7 +39,7 @@ BulletTriangleMesh()
/**
* Returns the number of triangles in this triangle mesh.
*/
int BulletTriangleMesh::
size_t BulletTriangleMesh::
get_num_triangles() const {
return _indices.size() / 3;
}

View File

@ -48,15 +48,24 @@ PUBLISHED:
void set_welding_distance(PN_stdfloat distance);
void preallocate(int num_verts, int num_indices);
int get_num_triangles() const;
size_t get_num_triangles() const;
PN_stdfloat get_welding_distance() const;
virtual void output(ostream &out) const;
virtual void write(ostream &out, int indent_level) const;
MAKE_PROPERTY(num_triangles, get_num_triangles);
public:
INLINE size_t get_num_vertices() const;
INLINE LPoint3 get_vertex(size_t index) const;
INLINE LVecBase3i get_triangle(size_t index) const;
PUBLISHED:
MAKE_PROPERTY(welding_distance, get_welding_distance, set_welding_distance);
MAKE_SEQ_PROPERTY(vertices, get_num_vertices, get_vertex);
MAKE_SEQ_PROPERTY(triangles, get_num_triangles, get_triangle);
public:
INLINE btStridingMeshInterface *ptr() const;