- Home /
mesh generation in unity
I don't know if this is considered mesh generation but it may be.
So, lets say i have a tower, tower a. Now lets say theres a towe r b. What i ould want to do is generate a"wall" from tower a's position to tower b's position. I don't think i could do it by scaling because im going to have it textured so if i scale so does the texture. So like. If i put two towers at any position and are at any angle at any distance away from each other i could make or generate a wall from point a to point b and have it textured. Thats basically what i want. Would any one know how to get that?
You can do it by scaling, by setting the material's tiling values as appropriate. However you'd need a material for every wall.
I think may have a problem now. So. I think your answer would work, im pretty sure it would, for a flat area. But lets say theres an angle involved of x degrees. How would i combine segments then when the angle the points are at could be any number? So like point a is 0,0 and point b is 5, (any number here). Then how would i combine them then when im not sure what angle the two points are at? Do you think mesh.combine$$anonymous$$eshes would still work? I cant create a mesh at every angle and combine it because its too time consu$$anonymous$$g. Do you think anything else would work or would i need to extrude through scripting from point a to point b?
Answer by VesuvianPrime · Sep 10, 2014 at 10:08 PM
Assuming your wall segments are nice and small (i.e. you would never need to cut one in half to make it fit between the towers) this is actually very simple to do.
You can build an array of CombineInstances and set the transform matrix on each such that the segments are arranged in a straight line. You then turn your CombineInstance array into a Mesh via Mesh.CombineMeshes.
Assuming your geometry isn't too dense, this is a pretty fast operation, and will save you a ton of drawcalls.
VesuvianPrime, i get what you're saying but it may take me a while as i haven't ever used mesh.combine$$anonymous$$eshes before. I catch on pretty quick though so thank you for the answer, but a thought came to me... Could i just create, per say, the "left" side and then extrude in unity through code frompoint a to point b?
I also have another question, im on my phone because i don't have internet at the time. Do yall know of an app or something i can check this on? I noticed the unity site isnt very friendly to mobile devices and t is only letting me read half your answer. Fron whati read though, i think i get what you're saying. And thank you. :)
Writing code to extrude geometry is going to be way harder than just combining a bunch of wall tiles. I think you'll find the CombineInstance method to be very straight-forward when you give it a go.
I don't know of Unity having an app for viewing Unity Anwers.
So i think this will work for flat surfaces, but what should i do if the two points are at angle(one higher than the other) and the angle is an unknown angle that could be any number? I csnt create a mesh for every angle so what would i do? Would sxtruding in code from a to b work then? Would anything else work besides just extruding?
Aha, I see, didn't know the wall needed to slope!
One solution would be to stagger the wall: http://imageshack.us/a/img202/9891/aoe0046.png
If you still want to extrude the wall you will need to:
Get an ordered list of the edge verts on the start wall piece.
Get a matching list of edge verts on the end wall piece.
Create a new $$anonymous$$esh
Loop over the verts and create triangles to stitch the pieces together. Add these triangles to the new mesh.
Generate UVs for your new triangles.
Combine the new mesh with the start and end wall geometry.