diff options
Diffstat (limited to 'modules/gltf')
-rw-r--r-- | modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp | 2 | ||||
-rw-r--r-- | modules/gltf/extensions/physics/gltf_physics_shape.cpp | 14 | ||||
-rw-r--r-- | modules/gltf/gltf_document.cpp | 17 | ||||
-rw-r--r-- | modules/gltf/structures/gltf_mesh.cpp | 2 | ||||
-rw-r--r-- | modules/gltf/structures/gltf_mesh.h | 2 | ||||
-rw-r--r-- | modules/gltf/structures/gltf_skin.cpp | 2 | ||||
-rw-r--r-- | modules/gltf/structures/gltf_skin.h | 2 |
7 files changed, 27 insertions, 14 deletions
diff --git a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp index 2af716b867..1e64a6daa4 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp @@ -32,7 +32,7 @@ #include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/mesh_instance_3d.h" -#include "scene/resources/importer_mesh.h" +#include "scene/resources/3d/importer_mesh.h" void GLTFDocumentExtensionConvertImporterMesh::_bind_methods() { } diff --git a/modules/gltf/extensions/physics/gltf_physics_shape.cpp b/modules/gltf/extensions/physics/gltf_physics_shape.cpp index af4ac10313..467499a03f 100644 --- a/modules/gltf/extensions/physics/gltf_physics_shape.cpp +++ b/modules/gltf/extensions/physics/gltf_physics_shape.cpp @@ -34,13 +34,13 @@ #include "core/math/convex_hull.h" #include "scene/3d/area_3d.h" -#include "scene/resources/box_shape_3d.h" -#include "scene/resources/capsule_shape_3d.h" -#include "scene/resources/concave_polygon_shape_3d.h" -#include "scene/resources/convex_polygon_shape_3d.h" -#include "scene/resources/cylinder_shape_3d.h" -#include "scene/resources/importer_mesh.h" -#include "scene/resources/sphere_shape_3d.h" +#include "scene/resources/3d/box_shape_3d.h" +#include "scene/resources/3d/capsule_shape_3d.h" +#include "scene/resources/3d/concave_polygon_shape_3d.h" +#include "scene/resources/3d/convex_polygon_shape_3d.h" +#include "scene/resources/3d/cylinder_shape_3d.h" +#include "scene/resources/3d/importer_mesh.h" +#include "scene/resources/3d/sphere_shape_3d.h" void GLTFPhysicsShape::_bind_methods() { ClassDB::bind_static_method("GLTFPhysicsShape", D_METHOD("from_node", "shape_node"), &GLTFPhysicsShape::from_node); diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index afb3659699..0ed2100041 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -50,9 +50,9 @@ #include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/multimesh_instance_3d.h" +#include "scene/resources/3d/skin.h" #include "scene/resources/image_texture.h" #include "scene/resources/portable_compressed_texture.h" -#include "scene/resources/skin.h" #include "scene/resources/surface_tool.h" #ifdef TOOLS_ENABLED @@ -2796,7 +2796,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { Vector<Vector3> normals = array[Mesh::ARRAY_NORMAL]; for (int k = 0; k < vertex_num; k++) { - Vector3 tan = Vector3(0.0, 1.0, 0.0).cross(normals[k]); + Vector3 tan = Vector3(normals[i].z, -normals[i].x, normals[i].y).cross(normals[k].normalized()).normalized(); tangentsw[k * 4 + 0] = tan.x; tangentsw[k * 4 + 1] = tan.y; tangentsw[k * 4 + 2] = tan.z; @@ -2822,6 +2822,19 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { } array = mesh_surface_tool->commit_to_arrays(); + if ((flags & RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES) && a.has("NORMAL") && (a.has("TANGENT") || generate_tangents)) { + // Compression is enabled, so let's validate that the normals and tangents are correct. + Vector<Vector3> normals = array[Mesh::ARRAY_NORMAL]; + Vector<float> tangents = array[Mesh::ARRAY_TANGENT]; + for (int vert = 0; vert < normals.size(); vert++) { + Vector3 tan = Vector3(tangents[vert * 4 + 0], tangents[vert * 4 + 1], tangents[vert * 4 + 2]); + if (abs(tan.dot(normals[vert])) > 0.0001) { + // Tangent is not perpendicular to the normal, so we can't use compression. + flags &= ~RS::ARRAY_FLAG_COMPRESS_ATTRIBUTES; + } + } + } + Array morphs; //blend shapes if (p.has("targets")) { diff --git a/modules/gltf/structures/gltf_mesh.cpp b/modules/gltf/structures/gltf_mesh.cpp index d04d3fcd7f..9566cc2379 100644 --- a/modules/gltf/structures/gltf_mesh.cpp +++ b/modules/gltf/structures/gltf_mesh.cpp @@ -30,7 +30,7 @@ #include "gltf_mesh.h" -#include "scene/resources/importer_mesh.h" +#include "scene/resources/3d/importer_mesh.h" void GLTFMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_original_name"), &GLTFMesh::get_original_name); diff --git a/modules/gltf/structures/gltf_mesh.h b/modules/gltf/structures/gltf_mesh.h index c33e39df84..6983efeb2a 100644 --- a/modules/gltf/structures/gltf_mesh.h +++ b/modules/gltf/structures/gltf_mesh.h @@ -33,7 +33,7 @@ #include "../gltf_defines.h" -#include "scene/resources/importer_mesh.h" +#include "scene/resources/3d/importer_mesh.h" class GLTFMesh : public Resource { GDCLASS(GLTFMesh, Resource); diff --git a/modules/gltf/structures/gltf_skin.cpp b/modules/gltf/structures/gltf_skin.cpp index 8097c7b3d0..18aa90a628 100644 --- a/modules/gltf/structures/gltf_skin.cpp +++ b/modules/gltf/structures/gltf_skin.cpp @@ -33,7 +33,7 @@ #include "../gltf_template_convert.h" #include "core/variant/typed_array.h" -#include "scene/resources/skin.h" +#include "scene/resources/3d/skin.h" void GLTFSkin::_bind_methods() { ClassDB::bind_method(D_METHOD("get_skin_root"), &GLTFSkin::get_skin_root); diff --git a/modules/gltf/structures/gltf_skin.h b/modules/gltf/structures/gltf_skin.h index ce863da45d..4649a918e3 100644 --- a/modules/gltf/structures/gltf_skin.h +++ b/modules/gltf/structures/gltf_skin.h @@ -34,7 +34,7 @@ #include "../gltf_defines.h" #include "core/io/resource.h" -#include "scene/resources/skin.h" +#include "scene/resources/3d/skin.h" template <typename T> class TypedArray; |