Skip to content

FBX importer searches for textures relative to .godot/imported #72503

Description

@lyuma

Godot version

4.0.beta16+

System information

Windows 10

Issue description

EditorSceneFormatImporterFBX (modules/gltf/editor/editor_scene_importer_fbx.cpp) calcualates the following path for embedded glb files.

	const String sink = ProjectSettings::get_singleton()->get_imported_files_path().path_join(
			vformat("%s-%s.glb", p_path.get_file().get_basename(), p_path.md5_text()));

Do to a "feature" of FBX2glTF, it embeds all textures into the .glb file, which means we attempt to extract them once again. The glTF importer has no idea where the original FBX was, so it attempts to extract them into .godot/imported, which then fails because Godot is not designed to import extracted textures from .godot/imported.

One source of this bug is that we're using the --binary option for FBX2glTF, which uses it to embed textures. If we used --text, then we'd hit another bug, namely that FBX2glTF hardcodes buffer.bin so multiple gltf files will overwrite each other's bin file. It would be nice to modify FBX2glTF to handle this better.

An easy fix would be to use GLTFDocument::append_from_buffer instead of GLTFDocument::append_from_file so that we can pass in the original base_path of the fbx file and allow lookups from the right location. It's still awkward that textures are being embedded and then extracted again.

Steps to reproduce

  1. import a .fbx which references textures such as in the MRP. I used https://sketchfab.com/3d-models/magic-girl-sparkles-5f842cde310d4d849ab877242908440c with textures moved to be in the same directory such that FBX2glTF finds them.
  2. Allow Godot to import the .fbx file (needs FBX2glTF in project settings)
  3. See errors:
ERROR: Can't find file 'res://.godot/imported/magic_girl-60bb0051c272cdf2d62ba4edb599c31c_henshin_acs_t.png'.
   at: (editor\editor_file_system.cpp:1907)
ERROR: Failed loading resource: res://.godot/imported/magic_girl-60bb0051c272cdf2d62ba4edb599c31c_henshin_acs_t.png. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core\io\resource_loader.cpp:222)
WARNING: glTF: Image index '0' couldn't be loaded with the name: henshin_acs_t. Skipping it.
     at: GLTFDocument::_parse_images (modules\gltf\gltf_document.cpp:3289)
ERROR: Can't find file 'res://.godot/imported/magic_girl-60bb0051c272cdf2d62ba4edb599c31c_shoes_t.png'.
   at: (editor\editor_file_system.cpp:1907)
ERROR: Failed loading resource: res://.godot/imported/magic_girl-60bb0051c272cdf2d62ba4edb599c31c_shoes_t.png. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core\io\resource_loader.cpp:222)
WARNING: glTF: Image index '1' couldn't be loaded with the name: shoes_t. Skipping it.

These are due to attempting to import and load resources within .godot/imported, relative to the intermediate .godot/imported/magic_girl-60bb0051c272cdf2d62ba4edb599c31c.glb file.

Minimal reproduction project

magic_girl_fbx_repro.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions