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



我使用的是带有Helix Toolkit的WPF应用程序,在其中我将多个3D对象动态添加到Viewport中。对象的视觉效果已成功添加,但最近添加的一些对象(在本例中为管状对象(没有触发事件,也没有显示相应的工具提示消息。在与应用程序的GUI进行一些交互并将新的附加3D对象添加到Viewport后,旧的已添加对象将触发事件并显示其工具提示消息。。。我还注意到,如果我添加一些其他新的3D对象,如果我用鼠标右键旋转相机,它们就会做出响应!

那么是什么导致了这个问题呢?是否存在渲染或相机问题或其他问题?

我使用的是关于带有SortingVisual3D的Viewport的以下代码,其中所有对象都添加到透明表面后面:


<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>

这就是我动态添加对象的方式:

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 !

最近插入的对象的即时响应问题用以下代码解决:

<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>

因此,变化在于将ContainerUIElement3D使用到MeshGeometryVisual3D中。。对象对鼠标事件立即做出响应。

相关内容

  • 没有找到相关文章

最新更新