STL with multiple solids in a single file

I am trying to use the STLReader in vtk.js to show STL files that may contain multiple “solid” tags.
Is there functionality to identify each “solid” region and assign different properties (color, id, …)?

Thank you.

Yes. Although not sure if it’s available on js.
If I remember well it was something like: vtkPolyDataConnectivityFilter with ColorRegions=True, then for each color vtkThreshold + vtkGeometryFilter

Hope it helps

Thanks, but I do not see vtkPolyDataConnectivityFilter in vtk.js

The STL reader in VTK.js does not supports solid tags.

You might want to do a PR to add such feature to STLReader/index.js.

You can consider looking at the C++ vtkSTLReader.cxx code.

1 Like

Thank you. I will look into it.

Having multiple solid tags a non-standard variant of the STL file format, which very few implementations support. Although multiple solids are not explicitly prohibited in the STL standard, the fact that this feature is not available in the binary format indicates that an STL file is not intended to store multiple meshes. (Not that you could take the “STL standard” too seriously, as it contains nonsense such as all coordinates must be positive.)

Even if you develop something and send a merge request, VTK developers will need to spend time with reviewing it and if they decide to integrate it then they need to support it practically forever. This could be a significant effort in the long term, which would be much better spent on improving support of more modern mesh file formats.

@lassoan improving another format is not going to address the issue I asked about since multi-solid STL format is a need of my use case.

If there is no interest in a solution or a PR, I won’t spend time on it and just look at alternative libraries which have the feature already since I do not want to have to backport changes every time vtk.js updates.

P.S. While I have no interest in discussing format preferences because I find them pointless, the use of the “solid” keyword is from the original specification from 3D Systems from 1989 ( The StL Format | ). Using solid tags to identify different regions seems like a choice made by some vendors, but it is quite widespread in geometry and meshing tools, both commercial and open source (in binary format the solids are tagged in some tools using the additional UINT16 attribute, but this is indeed non-standard). If not used for that, it seems entirely unnecessary to have the keyword though :slight_smile:
Finally, VTK/paraview have supported multi-solid STLs for a long time too, so it is vtk.js to be inconsistent (not only in this, I am finding out :sweat_smile:).

VTK hasn’t been supporting storing multiple mesh components in a single STL file: only reading and only ASCII variant (which - according to the STL “standard” you cited - is intended for testing purposes).

I see that you would rather not discuss if use of STL is appropriate. However, if the outcome of the discussion may be that more advanced STL support is actually not needed then it is important to have this conversation here. Can you tell a bit about your use case?

  • What software do you use to create these multi-solid STL files?
  • What other file formats that software can write? Could you switch to one of those?
  • Are the other serious limitations of STL not causing problems for you (e.g., you lose surface normals when you write out to STL and sometimes correctly recomputing them is not trivial; when you read someone else’s STL then you never know what is the coordinate unit, only triangle cells are supported, you cannot specify colors, etc.)?

I don’t have a say about the file format to be used, so I need to support reading (not writing) multi-solid STL in my scenario.

The background story is that I’m evaluating the possibility of using vtk.js in place of another WebGL library. The scope of the project involves both geometry and data visualization. In this context, vtk.js is of interest mostly for the second aspect (remote capabilities in particular). However, it would be ideal to have also the geometry work done with it, if feasible without excessive hoops, which is why I need to import multi-solid STL files, among the (many) other things.

In any case, supporting multi-solid stl files isn’t such a big hurdle if each solid/endsolid block is treated as a separate actor in vtk. The current reader doesn’t strip out the solid tags, it simply ignores them. So it can take care of the work of identifying the solid regions and tagging them with their names after fetching the file. Once that’s done, the rest is standard code already in vtk.js to set the properties of each solid (actor). :thinking:

Thank you for providing more details. It seems that you got into a situation where you need this feature for your project, but probably very few others would use it.

Probably you would need to implement the feature yourself, submit a merge request, and then see if maintainers would take your changes (and so committing to maintenance & support). If it is a simple, non-invasive change and it comes with tests, documentation updates, etc. then it is more likely they will take it, even if there is very limited need for it outside your project.

1 Like