diff --git a/panda/src/bullet/bulletTriangleMesh.I b/panda/src/bullet/bulletTriangleMesh.I index 33b9b9bf47..b6965303aa 100644 --- a/panda/src/bullet/bulletTriangleMesh.I +++ b/panda/src/bullet/bulletTriangleMesh.I @@ -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]); +} + /** * */ diff --git a/panda/src/bullet/bulletTriangleMesh.cxx b/panda/src/bullet/bulletTriangleMesh.cxx index 8a74e61ff5..3138e28efd 100644 --- a/panda/src/bullet/bulletTriangleMesh.cxx +++ b/panda/src/bullet/bulletTriangleMesh.cxx @@ -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; } diff --git a/panda/src/bullet/bulletTriangleMesh.h b/panda/src/bullet/bulletTriangleMesh.h index 2c3b5c0626..64973d83e8 100644 --- a/panda/src/bullet/bulletTriangleMesh.h +++ b/panda/src/bullet/bulletTriangleMesh.h @@ -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;