From 40b81339d098d04003ea474aa7690e42bd858091 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 4 Dec 2020 19:26:29 -0500 Subject: [PATCH] Rebind Mesh/ArrayMesh enums --- doc/classes/ArrayMesh.xml | 10 +++++-- doc/classes/Mesh.xml | 28 ++++++++----------- doc/classes/RenderingServer.xml | 2 +- editor/import/editor_import_collada.cpp | 4 +-- editor/import/editor_scene_importer_gltf.cpp | 2 +- .../assimp/editor_scene_importer_assimp.cpp | 2 +- scene/resources/mesh.cpp | 6 ++-- scene/resources/mesh.h | 13 +++++---- 8 files changed, 35 insertions(+), 32 deletions(-) diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index 3f9083ed6eb..ef33d7ea776 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -209,13 +209,19 @@ - - Sets the blend shape mode to one of [enum Mesh.BlendShapeMode]. + + Sets the blend shape mode to one of [enum ArrayMesh.BlendShapeMode]. Overrides the [AABB] with one defined by user for use with frustum culling. Especially useful to avoid unexpected culling when using a shader to offset vertices. + + Blend shapes are normalized. + + + Blend shapes are relative to base weight. + diff --git a/doc/classes/Mesh.xml b/doc/classes/Mesh.xml index e6643ef578e..dff4b4f7ab7 100644 --- a/doc/classes/Mesh.xml +++ b/doc/classes/Mesh.xml @@ -126,29 +126,23 @@ Render array as triangle strips. - - Blend shapes are normalized. - - - Blend shapes are relative to base weight. - - Array of vertices. + [PackedVector3Array], [PackedVector2Array], or [Array] of vertex positions. - Array of normals. + [PackedVector3Array] of vertex normals. - Array of tangents as an array of floats, 4 floats per tangent. + [PackedFloat32Array] of vertex tangents. Each element in groups of 4 floats, first 3 floats determine the tangent, and the last the binormal direction as -1 or 1. - Array of colors. + [PackedColorArray] of vertex colors. - Array of UV coordinates. + [PackedVector2Array] for UV coordinates. - Array of second set of UV coordinates. + [PackedVector2Array] for second UV coordinates. @@ -159,13 +153,14 @@ - Array of bone data. + [PackedFloat32Array] or [PackedInt32Array] of bone indices. Each element is a group of 4 numbers. - Array of weights. + [PackedFloat32Array] of bone weights. Each element in groups of 4 floats. - Array of indices. + [PackedInt32Array] of integers used as indices referencing vertices, colors, normals, tangents, and textures. All of those arrays must have the same number of elements as the vertex array. No index can be beyond the vertex array size. When this index array is present, it puts the function into "index mode," where the index selects the *i*'th vertex, normal, tangent, color, UV, etc. This means if you want to have different normals or colors along an edge, you have to duplicate the vertices. + For triangles, the index array is interpreted as triples, referring to the vertices of each triangle. For lines, the index array is in pairs indicating the start and end of each line. Represents the size of the [enum ArrayType] enum. @@ -187,6 +182,7 @@ + Represents the size of the [enum ArrayCustomFormat] enum. Mesh array contains vertices. All meshes require a vertex array so this should always be present. @@ -223,7 +219,7 @@ Mesh array uses indices. - + diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index f36713a81a2..74eb6a17e5e 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -3123,7 +3123,7 @@ Flag used to mark an index array. - + diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 41099dc8ea1..b14dff711fb 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -470,9 +470,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p_me p_mesh->add_blend_shape(name); } if (p_morph_data->mode == "RELATIVE") { - p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_RELATIVE); + p_mesh->set_blend_shape_mode(ArrayMesh::BLEND_SHAPE_MODE_RELATIVE); } else if (p_morph_data->mode == "NORMALIZED") { - p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + p_mesh->set_blend_shape_mode(ArrayMesh::BLEND_SHAPE_MODE_NORMALIZED); } } diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index c1877895ce5..ac76f67ef99 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1112,7 +1112,7 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) { //ideally BLEND_SHAPE_MODE_RELATIVE since gltf2 stores in displacement //but it could require a larger refactor? - mesh.mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + mesh.mesh->set_blend_shape_mode(ArrayMesh::BLEND_SHAPE_MODE_NORMALIZED); if (j == 0) { const Array &target_names = extras.has("targetNames") ? (Array)extras["targetNames"] : Array(); diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index 21ba67ecd3e..796ee27a7dd 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -838,7 +838,7 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat String ai_anim_mesh_name = AssimpUtils::get_assimp_string(ai_mesh->mAnimMeshes[j]->mName); if (!morph_mesh_string_lookup.has(ai_anim_mesh_name)) { morph_mesh_string_lookup.insert(ai_anim_mesh_name, j); - mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); + mesh->set_blend_shape_mode(ArrayMesh::BLEND_SHAPE_MODE_NORMALIZED); if (ai_anim_mesh_name.empty()) { ai_anim_mesh_name = String("morph_") + itos(j); } diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index d12f92f8f79..c6815c8eccd 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -480,9 +480,6 @@ void Mesh::_bind_methods() { BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES); BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP); - BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED); - BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE); - BIND_ENUM_CONSTANT(ARRAY_VERTEX); BIND_ENUM_CONSTANT(ARRAY_NORMAL); BIND_ENUM_CONSTANT(ARRAY_TANGENT); @@ -1615,6 +1612,9 @@ void ArrayMesh::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_surfaces", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_surfaces", "_get_surfaces"); ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_shape_mode", PROPERTY_HINT_ENUM, "Normalized,Relative"), "set_blend_shape_mode", "get_blend_shape_mode"); ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, ""), "set_custom_aabb", "get_custom_aabb"); + + BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED); + BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE); } void ArrayMesh::reload_from_file() { diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 659574c2c4b..ae2139a0cf0 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -125,11 +125,6 @@ public: PRIMITIVE_MAX = RenderingServer::PRIMITIVE_MAX, }; - enum BlendShapeMode { - BLEND_SHAPE_MODE_NORMALIZED = RS::BLEND_SHAPE_MODE_NORMALIZED, - BLEND_SHAPE_MODE_RELATIVE = RS::BLEND_SHAPE_MODE_RELATIVE, - }; - virtual int get_surface_count() const = 0; virtual int surface_get_array_len(int p_idx) const = 0; virtual int surface_get_array_index_len(int p_idx) const = 0; @@ -176,6 +171,12 @@ class ArrayMesh : public Mesh { Array _get_surfaces() const; void _set_surfaces(const Array &p_data); +public: + enum BlendShapeMode { + BLEND_SHAPE_MODE_NORMALIZED = RS::BLEND_SHAPE_MODE_NORMALIZED, + BLEND_SHAPE_MODE_RELATIVE = RS::BLEND_SHAPE_MODE_RELATIVE, + }; + private: struct Surface { uint32_t format; @@ -267,6 +268,6 @@ VARIANT_ENUM_CAST(Mesh::ArrayType); VARIANT_ENUM_CAST(Mesh::ArrayFormat); VARIANT_ENUM_CAST(Mesh::ArrayCustomFormat); VARIANT_ENUM_CAST(Mesh::PrimitiveType); -VARIANT_ENUM_CAST(Mesh::BlendShapeMode); +VARIANT_ENUM_CAST(ArrayMesh::BlendShapeMode); #endif