Blender 3D: Noob to Pro/Hacking Blender

Blender is an Open Source project. That doesn’t just mean you get to use it for free, you also get to see how it works, and you can even make your own changes and share them with others.

Blender is also a large software project (well over a million lines of code), with a great many active contributors over a lifespan of more than a decade, and it continues to be developed at a rapid rate. This can make things somewhat intimidating for less-experienced programmers.

This unit assumes you have some decent programming experience under your belt. Blender is mainly programmed in the C, C++ and Python programming languages. It can be built using either the CMake or SCons build systems.

Getting the Blender Source Code

The official Blender source is kept in Git repositories located at developer.blender.org. There are actually several separate repositories:

Layout of the Blender Source

Say you’ve checked out a copy of the main Blender source tree. The top level looks like this:

Common Subdirectory Layout

Within many of the subdirectories in source/blender/ and intern/, you will see the following pattern:

The .h files define the functionality exported to other modules, while the intern subdirectory contains the .c or .cpp files that actually implement the module. Sometimes the .h files are put into an extern subdirectory instead of the upper directory level.

(And yes, these meanings of intern and extern are not the same as the meanings of intern and extern at the top directory level.)

Blender’s “Genetic Code”: “DNA” and “RNA”

You will find references to “DNA” (or “SDNA”) and “RNA” throughout Blender’s source code. The analogy to the terms from genetics is weak at best, but what they refer to is:

Here is Ton “Mr Blender” Roosendaal explaining DNA and RNA.

Special Globals: “G” and “U”

There is a frequently-referenced global variable named “G”, of type struct Global, declared in source/blender/blenkernel/BKE_global.h. The variable is defined in source/blender/blenkernel/intern/blender.c. This same file also defines the global “U”, of type struct UserDef, declared in source/blender/makesdna/DNA_userdef_types.h.

Naming Conventions

Some (but not all) global symbols have prefixes on their names indicating (roughly) where they come from. Here is a partial list.

Prefix Meaning Where Found
AUD_ audaspace sound library intern/audaspace/
BKE_ lowest-level (non-UI) Blender operations source/blender/blenkernel/
BLF_ Font/text-handling source/blender/blenfont/
BLI_ common library routines source/blender/blenlib/
BLO_ loading/saving .blend files source/blender/blenloader/
COM_ compositor source/blender/compositor/
CTX_ handling of bContext objects source/blender/blenkernel/BKE_context.h, source/blender/blenkernel/intern/context.c
DNA_ include files containing all type definitions that get saved into .blend files source/blender/makesdna/
ED_ editor UI routines source/blender/editors/
FRS_ Freestyle renderer source/blender/freestyle/
GHOST_ platform-independent UI layer intern/ghost/
IMB_ image-format handling source/blender/imbuf/
MEM_ memory management intern/memutil/
MOD_ modifiers source/blender/modifiers/
NOD_ node editor source/blender/nodes/
PIL_ platform-independent timing source/blender/blenlib/PIL_time.h. PIL_time_utildefines.h
RE_ common renderer handling source/blender/render/
RNA_ Python interface source/blender/makesrna/
STR_ string routines intern/string/
WM_ window management source/blender/windowmanager/

User-Interface Implementation

The UI code is structured into several layers. This code also handles finding of user-preference files and shared application data. Starting from the lowest, the layers are:

See Also

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.