In my application, there is a transparent InkCanvas
on top of a Viewport3D
object. The Viewport3D
shows a large 3D mesh. The user will sketch on the InkCanvas
in order to select a portion of the 3D model that the Viewport3D
is rendering. The user is allowed to draw circles on the InkCanvas
.
When the user sketches, I iterate over all the points that fall inside of the drawn circle and I use the VisualTreeHelper.HitTest
function to perform raycasting and determine which vertices of the Viewport3D
mesh coincide with the sketch.
The problem is that VisualTreeHelper.HitTest
is very slow. In case I used a Parallel.For
I still would not be able to perform multiple raycastings on the Viewport3D in parallel (due to the fact that the owning thread of the Viewport3D
object is the UI thread and I'd have to use Viewport3D
's Dispatcher.Invoke
function which will defeat the purpose of having a Parallel.For
in the first place.)
Is there a way to speed this up using multiple threads? Better yet, is there an alternative solution?