MySketchup 3D graphics editor
- Duration: Jan - May 2009
- Language used: C++ (in the Microsoft Visual C++ Express Edition 2008 IDE)
- Platform: Windows Vista (for the Win32 native API and OpenGL API)
Brief
MySketchUp is a 3D graphics editor I wrote for self-interest during my Bachelors, using Microsoft's implementation of the OpenGL Specification (opengl32.dll). The GUI of this editor is very similar to Google's SketchUp software, hence the name "MySketchUp". Using the editor, we can draw simple coloured 3D scenes (see the example screenshots).
Details
Initially, I had absolutely no idea what a 3D graphics editor should contain, or what tools it should have. When I googled for "3D graphics editors", I came across Maya3D. Although the 3D scenes created in Maya3D were very impressive, I felt that the GUI was really complicated to understand and learn. Later, I came across another 3D graphics editor called Google SketchUp. I was amazed by the simplicity of the toolset. There are a number of SketchUp video tutorials on the internet, which help you get started on drawing 3D scenes within minutes. I also checked some of the sample 3D scenes that have been created in SketchUp - they are quite detailed (I especially liked the architectural designs). SketchUp was not only easy to use, but also capable of drawing complex 3D scenes.
I tried to make my editor with the same easy-to-use GUI. The focus of the project was to understand how exactly the tools are implemented internally, and how to represent the 3D scenes with appropriate data structures. I didn't find much information on the internet regarding the internal working of 3D graphic editors; I had to figure out how to implement most of the tools. Luckily I am good at vector mathematics and co-ordinate geometry, which helped me a lot. I slowly implemented the editor one tool at a time (one of the difficult ones was the PushPull/Extrusion tool - it took me a while to implement it properly). The end result was very satisfying - I was able to draw some nice simple 3D scenes using my editor, something I never dreamed of doing before I started learning OpenGL. Check out the example screenshots.
I wrote a lot of on-source documentation for the editor code, however I did not write it in the proper Doxygen format (with the @ tags). The documentation generated by Doxygen is still useful though, especially to find in which header file each variable/new data type has been declared.
MySketchUp also supports saving the 3D scenes. There are standard file formats for 3D vector graphics, but I didn't use them. Due to limited time, I saved the scenes in a crude binary file format (a magic number at the beginning, followed by information about all objects in the scene). I also wanted to make some video tutorials (like in Google SketchUp) using the Wink software, but I didn't have time to finish them.
While I was developing the editor, I broke my head over a few simple bugs. Some of them which caused a lot of headache are below:
- The scene suddenly becomes black, and nothing can be drawn : this was due to a division by zero error
- The extrusion was occurring in wrong directions : this was because I had replaced a minus sign by a plus sign in the calculation of normals
The editor responds quickly, so it looks like my implementation of the tools is at least reasonably efficient. The aim of this project was to learn about OpenGL, Computer Graphics, and how to implement a 3D graphics editor like Google SketchUp, I'm happy that I was able to do all of these.
Implementation
I implemented the editor using Standard C++ (the STL library came in very useful, I used it extensively). I used an Object-Oriented approach. For creating the windows, menu, toolbar and performing I/O, I used the Native Win32 APIs. For drawing the 3D scenes, I used OpenGL.
Experience gained
- This project helped me gain experience in writing code using multiple source files (I created around 30 headers and 30 source files). I was able to understand the concepts and pitfalls of using multiple source files (circular dependencies, multiple declarations one definition rule, private and public headers, importance of makefiles).
- The project helped me understand native Windows Programming. I learnt Windows Programming from the book by Charles Petzold, an excellent book.
- I learnt OpenGL from the Red book, another excellent book. OpenGL is one of the best C libraries I have used, I think it has been designed really well. The documentation (the Blue Book) also reflects this. Moreover, OpenGL is perfect for anyone who wants to study Computer Graphics in a "learn-by-doing" manner.
- I used the C++ standard template library extensively, including my own implementation of smart pointers (which are now part of the new C++ standard)
References
OpenGL API
- OpenGL Programming Guide (The Red Book): Great tutorial for learning OpenGL and Computer Graphics
- OpenGL Reference Manual (The Blue Book): Excellent documentation of all OpenGL functions
Google SketchUp
Vector Math Algorithms
- Mathematics for Class 12 (Part B), R D Sharma: For basic vector mathematics
- List of Graphics Algorithms
Windows Programming
- Programming Windows: The best book to learn native Windows programming from scratch
- The MSDN Library
Standard C++
Downloads
The Source code is open-source. You are free to modify it and use it for any research/study purposes. However, you cannot use it for any commercial purposes. Since I have used icons from Google SketchUp (which are under copyright), the executable of MySketchUp is not for public distribution - the exe file below is password protected. Rename it with a '.zip' extension, and extract it after entering the password. The scene files can be opened and edited with MySketchup.