From 4e7acc4be8d03111b1c1245f263b1b8f5328b761 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Sat, 24 May 2025 15:22:19 +0200 Subject: [PATCH] Fix #138834: FBX import improved pivot handling This does not fully fix the issue (pivots are still not handled correctly when an object contains negative scale -- filed upstream ufbx issue https://github.com/ufbx/ufbx/issues/218), but for regular cases the pivots are in much better places now. Pull Request: https://projects.blender.org/blender/blender/pulls/139381 --- source/blender/io/fbx/importer/fbx_import.cc | 2 + .../files/io_tests/fbx/issue138834_pivots.fbx | 3 + .../fbx/reference/issue138834_pivots.txt | 76 +++++++++++++++++++ .../ufbx_motionbuilder_pivot_7700a.txt | 55 ++++++++++++++ .../fbx/ufbx_motionbuilder_pivot_7700a.fbx | 3 + 5 files changed, 139 insertions(+) create mode 100644 tests/files/io_tests/fbx/issue138834_pivots.fbx create mode 100644 tests/files/io_tests/fbx/reference/issue138834_pivots.txt create mode 100644 tests/files/io_tests/fbx/reference/ufbx_motionbuilder_pivot_7700a.txt create mode 100644 tests/files/io_tests/fbx/ufbx_motionbuilder_pivot_7700a.fbx diff --git a/source/blender/io/fbx/importer/fbx_import.cc b/source/blender/io/fbx/importer/fbx_import.cc index 80572d73eb4..4ada3e4beff 100644 --- a/source/blender/io/fbx/importer/fbx_import.cc +++ b/source/blender/io/fbx/importer/fbx_import.cc @@ -343,6 +343,8 @@ void importer_main(Main *bmain, Scene *scene, ViewLayer *view_layer, const FBXIm * cause armatures/skins to not import correctly, when inserted in the middle of bone chain. */ opts.geometry_transform_handling = UFBX_GEOMETRY_TRANSFORM_HANDLING_MODIFY_GEOMETRY_NO_FALLBACK; + opts.pivot_handling = UFBX_PIVOT_HANDLING_ADJUST_TO_PIVOT; + opts.space_conversion = UFBX_SPACE_CONVERSION_ADJUST_TRANSFORMS; opts.target_axes.right = UFBX_COORDINATE_AXIS_POSITIVE_X; opts.target_axes.up = UFBX_COORDINATE_AXIS_POSITIVE_Z; diff --git a/tests/files/io_tests/fbx/issue138834_pivots.fbx b/tests/files/io_tests/fbx/issue138834_pivots.fbx new file mode 100644 index 00000000000..2067273fd92 --- /dev/null +++ b/tests/files/io_tests/fbx/issue138834_pivots.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6b61d87ad4e627a383a4af1ff73f5bcf1b9b5c34b39185005542b79c94294d3 +size 25584 diff --git a/tests/files/io_tests/fbx/reference/issue138834_pivots.txt b/tests/files/io_tests/fbx/reference/issue138834_pivots.txt new file mode 100644 index 00000000000..81df96d144f --- /dev/null +++ b/tests/files/io_tests/fbx/reference/issue138834_pivots.txt @@ -0,0 +1,76 @@ +==== Meshes: 4 +- Mesh 'Mesh' vtx:86 face:67 loop:300 edge:159 + - 2 0 1 3 6 ... 36 16 17 41 40 + - 2/3 0/2 0/1 1/3 4/6 ... 81/85 13/37 12/36 17/41 16/40 + - attr 'position' FLOAT_VECTOR POINT + - (94.377, 9.507, 3.486) + - (8.077, 9.507, 3.486) + - (94.377, 213.684, 3.486) + ... + - (93.954, 158.336, 9.005) + - (97.952, 159.099, 8.925) + - (100.487, 156.998, 9.133) + +- Mesh 'Mesh.001' vtx:86 face:67 loop:300 edge:159 + - 2 3 1 0 6 ... 16 16 40 41 17 + - 0/2 2/3 1/3 0/1 6/7 ... 81/85 13/37 12/36 17/41 16/40 + - attr 'position' FLOAT_VECTOR POINT + - (-94.377, 9.507, 3.486) + - (-8.077, 9.507, 3.486) + - (-94.377, 213.684, 3.486) + ... + - (-93.954, 158.336, 9.005) + - (-97.952, 159.099, 8.925) + - (-100.487, 156.998, 9.133) + +- Mesh 'Mesh.002' vtx:86 face:67 loop:300 edge:159 + - 2 0 1 3 6 ... 36 16 17 41 40 + - 2/3 0/2 0/1 1/3 4/6 ... 81/85 13/37 12/36 17/41 16/40 + - attr 'position' FLOAT_VECTOR POINT + - (541.521, 28.042, -164.886) + - (455.221, 28.042, -164.886) + - (541.521, 232.219, -164.886) + ... + - (541.098, 176.871, -159.367) + - (545.096, 177.634, -159.447) + - (547.631, 175.533, -159.239) + +- Mesh 'Mesh.003' vtx:52 face:44 loop:176 edge:92 + - 2 0 1 3 6 ... 50 28 30 48 51 + - 2/3 0/2 0/1 1/3 4/6 ... 26/47 30/48 42/49 41/50 28/51 + - attr 'position' FLOAT_VECTOR POINT + - (-10.789, 100.289, -4.808) + - (-91.753, 100.289, -4.808) + - (-10.789, 211.997, -4.808) + ... + - (-66.088, 88.947, 5.940) + - (-66.088, 93.392, 5.940) + - (-66.088, 93.392, 10.185) + +==== Objects: 5 +- Obj '01' EMPTY + - pos 0.000, 0.000, 0.000 + - rot 1.571, 0.000, 0.000 (XYZ) + - scl 0.010, 0.010, 0.010 + - props: str:currentUVSet='map1' +- Obj 'Door_01' MESH data:'Mesh' par:'01' + - pos -102.530, 18.535, 136.567 + - rot 0.000, 0.000, 0.000 (XYZ) + - scl 1.000, 1.000, 1.000 + - props: str:currentUVSet='map1' +- Obj 'Door_02' MESH data:'Mesh.001' par:'01' + - pos 102.530, 18.535, 136.567 + - rot 0.000, 0.000, 0.000 (XYZ) + - scl 1.000, 1.000, 1.000 + - props: str:currentUVSet='map1' +- Obj 'Door_03' MESH data:'Mesh.002' par:'01' + - pos 710.133, 300.000, 305.051 + - rot 3.142, 0.000, 0.000 (XYZ) + - scl -1.000, -1.000, -1.000 + - props: str:currentUVSet='map1' +- Obj 'Door_04' MESH data:'Mesh.003' par:'01' + - pos 203.475, 18.535, -332.622 + - rot 0.000, 0.000, 0.000 (XYZ) + - scl 1.000, 1.000, 1.000 + - props: str:currentUVSet='map1' + diff --git a/tests/files/io_tests/fbx/reference/ufbx_motionbuilder_pivot_7700a.txt b/tests/files/io_tests/fbx/reference/ufbx_motionbuilder_pivot_7700a.txt new file mode 100644 index 00000000000..9a5c34a3c20 --- /dev/null +++ b/tests/files/io_tests/fbx/reference/ufbx_motionbuilder_pivot_7700a.txt @@ -0,0 +1,55 @@ +==== Meshes: 1 +- Mesh 'Mesh' vtx:8 face:6 loop:24 edge:12 + - 0 1 3 2 2 ... 3 6 0 2 4 + - 0/2 0/1 1/3 2/3 2/4 ... 4/6 5/7 6/7 0/6 1/7 + - attr 'position' FLOAT_VECTOR POINT + - (-4.183, 1.500, 3.683) + - (-3.317, 1.500, 3.183) + - (-4.183, 2.500, 3.683) + ... + - (-3.817, 2.500, 2.317) + - (-4.683, 1.500, 2.817) + - (-3.817, 1.500, 2.317) + - attr 'sharp_edge' BOOLEAN EDGE + - 1 1 1 1 1 ... 1 1 1 1 1 + - attr 'material_index' INT FACE + - 0 0 0 0 0 0 + - attr 'custom_normal' INT16_2D CORNER + - (0, 0) + - (0, 0) + - (0, 0) + ... + - (0, 0) + - (0, 0) + - (0, 0) + - attr 'map1' FLOAT2 CORNER + - (0.375, 0.000) + - (0.625, 0.000) + - (0.625, 0.250) + ... + - (0.375, 0.000) + - (0.375, 0.250) + - (0.125, 0.250) + - 1 materials + - 'lambert1' + +==== Objects: 1 +- Obj 'pCube1' MESH data:'Mesh' + - pos 0.050, 0.000, 0.000 + - rot 1.571, 0.000, -0.785 (XYZ) + - scl 0.010, 0.010, 0.010 + +==== Materials: 1 +- Mat 'lambert1' + - base color (0.500, 0.500, 0.500) + - specular ior 0.500 + - specular tint (1.000, 1.000, 1.000) + - roughness 0.500 + - metallic 0.000 + - ior 1.500 + - viewport diffuse (0.500, 0.500, 0.500, 1.000) + - viewport specular (1.000, 1.000, 1.000), intensity 0.500 + - viewport metallic 0.000, roughness 0.500 + - backface False probe True shadow False + - props: f3:Ambient=(0.000, 0.000, 0.000) f3:Diffuse=(0.400, 0.400, 0.400) f3:Emissive=(0.000, 0.000, 0.000) fl:Opacity=1.000 + diff --git a/tests/files/io_tests/fbx/ufbx_motionbuilder_pivot_7700a.fbx b/tests/files/io_tests/fbx/ufbx_motionbuilder_pivot_7700a.fbx new file mode 100644 index 00000000000..517859b688d --- /dev/null +++ b/tests/files/io_tests/fbx/ufbx_motionbuilder_pivot_7700a.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce1b6168a4ad4d1b360df9271e95bc565315175b00c966ba7c6dcd11c09520bf +size 38612