feat:3d控件

master
Tongg 7 months ago
parent dd57554f39
commit cc97863e60
  1. BIN
      Resource/Images/UserControl/Bottom@3x.png
  2. BIN
      Resource/Images/UserControl/Top@3x.png
  3. BIN
      Resource/Images/UserControl/arrow.png
  4. BIN
      Resource/Images/UserControl/biaochi1@3x.png
  5. BIN
      Resource/Images/UserControl/biaochi2@3x.png
  6. BIN
      Resource/Images/UserControl/zuanshi@1x.png
  7. BIN
      Resource/Images/UserControl/zuanshi@3x.png
  8. 15
      SparkClient.csproj
  9. 61
      Views/Grading/GradingResult.xaml
  10. 172
      Views/Grading/GradingResult.xaml.cs
  11. 112
      Views/UserControl/Viewport3D.xaml
  12. 12
      Views/UserControl/Viewport3D.xaml.cs

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -95,6 +95,21 @@
<None Remove="Resource\Images\Temp\top.png" />
<EmbeddedResource Remove="Resource\Images\Temp\**" />
<None Remove="Resource\Images\Temp\**" />
<None Remove="Resource\Images\UserControl\zuanshi@1x.png" />
<Resource Include="Resource\Images\UserControl\zuanshi@1x.png" />
<None Remove="Resource\Images\UserControl\biaochi1@3x.png" />
<Resource Include="Resource\Images\UserControl\biaochi1@3x.png" />
<None Remove="Resource\Images\UserControl\biaochi2@3x.png" />
<Resource Include="Resource\Images\UserControl\biaochi2@3x.png" />
<None Remove="Resource\Images\UserControl\Bottom@3x.png" />
<Resource Include="Resource\Images\UserControl\Bottom@3x.png" />
<None Remove="Resource\Images\UserControl\Top@3x.png" />
<Resource Include="Resource\Images\UserControl\Top@3x.png" />
<None Remove="Resource\Images\UserControl\zuanshi@3x.png" />
<Resource Include="Resource\Images\UserControl\zuanshi@3x.png" />
<None Remove="Resource\Images\UserControl\arrow.svg" />
<None Remove="Resource\Images\UserControl\arrow.png" />
<Resource Include="Resource\Images\UserControl\arrow.png" />
</ItemGroup>
<ItemGroup>

@ -6,6 +6,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:SparkClient.Views.Grading"
xmlns:hx="http://helix-toolkit.org/wpf/SharpDX"
xmlns:userControl="clr-namespace:SparkClient.Views.UserControl"
mc:Ignorable="d"
d:DesignWidth="1000"
d:DesignHeight="600"
@ -134,39 +135,39 @@
<Border Grid.Row="1" Grid.Column="2" Background="Aquamarine">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<!-- <RowDefinition Height="50"></RowDefinition> -->
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="Fuchsia" />
<Border Grid.Row="1" BorderThickness="1" CornerRadius="0" BorderBrush="Black" Margin="5">
<hx:Viewport3DX Grid.Column="0" x:Name="Viewport3Dx" MouseLeftButtonDown="Viewport3Dx_OnMouseLeftButtonDown" ClipToBounds="True">
<hx:Viewport3DX.InputBindings>
<KeyBinding Key="B" Command="hx:ViewportCommands.BackView" />
<KeyBinding Key="F" Command="hx:ViewportCommands.FrontView" />
<KeyBinding Key="U" Command="hx:ViewportCommands.TopView" />
<KeyBinding Key="D" Command="hx:ViewportCommands.BottomView" />
<KeyBinding Key="L" Command="hx:ViewportCommands.LeftView" />
<KeyBinding Key="R" Command="hx:ViewportCommands.RightView" />
<KeyBinding Command="hx:ViewportCommands.ZoomExtents" Gesture="Control+E" />
<MouseBinding Command="hx:ViewportCommands.Rotate" Gesture="RightClick" />
<MouseBinding Command="hx:ViewportCommands.Zoom" Gesture="MiddleClick" />
<MouseBinding Command="hx:ViewportCommands.Pan" Gesture="LeftClick" />
</hx:Viewport3DX.InputBindings>
<!-- <hx:DirectionalLight3D x:Name="MainDirectionalLight" /> -->
<!-- <hx:PointLight3D x:Name="MainPointLight" /> -->
<!-- <hx:AmbientLight3D x:Name="AmbientLight" /> -->
<!-- <hx:AxisPlaneGridModel3D -->
<!-- AutoSpacing="false" -->
<!-- RenderShadowMap="true" -->
<!-- Offset="-65" /> -->
</hx:Viewport3DX>
</Border>
<userControl:Viewport3D ></userControl:Viewport3D>
<!-- <Border Grid.Row="0" Background="Fuchsia" /> -->
<!-- <Border Grid.Row="1" BorderThickness="1" CornerRadius="0" BorderBrush="Black" Margin="5"> -->
<!-- <hx:Viewport3DX Grid.Column="0" x:Name="Viewport3Dx" MouseLeftButtonDown="Viewport3Dx_OnMouseLeftButtonDown" ClipToBounds="True"> -->
<!-- <hx:Viewport3DX.InputBindings> -->
<!-- <KeyBinding Key="B" Command="hx:ViewportCommands.BackView" /> -->
<!-- <KeyBinding Key="F" Command="hx:ViewportCommands.FrontView" /> -->
<!-- <KeyBinding Key="U" Command="hx:ViewportCommands.TopView" /> -->
<!-- <KeyBinding Key="D" Command="hx:ViewportCommands.BottomView" /> -->
<!-- <KeyBinding Key="L" Command="hx:ViewportCommands.LeftView" /> -->
<!-- <KeyBinding Key="R" Command="hx:ViewportCommands.RightView" /> -->
<!-- <KeyBinding Command="hx:ViewportCommands.ZoomExtents" Gesture="Control+E" /> -->
<!-- <MouseBinding Command="hx:ViewportCommands.Rotate" Gesture="RightClick" /> -->
<!-- <MouseBinding Command="hx:ViewportCommands.Zoom" Gesture="MiddleClick" /> -->
<!-- <MouseBinding Command="hx:ViewportCommands.Pan" Gesture="LeftClick" /> -->
<!-- </hx:Viewport3DX.InputBindings> -->
<!-- ~1~ <hx:DirectionalLight3D x:Name="MainDirectionalLight" /> @1@ -->
<!-- ~1~ <hx:PointLight3D x:Name="MainPointLight" /> @1@ -->
<!-- ~1~ <hx:AmbientLight3D x:Name="AmbientLight" /> @1@ -->
<!-- ~1~ <hx:AxisPlaneGridModel3D @1@ -->
<!-- ~1~ AutoSpacing="false" @1@ -->
<!-- ~1~ RenderShadowMap="true" @1@ -->
<!-- ~1~ Offset="-65" /> @1@ -->
<!-- </hx:Viewport3DX> -->
<!-- </Border> -->
</Grid>
</Border>
</Grid>
</Border>

@ -22,21 +22,21 @@ public partial class GradingResult
DataContext = new GradingResultVM(null);
this.Viewport3Dx.EffectsManager = new DefaultEffectsManager();
this.Viewport3Dx.Camera = new PerspectiveCamera()
{
Position = new Point3D(0, 0, 5),
LookDirection = new Vector3D(0, 0, -1),
UpDirection = new Vector3D(0, 1, 0),
FarPlaneDistance = 1000,
NearPlaneDistance = 0.1
};
Loaded += (sender, args) =>
{
var entities = Viewport3DHelper.InitDemo(Viewport3Dx);
triangles.AddRange(entities);
};
// this.Viewport3Dx.EffectsManager = new DefaultEffectsManager();
// this.Viewport3Dx.Camera = new PerspectiveCamera()
// {
// Position = new Point3D(0, 0, 5),
// LookDirection = new Vector3D(0, 0, -1),
// UpDirection = new Vector3D(0, 1, 0),
// FarPlaneDistance = 1000,
// NearPlaneDistance = 0.1
// };
// Loaded += (sender, args) =>
// {
// var entities = Viewport3DHelper.InitDemo(Viewport3Dx);
// triangles.AddRange(entities);
// };
}
@ -47,77 +47,77 @@ public partial class GradingResult
/// <param name="e"></param>
private void Viewport3Dx_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 获取鼠标点击位置
var mousePosition = e.GetPosition(Viewport3Dx);
// 查找鼠标点击的 3D 对象
var hits = Viewport3Dx.FindHits(mousePosition);
// 如果没有命中任何 3D 对象
if (hits == null || hits.Count == 0)
{
Console.WriteLine("未点击到任何模型");
foreach (var item in mouseAddModels)
{
Viewport3Dx.Items.Remove(item);
}
mouseAddModels.Clear();
return;
}
// 获取第一个命中的对象
var hit = hits[0];
// 检查是否是 MeshGeometryModel3D
if (hit.ModelHit is MeshGeometryModel3D modelHit)
{
foreach (var item in mouseAddModels)
{
Viewport3Dx.Items.Remove(item);
}
mouseAddModels.Clear();
// 获取几何信息
var geometry = modelHit.Geometry as MeshGeometry3D;
if (geometry != null)
{
// 获取命中的三角形索引
var triangleIndex = hit.TriangleIndices;
// 获取三角形顶点
var vertex1 = geometry.Positions[triangleIndex.Item1];
var vertex2 = geometry.Positions[triangleIndex.Item2];
var vertex3 = geometry.Positions[triangleIndex.Item3];
string strPoint = vertex1.X + ","+ vertex1.Y+","+ vertex1.Z + ";"+ vertex2.X + ","+ vertex2.Y + ","+ vertex2.Z+";"+vertex3.X + ","+ vertex3.Y + ","+ vertex3.Z;
string triangleCode = Viewport3DTriangleEntity.GenerateMD5Hash(strPoint);
//命中实体
Viewport3DTriangleEntity res = triangles.Find(e => triangleCode.Equals(e.TriangleCode));
if (res == null)
return;
//命中面
List<Viewport3DTriangleEntity> facet = triangles.Where(e => res.PlaneCode.Equals(e.PlaneCode)).ToList();
var colorFacet = new Color4(1.0f, 1.0f, 0.0f, 1.0f);
var data1 = Viewport3DHelper.GenerateEmissiveModelByEntity(Viewport3Dx,facet,colorFacet);
mouseAddModels.AddRange(data1);
//命中面标线
var data2 = Viewport3DHelper.GenerateLineTextModelByEntity(Viewport3Dx, facet);
mouseAddModels.AddRange(data2);
//命中同类面
List<Viewport3DTriangleEntity> facetType = triangles.Where(e => res.PlaneType.Equals(e.PlaneType)).ToList();
//排除自己
facet.ForEach(e=>facetType.Remove(e));
var colorFacetType = new Color4(0.9f, 0.9f, 0.7f, 1.0f);
var data3 = Viewport3DHelper.GenerateEmissiveModelByEntity(Viewport3Dx,facetType,colorFacetType);
mouseAddModels.AddRange(data3);
}
}
else
{
Console.WriteLine("点击的对象不是 MeshGeometryModel3D");
}
// // 获取鼠标点击位置
// var mousePosition = e.GetPosition(Viewport3Dx);
//
// // 查找鼠标点击的 3D 对象
// var hits = Viewport3Dx.FindHits(mousePosition);
//
// // 如果没有命中任何 3D 对象
// if (hits == null || hits.Count == 0)
// {
// Console.WriteLine("未点击到任何模型");
// foreach (var item in mouseAddModels)
// {
// Viewport3Dx.Items.Remove(item);
// }
// mouseAddModels.Clear();
// return;
// }
//
// // 获取第一个命中的对象
// var hit = hits[0];
//
// // 检查是否是 MeshGeometryModel3D
// if (hit.ModelHit is MeshGeometryModel3D modelHit)
// {
// foreach (var item in mouseAddModels)
// {
// Viewport3Dx.Items.Remove(item);
// }
// mouseAddModels.Clear();
// // 获取几何信息
// var geometry = modelHit.Geometry as MeshGeometry3D;
// if (geometry != null)
// {
// // 获取命中的三角形索引
// var triangleIndex = hit.TriangleIndices;
//
// // 获取三角形顶点
// var vertex1 = geometry.Positions[triangleIndex.Item1];
// var vertex2 = geometry.Positions[triangleIndex.Item2];
// var vertex3 = geometry.Positions[triangleIndex.Item3];
//
// string strPoint = vertex1.X + ","+ vertex1.Y+","+ vertex1.Z + ";"+ vertex2.X + ","+ vertex2.Y + ","+ vertex2.Z+";"+vertex3.X + ","+ vertex3.Y + ","+ vertex3.Z;
// string triangleCode = Viewport3DTriangleEntity.GenerateMD5Hash(strPoint);
//
// //命中实体
// Viewport3DTriangleEntity res = triangles.Find(e => triangleCode.Equals(e.TriangleCode));
//
// if (res == null)
// return;
//
// //命中面
// List<Viewport3DTriangleEntity> facet = triangles.Where(e => res.PlaneCode.Equals(e.PlaneCode)).ToList();
// var colorFacet = new Color4(1.0f, 1.0f, 0.0f, 1.0f);
// var data1 = Viewport3DHelper.GenerateEmissiveModelByEntity(Viewport3Dx,facet,colorFacet);
// mouseAddModels.AddRange(data1);
// //命中面标线
// var data2 = Viewport3DHelper.GenerateLineTextModelByEntity(Viewport3Dx, facet);
// mouseAddModels.AddRange(data2);
// //命中同类面
// List<Viewport3DTriangleEntity> facetType = triangles.Where(e => res.PlaneType.Equals(e.PlaneType)).ToList();
// //排除自己
// facet.ForEach(e=>facetType.Remove(e));
// var colorFacetType = new Color4(0.9f, 0.9f, 0.7f, 1.0f);
// var data3 = Viewport3DHelper.GenerateEmissiveModelByEntity(Viewport3Dx,facetType,colorFacetType);
// mouseAddModels.AddRange(data3);
// }
// }
// else
// {
// Console.WriteLine("点击的对象不是 MeshGeometryModel3D");
// }
}
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)

@ -0,0 +1,112 @@
<Border x:Class="SparkClient.Views.UserControl.Viewport3D"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SparkClient.Views.UserControl"
xmlns:hx="http://helix-toolkit.org/wpf/SharpDX"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Height="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Background="Transparent" BorderBrush="Transparent" Height="50" Padding="2">
<Border BorderBrush="DarkGoldenrod" BorderThickness="1" CornerRadius="10" Padding="5" >
<Image Source="pack://Application:,,,/Resource/Images/UserControl/zuanshi@3x.png" ></Image>
</Border>
</Button>
<Button Grid.Column="1" Background="Transparent" BorderBrush="Transparent" Height="50" Padding="2">
<Border BorderBrush="DarkGoldenrod" BorderThickness="1" CornerRadius="10" Padding="5" >
<Image Source="pack://Application:,,,/Resource/Images/UserControl/Top@3x.png" ></Image>
</Border>
</Button>
<Button Grid.Column="2" Background="Transparent" BorderBrush="Transparent" Height="50" Padding="2">
<Border BorderBrush="DarkGoldenrod" BorderThickness="1" CornerRadius="10" Padding="5" >
<Image Source="pack://Application:,,,/Resource/Images/UserControl/Bottom@3x.png" ></Image>
</Border>
</Button>
<Button Grid.Column="3" Background="Transparent" BorderBrush="Transparent" Height="50" Padding="2">
<Border BorderBrush="DarkGoldenrod" BorderThickness="1" CornerRadius="10" Padding="5" >
<Image Source="pack://Application:,,,/Resource/Images/UserControl/biaochi1@3x.png" ></Image>
</Border>
</Button>
<Button Grid.Column="4" Background="Transparent" BorderBrush="Transparent" Height="50" Padding="2">
<Border BorderBrush="DarkGoldenrod" BorderThickness="1" CornerRadius="10" Padding="5" >
<Image Source="pack://Application:,,,/Resource/Images/UserControl/biaochi2@3x.png" ></Image>
</Border>
</Button>
</Grid>
<Border Grid.Row="1">
<hx:Viewport3DX ShowCoordinateSystem="True">
<hx:Viewport3DX.EffectsManager><hx:EffectsManager ></hx:EffectsManager></hx:Viewport3DX.EffectsManager>
<hx:Viewport3DX.InputBindings>
<KeyBinding Key="B" Command="hx:ViewportCommands.BackView" />
<KeyBinding Key="F" Command="hx:ViewportCommands.FrontView" />
<KeyBinding Key="U" Command="hx:ViewportCommands.TopView" />
<KeyBinding Key="D" Command="hx:ViewportCommands.BottomView" />
<KeyBinding Key="L" Command="hx:ViewportCommands.LeftView" />
<KeyBinding Key="R" Command="hx:ViewportCommands.RightView" />
<KeyBinding Command="hx:ViewportCommands.ZoomExtents" Gesture="Control+E" />
<MouseBinding Command="hx:ViewportCommands.Rotate" Gesture="RightClick" />
<MouseBinding Command="hx:ViewportCommands.Zoom" Gesture="MiddleClick" />
<MouseBinding Command="hx:ViewportCommands.Pan" Gesture="LeftClick" />
</hx:Viewport3DX.InputBindings>
</hx:Viewport3DX>
</Border>
<Grid Grid.Row="2" Height="100">
<Grid Width="100">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Button Grid.Column="1" Grid.Row="0" Padding="0" Background="Transparent" BorderBrush="Transparent" >
<Image Source="../../Resource/Images/UserControl/arrow.png" />
</Button>
<Button Grid.Column="0" Grid.Row="1" Padding="0" Background="Transparent" BorderBrush="Transparent" >
<Image Source="../../Resource/Images/UserControl/arrow.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform >
<RotateTransform Angle="-90" ></RotateTransform>
</Image.RenderTransform>
</Image>
</Button>
<Button Grid.Column="2" Grid.Row="1" Padding="0" Background="Transparent" BorderBrush="Transparent" >
<Image Source="../../Resource/Images/UserControl/arrow.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform >
<RotateTransform Angle="90" ></RotateTransform>
</Image.RenderTransform>
</Image>
</Button>
<Button Grid.Column="1" Grid.Row="2" Padding="0" Background="Transparent" BorderBrush="Transparent" >
<Image Source="../../Resource/Images/UserControl/arrow.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform >
<RotateTransform Angle="180" ></RotateTransform>
</Image.RenderTransform>
</Image>
</Button>
<TextBox Grid.Column="1" Grid.Row="1" Style="{StaticResource TextBoxExtend}" Padding="0" TextAlignment="Center" Text="123">
</TextBox>
</Grid>
</Grid>
</Grid>
</Border>

@ -0,0 +1,12 @@
using System.Windows.Controls;
namespace SparkClient.Views.UserControl;
public partial class Viewport3D
{
public Viewport3D()
{
InitializeComponent();
DataContext = this;
}
}
Loading…
Cancel
Save