Patch attempting to use cached meshes in llCastRay V3. Thanks to dahlia making the physics mesh cache available for this.

The first time a new shape, sculpt or mesh is encountered, the overhead of processing and caching it is 40-50% higher than without caching, on both a high-end server and an ordinary laptop in my performance tests. However, on renewed encounters, the caching saves about 55-60% call time on a high-end server and 60-70% on an ordinary laptop.

This first, dysfunctional version do prims right, but appears to get corrupt data when trying to mesh sculpts and meshes from assets. The error is probably at line 14176:
shape.SculptData = World.AssetService.GetData(shape.SculptTexture.ToString());
I'm lost at how to load and use the assets in a correct way though, so any suggestions are welcome. The other possibility is a bug in the mesher used, but I can't find anything obvious in the code so I find that less likely.

The new patch 0001-Use-own-mesh-cache-in-llCastRay-V3.patch is fully functional. It sets up an own mesh cache optimized for llCastRay V3 and uses libopenmetaverse mesher instead of Meshmerizer. It works fully with sculpts and meshes again, eliminates the 40-50% overhead on first encounter with a shape, sculpt or mesh, increases the time save when using cached geometries to about 65% on a high-end server and 75% on an ordinary laptop in my performance tests.

Since the physics mesh cache isn't populated by BulletSim and llCastRay V3 stores and uses geometries without scaling and rotation, it's really not much use to use the un-optimized physics mesh cache in particular for llCastRay V3.

This patch also includes a minor fix where calculation errors sometimes made hits fall outside triangle bounding boxes and be discarded, especially when triangle planes are parallel with the local XY, XZ or YZ plane. To deal with this, error tolerances were increased by a factor of 10. (Old tolerance 0.000001, actual calculation error 0.000003-0.000004, new tolerance 0.00001.)

The patch 0001-Use-own-mesh-cache-in-llCastRay-V3.patch won't apply after the patch 0001-Throttle-llCastRay-V3.patch from Mantis 7568.

The new patch 0001-Use-own-mesh-cache-in-llCastRay-V3-after-throttling.patch will apply after the patch 0001-Throttle-llCastRay-V3.patch from Mantis 7568. It also makes the caching optional by configuration, since the caching increases memory usage, which may be undesirable in some situations.