KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 317 forks source link

glb import error when None is given as a float parameter #2275

Closed ieskudero closed 3 months ago

ieskudero commented 3 months ago

Describe the bug With a model exported with ThreeJS GLTF exporter, there is a case apparently where a float comes as None, and the blender addon crashes on importing the file.

To Reproduce Steps to reproduce the behavior:

  1. Open blender
  2. Import the attached .GLB file
  3. Check error on console

Expected behavior The importer should maybe convert values as False ->0, True ->1 or None->0 before passing the assert method

.blend file/ .gltf (mandatory) 2024617_301.zip

Version

Additional context I don't know if the bug comes from the ThreeJS exporter or in the Blender addon, but it can be fixed parsing values like False, True, None ... to numeric values instead of only checking for type. In this case, I changed the file glt2_io.py in the scripts\addons\io_scene_gltf2\io\com\ folder, from this:

def from_float(x):
    assert isinstance(x, (float, int)) and not isinstance(x, bool)
    return float(x)

to this:

def from_float(x):
    if x == False or x == None:
        x = 0
    if x == True:
        x = 1
    assert isinstance(x, (float, int)) and not isinstance(x, bool)
    return float(x)
julienduroure commented 3 months ago

The glb provided is not a valid glTF/glb file. None is not a valid value for float. Even this can be workaround, we will probably not fix it, as we don't want that some not valid files become the de facto norm. You should report a bug to the ThreeJS GLTF exporter team.

You can check the validity of a file here: https://github.khronos.org/glTF-Validator/