A scaled down 3D engine in WPF

Over the last few days I have been exploring some interesting ideas in my current project. One of the requirements was to visualize some data in 3D. Of course you would say: “that should be easy: WPF has Viewport3D”. And certainly you are right. In fact that was my initial reaction too. When I got down to building some of the visualizations I soon realized some inherent deficiencies: I cannot draw lines, simple shapes and in general cannot build wireframes.

After some exploration I found SceenSpaceLines3D, which is part of the 3DTools project. This is an interesting solution but is pretty slow and looked more of a hack (and a clever one).

  • I needed something much more natural to deal with
  • I did not want the burden of a Viewport3D and I did not want to create complex meshes
  • I wanted something that would blend well with 2D content without using lot of 3D math (like the way ScreenSpaceLines3D does)
  • I did not want texture mapping since all of my objects would be solid with varying opacities
  • In my current version I am not even particular about depth-sorting the polygons or hidden surface removal

 

A scaled down 3D engine

image

After some back and forth I decided to write a simple 3D engine that had all of the features above. In fact the engine is just two C# files and the total LOC is ~150. It contains 2 classes: View3DPresenter and MapItemVisual3D. The View3DPresenter is responsible for managing the models, Camera and initiates the rendering of the models. You can also control the orientation of the camera using the mouse.

The MapItemVisual3D does the actual rendering by projecting its 3D points to a 2D plane and then drawing polygons for all the faces. In addition to these classes I also have some simple surfaces like Cube, Sphere, Cylinder, Torus and Cone, all of which derive from MapItemVisual3D. I plan to add a few more to this library. Transformations like Scale, Translation and Rotation can also be applied on models.

 image

 

I will go into more details in a future post and also some applications of this engine. It is still in a very nascent stage and also has a few performance issues.

Here are some shapes after applying Scale transformations. Can you recognize the original ones ?

image

 

I’ll post a video soon showing the interactive features. Until then…

Similar Posts:

11 responses to “A scaled down 3D engine in WPF”

  1. ShaharY

    Is your engine written with pure C# or does it wrap a C++ 3D engine?
    You can achieve all that and more by using a free open source C++ 3D engine like OSG – http://www.openscenegraph.org/projects/osg
    or VTK – http://www.vtk.org/

  2. Video of the simple 3D engine in WPF | Pixel in Gene

    [...] my previous post I mentioned about a really simple 3D engine that can be used for experimenting with lines, polygons [...]

  3. Hung

    Hung
    November 14th, 2008
    How can you create objects with non-triangular faces? As i know, everything in WPF is triangular. Why does everything have to be about triangles? Can you post a simple sample source code to create a cube with squared faces. I need this so bad.

  4. Don

    No source. Whats the point?

  5. Pete

    The rendering of those objects is lovely, especially the lines along some of the poly edges. Care to share how you managed that? :)

  6. Pank

    If possible please share the code for how to do it.
    M badly in need of it.

  7. Source code of Simple 3D Engine, now part of FluidKit

    [...] this blog, I have decided to release the source of the little 3D engine I wrote a long time back (here and [...]

  8. solve quick tasks earn $$

    Just have bookmarked your website, and waiting for the next interesting article

Leave a Reply