Issues with pymeshlab

Hello!

I’m trying to use pymeshlab with compas in a project. To avoid writing a conversion from meshlab meshes to compas meshes I was just exporting the meshes after processing them with meshlab to a ply file. Strangely, Compas cannot read the faces in a MeshLab meshes saved as ply. It does work with obj files, though.

I also get an error with the viewer. Here is an code example that triggers the error

import compas
import pymeshlab
from compas.geometry import Box
from compas.geometry import Frame
from compas.geometry import Point
from compas.geometry import Line
from compas.datastructures import Mesh
from compas_view2.app import App

CH = 'convex_hull.obj'

mesh = Mesh.from_ply(compas.get('bunny.ply'))

# =============================================================================
# MeshLab meshes
# =============================================================================

ms = pymeshlab.MeshSet()
ms.create_cube()
ms.save_current_mesh(CH)

# =============================================================================
# MeshLab to Compas
# =============================================================================

box = Mesh.from_obj(CH)
print(box.number_of_vertices())
print(box.number_of_faces())

# =============================================================================
# Viz
# =============================================================================

viewer = App()
viewer.view.camera.position = [5, -3, 2]
viewer.view.camera.look_at([0, 0, 0])

viewer.add(mesh)
viewer.add(box)

viewer.show()

This is the console output:

8
6
QObject::moveToThread: Current thread (0x297ea7d7400) is not the object's thread (0x297e371f8d0).
Cannot move to target thread (0x297ea7d7400)

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: windows, direct2d, minimal, offscreen, webgl.

Might it be the case that pymeshlab and compas.view2 depend on different versions of qt?

Thanks,

the Qt error doesn’t seem to be version related necessarily, but perhaps try to make to separate environments to see if the problem goes away.

related to the PLY thing.
can you post the PLY file that COMPAS is unable to load?

It works in the same environment. I just have to separate all the pymeshlab code from the compas code in different scripts.

I’m not allowed to post the PLY file here, but any simple cube will show the issue. For instance, in the above code just changing CH = 'convex_hull.ply will save the cube as PLY. Then changing the line box = Mesh.from_ply(CH) will import the ply file created by Meshlab with a simple cube. You will see that it will print 0 faces.

Here are some links to two different ply files saved with meshlab:

seems to be something wrong with these files. if i use the PLY reader directly it complains about the encoding, and if i try loading them in Rhino they have no content either…

could you try exporting the files in ascii format (text-based PLY) so we can have a look at what is inside?

It opens fine in Rhino on my side. Here is a printscreen:

And here is the same cube but saved in ASCII:

If you change the above code from binary to ASCII, compas can read the file correctly.

import compas
import pymeshlab
from compas.geometry import Box
from compas.geometry import Frame
from compas.geometry import Point
from compas.geometry import Line
from compas.datastructures import Mesh
from compas_view2.app import App

CH = 'box.ply'
# =============================================================================
# MeshLab meshes
# =============================================================================

ms = pymeshlab.MeshSet()
ms.create_cube()
ms.save_current_mesh(CH, binary=False)

# =============================================================================
# MeshLab to Compas
# =============================================================================

box = Mesh.from_ply(CH)
print(box.number_of_vertices())
print(box.number_of_faces())

okay, weird. the reader is supposed to be able to handle binary files so i will check what is going on there. in the meantime, you can work with the ASCII encoding?

Yes, no problem. Thanks