0

I want to visualize a wireframe 3d model using helixtoolkit in a WPF project (a building frame). the elements should be clickable so the user could interact with them. also when the mouse is hovering above the objects, their color should change. so basically I need both Mouse Enter/Leave and Mouse Down event on them. I wasn't aware that the library didn't implement events. is there any way that I could add these events to a custom class by inheriting from let's say LinesVisual3D class?

P.S. I'm thinking maybe writing my own Routed Events, is it possible? Also I appreciate any ideas on how to implement this using other tools rather than helix.

Null Pointer
  • 13
  • 1
  • 3
  • The scope of this question seems quite broad. I've not come across a graphics toolkit yet that automatically implements mouse events such as hover or select as no single solution will be flexible enough. Have you looked at the examples yet? There is one that appears to implement a rudimentary selection mechanism https://github.com/helix-toolkit/helix-toolkit/tree/develop/Source/Examples/WPF/ExampleBrowser/Examples/BuildingDemo . I haven't tried it myself as I tend to use the incompatible SharpDX version of the library. – Matt Breckon Jun 16 '20 at 12:53
  • @MattBreckon Thanks for the link, I've checked some of the examples, but I didn't see that one. hopefully it has some features I could add to my project. though I managed to solve my problem adding UIElement3D derived objects to HelixViewport3D as children. maybe I paste some codes here for anyone with the same problem. – Null Pointer Jun 16 '20 at 15:27
  • Adding a clear description as an answer to your own question is a very valid thing to do on StackOverflow and would add to the available documentation for the toolkit (as you can see Helix Toolkit needs some help in that area!). I'm not a maintainer but I'm chipping in where I can. – Matt Breckon Jun 16 '20 at 16:17

1 Answers1

0

I found the answer so I'm posting it here. so basically if you want to use mouse events on your objects you should inherit from UIElement3D class, it has many built in events. use MeshBuilder to create 3D bodies, add it to Geometry property of GeometryModel3D type. and then set the Visual3DModel property of your class equal to GeometryModel3D object.

   public class Structural3D : UIElement3D
{
    public Structural3D()
    {
        var modelMesh = new MeshBuilder();
        modelMesh.AddBox(new Point3D(1, 1, 1), 0.5, 0.5, 2);
        var geometryModel3D = new GeometryModel3D();
        geometryModel3D.Geometry = modelMesh.ToMesh();
        geometryModel3D.Material = Material;
        Visual3DModel = geometryModel3D;
    }       
}

now you can override mouse handlers

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        //do something here, change color, etc
        base.OnMouseLeftButtonDown(e);
    }
Null Pointer
  • 13
  • 1
  • 3