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).
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…