How to draw rectangles around each vertex in Viewport3D? RRS feed

  • Question

  • Hi!

    I'm using a Viewport3D to display 3D Meshes. Now I want to show a "Gizmo" around each vertex like in most 3d applications like 3ds max or Blender. Such applications draw a rectancle or a circle around each vertex which can be selected and moved using mouse interaction. These "Gizmos" have a constant size in screen space, so my first idea was to draw a simple bitmap containing this rectangle or circle on top of each vertex, facing the camera. But I don't have the coordinates of the vertices in screen space, and I'm out of ideas how to achieve this. Can anyone give me a hint?

    If you can't imagine what I actually mean, please take a look at this picture:, the blue squares represent the vertices.

    Thank you very much,



    Friday, July 16, 2010 5:05 PM

All replies

  • I think those are 3d cubes, and the camera is orthogonal.  Couldn't you just draw a cube or sphere at each vertex?  Depending on the number of vertices you have this may not be an option for performance reasons.  I don't think you want to mess around with screen coordinates, just put the objects in the 3D Model.
    Friday, July 16, 2010 5:13 PM
  • Unfortunately, it must also work for perspective cameras. And I guess I need to take the screen coordinates into account because the "Gizmos" have a constant size that doesn't change on zooming the camera. That's why I thought of simply displaying bitmaps on the canvas.

    I also tried the 3DTools library and the WireFrame library by Charles Petzold, but screen space coordinates are only used for a constant line width, not for object sizes.
    Friday, July 16, 2010 5:26 PM
  • Hi Mr Sparkle,

    You can use Charles Petzold's library to achieve what you want. If you are having difficulties, would you please provide us a simple example that can reproduce your problem? So we can fix it for you.

    Thank you and have a nice day!

    Best regards,


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, July 22, 2010 3:10 AM
  • Thank you! I'm already using Charles Petzolds library but it is really difficult to understand how it works, because the code is not commented at all :)

    I guess I have to create a new class (based on the WireBase class) that draws the vertex gizmos in camera space. But the classes in the library are made to draw lines between world-space points, so all world-space to screen-space conversion methods and matrices are declared as private in the WireBase class. That's why I still don't have any idea how I can draw a simple 3x3 pixel wide rectangle around a vertex.



    Thursday, July 22, 2010 9:15 AM