Skip to content

Instantly share code, notes, and snippets.

@shubhamwagh
Last active October 9, 2024 09:32
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!

@ranjamm
Copy link

ranjamm commented Sep 23, 2020

Thanks a lot! I repeated the steps again, the mesh looks very promising and better than any other approaches I have used.
However, it shows these lines as in the image... Any idea why that is?
Capture

@ranjamm
Copy link

ranjamm commented Sep 23, 2020

Actually, Filters -> Texture -> Transfer: Vertex Color to Texture didn't work for me. So I used Transfer: Vertex Attribute to Texture.. maybe they are different?

@shubhamwagh
Copy link
Author

shubhamwagh commented Oct 6, 2020

@ranjamm , the image you have posted looks like mesh triangle edges, maybe you enabled that in your visualization? Vertex attribute to texture should be similar to Vertex color to texture I think.

@mcfly3001
Copy link

Thanks for the great explanation! Really helpful.

Instead of Poisson sampling I went for the ball pivoting reconstruction. This is not forcing a closed surface which was important in my case.

@ranjamm: I had the same problem. I could solve it by setting a higher value for the 'Inter-Triangle Border' when doing the parameterization. Maybe this also solves your issue?

@humbletang
Copy link

I've found that I end up with a pretty messy texture when I use the trivial per-triangle parameterization, Has anyone had these kinds of issues and been able to resolve them? You can see my example here https://photos.google.com/photo/AF1QipMtdTXAM0aBbJlji-8gPCqIpZkJ2Wg4EnPIxoxH

@Harin99
Copy link

Harin99 commented Jan 4, 2021

Thank you for your great explanation!!!

I did it by your method.
And then, i put the obj, mtl, png file into Unity Assets.
But nothing appear..
Do you know what's wrong on that?
I want to import this textured mesh into Unity ... But nothing appeared on Unity Scene.
Please help me T.T!!

Also, Can you tell me what 'Per Vertex Texture Function' function is?
I heard that texture coordinates(u, v) is calculated by position(3d x,y,z).
Also, u can be calculated using all x,y and z. v either.
So i put like this photo. ( Previous i just put the default value like, u = x, v = y )
image

Is it correct to do like this??

@MuslemRahimi
Copy link

MuslemRahimi commented Jan 13, 2021

I like trains, but also very good explanation. Thanks!

@jonalex
Copy link

jonalex commented Apr 27, 2021

Thanks a lot! I repeated the steps again, the mesh looks very promising and better than any other approaches I have used.
However, it shows these lines as in the image... Any idea why that is?
Capture

I have this exact same problem. It seems to embed the wireframe onto the texture, or leave that space.
I tried putting 0 as a border when Trival Per-Triangle, but same results.
image

Any thoughts?

@shubhamwagh
Copy link
Author

@jonalex Glad, you found the mesh texturing steps helpful. It has been a long time since I used meshlab. Can you confirm if you have disabled mesh triangle edges for your mesh in the viewer?

Also, @mcfly3001 was facing a similar problem. He could solve it by setting a higher value for the 'Inter-Triangle Border' when doing the parameterization. See if it works for you as well.

@lecaum
Copy link

lecaum commented May 20, 2021

Thanks a lot! I repeated the steps again, the mesh looks very promising and better than any other approaches I have used.
However, it shows these lines as in the image... Any idea why that is?
Capture

I have this exact same problem. It seems to embed the wireframe onto the texture, or leave that space.
I tried putting 0 as a border when Trival Per-Triangle, but same results.
image

Any thoughts?

I'm facing the exact same problem... Did you solve it?

@Kilderan100
Copy link

For the life of me I can't work out why I don't have the option to "" File -> Save Project As... Save the project in ".mlp" file format. ""
Followed steps for texturing using the Poisson

is this something I can skip? Thanks!

@dyvniy
Copy link

dyvniy commented Nov 24, 2021

Any idea why that is?

I have the same problem & I think it is border problem.
When program pleces triangles to texture, it mast make 2 pixels border to prevent this. Instead zero now. And tiangles in texture must be near another by geometry, not by number in array.
I don't know how it fix in Meshlab.

@osernchang
Copy link

osernchang commented Jan 28, 2022

For font view scan,I happened to solve the stranger lines problem in these procedures, by using other than "Trivial per triangle" , I used " Parametrization: Flat plane" instead, and used "Transfer: Vertex Attribute to Texture" instead of "Transfer: Vertex color to Texture", the uv unwrap project worked like plane project from front side that some corner came out with projectile shadow, but it looks fine overall for selfie portrait.
The other way is using the .ply file generated after saving Meshlab project wile mesh generating had done without any texture handling, then edit the plt file in Blender3D, bake vertex color into another blank image, switch them then it works.
I did some how made those stranger lines disappeared disappeared with Meshlab, but I repeated the same steps and it keeps failing, it seems like that there are some glitches in there.

@ttsesm
Copy link

ttsesm commented Jan 31, 2022

I was having the same issues as described above with the strange lines showing up in the texture map. The way I solved it was:

  1. Filters --> Texture --> Parametrization: Voronoi Atlas (enable Overlap option) --> Apply
  2. Filters --> Texture --> Transfer: Vertex Attribute to Texture

Then save as .obj, and you should have a nice output (at least better from the one above).

@shubhamwagh
Copy link
Author

shubhamwagh commented Jan 31, 2022

@ttsesm, 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.

@osernchang
Copy link

@ttsesm , It crashes every time when I use Parametrization: Voronoi Atlas (enable Overlap option), how did you manage to make it work? Should we simplify point set first?

@ttsesm
Copy link

ttsesm commented Feb 1, 2022

@osernchang indeed there is a bug (cnr-isti-vclab/PyMeshLab#179). It is not always working. In the beginning to some of the files that I've tried it, it was working without issues but then on some others it was failing (in my case it was taking for ever, so I had to stop the process manually). I opened an issue in the pymeshlab repo (because I want to use this functionality through a python script) and they confirmed that there is a bug and I guess at the moment they are trying to fix it.

Btw, I also asked about the issue with the strange lines on the output of the "Parametrization: Trivial per triangle".

I hope that they will have both fixed soon.

@shubhamwagh if I find some time (really busy period) I might get to make the changes.

@MohammadCGRE
Copy link

MohammadCGRE commented Feb 24, 2022

@ttsesm @lecaum @osernchang
Hi

Since i see the same proble mwith you (shows the bold lines as in the texture ), i want to kindly ask you did you find any new solution? i also use voroni atlas but i tooks forever, ireally do not knwo how long it will take.

@TokyoWarfare
Copy link

Hi, I think the tutorial is meant to use "transfer: Vertex ATRIBUTES to Texture instead. Since, allows to use the HIGH density point cloud as source for the texture information, and target mesh you set the Poisson mesh. I've the same triangle edge issues described by others bu I'm confident one way or another I'll be fixing theese.

@TokyoWarfare
Copy link

Update. If you whant to get rid of the UV mapping error issue, bring the mesh to meshalb with already UV mapping coords and then simply you need to Filters -> Texture -> Transfer: Vertex Atributes, Choose the color source (the point cloud) and the target (the imported mesh) set the resolution and texture name and whait for the bake, Beware that as you scale up resolution time to compute rises exponentially if not log.

@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

@osernchang
Copy link

osernchang commented Jul 16, 2024 via email

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