I have a mesh that represents landscape. I need to work through this mesh from the bottom left to the top right in 50m squares, detecting whether this 50m square intersects with the mesh (z is ignored - only interested in x & y). Currently I do this by created points for the 50m square and ProjectToMesh - if any points hit the mesh - then I know that there is mesh in the area that I am interested in.
There must be a neater way to do this? Can I project the mesh to CPlane in C# (If so, how?) . If I have the mesh in the CPlane - I should be able to create 4 lines for the edges of the 50m square and check intersection with:
For project-to-CPlane, you can use the Plane.ClosestPoint method of the CPlane. Just modify each mesh vertex using this method.
In this case I would maybe create a small cube mesh of 50x50 that sits on both sides of the CPlane and intersect it with the projected mesh using Intersection.MeshMeshFast. But I guess that Intersection.MeshLine also works. It might even be faster, you only need to have one line with an intersection (not overlap) and you know that the square(s) bounding the intersecting line intersect the mesh.
You might even consider a divide-and-conquer approach by first testing larger lines and only testing smaller lines if the larger line has at least one intersection. I suppose it depends on the structure of the mesh and the number of expected intersections.
Thanks for your suggestions. I think I’m OK with the second half of it but I’m still struggling with the first half - getting the original mesh in the Construction Plane. I tried the suggestion from the link above by doing this:
I just get a copy of the original mesh with the same Z heights as before. Alternatively I tried to go through all the vertices and change their Z height - but can’t change that because “it’s not a variable”. I also tried the above transform on every vertex of the mesh - but that didn’t do anything either. Am I missing something stupid or is it more complicated than the attempts I’ve made so far!?