Cage opened this issue on Dec 20, 2006 · 1232 posts
Spanki posted Fri, 12 January 2007 at 4:54 PM
Not too bad (I used two identical meshes) - it found roughly 900 out of 1200 matches, but some of them were false matches (this is with the vertex/edge collision code in check_bounds() commented out, btw). Also of note here is the multi-grouped polygon display (hot pink)... note the strip of polygons to the right of center ended up in more than one group, but the ones to left of center did not (since the center vertices don't currently belong to more than one region).
You 'could' fix it by allowing the vertices to live in multiple regions, but that doesn't account for the region-spanning polygons I mentioned earlier. The better fix is still going to be using the edges in the region test, instead of the vertices.
Back to the earlier question of whether it matters if the intersection/bounds_check code worries about the direction of the rays being cast... having the region-culling in place takes care of most of that problem, but there can be some 'local' (to a region) problems as well. I think you need to let it search both directions along the ray (in case one mesh is bigger of smaller than the other), but some additional tests will need to be included to eliminate some of the false hits taking place.
normal direction test
I'd check to make sure that the polygon in question was facing the general direction as the vertex normal. You can do that by checking the Z component of the polygon normal against the Z component of the vertex normal - they should both either be positive or negative.
multiple hits
Currently, the first 'hit' breaks out of the loop. What I'd do is just note the distance of that hit and keep looking. Once you have all the hit polys and the distances, use the closest one (that also passes the above direction test).
...it's possible that the first test would eliminate the need for the second test.
Cinema4D Plugins (Home of Riptide, Riptide Pro, Undertow, Morph Mill, KyamaSlide and I/Ogre plugins) Poser products Freelance Modelling, Poser Rigging, UV-mapping work for hire.