From 17ebbfb56de980c5529c8a02a12141dd7bb766c8 Mon Sep 17 00:00:00 2001 From: AndreaCatania Date: Tue, 21 Nov 2017 01:36:32 +0100 Subject: Implemented Soft body - Soft Body Physics node - Soft Body Rendering - Soft body Editor - Soft body importer --- scene/resources/mesh.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'scene/resources/mesh.cpp') diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index b0620d3363..fe87dcdd2c 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -40,7 +40,6 @@ void Mesh::_clear_triangle_mesh() const { triangle_mesh.unref(); - ; } Ref Mesh::generate_triangle_mesh() const { @@ -110,6 +109,54 @@ Ref Mesh::generate_triangle_mesh() const { return triangle_mesh; } +void Mesh::generate_debug_mesh_lines(Vector &r_lines) { + + Ref tm = generate_triangle_mesh(); + if (tm.is_null()) + return; + + PoolVector triangle_indices; + tm->get_indices(&triangle_indices); + const int triangles_num = tm->get_triangles().size(); + PoolVector vertices = tm->get_vertices(); + + r_lines.resize(tm->get_triangles().size() * 6); // 3 lines x 2 points each line + + PoolVector::Read ind_r = triangle_indices.read(); + PoolVector::Read ver_r = vertices.read(); + for (int j = 0, x = 0, i = 0; i < triangles_num; j += 6, x += 3, ++i) { + // Triangle line 1 + r_lines[j + 0] = ver_r[ind_r[x + 0]]; + r_lines[j + 1] = ver_r[ind_r[x + 1]]; + + // Triangle line 2 + r_lines[j + 2] = ver_r[ind_r[x + 1]]; + r_lines[j + 3] = ver_r[ind_r[x + 2]]; + + // Triangle line 3 + r_lines[j + 4] = ver_r[ind_r[x + 2]]; + r_lines[j + 5] = ver_r[ind_r[x + 0]]; + } +} +void Mesh::generate_debug_mesh_indices(Vector &r_points) { + Ref tm = generate_triangle_mesh(); + if (tm.is_null()) + return; + + PoolVector vertices = tm->get_vertices(); + + int vertices_size = vertices.size(); + r_points.resize(vertices_size); + for (int i = 0; i < vertices_size; ++i) { + r_points[i] = vertices[i]; + } +} + +bool Mesh::surface_is_softbody_friendly(int p_idx) const { + const uint32_t surface_format = surface_get_format(p_idx); + return (surface_format & Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE && (!(surface_format & Mesh::ARRAY_COMPRESS_VERTEX)) && (!(surface_format & Mesh::ARRAY_COMPRESS_NORMAL))); +} + PoolVector Mesh::get_faces() const { Ref tm = generate_triangle_mesh(); @@ -484,6 +531,10 @@ void Mesh::_bind_methods() { BIND_ENUM_CONSTANT(ARRAY_MAX); } +void Mesh::clear_cache() { + _clear_triangle_mesh(); +} + Mesh::Mesh() { } -- cgit v1.2.3