Merge pull request #91529 from bqqbarbhg/ufbx-warnings

FBX: Print ufbx load warnings on import
This commit is contained in:
Rémi Verschelde 2024-05-07 13:48:56 +02:00
commit 82e77eab35
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -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 = {};
@ -2068,6 +2078,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);