Apparent 150x speed improvement using Rusty Raycast

Hello Everyone.
@tlaukkan and I have been working on a project [ GitHub - tlaukkan/rust-ray-intersect-js: Ray intersect ] to create Babylon bindings for Rust BVH [ GitHub - svenstaro/bvh: A fast BVH using SAH in rust ]

The initial results seem extremely promising

Raycasting against the damaged helmet gltf [https://www.babylonjs.com/Assets/DamagedHelmet/glTF/ ]

We are getting the following raycast results for 10’000 casts

Rusty intersect took 33 milliseconds. Intersected at {X:0 Y: 0 Z: -0.8676968216896057}
Babylon intersect took 5076 milliseconds. Intersected at {X: 0 Y:1.1658276451745614e-7 Z:-0.867697012799273}

As you can see, we are looking at a fairly ridiculous speed improvement.

Further, steps have been taken to ensure that we only reuse the rust octree, all intermediary structures are replicated every single time the raycast is made. Meaning that a solution with a reused IntersectResult would be even faster.

Further work is still pending on this library, but input is very appreciated at this time.

9 Likes

I do not think that ray casting is going to be a big part of what I am trying to do right now. I was though planning at some point to also do some rust to handle hot spots in my cpu based animation system. I have many things to do, and won’t know the true hot spots till later, but I like that someone has already proven the concept.

I like the very detailed read me. I might fork your repo as sort of a template. If I end up re-writing calculateNormals (very loopy & large), I probably make it a separate repo & make it public.

FYI, the helmet url is wrong, and if a playground is possible, that would probably a good way for someone anything they need to do. I am not sure when it come to node.

2 Likes

Holy snap, this is amazing. Thank you all for looking into this :smiley:

@JRuiseco, @tlaukkan, have you looked into deno (potential node killer :stuck_out_tongue: jk)? deno v1.0.0 just released a few days ago, has amazing built-in wasm support, built-in testing support, can spawn subprocesses for your bash scripts, and is partly built using Rust.