Search code examples
c#wpfhelix-3d-toolkit

HelixToolkit how to exclude elements from HitTest


I have a scene with a skybox and I would like to get the point the user clicked projected onto the skybox.

I'm using HelixViewport3D.FindNearestPoint(Point pt) to get the point, which works very well, except when there's anything between the click and the skybox. In this situation it returns the point projected onto the object in front of the skybok.

Is there any way to flag an element so it would be ignored in HitTests?


Solution

  • You can catch point on any Visual3D or Geometry3D Give names to your Visual3D objects.

    ModelVisual3D modelVisual3D = new ModelVisual3D();
    modelVisual3D.SetName("ModelName");
    

    You can use FindHits method with your HelixViewPort3D

    Point3D point3D;
    var hitList = yourHelixViewPort.ViewPort.FindHits(Point point);
    foreach (var hit in hitList)
    {
        if (hit.Visual != null) 
        {
            if (hit.Visual.GetName() == "ModelName")
            {
                point3D = hit.Position;
                // You can use also hit.Mesh
                // also hit.Model
                // also hit.Visual
                // also hit.Normal
            }
        }
    }