本文介绍了有没有办法在viewport3d中绘制2D形状,如直线,圆弧,点,平面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用Viewport3D,我在其中绘制所有3D形状,但我也想在Viewport3D中绘制弧,点和线。任何人都可以帮我吗?



我尝试过:



我使用路径几何绘制Arc但不知何故无法在viewport3D中添加它...我可以使用Viewport2DVisual3D.Visual吗?但我不知道如何使用它

Right now I am using Viewport3D in which I am drawing all 3D shapes but I also want to draw arc, point and lines in Viewport3D. Can anyone help me with this?

What I have tried:

I am using path geometry for drawing Arc but somehow unable to add it in viewport3D...Can i use Viewport2DVisual3D.Visual? but I dont know how to use it

推荐答案

ArcModel = new Viewport2DVisual3D();
 MeshGeometry3D testGeometry = new MeshGeometry3D();
 PathFigure pthFigure = new PathFigure();
 pthFigure.StartPoint = new Point(100, 10);

 ArcSegment arcSeg = new ArcSegment();
 arcSeg.Point = new Point(300, 30);
 arcSeg.Size = new Size(50, 5);
 arcSeg.IsLargeArc = true;
 arcSeg.SweepDirection = SweepDirection.Counterclockwise;
 //arcSeg.RotationAngle = 30;

 PathSegmentCollection myPathSegmentCollection = new    PathSegmentCollection();
 myPathSegmentCollection.Add(arcSeg);

 pthFigure.Segments = myPathSegmentCollection;

 PathFigureCollection pthFigureCollection = new PathFigureCollection();
 pthFigureCollection.Add(pthFigure);

 PathGeometry pthGeometry = new PathGeometry();
 pthGeometry.Figures = pthFigureCollection;

 Path arcPath = new Path();
 arcPath.Stroke = new SolidColorBrush(Colors.Violet);
 arcPath.StrokeThickness = 1;
 arcPath.Data = pthGeometry;



 Point3DCollection myPoint3DCollection = new Point3DCollection();
 myPoint3DCollection.Add(new Point3D(0, 0, 0));
 myPoint3DCollection.Add(new Point3D(0, 0, 2));
 myPoint3DCollection.Add(new Point3D(0, 2, 0));
 myPoint3DCollection.Add(new Point3D(0, 2, 2));
 testGeometry.Positions = myPoint3DCollection;

 PointCollection myPointCollection = new PointCollection();
 myPointCollection.Add(new Point(0, 1));
 myPointCollection.Add(new Point(1, 1));
 myPointCollection.Add(new Point(0, 0));
 myPointCollection.Add(new Point(1, 0));
 testGeometry.TextureCoordinates = myPointCollection;

 Int32Collection triangleIndicesCollection = new Int32Collection();
 triangleIndicesCollection.Add(0);
 triangleIndicesCollection.Add(1);
 triangleIndicesCollection.Add(2);
 triangleIndicesCollection.Add(2);
 triangleIndicesCollection.Add(1);
 triangleIndicesCollection.Add(3);
 testGeometry.TriangleIndices = triangleIndicesCollection;

 DiffuseMaterial myDiffuseMaterial = new DiffuseMaterial(Brushes.White);
 Viewport2DVisual3D.SetIsVisualHostMaterial(myDiffuseMaterial, true);

 Transform3DGroup myTransform3DGroup = new Transform3DGroup();

 RotateTransform3D rotateTransform = new RotateTransform3D()
 {
     Rotation = new AxisAngleRotation3D
     {
         Angle = 40,
         Axis = new Vector3D(0, 1, 0)
     }
 };


 myTransform3DGroup.Children.Add(rotateTransform);
 ArcModel.Transform = myTransform3DGroup;
 ArcModel.Material = myDiffuseMaterial;
 ArcModel.Geometry = testGeometry;
 ArcModel.Visual = arcPath;

 viewport.Children.Add(ArcModel);







希望这对某人有帮助!




hope this will help someone!


这篇关于有没有办法在viewport3d中绘制2D形状,如直线,圆弧,点,平面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 08:04