Parcourir la source

bullet: add interface to access BulletTriangleMesh vertices/triangles

rdb il y a 8 ans
Parent
commit
407c8e8712

+ 28 - 0
panda/src/bullet/bulletTriangleMesh.I

@@ -19,6 +19,34 @@ ptr() const {
   return (btStridingMeshInterface *)&_mesh;
   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]);
+}
+
 /**
 /**
  *
  *
  */
  */

+ 1 - 1
panda/src/bullet/bulletTriangleMesh.cxx

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

+ 11 - 2
panda/src/bullet/bulletTriangleMesh.h

@@ -48,15 +48,24 @@ PUBLISHED:
   void set_welding_distance(PN_stdfloat distance);
   void set_welding_distance(PN_stdfloat distance);
   void preallocate(int num_verts, int num_indices);
   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;
   PN_stdfloat get_welding_distance() const;
 
 
   virtual void output(ostream &out) const;
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, int indent_level) 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_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:
 public:
   INLINE btStridingMeshInterface *ptr() const;
   INLINE btStridingMeshInterface *ptr() const;