Added a method to find the index for a surface with a given name

This commit is contained in:
Bastiaan Olij 2018-07-28 10:34:31 +10:00
parent aecc3a444b
commit d41a4089c6
3 changed files with 33 additions and 1 deletions

View file

@ -40,18 +40,21 @@
<return type="void"> <return type="void">
</return> </return>
<description> <description>
Centers the geometry.
</description> </description>
</method> </method>
<method name="clear_blend_shapes"> <method name="clear_blend_shapes">
<return type="void"> <return type="void">
</return> </return>
<description> <description>
Remove all blend shapes from this [code]ArrayMesh[/code].
</description> </description>
</method> </method>
<method name="get_blend_shape_count" qualifiers="const"> <method name="get_blend_shape_count" qualifiers="const">
<return type="int"> <return type="int">
</return> </return>
<description> <description>
Returns the number of blend shapes that the [code]ArrayMesh[/code] holds.
</description> </description>
</method> </method>
<method name="get_blend_shape_name" qualifiers="const"> <method name="get_blend_shape_name" qualifiers="const">
@ -60,6 +63,7 @@
<argument index="0" name="index" type="int"> <argument index="0" name="index" type="int">
</argument> </argument>
<description> <description>
Returns the name of the blend shape at this index.
</description> </description>
</method> </method>
<method name="get_surface_count" qualifiers="const"> <method name="get_surface_count" qualifiers="const">
@ -77,12 +81,23 @@
<argument index="1" name="arg1" type="float"> <argument index="1" name="arg1" type="float">
</argument> </argument>
<description> <description>
Will perform a UV unwrap on the [code]ArrayMesh[/code] to prepare the mesh for lightmapping.
</description> </description>
</method> </method>
<method name="regen_normalmaps"> <method name="regen_normalmaps">
<return type="void"> <return type="void">
</return> </return>
<description> <description>
Will regenerate normal maps for the [code]ArrayMesh[/code].
</description>
</method>
<method name="surface_find_by_name" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="name" type="String">
</argument>
<description>
Return the index of the first surface with this name held within this [code]ArrayMesh[/code]. If none are found -1 is returned.
</description> </description>
</method> </method>
<method name="surface_get_array_index_len" qualifiers="const"> <method name="surface_get_array_index_len" qualifiers="const">
@ -109,6 +124,7 @@
<argument index="0" name="surf_idx" type="int"> <argument index="0" name="surf_idx" type="int">
</argument> </argument>
<description> <description>
Returns the arrays for the vertices, normals, uvs, etc. that make up the requested surface (see [method add_surface_from_arrays]).
</description> </description>
</method> </method>
<method name="surface_get_blend_shape_arrays" qualifiers="const"> <method name="surface_get_blend_shape_arrays" qualifiers="const">
@ -117,6 +133,7 @@
<argument index="0" name="surf_idx" type="int"> <argument index="0" name="surf_idx" type="int">
</argument> </argument>
<description> <description>
Returns the blend shape arrays for the requested surface.
</description> </description>
</method> </method>
<method name="surface_get_format" qualifiers="const"> <method name="surface_get_format" qualifiers="const">
@ -143,6 +160,7 @@
<argument index="0" name="surf_idx" type="int"> <argument index="0" name="surf_idx" type="int">
</argument> </argument>
<description> <description>
Get the name assigned to this surface.
</description> </description>
</method> </method>
<method name="surface_get_primitive_type" qualifiers="const"> <method name="surface_get_primitive_type" qualifiers="const">
@ -171,6 +189,7 @@
<argument index="1" name="material" type="Material"> <argument index="1" name="material" type="Material">
</argument> </argument>
<description> <description>
Set a [Material] for a given surface. Surface will be rendered using this material.
</description> </description>
</method> </method>
<method name="surface_set_name"> <method name="surface_set_name">
@ -181,7 +200,7 @@
<argument index="1" name="name" type="String"> <argument index="1" name="name" type="String">
</argument> </argument>
<description> <description>
Set a [Material] for a given surface. Surface will be rendered using this material. Set a name for a given surface.
</description> </description>
</method> </method>
<method name="surface_update_region"> <method name="surface_update_region">
@ -201,6 +220,7 @@
<member name="blend_shape_mode" type="int" setter="set_blend_shape_mode" getter="get_blend_shape_mode" enum="Mesh.BlendShapeMode"> <member name="blend_shape_mode" type="int" setter="set_blend_shape_mode" getter="get_blend_shape_mode" enum="Mesh.BlendShapeMode">
</member> </member>
<member name="custom_aabb" type="AABB" setter="set_custom_aabb" getter="get_custom_aabb"> <member name="custom_aabb" type="AABB" setter="set_custom_aabb" getter="get_custom_aabb">
An overriding bounding box for this mesh.
</member> </member>
</members> </members>
<constants> <constants>

View file

@ -966,6 +966,16 @@ void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material)
emit_changed(); 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) { void ArrayMesh::surface_set_name(int p_idx, const String &p_name) {
ERR_FAIL_INDEX(p_idx, surfaces.size()); 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_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_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_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_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_name", "surf_idx"), &ArrayMesh::surface_get_name);
ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &ArrayMesh::surface_get_arrays); ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &ArrayMesh::surface_get_arrays);

View file

@ -212,6 +212,7 @@ public:
void surface_set_material(int p_idx, const Ref<Material> &p_material); void surface_set_material(int p_idx, const Ref<Material> &p_material);
Ref<Material> surface_get_material(int p_idx) const; 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); void surface_set_name(int p_idx, const String &p_name);
String surface_get_name(int p_idx) const; String surface_get_name(int p_idx) const;