problem importing 3ds files
Posted: 19 Mar 2021, 15:50
Hi,
we are having a problem with a user importing 3ds files in our software (developed with Delphi). The software mimics the import procedure in the 3D demo which also fails to import this kind of 3ds files. I can see the import produces an exception when the 3ds file is read in Tsg3DNavigator.LoadFromFile
I was trying to narrow the problem and found a couple of things:
1) TMaterial3DS.shininess which is defined as a single in Type3DS. Then in GetOrAllocateMaterial, internal function of TGL3DSVectorFile.LoadFromStream in GLFile3DS.pas, shininess of a given material is stored in the property Shininess of the class TGLShader which has the type TShininess = 0..128. This is done in line 1749 of GLFile3DS.pas
given above line I assume material.Shininess is a Single meant for the range [0,1]. However, I can see that for the 3ds files of my user material.Shininess of one of the materials is 255 (like if it where meant in the range [0,255] rather than [0,1]). then the result of the left hand side in the above line of code is out of the range [0,128] which causes a range check error that triggers an exception. In our software we don't use shininess for anything so I just replaced the line by
2) Later in the execution flow, I had a second problem regarding camera objects in TGL3DSVectorFile.LoadFromStream at GLFile3DS.pas around line 2456
I can see in the 3ds files provided by the user, the argument of loadAnimation function is nil which causes an exception inside the function. Our software neither uses this camera for anything so I just skip the loading when the argument is nil like this
this is probably not a good solution because then I have an exception when freeing the navigator. Tsg3DNavigator.Free
When we built the importer in our software we tested a number of 3ds files having no problems with the import, however the user claims that all the 3ds files they create fail to be open, we suspect the problem might be related with the way the files are constructed. The 3ds files that cause the problem are created in Rhino (Version 6 SR11) following these instructions:
Select complete model, type command _mesh
Recommendation for the exact settings of the polygon mesh:
Density: 0.5
Maximum angle: 1.0
Maximum aspect ratio: 0.0
Minimum edge length: 1.0
Maximum edge length: 0.0
Maximum edge to face distance: 0.01
Minimum squares of initial mesh: 0
Refine polygon mesh: Check
Serrated seams: Check
Simple planes: Check
Compress textures: Uncheck
Obviously, each model has its own history, and the same settings cannot always be used.
Delete "old" surfaces so that only polygon meshes remain.
Save model as 3ds
an example 3ds file producing the exception is also attached as a zip file.
It would be really helpful if you could take a look to these problems and share a solution with us. Also Do you think a change on the workflow for the creation of the model might help to avoid the problems? Thank you
Regards, Carlos
we are having a problem with a user importing 3ds files in our software (developed with Delphi). The software mimics the import procedure in the 3D demo which also fails to import this kind of 3ds files. I can see the import produces an exception when the 3ds file is read in Tsg3DNavigator.LoadFromFile
I was trying to narrow the problem and found a couple of things:
1) TMaterial3DS.shininess which is defined as a single in Type3DS. Then in GetOrAllocateMaterial, internal function of TGL3DSVectorFile.LoadFromStream in GLFile3DS.pas, shininess of a given material is stored in the property Shininess of the class TGLShader which has the type TShininess = 0..128. This is done in line 1749 of GLFile3DS.pas
Code: Select all
Shininess := MaxInteger(0, integer(round((material.Shininess) * 128)));
Code: Select all
Shininess := MinInteger(MaxInteger(0, integer(round((material.Shininess) * 128))), 128);
Code: Select all
camera_mesh.LoadAnimation(KeyFramer.CameraMotion[I]);
Code: Select all
if Assigned(KeyFramer.CameraMotion[I]) then
camera_mesh.LoadAnimation(KeyFramer.CameraMotion[I]);
this is probably not a good solution because then I have an exception when freeing the navigator. Tsg3DNavigator.Free
When we built the importer in our software we tested a number of 3ds files having no problems with the import, however the user claims that all the 3ds files they create fail to be open, we suspect the problem might be related with the way the files are constructed. The 3ds files that cause the problem are created in Rhino (Version 6 SR11) following these instructions:
Select complete model, type command _mesh
Recommendation for the exact settings of the polygon mesh:
Density: 0.5
Maximum angle: 1.0
Maximum aspect ratio: 0.0
Minimum edge length: 1.0
Maximum edge length: 0.0
Maximum edge to face distance: 0.01
Minimum squares of initial mesh: 0
Refine polygon mesh: Check
Serrated seams: Check
Simple planes: Check
Compress textures: Uncheck
Obviously, each model has its own history, and the same settings cannot always be used.
Delete "old" surfaces so that only polygon meshes remain.
Save model as 3ds
an example 3ds file producing the exception is also attached as a zip file.
It would be really helpful if you could take a look to these problems and share a solution with us. Also Do you think a change on the workflow for the creation of the model might help to avoid the problems? Thank you
Regards, Carlos