From d41a4089c642584ff97b12e2f1321fea7591573d Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Sat, 28 Jul 2018 10:34:31 +1000 Subject: [PATCH] Added a method to find the index for a surface with a given name --- doc/classes/ArrayMesh.xml | 22 +++++++++++++++++++++- scene/resources/mesh.cpp | 11 +++++++++++ scene/resources/mesh.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index d805629b3d4..5ccf0b55aa3 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -40,18 +40,21 @@ + Centers the geometry. + Remove all blend shapes from this [code]ArrayMesh[/code]. + Returns the number of blend shapes that the [code]ArrayMesh[/code] holds. @@ -60,6 +63,7 @@ + Returns the name of the blend shape at this index. @@ -77,12 +81,23 @@ + Will perform a UV unwrap on the [code]ArrayMesh[/code] to prepare the mesh for lightmapping. + Will regenerate normal maps for the [code]ArrayMesh[/code]. + + + + + + + + + Return the index of the first surface with this name held within this [code]ArrayMesh[/code]. If none are found -1 is returned. @@ -109,6 +124,7 @@ + Returns the arrays for the vertices, normals, uvs, etc. that make up the requested surface (see [method add_surface_from_arrays]). @@ -117,6 +133,7 @@ + Returns the blend shape arrays for the requested surface. @@ -143,6 +160,7 @@ + Get the name assigned to this surface. @@ -171,6 +189,7 @@ + Set a [Material] for a given surface. Surface will be rendered using this material. @@ -181,7 +200,7 @@ - Set a [Material] for a given surface. Surface will be rendered using this material. + Set a name for a given surface. @@ -201,6 +220,7 @@ + An overriding bounding box for this mesh. diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index e74ad2e55b1..4e6004709eb 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -966,6 +966,16 @@ void ArrayMesh::surface_set_material(int p_idx, const Ref &p_material) emit_changed(); } +int ArrayMesh::surface_find_by_name(const String &p_name) const { + for (int i = 0; i < surfaces.size(); i++) { + if (surfaces[i].name == p_name) { + return i; + } + } + + return -1; +} + void ArrayMesh::surface_set_name(int p_idx, const String &p_name) { ERR_FAIL_INDEX(p_idx, surfaces.size()); @@ -1312,6 +1322,7 @@ void ArrayMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("surface_get_primitive_type", "surf_idx"), &ArrayMesh::surface_get_primitive_type); ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material"), &ArrayMesh::surface_set_material); ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &ArrayMesh::surface_get_material); + ClassDB::bind_method(D_METHOD("surface_find_by_name", "name"), &ArrayMesh::surface_find_by_name); ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name); ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name); ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &ArrayMesh::surface_get_arrays); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 2127eaae4c9..36bfca49f86 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -212,6 +212,7 @@ public: void surface_set_material(int p_idx, const Ref &p_material); Ref surface_get_material(int p_idx) const; + int surface_find_by_name(const String &p_name) const; void surface_set_name(int p_idx, const String &p_name); String surface_get_name(int p_idx) const;