WPF Viewport3D放置组件图像不清晰
Viewport3D内放置组件旋转,组件内包含图像的话,图像不清晰发虚,如何设置?
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
public class RotatingEffect
{
private AxisAngleRotation3D axisAngleRotation;
private double delay;
/// <summary>
/// 3D 旋转切换组件
/// </summary>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
/// <param name="direction">旋转方向 0-横向 1-纵向</param>
/// <param name="control_First">正面显示的组件</param>
/// <param name="control_Second">背面显示的组件</param>
/// <param name="timeDelay">动画时长</param>
/// <returns>Viewport3D 组件</returns>
public Viewport3D rotatingEffect(double width, double height, int direction, UserControl control_First, UserControl control_Second, double timeDelay)
{
delay = timeDelay;
double Mesh_Width = width / 2;
double Mesh_Height = height / 2;
Viewport3D viewport3D = new Viewport3D();
PerspectiveCamera perspectiveCamera = new PerspectiveCamera()
{
Position = new Point3D(0, 0, width * 2), // 可调整
LookDirection = new Vector3D(0, 0, -1),
NearPlaneDistance = 100 // 可调整
};
viewport3D.Camera = perspectiveCamera;
ContainerUIElement3D containerUIElement3D = new ContainerUIElement3D();
DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuseMaterial, true);
MeshGeometry3D MeshGeometry_1 = new MeshGeometry3D()
{
TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }),
TextureCoordinates = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) }),
Positions = new Point3DCollection(new Point3D[] {
new Point3D(-Mesh_Width, Mesh_Height, 0),
new Point3D(-Mesh_Width, -Mesh_Height, 0),
new Point3D(Mesh_Width, -Mesh_Height, 0),
new Point3D(Mesh_Width, Mesh_Height, 0)
})
};
Viewport2DVisual3D viewport2DVisual3D_1 = new Viewport2DVisual3D()
{
Geometry = MeshGeometry_1,
Visual = control_First,
Material = diffuseMaterial
};
PointCollection Direction;
Vector3D vector3D;
if (direction == 0)
{
Direction = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) });
vector3D = new Vector3D(0, 1, 0);
}
else
{
Direction = new PointCollection(new Point[] { new Point(1, 1), new Point(1, 0), new Point(0, 0), new Point(0, 1) });
vector3D = new Vector3D(1, 0, 0);
}
MeshGeometry3D MeshGeometry_2 = new MeshGeometry3D()
{
TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }),
TextureCoordinates = Direction,
Positions = new Point3DCollection(new Point3D[] {
new Point3D(Mesh_Width, Mesh_Height, 0),
new Point3D(Mesh_Width, -Mesh_Height, 0),
new Point3D(-Mesh_Width, -Mesh_Height, 0),
new Point3D(-Mesh_Width, Mesh_Height, 0)
})
};
Viewport2DVisual3D viewport2DVisual3D_2 = new Viewport2DVisual3D()
{
Geometry = MeshGeometry_2,
Visual = control_Second,
Material = diffuseMaterial
};
containerUIElement3D.Children.Add(viewport2DVisual3D_1);
containerUIElement3D.Children.Add(viewport2DVisual3D_2);
axisAngleRotation = new AxisAngleRotation3D()
{
Angle = 0,
Axis = vector3D
};
RotateTransform3D rotateTransform3D = new RotateTransform3D()
{
CenterX = 0.5,
CenterY = 0.5,
CenterZ = 0.5,
Rotation = axisAngleRotation
};
containerUIElement3D.Transform = rotateTransform3D;
ModelVisual3D modelVisual3D = new ModelVisual3D()
{
Content = new DirectionalLight(Colors.Transparent, new Vector3D(0, 0, -1))
};
viewport3D.Children.Add(containerUIElement3D);
viewport3D.Children.Add(modelVisual3D);
return viewport3D;
}
/// <summary>
/// 旋转角度
/// </summary>
/// <param name="degrees">角度</param>
public void Turn(double degrees)
{
DoubleAnimation da = new DoubleAnimation();
da.Duration = new Duration(TimeSpan.FromSeconds(delay));
da.To = degrees;
axisAngleRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
}
}
...全文
相关推荐
WPF 3D点云显示
本话题聚焦于“WPF 3D点云显示”,这是一个利用WPF实现的高效、高性能的3D点云数据展示解决方案。点云是由大量三维坐标点组成的集合,常用于3D扫描、无人机测绘、医学图像分析等场景。
C# WPF中基于OpenTK的3D虚拟地球实现:从球体贴图到卫星轨迹
3D可视化技术是数字孪生与虚拟仿真领域的重要基础,而虚拟地球作为地理空间信息展示的载体,在卫星轨道监测、轨迹回放等场景中应用广泛。实现一个可交互的3D地球通常需要解决球体网格生成、纹理贴图、相机控制与数据叠加等核心问题。基于OpenGL的渲染管线配合C#语言,可以在WPF桌面应用中构建离线运行的轻量级3D可视化方案。通过经纬度网格建模、UV映射以及四元数旋转控制,能够实现流畅的地球拖拽与缩放;借助实例化绘制和缓冲区局部更新策略,可支撑大量动态轨迹与标记点的实时渲染。本文将分享在C#桌面端集成OpenTK(O
WPF 3D图表
Viewport3DViewport3D 是 WPF 中用来显示三维场景的主要容器。所有的 3D 元素都必须放置在这个容器内部才能被正确渲染。##### 2. 相机相机定义了观察者的位置和视角。
wpf 图片3d效果
**组合3D元素**:将3D模型、相机和视口组合在一起,形成最终的3D图像。
WPF超给力的3D特效,值得拥有!
WPF是.NET Framework的一部分,提供了丰富的用户界面(UI)框架,包括2D图形、文本渲染、图像处理、媒体播放以及我们关注的3D图形功能。


