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

FBX: Print ufbx load warnings on import #91529

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions modules/fbx/fbx_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ static ufbx_skin_deformer *_find_skin_deformer(ufbx_skin_cluster *p_cluster) {
return nullptr;
}

static String _find_element_name(ufbx_element *p_element) {
if (p_element->name.length > 0) {
return FBXDocument::_as_string(p_element->name);
} else if (p_element->instances.count > 0) {
return _find_element_name(&p_element->instances[0]->element);
} else {
return "";
}
}

struct ThreadPoolFBX {
struct Group {
ufbx_thread_pool_context ctx = {};
Expand Down Expand Up @@ -2071,6 +2081,32 @@ Error FBXDocument::_parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess>
ERR_FAIL_V_MSG(ERR_PARSE_ERROR, err_buf);
}

const int max_warning_count = 10;
int warning_count[UFBX_WARNING_TYPE_COUNT] = {};
int ignored_warning_count = 0;
for (const ufbx_warning &warning : p_state->scene->metadata.warnings) {
if (warning_count[warning.type]++ < max_warning_count) {
if (warning.count > 1) {
WARN_PRINT(vformat("FBX: ufbx warning: %s (x%d)", _as_string(warning.description), (int)warning.count));
} else {
String element_name;
if (warning.element_id != UFBX_NO_INDEX) {
element_name = _find_element_name(p_state->scene->elements[warning.element_id]);
}
if (!element_name.is_empty()) {
WARN_PRINT(vformat("FBX: ufbx warning in '%s': %s", element_name, _as_string(warning.description)));
} else {
WARN_PRINT(vformat("FBX: ufbx warning: %s", _as_string(warning.description)));
}
}
} else {
ignored_warning_count++;
}
}
if (ignored_warning_count > 0) {
WARN_PRINT(vformat("FBX: ignored %d further ufbx warnings", ignored_warning_count));
}

err = _parse_fbx_state(p_state, p_path);
ERR_FAIL_COND_V(err != OK, err);

Expand Down