grabthefish / StlImporter

STL importer for Godot
MIT License
5 stars 5 forks source link

Error when opening stl file from fusion360 #1

Open Siuys opened 1 year ago

Siuys commented 1 year ago

Hi, First of all I would like to thank you for this code. I found that #this line in import_plugin.gd :

var attribute_byte_count = file.get_16() file.seek(file.get_position() + attribute_byte_count)

doesn't work with fusion360 file.

After investigation attribute_byte_count value is not 0 for their file (0x7FFF). These bits are normally used for integrity checking but no one uses them.

I replace it by: var useless_16b = file.get_16() and i remove file.seek(file.get_position() + attribute_byte_count)

Seens then it works perfectly.

aluaces commented 1 year ago

Hi, do you have a sample file to try? I also encountered some problems when loading binary STL files, and I looked for a solution in blender source, https://github.com/blender/blender/blob/9efd2c9ab6afeca71ee2752523183d3d7748ac89/source/blender/io/stl/importer/stl_import.cc#L76

There are programs as Soliworks which generate incorrect headers as well (in this case they write solid inside the header of a binary file, which is supposed to be forbidden) so I wanted to try if blender's solution fits both cases.

Siuys commented 1 year ago

From what I understood, the initial 80 bytes can contain software information. [https://en.wikipedia.org/wiki/STL_(file_format)] I have created a simple cube in Fusion 360, and the 2 bytes "attribute byte count" correspond to the 15-bit RGB color code (I just learned this from the English wiki). I will send you the file by mail. Can you provide a simple file from soliworks (stlb)? I don't have SolidWorks, but I would like to see if my software can open its files.

Siuys commented 1 year ago

Simple fusion 360 cube

Le jeu. 15 juin 2023 à 12:21, Alberto Luaces @.***> a écrit :

Hi, do you have a sample file to try? I also encountered some problems when loading binary STL files, and I looked for a solution in blender source, https://github.com/blender/blender/blob/9efd2c9ab6afeca71ee2752523183d3d7748ac89/source/blender/io/stl/importer/stl_import.cc#L76

There are programs as Soliworks which generate incorrect headers as well (in this case they write solid inside the header of a binary file, which is supposed to be forbidden) so I wanted to try if blender's solution fits both cases.

— Reply to this email directly, view it on GitHub https://github.com/grabthefish/StlImporter/issues/1#issuecomment-1592773194, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUPH2YOLOVHTS5HQ5DKHHHDXLLOZ3ANCNFSM6AAAAAAZFBI3KU . You are receiving this because you authored the thread.Message ID: @.***>

aluaces commented 1 year ago

Hi, I don't see your file. I think the STL format is not supported by github. As a workaround, maybe you can compress it to .zip and resend as I had to do.

Anyway, here is mine from Solidworks, when converting a part to a binary STL file.

It can be seen that it incorrectly uses the word solid in the first bytes of the file, even if it is a binary file. Cubo de carga.zip

Siuys commented 1 year ago

Hi, from what i read the 80 first bytes can be everything they want (Header). You need to start reading after that. The next 4 byte are the number of triangle and then you have every triangle (50 bytes each) as shown here: https://en.wikipedia.org/wiki/STL_(file_format) Look at Binary STL section. I will try your file tomorrow and send you the "fusion" cube.

Le mer. 21 juin 2023 à 11:13, Alberto Luaces @.***> a écrit :

Hi, I don't see your file. I think STL is not supported by github, maybe you can compress it to .zip and resend as I had to do.

Anyway, here is mine from Solidworks, when converting a part to a binary STL file.

It can be seen that it incorrectly uses the word solid in the first bytes of the file, even if it is a binary file. Cubo de carga.zip https://github.com/grabthefish/StlImporter/files/11815807/Cubo.de.carga.zip

— Reply to this email directly, view it on GitHub https://github.com/grabthefish/StlImporter/issues/1#issuecomment-1600482728, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUPH2YNM526M2FSPLQDEBX3XMK3LZANCNFSM6AAAAAAZFBI3KU . You are receiving this because you authored the thread.Message ID: @.***>

Siuys commented 1 year ago

Hey, I read again the wiki ^^. Yes it shouldn't begin with solid. An easy way to detect this error is to read the number of triangles and check if the size after the triangle number matches nb_triangle*50bytes. It will allow to bypass this error from solidworks. I hope you understand me ;)

Le mer. 21 juin 2023 à 20:28, Théo Lestienne @.***> a écrit :

Hi, from what i read the 80 first bytes can be everything they want (Header). You need to start reading after that. The next 4 byte are the number of triangle and then you have every triangle (50 bytes each) as shown here: https://en.wikipedia.org/wiki/STL_(file_format) Look at Binary STL section. I will try your file tomorrow and send you the "fusion" cube.

Le mer. 21 juin 2023 à 11:13, Alberto Luaces @.***> a écrit :

Hi, I don't see your file. I think STL is not supported by github, maybe you can compress it to .zip and resend as I had to do.

Anyway, here is mine from Solidworks, when converting a part to a binary STL file.

It can be seen that it incorrectly uses the word solid in the first bytes of the file, even if it is a binary file. Cubo de carga.zip https://github.com/grabthefish/StlImporter/files/11815807/Cubo.de.carga.zip

— Reply to this email directly, view it on GitHub https://github.com/grabthefish/StlImporter/issues/1#issuecomment-1600482728, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUPH2YNM526M2FSPLQDEBX3XMK3LZANCNFSM6AAAAAAZFBI3KU . You are receiving this because you authored the thread.Message ID: @.***>

Siuys commented 1 year ago

cube file

Le mer. 21 juin 2023 à 20:36, Théo Lestienne @.***> a écrit :

Hey, I read again the wiki ^^. Yes it shouldn't begin with solid. An easy way to detect this error is to read the number of triangles and check if the size after the triangle number matches nb_triangle*50bytes. It will allow to bypass this error from solidworks. I hope you understand me ;)

Le mer. 21 juin 2023 à 20:28, Théo Lestienne @.***> a écrit :

Hi, from what i read the 80 first bytes can be everything they want (Header). You need to start reading after that. The next 4 byte are the number of triangle and then you have every triangle (50 bytes each) as shown here: https://en.wikipedia.org/wiki/STL_(file_format) Look at Binary STL section. I will try your file tomorrow and send you the "fusion" cube.

Le mer. 21 juin 2023 à 11:13, Alberto Luaces @.***> a écrit :

Hi, I don't see your file. I think STL is not supported by github, maybe you can compress it to .zip and resend as I had to do.

Anyway, here is mine from Solidworks, when converting a part to a binary STL file.

It can be seen that it incorrectly uses the word solid in the first bytes of the file, even if it is a binary file. Cubo de carga.zip https://github.com/grabthefish/StlImporter/files/11815807/Cubo.de.carga.zip

— Reply to this email directly, view it on GitHub https://github.com/grabthefish/StlImporter/issues/1#issuecomment-1600482728, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUPH2YNM526M2FSPLQDEBX3XMK3LZANCNFSM6AAAAAAZFBI3KU . You are receiving this because you authored the thread.Message ID: @.***>