Skip to content

Instantly share code, notes, and snippets.

@shubhamwagh
Last active April 24, 2024 14:26
Show Gist options
  • Save shubhamwagh/0dc3b8173f662d39d4bf6f53d0f4d66b to your computer and use it in GitHub Desktop.
Save shubhamwagh/0dc3b8173f662d39d4bf6f53d0f4d66b to your computer and use it in GitHub Desktop.
Steps to create textured mesh from point cloud using Meshlab

Steps to create Textured Mesh from Point Cloud using Meshlab

Get your PointCloud into MeshLab

  • Import the pointcloud file in ".ply" file format in Meshlab. Before importing make sure you do some pre-processing / cleaning on point cloud so as to ease the process of meshing.

Point Cloud Simplification and Normals Computation

  • Next we need to reduce the number of point samples for smooth meshing.
    • So go to Filters -> Point Set -> Point Cloud Simplification. Enter Number of samples circa 5% of original number of points. Make sure Best Sample Heuristic is checked.
  • After point cloud simplification, make sure to select Simplified point cloud in the Show Layer Dialog on the right hand side. If not visible, it can be opened by navigating to View -> Show Layer Dialog. Now we need to compute normals for point set.
    • So go to Filters -> Point Set -> Compute normals for point sets . Enter Neighbour num between 10 - 100. Initially try with 10 and try to get a mesh and later see if this can be improved by increasing the neighbour number. For Smooth Iteration initially try with 0 value and may be later it can be tried with values between 5 - 10. I mostly use value 8.
  • Make sure if your normals are properly computed by going to Render -> Show Normal.

Meshing / Poisson Surface Reconstruction

  • Next we are going to use Poisson Surface reconstruction to do meshing.
    • So go to Filters ->Remeshing, Simplification and Reconstruction -> Screened Poisson Surface Reconstruction. Initially try with default parameters then later one can play around with reconstruction depth, number of samples and interpolation weight values.
    • This will create another mesh layer called Poisson in the Show layer Dialog which has surfaces now. Make sure to select that to peform further operations.
    • One can observe that it has also created some extra surfaces. To remove them go to Filters -> Selection -> Select Faces with edges longer than .... By default the value is automatically computed, just click on apply. Then click on delete face button (triangle face and three vertex with a cross over it). This will remove extra surfaces.
    • After this operation, still some noise faces can be seen. To remove them go to Filters -> Cleaning and Repairing -> Remove isolated pieces (wrt Face Num.). Use the default value and make sure Remove unreferenced vertices is checked. This will remove some noise faces.
    • Even after the above operation some noise faces are seen. To remove them go to Filters -> Selection -> Select non Manifold Vertices. Click apply. Then click on delete face button (triangle and threwe vertex with a cross over it). This will remove remaining extra faces.

Texturizing the Mesh using pointcloud color attributes.

  • Now that we have a mesh, next step is to get the texture for the mesh from the pointcloud.

  • Make sure to select Poisson in the Show layer Dialog to peform further operations.

  • Go to Filters -> Texture -> Per Vertex Texture Function. Click on apply.

  • Go to Filters -> Texture -> Convert PerVertex UV into PerWedge UV. Click on apply.

  • Go to Filters -> Texture -> Parametrization: trivial Per-triangle.

    • Quads -per -line : 0
    • Texture Dimension (px) : 4096 or (1024, 2048).
    • Inter-triangle border (px) : 0
    • Method : Basic (with Space-optimizing somethimes Meshlab crashes.)
    • Click on Apply.
  • Now go to File -> Save Project As... Save the project in ".mlp" file format.

  • Now go to File -> Export Mesh As... Save the mesh in ".obj" file format. After clicking on save, it will open saving options. Make sure under Wedge, TexCoord is checked. Then click on OK.

  • Now go to Filters -> Texture -> Transfer: Vertex Color to Texture.

    • Texture file : (If your mesh was saved as mesh_1.obj, the texture file name should be mesh_1.png)
    • Texture width (px) : 4096 (make sure this is same as Texture Dimension in the above steps)
    • Texture height (px) : 4096 (make sure this is same as Texture Dimension in the above steps)
    • Check Assign texture and Fill texture.
    • Click on Apply.
  • Now you have a textured mesh. There is also a texture image file saved in the same directory where original mesh was saved.

  • If originally you saved your mesh as mesh_1.obj, after the above operation it will create mesh_1.obj.mtl and mesh_1.png. These are the three files needed to view textured mesh on any ".obj" file viewing software like Blender or autodesk etc.

Initially I couldn't find any proper step-by-step process to create textured mesh on meshlab. I hope these steps help people to come up with their own textured mesh. :D

If something is not clear, don't hesistate to comment on this.

Cheers!

@shubhamwagh
Copy link
Author

@TokyoWarfare , can you please create a fork of this gist and update the instructions? Then I can add updated instructions (with credits). This will definitely help people in the future. It has been a long time now since I last used Meshlab.

@kielnino
Copy link

kielnino commented Jan 29, 2024

For everyone interested, I get similar results with the pymeshlab-package by following the steps described for the Meshlab-GUI:

from pymeshlab import MeshSet
ms = MeshSet()
# load colored pointcloud
ms.load_new_mesh("pointcloud.ply")
# load mesh (it is now the "current" mesh, to which the filters are applied)
ms.load_new_mesh("mesh.ply")
ms.apply_filter("compute_texcoord_by_function_per_vertex")
ms.apply_filter("compute_texcoord_transfer_vertex_to_wedge")
ms.apply_filter("compute_texcoord_parametrization_triangle_trivial_per_wedge", textdim=4096)
ms.apply_filter("transfer_attributes_to_texture_per_vertex", sourcemesh=0, targetmesh=1, textw=4096, texth=4096)
ms.save_current_mesh("mesh_tex.obj")

The mesh was created from the pointcloud with the open3d-package in my case.

@shubhamwagh
Copy link
Author

Interesting! @kielnino thanks for sharing.

@Kolbinuss
Copy link

Hey,
thank you so much for your explanation @shubhamwagh. I was following all these steps but when it comes to recreating the surfaces with poisson I struggle to get good results. I'm trying to convert a room scan into a mesh to further use it in a VR-Environment but when it comes to creating the mesh i always get kind of washy surfaces. As you can see in the screenshots chairs and tables melt into each other which doesn't look that good. Is there any way to clean this up? Also a lot of extra surfaces are created around the furniture.
I thought my scan data was pretty good so is there maybe some kind of option to cut out any surface that doesn't fit my original scan data?

The original point set had 9.8 million vertices while my simplified set had 1.5 million.
Poisson created 6.6 million faces and i tried to play around a lot with different construction depths and interpolation rates.

This is a screenshot of the original point cloud data:
PointCloud_Mesh1

This is the result of poisson:
Poisson_Mesh1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment