0

Cutting and showing the result in a Viewport | MeshGeometry3D to MeshVisual3D

FloP 4 years ago updated 4 years ago 1

Hi,
i have a problem with Cutting my objects and then showing them.
For the moment i just use the simple Helixtoolkit.Wpf.

To show them i use the MeshVisual3D whicht worked just fine.
Now i want to slice my object multiple times but therefore i need a MeshGeometry3D, which i can create.
My problem now is, how do i achieve that?
I couldnt find a way to convert my MeshGeometry3D to a MeshVisual3D or to a GeometryModel3D (which i think i could use to generate my MeshVisual3D). I also tried to convert it via MeshGeometryHelper which i also couldnt find a way to do it.

So the main question would be, how do i add my MeshGeometry3D to my HelixViewport3D?

I am sorry, if this is a simple question, but i couldnt find an answer yet.

What i do at the moment is as a bad workaround (but at least i can see something) is to convert the Points to Lines like this:

MeshGeometry3D cutted = MeshGeometryHelper.Cut(_compound, cutPlane, new Vector3D(0, 0, 1));
LinesVisual3D lines = new LinesVisual3D();
lines.Thickness = 3;
lines.Points = cutted.Positions;
lines.Color = System.Windows.Media.Colors.Orange;
_3DWindow.MainViewPort.Children.Add(lines);

But that is not really what i want.

Ok, i found a way how to easily convert them, but i dont know wether this is a good way or not:

private MeshVisual3D GetMeshVisual3D(MeshGeometry3D toTransform)
        {
            MeshVisual3D returnMesh = new MeshVisual3D();
            Mesh3D mesh;
            if (toTransform != null)
                mesh = new Mesh3D(toTransform.Positions, toTransform.TriangleIndices);
            else
                mesh = new Mesh3D(point3Ds, triangles);
            returnMesh.Mesh = mesh;
            return returnMesh;
        }

now my problem ist to get the slice thats created with the cutting (the 2D-View of the top-view from the cut) i know how i get the single points of that plane (with the MeshGeometryHelper.GetContourSegments), but unfortunatly they are not connected. Is there a way to get them connected?