Create Polygons Dinamically in wpf Viewport3d or Hilix Polygon3D

Marino Liranzo 81 Reputation points
2023-04-24T13:46:46.6566667+00:00

Hello, I try to create polygons dynamically that are represented as the points are established, I have tried the following code.

private void viewport1_PreviewMouseMove(object sender, MouseEventArgs e)
    {
        ptemp3d = new Point3D(pt3d.X, pt3d.Y, pt3d.Z); 

        if (geo.Positions.Count >= 3)
        {
            Polygon3D pol = new Polygon3D(); // Helix Impletentation
            pol.Points.Add(geo.Positions[0]); // geo.Positions is a Point3D Collection
            pol.Points.Add(geo.Positions[1]);
            pol.Points.Add(geo.Positions[2]);
            pol.Points.Add(ptemp3d);

            var meshBuilder = new MeshBuilder(false, false);
            meshBuilder.AddPolygon(pol.Points);

            // Create a mesh from the builder 
            var mesh = meshBuilder.ToMesh(true);
            MainModel3Dgroup.Children.Add(new GeometryModel3D
            {
                Geometry = mesh,
                Transform = new TranslateTransform3D(1, 0, 0),
                Material = LosasMaterial,
                BackMaterial = LosasMaterial
            });
        }
    }

Developer technologies Windows Presentation Foundation
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.