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.

1 Answer

1

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.

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.

Thank you for the answer. :) i'll try it. :D

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: 1. Get an ordered list of the edge verts on the start wall piece. 2. Get a matching list of edge verts on the end wall piece. 3. Create a new Mesh 4. Loop over the verts and create triangles to stitch the pieces together. Add these triangles to the new mesh. 5. Generate UVs for your new triangles. 6. Combine the new mesh with the start and end wall geometry.

Yeah, i guess i should've gave more info on what i want to do. Thank you for the help though. :) i might do the staggering example you showed but its a little unlikely. It looks like minecraft to me a little and this won't be one of those games. I guess im going to go with extruding, it sounds kind of hard. Do you know of any draw backs that extruding has over staggering? Is extruding less efficient that staggering? If it is, could i take the mesh ive created through extending and make it a prefab and then delete it and instantiate the prefab? Maybe that would be more efficient?