fix fbx runtime import not generating meshes properly

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
Co-authored-by: K. S. Ernest (iFire) Lee <fire@users.noreply.github.com>
Co-authored-by: Naming-things-is-hard-btw <ahmadmhamad12331233@gmail.com>
This commit is contained in:
zodywoolsey
2025-04-26 01:29:50 -06:00
parent e37c6261ea
commit a54301ef75
4 changed files with 64 additions and 14 deletions

View File

@ -2103,6 +2103,15 @@ Error FBXDocument::_parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess>
WARN_PRINT(vformat("FBX: ignored %d further ufbx warnings", ignored_warning_count));
}
document_extensions.clear();
for (Ref<GLTFDocumentExtension> ext : all_document_extensions) {
ERR_CONTINUE(ext.is_null());
err = ext->import_preflight(p_state, p_state->json["extensionsUsed"]);
if (err == OK) {
document_extensions.push_back(ext);
}
}
err = _parse_fbx_state(p_state, p_path);
ERR_FAIL_COND_V(err != OK, err);
@ -2130,6 +2139,27 @@ Node *FBXDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool
_import_animation(state, ap, i, p_trimming, p_remove_immutable_tracks);
}
}
for (KeyValue<GLTFNodeIndex, Node *> E : state->scene_nodes) {
ERR_CONTINUE(!E.value);
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
Dictionary node_json;
if (state->json.has("nodes")) {
Array nodes = state->json["nodes"];
if (0 <= E.key && E.key < nodes.size()) {
node_json = nodes[E.key];
}
}
Ref<GLTFNode> gltf_node = state->nodes[E.key];
Error err = ext->import_node(p_state, gltf_node, node_json, E.value);
ERR_CONTINUE(err != OK);
}
}
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
Error err = ext->import_post(p_state, root);
ERR_CONTINUE(err != OK);
}
ERR_FAIL_NULL_V(root, nullptr);
return root;
}
@ -2148,12 +2178,11 @@ Error FBXDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_pat
state->base_path = p_base_path.get_base_dir();
err = _parse(state, state->base_path, file_access);
ERR_FAIL_COND_V(err != OK, err);
// TODO: 202040118 // fire
// for (Ref<GLTFDocumentExtension> ext : get_all_gltf_document_extensions()) {
// ERR_CONTINUE(ext.is_null());
// err = ext->import_post_parse(state);
// ERR_FAIL_COND_V(err != OK, err);
// }
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
err = ext->import_post_parse(state);
ERR_FAIL_COND_V(err != OK, err);
}
return OK;
}
@ -2247,12 +2276,11 @@ Error FBXDocument::append_from_file(String p_path, Ref<GLTFState> p_state, uint3
state->base_path = base_path;
err = _parse(p_state, base_path, file);
ERR_FAIL_COND_V(err != OK, err);
// TODO: 20240118 // fire
// for (Ref<GLTFDocumentExtension> ext : document_extensions) {
// ERR_CONTINUE(ext.is_null());
// err = ext->import_post_parse(p_state);
// ERR_FAIL_COND_V(err != OK, err);
// }
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
err = ext->import_post_parse(p_state);
ERR_FAIL_COND_V(err != OK, err);
}
return OK;
}