summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/resources/mesh.cpp11
-rw-r--r--scene/resources/mesh.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index e74ad2e55b..4e6004709e 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<Material> &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 2127eaae4c..36bfca49f8 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<Material> &p_material);
Ref<Material> 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;