godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.5k stars 21.26k forks source link

UFBX importer doesn't work in-game [Godot 4.3] #96029

Open Naming-things-is-hard-btw opened 3 months ago

Naming-things-is-hard-btw commented 3 months ago

Tested versions

4.3

System information

manjaro linux godot 4.3-stable (this doesnt matter since this "bug" is on all platforms)

Issue description

the new ufbx importer for godot 4.3 cant import fbx files at runtime but gltf importer can

O. some notes:

  1. the engine can import gltf at runtime but not fbx
  2. the engine can import both gltf and fbx in the editor
  3. at runtime loading fbx file gives an unavailable error
  4. even tho now with godot 4.3 we have fbx document just like gltf document but it looks like its not working/implemented yet?

O. after some tests: i found is that it actually (kind of) imports everything correctly but all meshes are importer mesh type with no data so.... maybe importer mesh doesn't work in-game??

im currently looking at the source code to check whats going on with that i have a small experience with c++ and i'd love to help (since this matters alot to me)

Steps to reproduce

just try the MRP i gave run the project and it wont show anything (even tho im trying to load fbx with fbxDocument just like gltfDocument)

Minimal reproduction project (MRP)

MRP.zip

Naming-things-is-hard-btw commented 3 months ago

update: it looks like it imports mesh instances as importer mesh instances and it doesn't convert it back into a normal mesh via inportermesh::get_mesh()

update2: i will dig a bit more btw why does this importer use importer mesh instance class while gltf doesn't? edit: okay gltf also uses that.... but somehow converts it to a normal mesh instance hmmmm... maybe looping through the entire tree to convert importer mesh instance to a normal mesh instance might work? im fully open for any better ideas.

update3: actually this can be as simple as adding in fbxdocument::generate_scene() meshinst.mesh = importermesh.mesh.get_mesh(); in a recursive loop right???

AThousandShips commented 3 months ago

Please edit your earlier comments instead of commenting several times in a row, it creates a lot of unnecessary notifications

Naming-things-is-hard-btw commented 3 months ago

Please edit your earlier comments instead of commenting several times in a row, it creates a lot of unnecessary notifications

thanks i will do that

andreas-volz commented 3 months ago

My application could also load gltf with gdscript at runtime but if I just try the same with FBXDocument/FBXState I get this error:

E 0:00:28:0463 Viewer.gd:265 @ _load_gltf_or_fbx(): No loader found for resource: /home/andreas/Games/Assets/3d/kaykit/KayKit_Adventurers_1.0_SOURCE/Assets/fbx/rogue_texture.png (expected type: Texture2D) <C++-Fehler> Method/function failed. Returning: Ref() <C++-Quelle> core/io/resource_loader.cpp:291 @ _load()

Viewer.gd:265 @ _load_gltf_or_fbx() Viewer.gd:253 @ load_fbx() Viewer.gd:350 @ _on_files_dropped()

But the texture png exist at this path. I assume it's the same problem as it seems to be imported correct (e.g. animations are correctly read in) but the mesh is not available. My application is opensource. So in case the bug authors code isn't enough to analyze the problem I could link my code here.

Naming-things-is-hard-btw commented 3 months ago

My application could also load gltf with gdscript at runtime but if I just try the same with FBXDocument/FBXState I get this error:

E 0:00:28:0463 Viewer.gd:265 @ _load_gltf_or_fbx(): No loader found for resource: /home/andreas/Games/Assets/3d/kaykit/KayKit_Adventurers_1.0_SOURCE/Assets/fbx/rogue_texture.png (expected type: Texture2D) <C++-Fehler> Method/function failed. Returning: Ref() <C++-Quelle> core/io/resource_loader.cpp:291 @ _load() Viewer.gd:265 @ _load_gltf_or_fbx() Viewer.gd:253 @ load_fbx() Viewer.gd:350 @ _on_files_dropped()

But the texture png exist at this path. I assume it's the same problem as it seems to be imported correct (e.g. animations are correctly read in) but the mesh is not available. My application is opensource. So in case the bug authors code isn't enough to analyze the problem I could link my code here.

this seems off topic u should create a separate issue for that with a Minimal reproduction project (MRP) ill try to look into that too what version do you use i tried what u've said and gltf importer works flawlessly

edit: sorry i misunderstood ur comment ur issue is relevant to this topic

Naming-things-is-hard-btw commented 3 months ago

i was able to fix the issue [finally] but the "fix" is more of a flex tape rather than a real solution i added this at line 2144 in fbx_document.cpp file, almost exactly at the end of the generate_scene function

    _convert_meshimporters_recursive(root);
    return root;
}

void FBXDocument::_convert_meshimporters_recursive(Node *parent) {
    TypedArray<Node> children = parent->get_children();
    for (int i = 0; i < children.size(); i++) {
        _convert_meshimporters_recursive(cast_to<Node>(children[i]));
        ImporterMeshInstance3D *child = cast_to<ImporterMeshInstance3D>(children[i]);
        if (child == nullptr) {
            continue;
        }
        Ref<Mesh> imported_mesh = cast_to<ImporterMeshInstance3D>(child)->get_mesh()->get_mesh();
        MeshInstance3D *meshinst = memnew(MeshInstance3D);
        child->replace_by(meshinst);
        meshinst->set_name(child->get_name());
        meshinst->set_transform(child->get_transform());
        meshinst->set_mesh(imported_mesh);
        meshinst->set_skin(child->get_skin());
        meshinst->set_skeleton_path(child->get_skeleton_path());
        memfree(child);
    }
}

and in fbx_document.hpp at line 68 i added

void _convert_meshimporters_recursive(Node *parent);

and now it looks good but i will test it more first i still have to duplicate transforms and other variables too btw i only know gdscript this is the first time i do anything in c++ so please if u can help i will appreciate it and still we need to find the real problem cus this might create more problems than it fixes idk

Naming-things-is-hard-btw commented 3 months ago

Screenshot_20240824_223728 it works now all meshes are converted (the fix) all animations and transforms and materials imported (so it didn't break... cool) now i have no idea what to do hehe should i wait for review or pull or what exactly

andreas-volz commented 3 months ago

Thanks, I created a new ticket in #96043