From e6962729d570d99f04ccfac245585b066722f87e Mon Sep 17 00:00:00 2001 From: Lyuma Date: Sun, 22 Aug 2021 18:11:57 -0700 Subject: [PATCH] Implement set_surface_material and set_surface_name methods in EditorSceneImporterMesh, and add documentation. --- doc/classes/ArrayMesh.xml | 1 + doc/classes/EditorSceneImporterMesh.xml | 45 ++++++++++++++++++++++++- editor/import/scene_importer_mesh.cpp | 14 ++++++-- editor/import/scene_importer_mesh.h | 3 +- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index 637b9a9f16..670a25ab83 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -115,6 +115,7 @@ + Sets the name of the blend shape at this index. diff --git a/doc/classes/EditorSceneImporterMesh.xml b/doc/classes/EditorSceneImporterMesh.xml index 3a9eea87bb..b0f233da2f 100644 --- a/doc/classes/EditorSceneImporterMesh.xml +++ b/doc/classes/EditorSceneImporterMesh.xml @@ -1,8 +1,12 @@ + A [Resource] that contains vertex array-based geometry during the import process. + EditorSceneImporterMesh is a type of [Resource] analogous to [ArrayMesh]. It contains vertex array-based geometry, divided in [i]surfaces[/i]. Each surface contains a completely separate array and a material used to draw it. Design wise, a mesh with multiple surfaces is preferred to a single surface, because objects created in 3D editing software commonly contain multiple materials. + + Unlike its runtime counterpart, [EditorSceneImporterMesh] contains mesh data before various import steps, such as lod and shadow mesh generation, have taken place. Modify surface data by calling [method clear], followed by [method add_surface] for each surface. @@ -11,6 +15,7 @@ + Adds name for a blend shape that will be added with [method add_surface]. Must be called before surface is added. @@ -23,44 +28,56 @@ + Creates a new surface, analogous to [method ArrayMesh.add_surface_from_arrays]. + Surfaces are created to be rendered using a [code]primitive[/code], which may be any of the types defined in [enum Mesh.PrimitiveType]. (As a note, when using indices, it is recommended to only use points, lines, or triangles.) [method Mesh.get_surface_count] will become the [code]surf_idx[/code] for this new surface. + The [code]arrays[/code] argument is an array of arrays. See [enum Mesh.ArrayType] for the values used in this array. For example, [code]arrays[0][/code] is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array or be empty, except for [constant Mesh.ARRAY_INDEX] if it is used. + Removes all surfaces and blend shapes from this [EditorSceneImporterMesh]. + Returns the number of blend shapes that the mesh holds. + Returns the blend shape mode for this Mesh. + Returns the name of the blend shape at this index. + Returns the size hint of this mesh for lightmap-unwrapping in UV-space. - + + Returns the mesh data represented by this [EditorSceneImporterMesh] as a usable [ArrayMesh]. + This method caches the returned mesh, and subsequent calls will return the cached data until [method clear] is called. + If not yet cached and [code]base_mesh[/code] is provided, [code]base_mesh[/code] will be used and mutated. + Returns the arrays for the vertices, normals, uvs, etc. that make up the requested surface. See [method add_surface]. @@ -68,17 +85,20 @@ + Returns a single set of blend shape arrays for the requested blend shape index for a surface. + Returns the amount of surfaces that the mesh holds. + Returns the amount of lods that the mesh holds on a given surface. @@ -86,6 +106,7 @@ + Returns the index buffer of a lod for a surface. @@ -93,36 +114,58 @@ + Returns the screen ratio which activates a lod for a surface. + Returns a [Material] in a given surface. Surface is rendered using this material. + Gets the name assigned to this surface. + Returns the primitive type of the requested surface (see [method add_surface]). + Sets the blend shape mode to one of [enum Mesh.BlendShapeMode]. + Sets the size hint of this mesh for lightmap-unwrapping in UV-space. + + + + + + + + Sets a [Material] for a given surface. Surface will be rendered using this material. + + + + + + + + Sets a name for a given surface. diff --git a/editor/import/scene_importer_mesh.cpp b/editor/import/scene_importer_mesh.cpp index 0d14347225..06f373c54f 100644 --- a/editor/import/scene_importer_mesh.cpp +++ b/editor/import/scene_importer_mesh.cpp @@ -110,6 +110,12 @@ String EditorSceneImporterMesh::get_surface_name(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), String()); return surfaces[p_surface].name; } +void EditorSceneImporterMesh::set_surface_name(int p_surface, const String &p_name) { + ERR_FAIL_INDEX(p_surface, surfaces.size()); + surfaces.write[p_surface].name = p_name; + mesh.unref(); +} + Array EditorSceneImporterMesh::get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); ERR_FAIL_INDEX_V(p_blend_shape, surfaces[p_surface].blend_shape_data.size(), Array()); @@ -140,6 +146,7 @@ Ref EditorSceneImporterMesh::get_surface_material(int p_surface) const void EditorSceneImporterMesh::set_surface_material(int p_surface, const Ref &p_material) { ERR_FAIL_INDEX(p_surface, surfaces.size()); surfaces.write[p_surface].material = p_material; + mesh.unref(); } Basis EditorSceneImporterMesh::compute_rotation_matrix_from_ortho_6d(Vector3 p_x_raw, Vector3 p_y_raw) { @@ -244,7 +251,7 @@ bool EditorSceneImporterMesh::has_mesh() const { return mesh.is_valid(); } -Ref EditorSceneImporterMesh::get_mesh(const Ref &p_base) { +Ref EditorSceneImporterMesh::get_mesh(const Ref &p_base) { ERR_FAIL_COND_V(surfaces.size() == 0, Ref()); if (mesh.is_null()) { @@ -838,7 +845,10 @@ void EditorSceneImporterMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_surface_lod_indices", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_indices); ClassDB::bind_method(D_METHOD("get_surface_material", "surface_idx"), &EditorSceneImporterMesh::get_surface_material); - ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMesh::get_mesh); + ClassDB::bind_method(D_METHOD("set_surface_name", "surface_idx", "name"), &EditorSceneImporterMesh::set_surface_name); + ClassDB::bind_method(D_METHOD("set_surface_material", "surface_idx", "material"), &EditorSceneImporterMesh::set_surface_material); + + ClassDB::bind_method(D_METHOD("get_mesh", "base_mesh"), &EditorSceneImporterMesh::get_mesh, DEFVAL(Ref())); ClassDB::bind_method(D_METHOD("clear"), &EditorSceneImporterMesh::clear); ClassDB::bind_method(D_METHOD("_set_data", "data"), &EditorSceneImporterMesh::_set_data); diff --git a/editor/import/scene_importer_mesh.h b/editor/import/scene_importer_mesh.h index 2488de7ed0..e57e479d8e 100644 --- a/editor/import/scene_importer_mesh.h +++ b/editor/import/scene_importer_mesh.h @@ -88,6 +88,7 @@ public: Mesh::PrimitiveType get_surface_primitive_type(int p_surface); String get_surface_name(int p_surface) const; + void set_surface_name(int p_surface, const String &p_name); Array get_surface_arrays(int p_surface) const; Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const; int get_surface_lod_count(int p_surface) const; @@ -112,7 +113,7 @@ public: Size2i get_lightmap_size_hint() const; bool has_mesh() const; - Ref get_mesh(const Ref &p_base = Ref()); + Ref get_mesh(const Ref &p_base = Ref()); void clear(); }; #endif // EDITOR_SCENE_IMPORTER_MESH_H