Using CombineMesh with point topology?

I have two simple meshes which are using points topology and I am trying to combine them using Mesh.CombineMeshes. However, CombineMeshes seems to always triangulate my meshes and set the mesh to use Triangle topology. I want to keep the points. How can I combine meshes while preserving their topology? Am I really going to have to combine the meshes manually (much slower) or convert mesh to a Triangle topology (how)?

Mesh  enviroment = new Mesh{indexFormat = UnityEngine.Rendering.IndexFormat.UInt32};
Mesh mesh = pointCloudRenderer.getMesh ();    //mesh with point topology

CombineInstance[] combine = new CombineInstance[1];
combine[0].mesh = mesh;

enviroment.CombineMeshes(combine, true, false, false);

Error: Failed getting triangles. Submesh topology is lines or points.

I’m not sure what “point topology” is, but if you mean your geometry is just pure points without any triangles, then combining the mesh is simply concatenating two lists of vertices, nothing more.

Vertices have:

  • normals
  • colors
  • UVs
  • some other stuff:

See Unity - Scripting API: UIVertex

(the above is just a helper class in the UI VertexHelper class but it gives you the idea)

Triangles have:

  • index to 3 verts
  • submesh number (determines Material; this is stored more at the Mesh level than the triangle level)
  • possibly other stuff?

I mean MeshTopology.Points. I create the first mesh by this way:

positions = subscriber.GetPCL();
        colours = subscriber.GetPCLColor();
        if (positions == null)
        {
            return;
        }
        mesh.Clear();
        mesh.vertices = positions;
        mesh.colors = colours;

        //meshtopology points
        int[] indices = new int[positions.Length];

        for (int i = 0; i < positions.Length; i++)
        {
            indices[i] = i;
        }

        mesh.SetIndices(indices, MeshTopology.Points, 0);

I already tried concatenating two lists of vertices but the problem is what happens if there are points that exists in both meshes? There is no way to use CombineMeshes with MeshTopology.Points?

Well, even CombineMeshes would just keep both as this method does just simply combine the two meshes. There are no crossovers between the two meshes. If the meshes intersect before the combination, they would intersect afterwards as well.

The only thing you may need to keep an eye on is when your meshes should be translated / transformed in some way. This is usually done by the Transform component on an gameobject. When you combine objects with their specific object position / rotation / scale, you had to setup the transform matrix in each combine instance. When you combine them manually you would need to do the transformation yourself if it’s even necessary. We don’t know if that might be necessary in your case.

Anyways, combining meshes does not get rid of duplicates. If you want to get rid of duplicates you have to do that manually anyways. Could be done with a dictionary, however the exact procedure depends on what you consider as duplicate. Does two points at the same place count as duplicate even it has other vertex attributes that are different?

1 Like

Okay, I will try with a dictionary. Thanks.

Have you had any luck doing so ?

My last paragraph does apply to you as well:

Other vertex attributes include things like vertex color, normal / tangent and uv coordinates, if you have any of those in your meshes. If not and it’s only the position that matters, you still have to decide when you want to call them “duplicate”. With a dictionary it would only work if both meshes are defined in the same space to begin with. Otherwise due to the transformation you would get slight rounding issues and a dictionary would fail. In such cases you usually would define some “threshold” and filter out duplicates “manually” by checking each point against each other. There’s no way around that if you want to eliminate duplicates.