How to set UV (Map) for Mesh made by script without duplicating vertices?

Hello, and Happy New incoming Year!

// Story
I get an idea to create a “spiral stairs generator”. Since in my “game” should be many multi-leveled buildings, and I’d like to have nice architecture, spiral stairs are must. Normally I’d make a spiral stairs in Blender, set everything there and import into Unity. But, let’s say that I want different step length, so I have remade whole model. Using physics is also hard, since I don’t have acces to single step. Och, and changing amount of steps is also remaking whole model.

Having that in mind I wrote script, which can quite well generate it for me.
I’m making mesh from scratch of single step. Create multiple steps, then set their positions, and set steps as children of “mother-stairs”. Simple math.

// Question
However, there is going UV. I know, that UV is Vector2 with X,Y variables from range <0;1>, where values are percentage of width and height of texture (nice feature for different texture resolutons).

This is the effect of “hard set” for vertices.

Almost well.

In theory my Mesh (are), and its UVMap (should) look like this:

// TL;DR
As You can see in picture above, there are many occurences of one vertice in UVMap. Is there any way, to made proper UVMap without duplicates?
If it’s impossible, how to do duplicate it easily and properly?

Thank You in advance,
Drakonno

There is absolutely no problem with duplicating vertices.

This is something of a misunderstanding in 3D mesh tech. Note that in your case it’s inconceivable you could need to reduce the amount of vertices. So there’s just absolutely no problem at all with having “duplicate” (you could say “normal”) vertices; there is no downside, it’s simpler and in many ways better, it’s the normal thing to do and you should do it!

It’s possible for the vertices 1,2,3 and 4 in your schematic if they are laid out like that. The rest has to be duplicated, there’s no way around it. It’s what Unity does anyway when you import a mesh with shared vertices but where the UV map is laid out with unshared vertices. In the end, as long as you don’t create a mesh that doesn’t need to be cut at edges, you’ll be better of just generating each face seperately, without shared vertices.