Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip, fbx] Fix FBX file scaling #44653

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/fbx/data/import_state.h
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ struct ImportState {
String path = String();
Node3D *root_owner = nullptr;
Node3D *root = nullptr;
real_t scale = 0.01;
real_t scale = 1;
Ref<FBXNode> fbx_root_node = Ref<FBXNode>();
// skeleton map - merged automatically when they are on the same x node in the tree so we can merge them automatically.
Map<uint64_t, Ref<FBXSkeleton>> skeleton_map = Map<uint64_t, Ref<FBXSkeleton>>();
2 changes: 1 addition & 1 deletion modules/fbx/data/pivot_transform.cpp
Original file line number Diff line number Diff line change
@@ -281,7 +281,7 @@ void PivotTransform::ComputePivotTransform() {
GlobalTransform = (global_origin * local_translation_pivoted) * global_rotation_scale;

ImportUtils::debug_xform("local xform calculation", LocalTransform);
print_verbose("scale of node: " + S.basis.get_scale_local());
print_verbose("scale of node: " + GlobalTransform.basis.get_scale_abs());
print_verbose("---------------------------------------------------------------");
}

23 changes: 20 additions & 3 deletions modules/fbx/editor_scene_importer_fbx.cpp
Original file line number Diff line number Diff line change
@@ -347,10 +347,27 @@ Node3D *EditorSceneImporterFBX::_generate_scene(

// Size relative to cm.
const real_t fbx_unit_scale = p_document->GlobalSettingsPtr()->UnitScaleFactor();
const real_t fbx_original_scale = p_document->GlobalSettingsPtr()->OriginalUnitScaleFactor();
print_verbose("Final Scale: " + rtos(fbx_original_scale / fbx_unit_scale));

// Godot is in meters 100 cm in a meter
// If the FBX is not in the correct unit scale then we must calculate the scale value
if (fbx_unit_scale != 100) {
state.scale = fbx_unit_scale / 100;
} else {
// if the file has correct unit scale calculate we must scale scene to the value
state.scale = fbx_unit_scale; // correct for bistro
}
//
// if(!Math::is_equal_approx( fbx_unit_scale, 100.0f))
// {
// state.scale = (fbx_original_scale / fbx_unit_scale);
// }
// else
// {
// print_verbose("File is in meters no scaling required");
// }

print_verbose("FBX unit scale import value: " + rtos(fbx_unit_scale));
// Set FBX file scale is relative to CM must be converted to M
state.scale = fbx_unit_scale / 100.0;
print_verbose("FBX unit scale is: " + rtos(state.scale));

// Enabled by default.