Moguri / blend2bam

A CLI tool to convert Blender blend files to Panda3D BAM files
MIT License
66 stars 17 forks source link

Windows drive name is being added twice to filepath, causing conversion to fail #77

Closed theanine3D closed 1 year ago

theanine3D commented 1 year ago

blend2bam refuses to convert any blend file for me, no matter what blend file I use, even a default .blend file with just a default cube in it.

I've edited the code a bit so that it would show a more detailed error, and here's what it shows in the console:

Traceback (most recent call last):
  File "c:\panda3d\python\lib\site-packages\blend2bam\cli.py", line 89, in convert
    tmp2dst.convert_single(tmpfile.name, dst)
  File "c:\panda3d\python\lib\site-packages\blend2bam\gltf2bam.py", line 62, in convert_single
    run_gltf2bam(src, dst, self.cli_args)
  File "c:\panda3d\python\lib\site-packages\blend2bam\gltf2bam.py", line 26, in run_gltf2bam
    runpy.run_module('gltf.cli', run_name='__main__', alter_sys=True)
  File "c:\panda3d\python\lib\runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "c:\panda3d\python\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "c:\panda3d\python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\panda3d\python\lib\site-packages\gltf\cli.py", line 156, in <module>
    main()
  File "c:\panda3d\python\lib\site-packages\gltf\cli.py", line 120, in main
    gltf_data = parse_gltf_file(src)
  File "c:\panda3d\python\lib\site-packages\gltf\parseutils.py", line 58, in parse_gltf_file
    if is_glb_file(filepath):
  File "c:\panda3d\python\lib\site-packages\gltf\parseutils.py", line 6, in is_glb_file
    with open(filepath, 'rb') as glbfile:
OSError: [Errno 22] Invalid argument: 'C:\\C:\\Users\\pv\\AppData\\Local\\Temp\\tmpp34ayxrn'

It looks like the problem is on that last line of the error message - you can see that "C:\" is being added twice to the filepath.

I've encountered this problem with two different Python installations (the one from the Panda3D SDK, as well as Anaconda's). So it doesn't appear to be related to my Python setup.

My setup is: Python 3.7 (the one that comes with Panda SDK) Blender 3.5 Newest version of blend2bam Windows 11

theanine3D commented 1 year ago

After updating Blender to 3.5.1 the error is now totally different. It now looks like the cause is related to an incorrect filepath being generated by the scripts on Windows (the C:\ drive is being added twice). Very strange, but at least it looks like the issue is more clear now. I updated my post above with the new error.

Note that I am not encountering this error on Ubuntu Linux (22.04), with the same Blender version (3.5.1). On Linux it works fine, no error, and a .bam is produced as expected.

lishangqiu commented 1 year ago

I was having the same issue (tried Panda3d version 1.10.5, 1.10.11, 1.10.13), but I was able to temporarily fix the issue by editing panda3d-gltf library (blend2bam calls this library). The issue appears to be mostly caused by panda3d.core.Filename not handling the paths correctly??

  1. The absolute path of the current directory is added again to the path when it is already in absolute path form. This happens when .make_absolute() is called (this causes the issue you observed of C:\ being added twice). I commented out the problem causing function calls. In "cli.py" of gltf line111-114:
    src = p3d.Filename(args.src)
    # src.make_absolute() Commented out by me
    dst = p3d.Filename(args.dst)
    # dst.make_absolute() Commented out by me
  2. panda3d.core.Filename returns empty string for .get_dirname(). I replaced these calls with os.path.dirname(...). In "cli.py" of gltf line 116-117, replaced with:
    indir = p3d.Filename(os.path.dirname(args.src))
    outdir = p3d.Filename(os.path.dirname(args.dst))

    In "converter.py" line 105, replaced with:

        self.filedir = Filename(os.path.dirname(filepath))
  3. Somehow panda3d doesn't like full path for write_bam_file?? In "cli.py", replaced with:
    converter.active_scene.write_bam_file(os.path.basename(dst))

Honestly I'm a newbie here and there's probably more underlying problems??? but hope this helps.

Moguri commented 1 year ago

panda3d-gltf should be using

src = p3d.Filename.from_os_specific(args.src)
src.make_absolute()
dst = p3d.Filename.from_os_specific(args.dst)
dst.make_absolute()

I am surprised it took this long for this to be a problem. I am guessing gltf2bam does not get used much on Windows, and blend2bam just recently switched to going through the CLI interface for panda3d-gltf.

Moguri commented 1 year ago

I have published a new release of panda3d-gltf that fixes this issue. Please update that module (e.g., pip install --upgrade panda3d-gltf) and try again. If you are still having issues, feel free to reopen this issue.