alextsui05 / blender-off-addon

Import-export OFF meshes in Blender.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File Header Handling

Alphastrick opened this issue · comments

commented

During importing files from ModelNet40 an error occured (example file bathtub_0102.off).

Some files of ModelNet contain an formating error in the first line.

OFF9278 6940 0
-10.326050 27.195520 7.062850

This will lead to a parsing error:

Failed with model E:\ai_datasets\ModelNet40\bathtub\train\bathtub_0106.off
Error: Traceback (most recent call last):
  File "C:\Users\%userprofil%\AppData\Roaming\Blender Foundation\Blender\2.83\scripts\addons\import_off.py", line 97, in execute
    mesh = load(self, context, **keywords)
  File "C:\Users\%userprofile%\AppData\Roaming\Blender Foundation\Blender\2.83\scripts\addons\import_off.py", line 199, in load
    vcount, fcount, ecount = [int(x) for x in line.split()]
  File "C:\Users\%userprofile%\AppData\Roaming\Blender Foundation\Blender\2.83\scripts\addons\import_off.py", line 199, in <listcomp>
    vcount, fcount, ecount = [int(x) for x in line.split()]
ValueError: invalid literal for int() with base 10: '26.828400'

Proposed changes line 194:

    if len(first_line) > 4:
        # Parsing invalid off file header 
        line = first_line[3:]
    else:
        # handle blank and comment lines after the first line
        line = file.readline()

    while line.isspace() or line[0]=='#':
        line = file.readline()

Sorry for the lateness of my reply, and thanks for your interest.

I'm unfamiliar with the ModelNet40 dataset, but I'll download and have a look at some sample data. I guess ideally we'd be able to parse the vertex/face count even with the formatting error. I hope you were able to modify the addon to get it to work for your specific use case.

As for updating this project, I think first of all it'd be nice to get some sort of testbed or CI setup for the project so that we can move forward with development and test proposals like yours. As it is, the addon just kind of works as-is on simple, standard OFF files, but it's very hard to guarantee behavior. I'll look into setting this up in my spare time.