Skip to content

Commit

Permalink
Merge pull request #91529 from bqqbarbhg/ufbx-warnings
Browse files Browse the repository at this point in the history
FBX: Print ufbx load warnings on import
  • Loading branch information
akien-mga committed May 7, 2024
2 parents e8d5bdd + 04db5cf commit 82e77ea
Showing 1 changed file with 36 additions and 0 deletions.
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 @@ -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);

Expand Down

0 comments on commit 82e77ea

Please sign in to comment.