- Home /
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
Just BTW unrelated to your question. When generating objects, sometimes it is better to $$anonymous$$.I.S.S. I would consider making a routine which generates one GameObject being "one step unit", that is to say one riser + tread (plus carrier, nubs, or anything else).
For example, say you are generating a room. It's often better to simply have four separate GameObject for the walls, rather than one GameObject.
Apart from anything else, it's much easier to unit test, modify and so on. That's what I've found! Cheers
PS http://www.tradestairs.com/acatalog/stair-ter$$anonymous$$ology.GIF
Answer by Cherno · Dec 30, 2015 at 11:10 AM
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.
Thank You. If noone will get better idea, I accept this as answer. :)
Answer by Fattie · Dec 30, 2015 at 04:11 PM
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!
I'd like to add that it CAN become a problem when creating meshes with a lot of vertices, as they may only have ~65k vertices. Also, assigning a collision mesh is faster the less vertices it has. In the end, this can be avoided by dividing a large mesh into chunks, which is how most games do it.
For sure. As I said "in your case it's inconceivable you could need to reduce the amount of vertices".
You never, as a broad rule, use mesh colliders (generally the only time mesh colliders are used in vid games, is as the ground or terrain).
As you say if you are (for some incredible reason) making a mesh that has tens of thousands (!) of vertices, you would be dividing it up in some way.
In any event, the absolute fact is, in the actual situation presented, they should be shared ! Happy new year!
Your answer
Follow this Question
Related Questions
Mesh filters missing their meshes when project cloned from bitbucket 2 Answers
Array index is out of range in MeshMorpher 2 Answers
Can't change verts on mesh after assigning to meshfilter. 1 Answer
Creating a mesh for an overview map 0 Answers
Number of mesh vertices increase when imported into unity 1 Answer