0

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Roger Travis
  • 8,402
  • 18
  • 67
  • 94

2 Answers2

1

You should find the vertex points in MeshGeometry3D.Positions Property

foreach (var point3D in modelScull.Geometry.Positions)
LPL
  • 16,827
  • 6
  • 51
  • 95
1

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)

Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57
  • idea sound nice, but it throws Operator '<' cannot be applied to operands of type 'int' and 'System.Windows.Media.Int32Collection' – Roger Travis Sep 15 '13 at 13:45
  • I updated it, are there any problems now? Forgot the `Count` property, maybee you need `Count()` Can you update your post and add the new image? (show the previous also) – Jeroen van Langen Sep 15 '13 at 13:46
  • still looks messed up and veeery slow ( guess will have to look for some other method. ) – Roger Travis Sep 15 '13 at 13:53
  • 1
    My bad, try again plz.. i forgot something.. It won't be faster, but shouldn't mesh up anymore. Those TriangleIndices are indices to positions. Let me know plz. – Jeroen van Langen Sep 15 '13 at 13:58
  • the mesh looks correct, but veeery slow ) took about a minute or so to load up. – Roger Travis Sep 15 '13 at 14:17
  • Thats because all triangles will be handled as single mesh. Now it's your turn to try figure out, what lines you don't need, and if you want to speed it up, try to create a few lines that will handle more trigons. (1 touch draw). Maybee you could try to create a brute force to calculate the best way to draw the skull with a less as possible lines. (can you add the correct drawing also plz?) – Jeroen van Langen Sep 15 '13 at 14:23
  • As you can see, it's very dense. Many lines(meshes) are created (with their own matrices for rotation/translation) And will be drawn separately. The ScreenSpaceLines3D normally isn't used for drawing complex wireframes. But i think it's a challenge to draw it as one or few lines possible. – Jeroen van Langen Sep 15 '13 at 14:38
  • by the way, maybe there's an option to render the mesh just as flat shaded? – Roger Travis Sep 15 '13 at 14:46
  • Flatshading doesn't reduce the amount of polygons. If there is a way to 'optimize' the model, would help more. – Jeroen van Langen Sep 15 '13 at 14:51
  • no, no, I mean that I need to represent the mesh as it is, I shouldn't optimize it. So if it too slow to show as wireframe, showing it as gray flat shaded mesh would also do. ) – Roger Travis Sep 15 '13 at 15:33
  • I think render it a one mesh will speed up much, also you'll see some depth. – Jeroen van Langen Sep 15 '13 at 20:01