From 0b7c4db5ee5aadcbd90761ef976f285e09ae66d7 Mon Sep 17 00:00:00 2001 From: Andrea Catania Date: Thu, 7 Jun 2018 15:46:17 +0200 Subject: Added functions to get trimesh info --- core/math/triangle_mesh.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'core/math/triangle_mesh.cpp') diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index edd4ad344..0dd1cbf1c 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 *r_triangles_indices) const { + + if (!valid) + return; + + const int triangles_num = triangles.size(); + + // Parse vertices indices + PoolVector::Read triangles_read = triangles.read(); + + r_triangles_indices->resize(triangles_num * 3); + PoolVector::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 &p_faces) { valid = false; -- cgit v1.2.3-70-g09d2