#c# #wpf
#c# #wpf
Вопрос:
Я использую C # в VS 2019 для разработки 3D-проекта WPF. Я создал две 3D-линии в viewpoint3D, которые будут перемещаться при перемещении ползунка. Заказчик хочет, чтобы мы, я, изменили 3D-линию на 3D-плоскость, чтобы поперечное сечение 3D-объекта можно было показывать при перемещении плоскости для вырезания 3D-объекта.
Как я мог бы нарисовать 3D-плоскость вертикально в плоскости X-Y и вырезать 3D-объект, чтобы показать поперечное сечение необработанного 3D-объекта?
XAML:
<UserControl x:Class="STIGenericReport.UserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tool3d="clr-namespace:_3DTools;assembly=3DTools"
Height="407" Width="633" Background="White" BorderBrush="White" Focusable="False">
<Grid Name="maingrid" Background="White" Height="405" Width="616" MinWidth="500">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="619*" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height ="574*" />
<RowDefinition Height="26" MinHeight="16" />
</Grid.RowDefinitions>
<Viewport3D Name="mainViewport" ClipToBounds = "False"
IsHitTestVisible="false"
RenderOptions.EdgeMode="Aliased" Margin="12,52,144,47">
<Viewport3D.Camera>
<OrthographicCamera x:Name="camera" Width="2"
FarPlaneDistance="10"
NearPlaneDistance="1"
LookDirection="0,0,-1"
UpDirection="0,1,0"
Position="0,0,2" />
</Viewport3D.Camera>
<Viewport3D.Children>
<ModelVisual3D x:Name="Light1">
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="1, 1, -1" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="Light2">
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="-1, 1, -1" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="Light3">
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="0,-1,-0.5" />
</ModelVisual3D.Content>
</ModelVisual3D>
<tool3d:ScreenSpaceLines3D Points ="0,100,0,0,-100,0" Color="Black" Thickness="2">
<tool3d:ScreenSpaceLines3D.Transform>
<TranslateTransform3D OffsetX="{Binding ElementName=slider, Path=Value}" OffsetY="0" OffsetZ="0" />
</tool3d:ScreenSpaceLines3D.Transform>
</tool3d:ScreenSpaceLines3D>
<tool3d:ScreenSpaceLines3D Points ="100,0,0,-100,0,0" Color="Black" Thickness="2">
<tool3d:ScreenSpaceLines3D.Transform>
<TranslateTransform3D OffsetX="0" OffsetY="{Binding ElementName=slider1, Path=Value}" OffsetZ="0" />
</tool3d:ScreenSpaceLines3D.Transform>
</tool3d:ScreenSpaceLines3D>
</Viewport3D.Children>
</Viewport3D>
<Canvas x:Name="canvasOn3D" Background="#00E6FFFF"
Margin="20,52,102,18"></Canvas>
<Label Content="Trayinfo" FontSize="16" FontWeight="Bold" Height="34" HorizontalAlignment="Left" Margin="192,0,0,0" Name="lblTrayinfo" VerticalAlignment="Top" Width="194" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,257" Name="btn9" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,232" Name="btn8" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button HorizontalAlignment="Left" Margin="499,149,0,207" Name="btn7" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,182" Name="btn6" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,157" Name="btn5" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,132" Name="btn4" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,107" Name="btn3" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,82" Name="btn2" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,57" Name="btn1" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Button Height="25" HorizontalAlignment="Left" Margin="499,0,0,282" Name="btn10" VerticalAlignment="Bottom" Width="50" Background="White" BorderThickness="0" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,57" Name="lbl1" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,82" Name="lbl2" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,107" Name="lbl3" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,132" Name="lbl4" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,157" Name="lbl5" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,182" Name="lbl6" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,207" Name="lbl7" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,232" Name="lbl8" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,257" Name="lbl9" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Height="25" HorizontalAlignment="Right" Margin="0,0,12,282" Name="lbl10" VerticalAlignment="Bottom" Width="45" Background="White" BorderBrush="White" />
<Label Content="Pacakage info" HorizontalAlignment="Center" Width="Auto" Height="32" Name="lblPkgname" FontSize="16" FontWeight="Bold" Margin="204,378,286,-5" Grid.RowSpan="2" />
<Slider x:Name="slider" Minimum="-1" Maximum="1" HorizontalAlignment="Left" Margin="65,363,0,0" VerticalAlignment="Top" Width="345" Grid.RowSpan="2" RenderTransformOrigin="0.434,0.409"/>
<Slider x:Name="slider1" Minimum="-1" Maximum="1" HorizontalAlignment="Left" Margin="-115,182,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="338">
<Slider.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="270"/>
<TranslateTransform/>
</TransformGroup>
</Slider.RenderTransform>
</Slider>
</Grid>
Комментарии:
1. Это можно сделать в pixel shader (фрагментный шейдер). Если мир Z пикселя находится вне диапазона,
clip()
пиксель. И плоскость может быть сгенерирована с помощью геометрического шейдера. Но я не знаю, как получить доступ к шейдерам в WPF 3D.2. Я тоже не знаю…….
3. Пожалуйста, уточните более подробно
4. learn.microsoft.com/en-us/dotnet/api/… Есть только встроенные шейдеры. Я думаю, это невозможно. Попробуйте вместо этого helix toolkit. Это открытый исходный код на основе SharpDX.