Viewport3D,带有正交摄影机剪裁
本文关键字:摄影机 剪裁 Viewport3D | 更新日期: 2023-09-27 18:26:30
将ViewPort3D与正交摄影机一起使用时,3D模型正在剪裁,如您在下面的第二个链接中看到的那样。这就像视图是基于透视摄影机的,即使使用正交摄影机,也不会显示其背后的内容。
整个三维模型视图
透视图&正交视图
使用代码生成上方的图片
Used code to generate pictures above (toggling Orthographic to True/False)
<Window x:Class="HelixToolkitTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:helix="http://helix-toolkit.org/wpf"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<GeometryModel3D x:Key="GeometryModel">
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 3,4,5 "
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 "
TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0 "
Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 " />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Red" Offset="0.25" />
<GradientStop Color="Blue" Offset="0.75" />
<GradientStop Color="LimeGreen" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
<GeometryModel3D.Transform>
<ScaleTransform3D ScaleX="50" ScaleY="1" ScaleZ="1"/>
</GeometryModel3D.Transform>
</GeometryModel3D>
<DirectionalLight x:Key="DirectionalLight" Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
</Window.Resources>
<UniformGrid Columns="3">
<GroupBox Header="Perspective camera">
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera FarPlaneDistance="Infinity" NearPlaneDistance="0.1" LookDirection="12.064,-1.167,-0.831" UpDirection="-0.73,0.071,0.679"
Position="-12.064,1.167,0.831"/>
</Viewport3D.Camera>
<ModelVisual3D Content="{StaticResource DirectionalLight}"/>
<ModelVisual3D Content="{StaticResource GeometryModel}"/>
</Viewport3D>
</GroupBox>
<GroupBox Header="Orthographic camera">
<Viewport3D>
<Viewport3D.Camera>
<OrthographicCamera FarPlaneDistance="Infinity" NearPlaneDistance="0.1" LookDirection="12.064,-1.167,-0.831" UpDirection="-0.73,0.071,0.679"
Position="-12.064,1.167,0.831" Width="9.313"/>
</Viewport3D.Camera>
<ModelVisual3D Content="{StaticResource DirectionalLight}"/>
<ModelVisual3D Content="{StaticResource GeometryModel}"/>
</Viewport3D>
</GroupBox>
你知道如何解决这个问题吗?
谢谢,
编辑:我实际上找到了解决方案,你只需要将正交相机的NearPlaneDance设置为-Infinity,请参阅下面的代码:
<Window x:Class="HelixToolkitTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:helix="http://helix-toolkit.org/wpf"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<GeometryModel3D x:Key="GeometryModel">
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 3,4,5 "
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 "
TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0 "
Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 " />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Red" Offset="0.25" />
<GradientStop Color="Blue" Offset="0.75" />
<GradientStop Color="LimeGreen" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
<GeometryModel3D.Transform>
<ScaleTransform3D ScaleX="50" ScaleY="1" ScaleZ="1"/>
</GeometryModel3D.Transform>
</GeometryModel3D>
<DirectionalLight x:Key="DirectionalLight" Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
</Window.Resources>
<UniformGrid Columns="3">
<GroupBox Header="Perspective camera">
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera FarPlaneDistance="Infinity" NearPlaneDistance="0.1" LookDirection="12.064,-1.167,-0.831" UpDirection="-0.73,0.071,0.679"
Position="-12.064,1.167,0.831"/>
</Viewport3D.Camera>
<ModelVisual3D Content="{StaticResource DirectionalLight}"/>
<ModelVisual3D Content="{StaticResource GeometryModel}"/>
</Viewport3D>
</GroupBox>
<GroupBox Header="Orthographic camera">
<Viewport3D>
<Viewport3D.Camera>
<OrthographicCamera FarPlaneDistance="Infinity" NearPlaneDistance="-Infinity" LookDirection="12.064,-1.167,-0.831" UpDirection="-0.73,0.071,0.679"
Position="-12.064,1.167,0.831" Width="9.313"/>
</Viewport3D.Camera>
<ModelVisual3D Content="{StaticResource DirectionalLight}"/>
<ModelVisual3D Content="{StaticResource GeometryModel}"/>
</Viewport3D>
</GroupBox>
我遇到了和你一样的问题。通过测试几种解决方案,我终于找到了解决方案。
您必须增加或定义PerspectiveCamera的FarPlaneDance属性。
祝好运