[Closed] RayMeshGridIntersect
I think that it is the same method that you are using by just getting the distance of the hit from the ray.
I used RayMeshGridIntersect for much the same purpose as John I suspect, finding/eksporting an elevation grid from a TIN. As far as speed go, my experience is that voxel size doesn’t scale very well. My script was going to be used extensively, so speed was an important issue. I ended up writing a routine to split the mesh into seperate objects (and it was a real pain to make sure each piece had all the necessary faces included; its not trivial to find faces with no vertices inside your area using built-in functions) and then directing/hashing the rays to the corresponding object. Some quick examples (running times can vary, probably because of caching/memory allocation, but they give a rough idea.) using a 155K tris terrain, 2500x1750m area, 8m grid:
One object, voxel size 480: 78 sec.
One object, voxel size 40: 178 sec.
12×12 objects, voxel size 40: 20 sec.
The actual intersection calculations are even faster than this, but it takes a good while to sort the faces into 12×12 objects.
About the world coordinates of the hitpoint, all my vectors were facing straight down, so not really a problem for me
I’ve had some problems with mishits, but as far as I can tell, they are usually related to bad geometry (double faces/edges etc.). However, in those cases were I was getting lots of mishits, voxel size would affect the number of mishits. It is possible that a smaller number of singular, rare mishits are slipping through unnoticed, so perhaps I will look into John’s idea for handling that.
On a sidenote, I’ve also used RayMeshGridIntersect to correct a common problem with buildings created from map-data. These often have random face normals, which can sometimes be a problem, specially for real-time use. If one welds all the vertices so that structures can be isolated as “elements” using meshop.getElementsUsingFace, then one can build a mesh from each element, run a RayMeshGridIntersect on the element using each face normal as a ray and finally use a mod 2 on the returned number of hits to determine wether a given face should be flipped or not. I had to tweak the ray slightly to avoid hitting the original face. The result is not always 100% correct due to inconsistencies in the geometry, but it saves a lot of boring work.