Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 10-Mar-18 0:35am
v2

1 solution

Got the solution.

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!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900