-1

现在我正在使用 Viewport3D,我在其中绘制所有 3D 形状,但我还想在 Viewport3D 中绘制弧线、点和线。谁能帮我这个?

        private Viewport2DVisual3D ArcModel; 
        private Model3DGroup group;
        MeshGeometry3D testGeometry = new MeshGeometry3D();
        PathFigure pthFigure = new PathFigure();
        pthFigure.StartPoint = new Point(1, 1);

        ArcSegment arcSeg = new ArcSegment();
        arcSeg.Point = new Point(30, 30);
        arcSeg.Size = new Size(20, 20);
        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;
        //arcPath.Fill = new SolidColorBrush(Colors.Yellow);

        //Children.Add(arcPath);
        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);


        ArcModel = new Viewport2DVisual3D();
        ArcModel.Material = myDiffuseMaterial;
        ArcModel.Geometry = testGeometry;
        //group.Children.Add(ArcModel.Geometry);
        ArcModel.Visual = arcPath;
        ArcGeomodel = new GeometryModel3D(ArcModel.Geometry, myDiffuseMaterial);
        ArcGeomodel.Transform = new Transform3DGroup();

        group.Children.Add(ArcGeomodel);
        viewport.Children.Add(ArcModel);

我正在使用路径几何绘制这条弧线并将其添加到 Viewport2DVisual3D 中,但它没有显示出来......我在这里缺少什么......请提出任何解决方案

4

1 回答 1

0

终于得到了我所缺少的。我缺少向其添加变换和旋转以下是代码

 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);

希望这会对某人有所帮助!

于 2018-03-10T11:07:25.533 回答