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
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.
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 ?
I’ll post a video soon showing the interactive features. Until then…

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/
Hi Shahar,
The engine is pure C# and native WPF. It has no wrappers and does not use any 3rd party libraries. The reason I chose a pure WPF approach is to leverage rest of the framework capabilities like Data-Binding and Animation.
However I am open for using the “Math” part of the 3rd party libs
Hi pavan,
Is there a way to take a look at your source code, I am doing similar kind of project called lattice drawing. I would be really helpful, if i can see your stuff.
I really appreciate.
Hi pavan,
I just realized there are so many projects going on in this blog. I am interested in getting a source code for A scaled down 3D engine in WPF. Thanks for your time.
[...] my previous post I mentioned about a really simple 3D engine that can be used for experimenting with lines, polygons [...]
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.
No source. Whats the point?
The rendering of those objects is lovely, especially the lines along some of the poly edges. Care to share how you managed that?
If possible please share the code for how to do it.
M badly in need of it.
[...] this blog, I have decided to release the source of the little 3D engine I wrote a long time back (here and [...]
Just have bookmarked your website, and waiting for the next interesting article