summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-06-08 08:31:10 +0200
committerGitHub <noreply@github.com>2018-06-08 08:31:10 +0200
commit185ac7acd9eae17c5d4c14c43052379ec96d9215 (patch)
treeaa8dc573d5528f35049b340ba397b72c6fddd98b
parenta6c9b11de13181d02c67e23fdfb9ded72cb45669 (diff)
parent0b7c4db5ee5aadcbd90761ef976f285e09ae66d7 (diff)
Merge pull request #19407 from AndreaCatania/impTriMesh
Added functions to get trimesh info
-rw-r--r--core/math/triangle_mesh.cpp20
-rw-r--r--core/math/triangle_mesh.h4
2 files changed, 24 insertions, 0 deletions
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index edd4ad3441..0dd1cbf1c3 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -88,6 +88,26 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
return index;
}
+void TriangleMesh::get_indices(PoolVector<int> *r_triangles_indices) const {
+
+ if (!valid)
+ return;
+
+ const int triangles_num = triangles.size();
+
+ // Parse vertices indices
+ PoolVector<Triangle>::Read triangles_read = triangles.read();
+
+ r_triangles_indices->resize(triangles_num * 3);
+ PoolVector<int>::Write r_indices_write = r_triangles_indices->write();
+
+ for (int i = 0; i < triangles_num; ++i) {
+ r_indices_write[3 * i + 0] = triangles_read[i].indices[0];
+ r_indices_write[3 * i + 1] = triangles_read[i].indices[1];
+ r_indices_write[3 * i + 2] = triangles_read[i].indices[2];
+ }
+}
+
void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
valid = false;
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index 9f145f2afb..78de7ae7ee 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -92,6 +92,10 @@ public:
Vector3 get_area_normal(const AABB &p_aabb) const;
PoolVector<Face3> get_faces() const;
+ PoolVector<Triangle> get_triangles() const { return triangles; }
+ PoolVector<Vector3> get_vertices() const { return vertices; }
+ void get_indices(PoolVector<int> *p_triangles_indices) const;
+
void create(const PoolVector<Vector3> &p_faces);
TriangleMesh();
};