STLExport could use mesh name(s) instead than the generic stlmesh as solid label(s)

When using CreateSTL, ASCII STL files are generated ignoring mesh names and adding the generic “stlmesh” label after the “solid” and “endsolid” keyword:

The name of each mesh could be used to create separate solids, each with the name associated to the corresponding mesh “mesh.name”, or at least the option of customizing the standard name could be provided (there is one for the file name, but the solid name is hardcoded).

Do you think this would be an acceptable change/improvement?

Hi, it will not be enough, because this “hardcoded” name is outside the for loop, it is need to be inside. Even if I put it inside and use mesh names, later when I imported the stl file in a different app or program there was only one object :frowning: Everything was merged on import even if I didn’t see this option
But maybe I did something wrong
Let’s ping @Pryme8, STLExport creator :muscle:

Ohh gorsh, I do not remember the specifics of this it was sooooo long ago. Buuuuut, I can take a look here. Ill just have to go re-read the stl specs and make sure this is a things we can do.

Off the top of my head though I dont think mesh names are supported because but I may be wrong. Stl’s are a very very small set of data and I think was only vertices and faces (if I remember right).

@Pryme8 In the STL specification, the keyword “solid” can be followed by a name See: STL (file format) - Wikipedia There can be multiple in the same file to identify parts.

@MarianG the reason why everything is merged into one solid is that there is only one solid/endsolid group that contains all the information.
To separate in multiple parts, each mesh should be mapped to a

solid mesh_name
// other stuff here
endsolid mesh_name

My question was more along the lines of “will I break anything if I make a change like that” and open a PR? :slight_smile:

1 Like

Sounds like you got it sorted out!

I can’t imagine that would break anything :thinking:

I already did those changes with naming inside loop as I said and there are independent meshes inside stl file if I open it in editor but if you open it in a cad program they are still merged

Sounds good, I’ll give it a try.

1 Like

What CAD? Paraview should be able to distinguish different solids.
Do you have an example of the generated file from Babylon.js after your changes?

Hi, sure. Here is
the model
https://raw.githubusercontent.com/Bulisor/SmarTeam3D/master/assets/test/model3d.stl
the exporter
https://raw.githubusercontent.com/Bulisor/SmarTeam3D/master/assets/test/stlExport.ts

I had to import this in cadwork, and it didn’t work :frowning: so I ended up using obj export, convert to stp and use stp

Thank you, @MarianG

The exported STL you shared is actually working correctly, with solids split, in paraview and in my application too. I suspect the STL reader of the CAD you used does not consider separate solids from STLs (which would not be the first time for a CAD :frowning: ).

Paraview shows nine solids, each identified with its own color:

So, I think your code is fine.

One question: are you adding a random number to ensure uniqueness of the mesh name?

Hi, great!
Yes, that Math.random was for unique name. Maybe we can use loop index and mesh name and it should be enough

Excellent!

I would say, if mesh names can be assumed to be unique (they should if one wants to be able to retrieve objects by name), then the name should be sufficient.

In the STL specifications, it is acceptable to have the “solid” keyword without name.

If that is OK for you, the code is fine just removing the addition of the random number.

@MarianG just checking in: do you plan to submit a PR for this? :slight_smile:

Hi, sure. I completly forgot about this :frowning:

No worries! I wanted to touch base and ask if I could do anything on my end to help. :slight_smile:

It is here

2 Likes