Helix Toolkit 最近在 WPF 应用程序中添加了管对象,是否不触发事件或对鼠标交互做出反应?
Helix Toolkit recently added tube objects in WPF application, are not firing events or reacts on mouse interaction?
我正在使用带有 Helix Toolkit 的 WPF 应用程序,我在其中将多个 3D 对象动态添加到视口中。对象的视觉效果已成功添加,但最近添加的一些对象(在本例中为管对象)没有触发事件,也没有显示相应的工具提示消息。在与应用程序的 GUI 进行一些交互并将新的附加 3D 对象添加到视口之后,已添加的旧对象正在触发事件并显示其工具提示消息......
我还注意到,如果我添加一些其他新的 3D 对象,并且如果我在按下鼠标右键的情况下旋转相机,它们就会响应!
那么是什么导致了这个问题?是否存在渲染或相机问题或其他问题?
我正在使用这段关于带有 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>
这是我动态添加对象的方式:
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。对象会立即响应鼠标事件。
我正在使用带有 Helix Toolkit 的 WPF 应用程序,我在其中将多个 3D 对象动态添加到视口中。对象的视觉效果已成功添加,但最近添加的一些对象(在本例中为管对象)没有触发事件,也没有显示相应的工具提示消息。在与应用程序的 GUI 进行一些交互并将新的附加 3D 对象添加到视口之后,已添加的旧对象正在触发事件并显示其工具提示消息...... 我还注意到,如果我添加一些其他新的 3D 对象,并且如果我在按下鼠标右键的情况下旋转相机,它们就会响应!
那么是什么导致了这个问题?是否存在渲染或相机问题或其他问题?
我正在使用这段关于带有 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>
这是我动态添加对象的方式:
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。对象会立即响应鼠标事件。