0

I'm using HelixToolkit to see and interact with STL files. I need to draw or mark a point clicked by user on the window. I have the coordinates, I know where to draw that point, but I don't know how to draw it, can someone help me? I post some code to explain what I have right now:

    private void vierport3d_MouseRightClick(object sender, MouseButtonEventArgs e)
    {
        Point mousePos = e.GetPosition(viewPort3d);
        PointHitTestParameters hitParams = new PointHitTestParameters(mousePos);
        VisualTreeHelper.HitTest(viewPort3d, null, ResultCallback, hitParams);
    }

public HitTestResultBehavior ResultCallback(HitTestResult result)
    {
        RayHitTestResult rayResult = result as RayHitTestResult;
        if (rayResult != null)
        {
            RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;

            //HERE I HAVE THE LOCATION TO DRAW
            MessageBox.Show(rayMeshResult.PointHit.X + " " + rayMeshResult.PointHit.Y + " " + rayMeshResult.PointHit.Z);

            if (rayMeshResult != null)
            {
                // I THINK I HAVE TO DRAW THE POINT HERE
            }
        }

        return HitTestResultBehavior.Continue;
    }

PD: I show the stl on a viewport3d.

Imrik
  • 674
  • 2
  • 14
  • 32

2 Answers2

0

We had same scenario in our project and used a sphere to visually indicate the point.

<ht:SphereVisual3D Radius="0.75" Fill="Red" Center="{Binding ContactPoint}" />

ContactPoint is a Point3D type.

Nit
  • 11
  • 3
  • Just a thought.. the first line were you get a Point using the mouse click; using that and one of the helper method from helix Point2DToPoint3D you can get a Point3D to get the click point in 3d space and use that to draw the point. Or the other way, is the viewport has 'CursorOnelementPosition' property that gives the click point on the stl model. – Nit Oct 12 '15 at 19:59
0

This might help, but its probably not the most effecient. Try the following:

This will create a 3D sphere that can be rendered at the given coordinates.

var sphereSize = 0.025;
/* keep these values low, the higher the values the more detailed the sphere which may impact your rendering perfomance.*/
var phi   = 12;
var theta = 12;

MeshBuilder meshBuilder = new MeshBuilder();

Pass in your x,y,z to the first parameter. i.e. the click 3D location.

meshBuilder.AddSphere( new Point3D(x,y,z), sphereSize , theta, phi); 

GeometryModel3D sphereModel = new GeometryModel3D(meshBuilder.ToMesh(),MaterialHelper.CreateMaterial(Brushes.Green,null,null,1,0));

Rendering the Point in your viewport

You will need a ModelVisual3D component as a child of the HelixViewport. ( This can be implemented in C# or in XAML) its up to you, ill show both ways.

C# version

NB: You need a reference to the helixviewport if its defined in xaml. Set the x:Name:"" to something appropriate. e.g x:Name="helixViewPort"

ModelVisual3D visualizer = new ModelVisual3D();
visualizer.Content = sphereModel;
helixViewPort.Children.Add(visualizer);

XAML version

I'll assume your xaml code has at least a helix view port so you'll have to add a ModelVisual3D child to the helix viewport if there's none.

<h:HelixViewport3D x:Name="HelixPlotViewPort" >
   <h:DefaultLights/>
   <ModelVisual3D x:Name="Visualizer">

   </ModelVisual3D>

</h:HelixViewport3D>

//Then in C# add the following
Visualizer.Content = sphereModel;

That should do it, hope it helps, do inform us if you find a better solution. :)

Brian
  • 141
  • 2
  • 9