简体   繁体   English

Helix Toolkit 最近在 WPF 应用程序中添加了管对象,是不是触发事件或对鼠标交互做出反应?

[英]Helix Toolkit recently added tube objects in WPF application, are not firing events or reacts on mouse interaction?

I am using WPF application with Helix Toolkit, where I dynamically add multiple 3D objects into the Viewport.我正在使用带有 Helix Toolkit 的 WPF 应用程序,我在其中动态地将多个 3D 对象添加到视口中。 The Visuals of the objects are added successfully, but some of the recently added objects (in this case tube objects) are not firing events, neither show their appropriate tooltip message.对象的视觉效果已成功添加,但最近添加的一些对象(在本例中为管对象)不是触发事件,也不会显示其相应的工具提示消息。 After some interaction with the GUI of the app and adding new additional 3D objects to the Viewport, the old already added objects are firing events and show their tooltip message... Also I have noticed that if I add some other new 3D objects and if I rotate the camera with right button pressed of the mouse, they are coming responsive!在与应用程序的 GUI 进行一些交互并向视口添加新的附加 3D 对象后,已添加的旧对象正在触发事件并显示它们的工具提示消息......我还注意到,如果我添加一些其他新的 3D 对象,如果我用鼠标右键旋转相机,它们会响应!

So what Is causing this problem?那么是什么导致了这个问题呢? Is it there some rendering or camera problem or something else?是否有一些渲染或相机问题或其他问题?

I am using this code about the Viewport with SortingVisual3D where all of the objects are added behind the transparent surface:我正在使用有关带有 SortingVisual3D 的视口的代码,其中所有对象都添加在透明表面后面:


<helix:HelixViewport3D Grid.Column="0" Grid.Row="1" Grid.RowSpan="10" Background="GhostWhite"  Name="_viewport"  ShowFrameRate="True"  ShowTriangleCountInfo="True" ShowViewCube="True"  IsHitTestVisible="True" CalculateCursorPosition="True" ShowCoordinateSystem="True" >

<helix:DefaultLights/>

<helix:SortingVisual3D x:Name="sortingVisual1"  Method="BoundingBoxCorners" IsSorting="True"  SortingFrequency="4"  >
                <helix:MeshGeometryVisual3D x:Name="_cubeObjects">
                </helix:MeshGeometryVisual3D>                

                <helix:MeshGeometryVisual3D x:Name="_tubeObjects">

                </helix:MeshGeometryVisual3D>             

               //Transparent surface

                <helix:MeshGeometryVisual3D x:Name="_transparentSurface"  >

                </helix:MeshGeometryVisual3D>            

            </helix:SortingVisual3D>
        </helix:HelixViewport3D>
      </strike>

This is how I dynamically add the objects:这就是我动态添加对象的方式:

AddObject tubeObject = new AddObject(points3dCollection, "Tube Object", tubeDiameter, 36, objectMaterial);
                                     
                   tubeObject.MouseLeftButtonDown += new MouseButtonEventHandler(tubeObjectClick);
                    tubeObject.IsHitTestVisible = true;              
                    tubeObject.SetName("Tube Object");

 ContainerUIElement3D cui = new ContainerUIElement3D();               
                cui.Children.Add(tubeObject);
                _tubeObjects.Children.Add(cui);


'-------------------This is the class AddObject definition:-------------------------------'


class AddObject : UIElement3D,INotifyCollectionChanged
    {       

        private readonly Timer _timer;
        private readonly ToolTip _toolTip;

        public AddObject DataContext { get; }
            
      
        public AddObject(Point3DCollection path, string objectName, double diametar_1, int thetaDiv, Material material)
        {
            MeshBuilder builder = new MeshBuilder();       
                           
               
                List<Point3D> list = new List<Point3D>();

                for (int i = 0; i < path.Count; i++)
                {

                    list.Add(path[i]);

                }               

                list = CanonicalSplineHelper.CreateSpline(list, 0.5, null, false, 0.9);
            
                builder.AddTube(list, diametar_1, thetaDiv, false, true, true);          
           
                GeometryModel3D model = new GeometryModel3D(builder.ToMesh(), material);             
                model.SetName(objectName);
                Visual3DModel = model;            
             
                _toolTip = new ToolTip();
              
                _timer = new Timer { AutoReset = false };
                _timer.Elapsed += ShowToolTip;

                DataContext = this;        
          


        }

 public event NotifyCollectionChangedEventHandler CollectionChanged
        {
            add
            {
                ((INotifyCollectionChanged)DataContext).CollectionChanged += value;
            }

            remove
            {
                ((INotifyCollectionChanged)DataContext).CollectionChanged -= value;
            }
        }

        public object ToolTipContent { get { return _toolTip.Content; } set { _toolTip.Content = value; } }    

        private void ShowToolTip(object sender, ElapsedEventArgs e)
        {
            _timer.Stop();
            if (_toolTip != null)
                _toolTip.Dispatcher.Invoke(new Action(() => { _toolTip.IsOpen = true; }));
        }

       protected override void OnMouseEnter(MouseEventArgs e)
        {
            base.OnMouseEnter(e);

            var gm = Visual3DModel as GeometryModel3D;        

            gm.Material = gm.Material == materialtype ? Materials.Yellow : materialtype;

            if (_toolTip != null)
            {
                _toolTip.IsOpen = true;
                _toolTip.Content = gm.GetName().ToString().Trim() + " vein "; }
            //  _timer.Interval = ToolTipService.GetInitialShowDelay(Application.Current.MainWindow);
            _timer.Interval = 50;
            _timer.Start();          

            e.Handled = true;
        }

        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);

            var gm = Visual3DModel as GeometryModel3D;
            gm.Material = gm.Material == materialtype ? Materials.Yellow : materialtype;

            _timer.Stop();
            if (_toolTip != null)
            { _toolTip.IsOpen = false;
                _toolTip.Content = "";            
            }           

            e.Handled = true;

        }

}


What should I check at first? Any idea is welcomed ! Please help !

The immediate response problem of the recently inserted objects is solved with this code:最近插入的对象的即时响应问题通过以下代码解决:

<helix:MeshGeometryVisual3D >
                <ContainerUIElement3D x:Name="_cubeObjects">
            </ContainerUIElement3D>
                </helix:MeshGeometryVisual3D>
            <helix:MeshGeometryVisual3D >
                <ContainerUIElement3D x:Name="_ballClickPoints">
                </ContainerUIElement3D>

            </helix:MeshGeometryVisual3D>
                <helix:MeshGeometryVisual3D >
                <ContainerUIElement3D x:Name="_tubeObjects">
                </ContainerUIElement3D>

            </helix:MeshGeometryVisual3D>
           
                        <helix:MeshGeometryVisual3D x:Name="_transparentSurface">

            </helix:MeshGeometryVisual3D>

So the change is in using ContainerUIElement3D into MeshGeometryVisual3D.. The objects are responding immediately on mouse events.所以变化是在使用 ContainerUIElement3D 到 MeshGeometryVisual3D 中。对象立即响应鼠标事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM