summaryrefslogtreecommitdiff
path: root/modules/fbx/data/fbx_mesh_data.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/fbx/data/fbx_mesh_data.cpp')
-rw-r--r--modules/fbx/data/fbx_mesh_data.cpp48
1 files changed, 17 insertions, 31 deletions
diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp
index 0728866adb..963a815896 100644
--- a/modules/fbx/data/fbx_mesh_data.cpp
+++ b/modules/fbx/data/fbx_mesh_data.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -38,7 +38,7 @@
template <class T>
T collect_first(const Vector<VertexData<T>> *p_data, T p_fall_back) {
- if (p_data->empty()) {
+ if (p_data->is_empty()) {
return p_fall_back;
}
@@ -47,7 +47,7 @@ T collect_first(const Vector<VertexData<T>> *p_data, T p_fall_back) {
template <class T>
HashMap<int, T> collect_all(const Vector<VertexData<T>> *p_data, HashMap<int, T> p_fall_back) {
- if (p_data->empty()) {
+ if (p_data->is_empty()) {
return p_fall_back;
}
@@ -61,7 +61,7 @@ HashMap<int, T> collect_all(const Vector<VertexData<T>> *p_data, HashMap<int, T>
template <class T>
T collect_average(const Vector<VertexData<T>> *p_data, T p_fall_back) {
- if (p_data->empty()) {
+ if (p_data->is_empty()) {
return p_fall_back;
}
@@ -76,7 +76,7 @@ T collect_average(const Vector<VertexData<T>> *p_data, T p_fall_back) {
}
HashMap<int, Vector3> collect_normal(const Vector<VertexData<Vector3>> *p_data, HashMap<int, Vector3> p_fall_back) {
- if (p_data->empty()) {
+ if (p_data->is_empty()) {
return p_fall_back;
}
@@ -89,7 +89,7 @@ HashMap<int, Vector3> collect_normal(const Vector<VertexData<Vector3>> *p_data,
}
HashMap<int, Vector2> collect_uv(const Vector<VertexData<Vector2>> *p_data, HashMap<int, Vector2> p_fall_back) {
- if (p_data->empty()) {
+ if (p_data->is_empty()) {
return p_fall_back;
}
@@ -135,26 +135,6 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s
&collect_all,
HashMap<int, Vector3>());
- // List<int> keys;
- // normals.get_key_list(&keys);
- //
- // const std::vector<Assimp::FBX::MeshGeometry::Edge>& edges = mesh_geometry->get_edge_map();
- // for (int index = 0; index < keys.size(); index++) {
- // const int key = keys[index];
- // const int v1 = edges[key].vertex_0;
- // const int v2 = edges[key].vertex_1;
- // const Vector3& n1 = normals.get(v1);
- // const Vector3& n2 = normals.get(v2);
- // print_verbose("[" + itos(v1) + "] n1: " + n1 + "\n[" + itos(v2) + "] n2: " + n2);
- // //print_verbose("[" + itos(key) + "] n1: " + n1 + ", n2: " + n2) ;
- // //print_verbose("vindex: " + itos(edges[key].vertex_0) + ", vindex2: " + itos(edges[key].vertex_1));
- // //Vector3 ver1 = vertices[edges[key].vertex_0];
- // //Vector3 ver2 = vertices[edges[key].vertex_1];
- // /*real_t angle1 = Math::rad2deg(n1.angle_to(n2));
- // real_t angle2 = Math::rad2deg(n2.angle_to(n1));
- // print_verbose("angle of normals: " + rtos(angle1) + " angle 2" + rtos(angle2));*/
- // }
-
HashMap<int, Vector2> uvs_0;
HashMap<int, HashMap<int, Vector2>> uvs_0_raw = extract_per_vertex_data(
vertices.size(),
@@ -231,7 +211,7 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s
// Phase 2. For each material create a surface tool (So a different mesh).
{
- if (polygon_surfaces.empty()) {
+ if (polygon_surfaces.is_empty()) {
// No material, just use the default one with index -1.
// Set -1 to all polygons.
const int polygon_count = count_polygons(polygon_indices);
@@ -371,6 +351,9 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s
normals_ptr[vertex]);
}
+ if (state.is_blender_fbx) {
+ morph_st->generate_normals();
+ }
morph_st->generate_tangents();
surface->morphs.push_back(morph_st->commit_to_arrays());
}
@@ -393,6 +376,9 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s
for (const SurfaceId *surface_id = surfaces.next(nullptr); surface_id != nullptr; surface_id = surfaces.next(surface_id)) {
SurfaceData *surface = surfaces.getptr(*surface_id);
+ if (state.is_blender_fbx) {
+ surface->surface_tool->generate_normals();
+ }
// you can't generate them without a valid uv map.
if (uvs_0_raw.size() > 0) {
surface->surface_tool->generate_tangents();
@@ -785,7 +771,7 @@ void FBXMeshData::add_vertex(
const Vector3 &p_morph_normal) {
ERR_FAIL_INDEX_MSG(p_vertex, (Vertex)p_vertices_position.size(), "FBX file is corrupted, the position of the vertex can't be retrieved.");
- if (p_normals.has(p_vertex)) {
+ if (p_normals.has(p_vertex) && !state.is_blender_fbx) {
p_surface_tool->set_normal(p_normals[p_vertex] + p_morph_normal);
}
@@ -990,7 +976,7 @@ void FBXMeshData::triangulate_polygon(Ref<SurfaceTool> st, Vector<int> p_polygon
}
void FBXMeshData::gen_weight_info(Ref<SurfaceTool> st, Vertex vertex_id) const {
- if (vertex_weights.empty()) {
+ if (vertex_weights.is_empty()) {
return;
}
@@ -1417,7 +1403,7 @@ void FBXMeshData::extract_morphs(const FBXDocParser::MeshGeometry *mesh_geometry
const std::vector<const FBXDocParser::ShapeGeometry *> &shape_geometries = blend_shape_channel->GetShapeGeometries();
for (const FBXDocParser::ShapeGeometry *shape_geometry : shape_geometries) {
String morph_name = ImportUtils::FBXAnimMeshName(shape_geometry->Name()).c_str();
- if (morph_name.empty()) {
+ if (morph_name.is_empty()) {
morph_name = "morph";
}