Create Custom mesh.Select Vertices and create Polygon Mesh. How to calculate (vertex winding ) indices?

Hi,
I am trying to create custom mesh using vertex data.
Check out this : https://www.babylonjs-playground.com/#VKBJN#598
Click on atleast 4 different points in anti clock sequence of plane. then click create mesh.
You can see a mesh with selected area.
I am able to create planes like wall and window I can create.
But for floor I need to capture more then 4 points.You can try it by clicking more then 4 points I am able to capture vertext position and there uv point I already did that to need (vertex winding order) indices also in same manner but I dont know How to calculate indices dynamically.
I want it to work for any no of points.
Clock wise or anticlockwise.

Maybe you could use PolygonMeshBuilder?

thanks @jeff2365 . I tried it worked without uvs . How to apply uvs?

The uvs should already be applied https://www.babylonjs-playground.com/#1BIQIC#6

thanks @JohnK pg you shared as i understand applying path and material.
If you see my pg i am tracing uv from the points I hit. I want use those Uvs .
Here i am trying with polygon mesh.
https://www.babylonjs-playground.com/#VKBJN#600