Pick a PipeVisual3D object

Sep 27, 2013 at 9:05 AM
Hi all,
I need to delect a PipeVisual3D object in the viewport, and I followed the example "UIelement", adding a sphere and a PipeVisual3D object. Unfortunately I cannot pick the PipeVisual3D object. Why it doesn't work?
The code I used is below:
        ' selezione
        Dim container = New ContainerUIElement3D()
        Dim element = New ModelUIElement3D()
        Dim geometry = New GeometryModel3D()
        Dim meshBuilder = New MeshBuilder()
        meshBuilder.AddSphere(New Point3D(0, 0, 0), 2, 100, 50)
        'meshBuilder.AddQuad(pt, pt1, pt1, pt)
        geometry.Geometry = meshBuilder.ToMesh()
        geometry.Material = Materials.Green
        element.Model = geometry
        element.Transform = New TranslateTransform3D(5, 0, 0)

        ' genera linee in modelspace
        Dim ts2 As New PipeVisual3D
        Dim pt1 As New Point3D(10, 10, 10)
        Dim pt2 As New Point3D(20, 10, 10)
        ts2.Point1 = pt1
        ts2.Point2 = pt2
        ts2.Material = Materials.Green
        ts2.Diameter = 0.1

        AddHandler element.MouseDown, AddressOf Me.ContainerElementMouseDown
        ' add lines and points to the container


        'container.Children.Add(New AmbientLight(Colors.White))
I used the ContainerElementMouseDown sub that I found in the example, but as I said it works only for the sphere:
    Private Sub ContainerElementMouseDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        If e.LeftButton = MouseButtonState.Pressed Then
            Dim element = TryCast(sender, ModelUIElement3D)
            Dim model = TryCast(element.Model, GeometryModel3D)
            If model.Material Is Materials.Green Then
                model.Material = Materials.Yellow
            ElseIf model.Material Is Materials.Yellow Then
                model.Material = Materials.Green
            End If
            'model.Material = If(model.Material Is Materials.Green, Materials.Gray, Materials.Green)
            e.Handled = True
        End If
    End Sub
I supposed that I cannot use the LinesVisual3D because they are in the in the screen space; I though I have to use something that is in the model space. Is it right?

Sep 29, 2013 at 7:27 AM
Right, the LinesVisual3D is not derived from UIElement3D and will not receive mouse events. But the lines are rendered as MeshGeometry3D in the model space and it should be possible to implement the same functionality in a 3D UI element!
Sep 29, 2013 at 10:32 AM
Edited Sep 29, 2013 at 10:44 AM
Thank you for your answer. I can always use PipeVisual3D instead of LinesVisual3D.
As far I've understood, PipeVisual3D has the capability for receiving mouse events. I found how to add a Pipe in ModelUIElement3D.
But how can I use the mouse events to pick (e.g. select) a Pipe instead of another? Is there a property ti do so?

Sep 29, 2013 at 3:05 PM
Edited Sep 30, 2013 at 10:49 AM
I used as many container as element, so any object ban be selected alone. Is it the best way?

Furthermore, is it another command that allows picking objects by drawing an imaginary box that intersecates one or more elements? Such as Autocad...

Oct 1, 2013 at 1:02 PM
Anyone has the same problem?
Oct 1, 2013 at 3:35 PM
The pipevisual is never connected to the 'element' object. The 'element' object triggers the ContainerElementMouseDown event in this case.
If you change it like this it will trigger the event:
        PipeVisual3D pipe = new PipeVisual3D();
        pipe.Point1 = new Point3D(10, 10, 10);
        pipe.Point2 = new Point3D(20, 10, 10);
        pipe.Material = Materials.Green;
        pipe.Diameter = 0.1;
        var element2 = new ModelUIElement3D();
        element2.Model = pipe.Model;
        element2.MouseDown += this.ContainerElementMouseDown;
Oct 3, 2013 at 7:50 PM
Thanks for your reply, I've solved in VB.net as follow:
Dim pipe As New PipeVisual3D()
pipe.Point1 = New Point3D(10, 10, 10)
pipe.Point2 = New Point3D(20, 10, 10)
pipe.Material = Materials.Green
pipe.Diameter = 0.1
Dim element2 = New ModelUIElement3D()
element2.Model = pipe.Model
AddHandler element2.MouseDown, AddressOf Me.ContainerElementMouseDown
anyway, now I just need to have the box selection instead of single click-on-object selection. Any idea?
Jun 28, 2014 at 3:18 PM
Hi rinaldin,
I also work in VB and while this response is for an old post I have a few ideas that may be applicable to your needs.

objo sent the following reply to my post "How to draw a funnel"

See the usage of MeshBuilder.AddSurfaceOfRevolution in the example Source\Examples\WPF\ExampleBrowser\Examples\BuildingDemo\SiloVisual3D.cs, I think a similar approach can be used to model a funnel.

After a lot of experimenting I was finally able to open the BuildingDemo project albeit in C#. I noticed (for the first time) that when you click on a silo/tank in the viewport, a property page appeared on the right side of the screen, and, more interestingly, if you clicked on a chimney a different property page appeared. But the cool thing is that a change in the property actually changes the visual! There are two chimneys in the illustration, but only one visual redraws with the new parameters! So there is a lot in this demo that may be useful to you.

I have converted the parts I needed to VB and have more complex visual mouse click selections already working in my own project.

In fact, I have a property page live modification of an object working in a VB project with exactly two lines of code and no code behind in the view. To accomplish this you need 3 things:
  1. You need to be using Caliburn Micro (It is absolutely the best for MVVM applications) If you don't have it you can get it here.
  2. You need to grab the PropertyGrid at this web site
  3. Selecting an item and dispaying its propertys in an interactive propertygrid has a lot to do with your projects organization. I was successful because I used the same design concepts that are illustrated in the SiloVisual3D.vb class
While this is a late response, I hope it may help in your work,

Bob Ranck