meshmeshlabstl-format

Meshlabserver: How to convert STL to PLY and unify vertices?


I have several .stl files that I would like to convert to .ply by calling meshlabserver from the command line. When I go the straightforward way

> meshlabserver -i cube-binary.stl -o cube.ply

(where cube.stl is a sample file given below with 12 faces), the resulting mesh has 12 faces and 36 vertices. This means that no unification of repeated vertices has happened, although that was the very reason why I wanted to go for .ply instead of .stl.

Now, I assume that it is not possible for the same reason it was impossible make the vertex unification default in the Meshlab GUI (I asked about it some time ago, although it later turned out that such a question had already existed). But maybe someone knows some trick? Browsing through possible filters after -om, I did not find a solution.

The behaviour was tested with Meshlab 2016 on Open SUSE and with Meshlab v1.3.2_64bit on Ubuntu.

The sample file

(also created by Meshlab)

solid vcg
  facet normal  0.000000e+00  0.000000e+00  1.000000e+00
    outer loop
      vertex   5.000000e-01  5.000000e-01  5.000000e-01
      vertex  -5.000000e-01  5.000000e-01  5.000000e-01
      vertex   5.000000e-01 -5.000000e-01  5.000000e-01
    endloop
  endfacet
  facet normal  0.000000e+00  0.000000e+00  1.000000e+00
    outer loop
      vertex  -5.000000e-01 -5.000000e-01  5.000000e-01
      vertex   5.000000e-01 -5.000000e-01  5.000000e-01
      vertex  -5.000000e-01  5.000000e-01  5.000000e-01
    endloop
  endfacet
  facet normal  1.000000e+00  0.000000e+00  0.000000e+00
    outer loop
      vertex   5.000000e-01  5.000000e-01  5.000000e-01
      vertex   5.000000e-01 -5.000000e-01  5.000000e-01
      vertex   5.000000e-01  5.000000e-01 -5.000000e-01
    endloop
  endfacet
  facet normal  1.000000e+00  0.000000e+00  0.000000e+00
    outer loop
      vertex   5.000000e-01 -5.000000e-01 -5.000000e-01
      vertex   5.000000e-01  5.000000e-01 -5.000000e-01
      vertex   5.000000e-01 -5.000000e-01  5.000000e-01
    endloop
  endfacet
  facet normal  0.000000e+00  1.000000e+00  0.000000e+00
    outer loop
      vertex   5.000000e-01  5.000000e-01  5.000000e-01
      vertex   5.000000e-01  5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01  5.000000e-01  5.000000e-01
    endloop
  endfacet
  facet normal  0.000000e+00  1.000000e+00  0.000000e+00
    outer loop
      vertex  -5.000000e-01  5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01  5.000000e-01  5.000000e-01
      vertex   5.000000e-01  5.000000e-01 -5.000000e-01
    endloop
  endfacet
  facet normal  0.000000e+00  0.000000e+00 -1.000000e+00
    outer loop
      vertex  -5.000000e-01 -5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01  5.000000e-01 -5.000000e-01
      vertex   5.000000e-01 -5.000000e-01 -5.000000e-01
    endloop
  endfacet
  facet normal -0.000000e+00 -0.000000e+00 -1.000000e+00
    outer loop
      vertex   5.000000e-01  5.000000e-01 -5.000000e-01
      vertex   5.000000e-01 -5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01  5.000000e-01 -5.000000e-01
    endloop
  endfacet
  facet normal  0.000000e+00 -1.000000e+00  0.000000e+00
    outer loop
      vertex  -5.000000e-01 -5.000000e-01 -5.000000e-01
      vertex   5.000000e-01 -5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01 -5.000000e-01  5.000000e-01
    endloop
  endfacet
  facet normal -0.000000e+00 -1.000000e+00 -0.000000e+00
    outer loop
      vertex   5.000000e-01 -5.000000e-01  5.000000e-01
      vertex  -5.000000e-01 -5.000000e-01  5.000000e-01
      vertex   5.000000e-01 -5.000000e-01 -5.000000e-01
    endloop
  endfacet
  facet normal -1.000000e+00  0.000000e+00  0.000000e+00
    outer loop
      vertex  -5.000000e-01 -5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01 -5.000000e-01  5.000000e-01
      vertex  -5.000000e-01  5.000000e-01 -5.000000e-01
    endloop
  endfacet
  facet normal -1.000000e+00 -0.000000e+00 -0.000000e+00
    outer loop
      vertex  -5.000000e-01  5.000000e-01  5.000000e-01
      vertex  -5.000000e-01  5.000000e-01 -5.000000e-01
      vertex  -5.000000e-01 -5.000000e-01  5.000000e-01
    endloop
  endfacet
endsolid vcg

Solution

  • The easiest way is to use a script that apply the Remove Duplicate Vertices filter.

    Try saving this to a file named cleanVertex.mlx

    <!DOCTYPE FilterScript>
    <FilterScript>
     <filter name="Remove Duplicate Vertices"/>
     <filter name="Remove Unreferenced Vertices"/>
    </FilterScript>
    
    

    And then using the command:

    > meshlabserver -i cube-binary.stl -o cube.ply -s cleanVertex.mlx