How to create mesh if I have the triangles?

So lets assume I have an array or list of Triangle objects. The order of the triangles in the array is not the order in which they should appear on the mesh (so its a random order). How can I build the mesh if I have only this array/list?
I was thinking about making a Geometry for every triangle and then attach them to a node and attach this node to the rootNode. Could this be the solution?

Depends, if all you want is some triangles, then sure, make geometries from each and then batch them.
Batching means all triangles using the same material will end up as one object… which is good since lots of objects is a very efficient way of nuking your fps.

If you want more than that from those triangles then we’ll need more info.

Have you looked at the custom mesh tutorial?

(Individual geometries per triangle will give terrible performance btw - at the very least you will need to batch them as previously mentioned but even that isn’t ideal).

Yes, I read that tutorial, but it says i have to define the mesh by the vertex and index buffer, of which i dont have information.

All I want is to make one object from a list of triangles. Btw the triangles have common edges/vertices so in the end it will be one convex and closed mesh.

This explains how the vertex buffer and the index buffer works together.

I know how they work, it is not the problem. The problem is that I only have the triangles (thousands of them) and i want to build the mesh from these triangles. I cant build the mesh by defining the vertex and index buffers because i have no idea how the mesh will look like, what are the vertex coordinates, but most importantly what is the index buffer should look like.

Why not? You have all the information there you just need to organise it.

At its simplest define the vertex buffer = numtriangles*3, index buffer the same size.

Loop through the triangles putting their vertices into the vertex buffer, indices into the index buffer.

The next step would be to optimise the mesh by removing duplicates but stick with simple first.

Wow, I didnt even think of this. I will definitely gonna try it. So the order of the vertices in the buffer doesnt matter? I mean every 3 consecutive vertices must create a triangle, but the order of these triplets is not important?

@a.bedleg said: Wow, I didnt even think of this. I will definitely gonna try it. So the order of the vertices in the buffer doesnt matter? I mean every 3 consecutive vertices must create a triangle, but the order of these triplets is not important?

Put them in the vertex buffer in whatever order you want but the index buffer must refer to them in counter clockwise order… or turn of backface culling.

If you aren’t sharing vertexes between triangles then you shouldn’t need an index buffer at all. Just put the triangle vertexes together in the vertex buffer… triples for each triangle.

Hi again. I realized that the easiest solution in my case would be the geometry batching. However, I am facing a problem. Whenever I call GeometryBatchFactory.optimize(Node n), or GeometryBatchFactory.mergeGeometries(List g, Mesh out), I get only one vertex. I mean, if my mesh has X vertices, I get the same vertex X times, so at the end I dont get the resulting mesh, but only one vertex. The List or the Node contains the correct geometries(triangles).

Nevermind, I made it with buffers, but if someone knows the answer to my issue stated in my previous post, I will gladly hear the answer :slight_smile: