Some people wanted to know how I manage my own code, find things in Blender’s code etc. when I code, so I’m going to write about it now.
I use Ubuntu and this should work on Fedora/OpenSUSE/whatever (Of course using their respective package managers). Most things here are also applicable to OS X.
Building Blender quickly and easily
I use CMake, because it seems to be the faster than SCons on Linux.
First, follow this guide:
http://wiki.blender.org/index.php/Dev:2.5/Doc/Building_Blender/Linux/Ubuntu/CMake
Personally, I use the folder names “.bsvn” instead of “blender-svn” and “cmake” instead of “build” because they’re easier to type when using the command line. I’m lazy like that.
Once you have followed that guide and built Blender once, create a script like this:
#!/bin/sh
cd ~/.bsvn/blender
svn up
cd ~/.bsvn/cmake
cmake ../blender
make -j3
make install
(I’m not sure if “cmake …/blender” is necessary)
Personally I use a much longer and more complex script that basically does this, but is more careful about it. This works for simple building though.
Save this as build_blender.sh, save it somewhere out of the way, and make it executable:
$ chmod u+x build_blender.sh
Then create a link on your desktop that runs that script.
I also create a link on my desktop to my build of Blender, you can find it here (If you used my folder names): ~/.bsvn/cmake/bin/blender
Finding things in the source code
Blender has a lot of code. Around a million lines. Although this might be a lot/little, it doesn’t matter; All it means is that if you are looking for something, it can take you a long time unless you know what you’re doing.
This is why grep is your friend. Go to your Blender source directory, in my case ~/.bsvn/blender and use this command to search:
grep -irn --exclude="*\.svn*" "your search string here" *
The --exclude argument makes sure that you don’t waste time searching through SVN’s cache. The -irn arguments mean:
- Case insensitive (It treats a search for “TEST” and “test” the same)
- Recursive (It looks through all the directories under the working directory)
- Line numbers (It tells you which line number each search result appears on)
If you know that you’re looking for something that is not written in Python (Like the Python files where the buttons, sliders, and other UI elements are actually declared), you can go to blender/source/blender and search from there. It will eliminate any Python-related search results and take less time.
There are a few things I could say about the actual source directories and what they contain, but I don’t feel qualified to say more than that the interesting editor code is in blender/source/blender/editors/. Each editor (view3d, properties editor, UV/Image editor etc.) has its own folder. Within each folder, there are files related to drawing the editor/space, the operators that the space uses, the inner workings of the space, and a lot of other things.
Have a look at this image if you want to know more.
Managing your own code
Keeping track of what code you wrote, making sure your code works with the latest revision of Blender, etc.
I use this method of keeping track of my own code:
I was going to write about this myself, but take the time to watch the video instead. There you’ll see what I was going to explain, and you’ll see it happen too. All I’ll say is that it allows you to easily make local branches that you can quickly sync with trunk and create patches from.
Writing code
I use gedit. It has nice code highlighting and works for me.
Reading code
Reading code can be more challenging than writing code. The only advice I can really give you is to read slowly and carefully, and Don’t Panic.