facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.68k stars 1.3k forks source link

Experimental GLTF Loader supports both GLTF and GLB formats, but returns None for GLTF #1405

Open Hafplo opened 1 year ago

Hafplo commented 1 year ago

If you do not know the root cause of the problem / bug, and wish someone to help you, please post according to this template:

🐛 Bugs / Unexpected behaviors

Using the experimental gltf loader 'MeshGlbFormat' - it has a flag for 'known_suffixes' which only accounts for "glb" type. Looking deeper at the code (class '_GLTFLoader'), it supports the gltf type as well. I renamed my file extension from 'gltf' to 'glb' and it loads. Seemed to load correctly.

Instructions To Reproduce the Issue:

Please include the following (depending on what the issue is):

  1. Any changes you made (git diff) or code you wrote: None
  2. The exact command(s) you ran:

    • get gltf file
    • run the following
      
      from pytorch3d.io import IO
      from pytorch3d.io.experimental_gltf_io import MeshGlbFormat

    io = IO() io.register_meshes_format(MeshGlbFormat()) mesh = io.load_mesh(path_to_gltf, include_textures=False)

    
    * the 'mesh' object is None
  1. What you observed (including the full logs): None
bottler commented 1 year ago

There are several ways to store data in glTF format. When the whole thing is stored as binary in a single file (rather than as separate chunks in several files) then that file should end with the ".glb" extension. At the moment we only support that single file representation, which is what you have. So I don't think it would be right to add ".gltf" to known_suffixes.

If you have a file which should have a ".glb" ending but doesn't, and you /really/ want to load from it without renaming, you can do this manually as follows, because all the format objects are designed to accept streams unconditionally.

format = MeshGlbFormat()
io = IO()
with open(path_to_gltf, "rb") as f:
    mesh = format.load(f, include_textures=False, device="cpu", path_manager=io.path_manager)