3d line drawing in wpf

I am trying to draw a 3D string in wpf and I have this xaml code:

<Grid>
    <Viewport3D x:Name="ViewerViewport"
                RenderOptions.BitmapScalingMode="HighQuality"
                Focusable="True" Grid.RowSpan="2">

        <ModelVisual3D x:Name="Model">

        </ModelVisual3D>

        <!-- Camera -->
        <Viewport3D.Camera>
            <PerspectiveCamera x:Name="Camera"
                               Position="0,0,0"
                               LookDirection="0,1,0"
                               UpDirection="0,0,1"
                               FieldOfView="100"
                               FarPlaneDistance="10"
                               NearPlaneDistance="0.1"/>
        </Viewport3D.Camera>

    </Viewport3D>

</Grid>

and this C # code:

public MainWindow()
{
        InitializeComponent();
        var ModelsGroup = new Model3DGroup();
         ModelsGroup.Children.Add(this.AddLine(new Point3D(0, 0, 100), new Point3D(0, 100, 100),"line 1)"));
         ModelsGroup.Children.Add(new AmbientLight(Colors.White));
        Model.Content = ModelsGroup;
}

and line creation code:

  private Model3D AddLine(Point3D startPoint, Point3D EndPoint, string name)
    {
        SolidColorBrush brush = new SolidColorBrush(Colors.Black);
        var material = new DiffuseMaterial(brush);
        var mesh = new MeshGeometry3D();
        mesh.Positions.Add(startPoint);
        mesh.Positions.Add(EndPoint);
        mesh.TriangleIndices.Add(0);
        mesh.TriangleIndices.Add(1);
        mesh.TriangleIndices.Add(0);
        return new GeometryModel3D(mesh, material);
    }

but it does not display the line in the output?

What is wrong with that?

I know there are some 3d libraries that can do this easily, but I like to learn how to do it in WPF and then explore how to do it using libraries (like helix3d)

+4
source share
3 answers

You create a triangle in which two angles are at the same point, that is, a triangle with a zero region, so it is never visible at any angle. WPF only uses area triangles

, , . , , "0 1 2 0 1 3". , , , , .

google bing helix, 3D WPF. .

+3

. 3D . , normals. , .


Position - z (- 0, 0, 2 5, 0, 20), LookDirection 0, 0, -1 UpDirection vector 0, 1, 0. , ( y , x ).
UpDirection 1, 0, 0, x y.
Position z- (0, 0, -5) LookDirection 0, 0, 1, "", x ( ), y .

y z. X - . . 100, 0, 100, .

mesh.Positions.Add(startPoint);
mesh.Positions.Add(endPoint);
mesh.Positions.Add(new Point3D(100, 0, 100));
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);

- - 100. @Samuels , - FarPlaneDistance="10".

+1

... - WPF.... , ( ), , ( ^ ^, , , , , )

0

Source: https://habr.com/ru/post/1569416/


All Articles