문제

I've loaded a 3d model using Helix toolking like this

modelGroupScull = importer.Load("C:\\Users\\Robert\\Desktop\\a.obj");
GeometryModel3D modelScull = (GeometryModel3D)modelGroupScull.Children[0];

and I also have _3DTools that can draw lines from point-to-point in 3d space. now to draw a wireframe of my GeometryModel3D I guess I have to cycle to its vertexes and add them to ScreenSpaceLines3D.

ScreenSpaceLines3D wireframe = new ScreenSpaceLines3D();

// need to cycle through all vertexes of modelScull as Points, to add them to wireframe
wireframe.Points.Add(new Point3D(1, 2, 3));


wireframe.Color = Colors.LightBlue;
wireframe.Thickness = 3;

Viewport3D1.Children.Add(wireframe);

But... how do I actually get this vertex points?

EDIT:

Thanks for the answer. It did add the points

        ScreenSpaceLines3D wireframe = new ScreenSpaceLines3D();

        MeshGeometry3D mg3 = (MeshGeometry3D)modelScull.Geometry;

        foreach (Point3D point3D in mg3.Positions)
        {
            wireframe.Points.Add(point3D);
        }


        wireframe.Color = Colors.LightBlue;
        wireframe.Thickness = 1;

        Viewport3D1.Children.Add(wireframe);

but the wireframe is messed up )

enter image description here
(source: gyazo.com)

maybe someone knows of other ways to draw wireframes? )

도움이 되었습니까?

해결책

Normally the trigons are drawn with index buffers (to prevent extra rotations of vertices) Take a look at the TriangleIndices:

if you do something like this: (not tested it)

    MeshGeometry3D mg3 = (MeshGeometry3D)modelScull.Geometry;

    for(int index=0;index<mg3.TriangleIndices.Count; index+=3)
    {
        ScreenSpaceLines3D wireframe = new ScreenSpaceLines3D();

        wireframe.Points.Add(mg3.Positions[mg3.TriangleIndices[index]]);
        wireframe.Points.Add(mg3.Positions[mg3.TriangleIndices[index+1]]);
        wireframe.Points.Add(mg3.Positions[mg3.TriangleIndices[index+2]]);
        wireframe.Points.Add(mg3.Positions[mg3.TriangleIndices[index]]);

        wireframe.Color = Colors.LightBlue;
        wireframe.Thickness = 1;

        Viewport3D1.Children.Add(wireframe);
    }

But, this can create some overdraw (2 lines on the same coordinates) and probably very slow. If you put each side into a list and use something like a Distinct on it, it will be better.

The problem with the ScreenSpaceLines3D is that will continue the line, instead of create 1 line (start/end).

If you can manage a algoritm that tries to draw you model with 1 line, it will go faster.

Wireframes are very slow in WPF. (because they are created with trigons)

다른 팁

You should find the vertex points in MeshGeometry3D.Positions Property

foreach (var point3D in modelScull.Geometry.Positions)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top