summaryrefslogtreecommitdiff
path: root/modules/fbx/data
diff options
context:
space:
mode:
authorGordon MacPherson <gordon@gordonite.tech>2021-01-03 20:29:38 +0000
committerGordon MacPherson <gordon@gordonite.tech>2021-01-05 21:58:58 +0000
commit74a72cf85eb52f92436ea2e1bf1f74b6fc4ef912 (patch)
tree1263d2bbf15e2e7fba75dd22788492f33a949110 /modules/fbx/data
parentcdfcf68af96fa3b9c0e78445e042bc60dff365f7 (diff)
Preliminary Blender FBX support [4.0]
limitations: - always has to use generated normal's. - some animations won't be compatible (yet) Co-authored-by: RĂ©mi Verschelde <rverschelde@gmail.com>
Diffstat (limited to 'modules/fbx/data')
-rw-r--r--modules/fbx/data/fbx_mesh_data.cpp28
-rw-r--r--modules/fbx/data/import_state.h1
2 files changed, 8 insertions, 21 deletions
diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp
index d84a7ab17c..963a815896 100644
--- a/modules/fbx/data/fbx_mesh_data.cpp
+++ b/modules/fbx/data/fbx_mesh_data.cpp
@@ -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(),
@@ -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);
}
diff --git a/modules/fbx/data/import_state.h b/modules/fbx/data/import_state.h
index 1d664a5212..83bc43faff 100644
--- a/modules/fbx/data/import_state.h
+++ b/modules/fbx/data/import_state.h
@@ -64,6 +64,7 @@ struct FBXSkeleton;
struct ImportState {
bool enable_material_import = true;
bool enable_animation_import = true;
+ bool is_blender_fbx = false;
Map<StringName, Ref<Texture>> cached_image_searches;
Map<uint64_t, Ref<Material>> cached_materials;