Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: cannot convert float NaN to integer #1446

Closed
pafurijaz opened this issue Aug 12, 2021 · 11 comments · Fixed by #1458
Closed

ValueError: cannot convert float NaN to integer #1446

pafurijaz opened this issue Aug 12, 2021 · 11 comments · Fixed by #1458
Labels
exporter This involves or affects the export process Mesh_&_Object question Further information is requested

Comments

@pafurijaz
Copy link

Describe the bug
I attached the file that I cannot export and it took me 3 hours to find the problem because the script does not indicate the object that creates problems. 
but it generates a generic report, this is something that is not a big problem with a few objects but with my file with over 1700 objects it was difficult to locate the object.

Python: Traceback (most recent call last):
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/__init__.py", line 626, in execute
    return gltf2_blender_export.save(context, export_settings)
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 46, in save
    json, buffer = __export(export_settings)
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 66, in __export
    json = __fix_json(exporter.glTF.to_dict())
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 109, in __fix_json
    fixed[key] = __fix_json(value)
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 113, in __fix_json
    fixed.append(__fix_json(value))
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 109, in __fix_json
    fixed[key] = __fix_json(value)
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 113, in __fix_json
    fixed.append(__fix_json(value))
  File "/home/root/Software/blender-2.93.3/2.93/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 116, in __fix_json
    if int(obj) == obj:
ValueError: cannot convert float NaN to integer

location: <unknown location>:-1

.blend file/ .gltf
Nan-float.blend.tar.gz

Version

  • OS: Linux
  • Blender Version LTS 2.93.2 and the latest under development v3.00 daily build
@julienduroure
Copy link
Collaborator

Hello,
Confirmed, but not sure this is something we can work on.
The problem come from the mesh that is corrupt inside blender itself.
How to fix it:

  • go to edit mode
  • select all visible vertices
    • with Box or Circle selection, on wireframe mode
    • do not use A to select all
    • do not use L to selected linked vertices
  • Invert selection by Ctrl+I
  • You should now have 91 vertices selected
  • Delete them ( X )
  • You should now by able to export

If you now how you was able to produce this corrupt file don't hesitate to open a ticket on https://developer.blender.org/

@julienduroure julienduroure added exporter This involves or affects the export process Mesh_&_Object question Further information is requested labels Aug 13, 2021
@pafurijaz
Copy link
Author

With OBJ exporter works well
OBJ-saved

@pafurijaz
Copy link
Author

Anyway thanks for the suggestion I will test your solution

@julienduroure
Copy link
Collaborator

I confirm that you mesh is corrupt, you can see it in UI :
image

@pafurijaz
Copy link
Author

OK I try to make a bug report on Blender developer, I saw the nan number also in the new spreadsheet windows thanks, but why this with obj works?
image

@julienduroure
Copy link
Collaborator

Obj are exported but contains NaN values:
image

Means that maybe other softwares are not able to import it correctly.

glTF specification enforces to write min/max values in json. Having NaN values is not authorized in JSON

@lexaknyazev
Copy link
Member

Besides JSON not supporting NaN values, glTF forbids them in binary mesh data as well. The IO plugin should probably either reject export operation until such vertices are removed or gracefully skip them.

@pafurijaz
Copy link
Author

Well, if the exporter does not support this exception, it should be reported in the report which object or mesh contains the particular problem this could help when there are many objects, so as to be able to quickly identify the problem.

@pafurijaz
Copy link
Author

By exporting this model in PLY format I can correct the problem by easily deleting the corrupted vertices, I have only deleted the vertices outside the model, and after this fix the exporter works.
Maybe can be useful for a fix inside the exporter.
PLY-exported-model

@pafurijaz
Copy link
Author

I got an answer, from the developers, and with this command executed in the python console in object mode C.active_object.data.validate(verbose=True) I was able to solve the problem by identifying the problem and eliminating the vertices which are actually very few (14)
Maybe this could be useful to create a solution in these cases.
image

@julienduroure
Copy link
Collaborator

@pafurijaz Thanks a lot. It seems to solve the issue

julienduroure added a commit that referenced this issue Sep 15, 2021
Fix #1446 : validate meshes before export, removing NaN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter This involves or affects the export process Mesh_&_Object question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants