diff options
Diffstat (limited to 'modules/fbx/data')
-rw-r--r-- | modules/fbx/data/fbx_material.cpp | 4 | ||||
-rw-r--r-- | modules/fbx/data/fbx_mesh_data.cpp | 35 | ||||
-rw-r--r-- | modules/fbx/data/fbx_mesh_data.h | 18 | ||||
-rw-r--r-- | modules/fbx/data/pivot_transform.cpp | 2 |
4 files changed, 32 insertions, 27 deletions
diff --git a/modules/fbx/data/fbx_material.cpp b/modules/fbx/data/fbx_material.cpp index 5995097b2f..d54ac86e9f 100644 --- a/modules/fbx/data/fbx_material.cpp +++ b/modules/fbx/data/fbx_material.cpp @@ -277,7 +277,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { } /// ALL below is related to properties - for (FBXDocParser::LazyPropertyMap::value_type iter : material->Props()->GetLazyProperties()) { + for (FBXDocParser::LazyPropertyMap::value_type iter : material->GetLazyProperties()) { const std::string name = iter.first; if (name.empty()) { @@ -317,7 +317,7 @@ Ref<StandardMaterial3D> FBXMaterial::import_material(ImportState &state) { ERR_CONTINUE_MSG(desc == PROPERTY_DESC_NOT_FOUND, "The FBX material parameter: `" + String(name.c_str()) + "` was not recognized. Please open an issue so we can add the support to it."); - const FBXDocParser::PropertyTable *tbl = material->Props(); + const FBXDocParser::PropertyTable *tbl = material; FBXDocParser::PropertyPtr prop = tbl->Get(name); ERR_CONTINUE_MSG(prop == nullptr, "This file may be corrupted because is not possible to extract the material parameter: " + String(name.c_str())); diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp index b088dd8640..304d1598f6 100644 --- a/modules/fbx/data/fbx_mesh_data.cpp +++ b/modules/fbx/data/fbx_mesh_data.cpp @@ -101,20 +101,6 @@ HashMap<int, Vector2> collect_uv(const Vector<VertexData<Vector2>> *p_data, Hash return collection; } -typedef int Vertex; -typedef int SurfaceId; -typedef int PolygonId; -typedef int DataIndex; - -struct SurfaceData { - Ref<SurfaceTool> surface_tool; - OrderedHashMap<Vertex, int> lookup_table; // proposed fix is to replace lookup_table[vertex_id] to give the position of the vertices_map[int] index. - LocalVector<Vertex> vertices_map; // this must be ordered the same as insertion <-- slow to do find() operation. - Ref<Material> material; - HashMap<PolygonId, Vector<DataIndex>> surface_polygon_vertex; - Array morphs; -}; - EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &state, const FBXDocParser::MeshGeometry *p_mesh_geometry, const FBXDocParser::Model *model, bool use_compression) { mesh_geometry = p_mesh_geometry; // todo: make this just use a uint64_t FBX ID this is a copy of our original materials unfortunately. @@ -307,11 +293,9 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s // Triangulate the various polygons and add the indices. for (const PolygonId *polygon_id = surface->surface_polygon_vertex.next(nullptr); polygon_id != nullptr; polygon_id = surface->surface_polygon_vertex.next(polygon_id)) { const Vector<DataIndex> *indices = surface->surface_polygon_vertex.getptr(*polygon_id); - triangulate_polygon( - surface->surface_tool, + surface, *indices, - surface->vertices_map, vertices); } } @@ -336,7 +320,7 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s morph_st->begin(Mesh::PRIMITIVE_TRIANGLES); for (unsigned int vi = 0; vi < surface->vertices_map.size(); vi += 1) { - const Vertex vertex = surface->vertices_map[vi]; + const Vertex &vertex = surface->vertices_map[vi]; add_vertex( state, morph_st, @@ -398,6 +382,9 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s EditorSceneImporterMeshNode3D *godot_mesh = memnew(EditorSceneImporterMeshNode3D); godot_mesh->set_mesh(mesh); + const String name = ImportUtils::FBXNodeToName(model->Name()); + godot_mesh->set_name(name); // hurry up compiling >.< + mesh->set_name("mesh3d-" + name); return godot_mesh; } @@ -816,8 +803,10 @@ void FBXMeshData::add_vertex( p_surface_tool->add_vertex((p_vertices_position[p_vertex] + p_morph_value) * p_scale); } -void FBXMeshData::triangulate_polygon(Ref<SurfaceTool> st, Vector<int> p_polygon_vertex, const Vector<Vertex> p_surface_vertex_map, const std::vector<Vector3> &p_vertices) const { +void FBXMeshData::triangulate_polygon(SurfaceData *surface, const Vector<int> &p_polygon_vertex, const std::vector<Vector3> &p_vertices) const { + Ref<SurfaceTool> st(surface->surface_tool); const int polygon_vertex_count = p_polygon_vertex.size(); + //const Vector<Vertex>& p_surface_vertex_map if (polygon_vertex_count == 1) { // point to triangle st->add_index(p_polygon_vertex[0]); @@ -856,9 +845,9 @@ void FBXMeshData::triangulate_polygon(Ref<SurfaceTool> st, Vector<int> p_polygon is_simple_convex = true; Vector3 first_vec; for (int i = 0; i < polygon_vertex_count; i += 1) { - const Vector3 p1 = p_vertices[p_surface_vertex_map[p_polygon_vertex[i]]]; - const Vector3 p2 = p_vertices[p_surface_vertex_map[p_polygon_vertex[(i + 1) % polygon_vertex_count]]]; - const Vector3 p3 = p_vertices[p_surface_vertex_map[p_polygon_vertex[(i + 2) % polygon_vertex_count]]]; + const Vector3 p1 = p_vertices[surface->vertices_map[p_polygon_vertex[i]]]; + const Vector3 p2 = p_vertices[surface->vertices_map[p_polygon_vertex[(i + 1) % polygon_vertex_count]]]; + const Vector3 p3 = p_vertices[surface->vertices_map[p_polygon_vertex[(i + 2) % polygon_vertex_count]]]; const Vector3 edge1 = p1 - p2; const Vector3 edge2 = p3 - p2; @@ -893,7 +882,7 @@ void FBXMeshData::triangulate_polygon(Ref<SurfaceTool> st, Vector<int> p_polygon std::vector<Vector3> poly_vertices(polygon_vertex_count); for (int i = 0; i < polygon_vertex_count; i += 1) { - poly_vertices[i] = p_vertices[p_surface_vertex_map[p_polygon_vertex[i]]]; + poly_vertices[i] = p_vertices[surface->vertices_map[p_polygon_vertex[i]]]; } const Vector3 poly_norm = get_poly_normal(poly_vertices); diff --git a/modules/fbx/data/fbx_mesh_data.h b/modules/fbx/data/fbx_mesh_data.h index 77510ff2ec..575f833584 100644 --- a/modules/fbx/data/fbx_mesh_data.h +++ b/modules/fbx/data/fbx_mesh_data.h @@ -32,6 +32,8 @@ #define FBX_MESH_DATA_H #include "core/templates/hash_map.h" +#include "core/templates/local_vector.h" +#include "core/templates/ordered_hash_map.h" #include "editor/import/resource_importer_scene.h" #include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/mesh_instance_3d.h" @@ -47,6 +49,20 @@ struct FBXMeshData; struct FBXBone; struct ImportState; +typedef int Vertex; +typedef int SurfaceId; +typedef int PolygonId; +typedef int DataIndex; + +struct SurfaceData { + Ref<SurfaceTool> surface_tool; + OrderedHashMap<Vertex, int> lookup_table; // proposed fix is to replace lookup_table[vertex_id] to give the position of the vertices_map[int] index. + LocalVector<Vertex> vertices_map; // this must be ordered the same as insertion <-- slow to do find() operation. + Ref<Material> material; + HashMap<PolygonId, Vector<DataIndex>> surface_polygon_vertex; + Array morphs; +}; + struct VertexWeightMapping { Vector<real_t> weights; Vector<int> bones; @@ -127,7 +143,7 @@ private: const Vector3 &p_morph_value = Vector3(), const Vector3 &p_morph_normal = Vector3()); - void triangulate_polygon(Ref<SurfaceTool> st, Vector<int> p_polygon_vertex, Vector<int> p_surface_vertex_map, const std::vector<Vector3> &p_vertices) const; + void triangulate_polygon(SurfaceData *surface, const Vector<int> &p_polygon_vertex, const std::vector<Vector3> &p_vertices) const; /// This function is responsible to convert the FBX polygon vertex to /// vertex index. diff --git a/modules/fbx/data/pivot_transform.cpp b/modules/fbx/data/pivot_transform.cpp index 1895af6f9f..f4055c830f 100644 --- a/modules/fbx/data/pivot_transform.cpp +++ b/modules/fbx/data/pivot_transform.cpp @@ -33,7 +33,7 @@ #include "tools/import_utils.h" void PivotTransform::ReadTransformChain() { - const FBXDocParser::PropertyTable *props = fbx_model->Props(); + const FBXDocParser::PropertyTable *props = fbx_model; const FBXDocParser::Model::RotOrder &rot = fbx_model->RotationOrder(); const FBXDocParser::TransformInheritance &inheritType = fbx_model->InheritType(); inherit_type = inheritType; // copy the inherit type we need it in the second step. |