Hi! I hope someone can solve this better than me.
I have two type of meshes…
rectangular/squared (most terrains)
unequal sides:
I simply need to know if the mesh I’m introducing to my script is RECTANGULAR (symmetric) or not… (on XZ axis)
I did it by finding the edges and bounds of the edge… but if there are too many vertices this is an slow solution…
I don’t think symmetry is the word you’re looking for. Nothing above looks symmetrical.
One of the meshes appears rectilinear in the X/Z bounds and one does not.
Are you making and loading these in the project? Why not just make a table of them and mark which ones meet your criteria or not? Code you don’t have to write also does not have to be debugged. It’s kinda cool.
I guess you could see what the min/max X and Z values are, then see if there are more than a certain fraction of the extreme verts at that same linear position… are the verts utterly random or in a grid?
if in a grid, find the min/max X for each Z line of verts, see if those Min/Max X are mostly in line with each other at each end
You could lay a finer (or coarser?) grid over it and mark which verts touch each one (bucketizing), then study the edge of that finer grid and see if all the limit verts are roughly in line.
I guess this can certainly be done analytically… but is there any reason to do so? You’re presumably either creating these meshes at runtime or loading them in yourself, right? Any reason you can’t just store an enum value association for the shape somewhere on or related to the object?
The only reason to do this analytically as far as I can reckon is if it’s user-generated content or something.
I believe if the user has to do less is better user experience… I guess I’ll just grab the (4)bound points and ray cast as Putcho suggested to see if they are inside the mesh or not… if they are then rectangular shape
This may be true. However what is the relative effort of having the user design a huge landscape versus clicking a checkbox that says rectangular when you’re done?!?
I imagine the two are quite different levels of effort, but it’s your project.
Meanwhile remember that all the time you are debating working on this problem, your game is not getting closer to shipping.