Message Boards Message Boards

Converting STL file to dat file

Posted 2 years ago

Consider the following answer by the writer of pgfplots, Christian Feuersänger, for drawing a 3d object in LaTeX.

The problem I am facing now is how to convert a STL file to such a collection of dat files.

I am positive Mathematica can do that. But I need some help.

I imported a sample STL part and looked at its FullForm:

Import["ExampleData/seashell.stl"]//FullForm

It is actually a MeshRegion:

MeshRegion[
    {
        {-0.4408000111579895`, -0.010666999965906143`, 
        0.01866699941456318`}, {-0.2808000147342682`, 0.02133299969136715`, 
        0.01866699941456318`}, etc.
    },
    {Polygon[{
        {1,2,3},{1,3,4},{2,5,6},{2,6,3},{5,7,8}, etc.
        }]
    ]

If I understand correctly, the dat file should be composed of 3 different files:

  1. facetIdx.dat (facet index file?)
  2. patches.dat (each row is one vertex; three (or four) consecutive vertices make one facet (patch))
  3. vertices.dat (every row is a xyz coordinate of a vertix?)

Sample files, specifically the one used in the answer linked above, can be found here.

(You can get a meaningful plot by working with only one file)

I am not 100% understand what is the syntax of the dat files.

Does anyone have any experience with such files?

How can Mathematica generate such dat files?

POSTED BY: Ehud Behar
2 Replies
Posted 2 years ago

POSTED BY: Eric Rimbey
Posted 2 years ago

@Eric Rimbey This is very helpful. Also, this is the first time I see the ... and Optional functions. I am glad I discovered them.

POSTED BY: Ehud Behar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract