Blender 3D:第四单元:与高级教程起飞
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.
::本单元假定你有相当的编程经验. Blender 主要是用C,C++和Python编程语言编程. 它可以使用CMake或SCons构建系统构建.
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:
::官方的Blender源码存储在developer.blender.org的Git仓库中.实际上有几个独立的仓库:
-
blender-main
— the main part of the Blender source, excluding most Python addons.
::混合器-主 混合器源的主要部分,不包括大多数Python附加程序. -
blender-addons
— the Python addons included in the standard Blender distribution.
::混合器附加程序 标准混合器发行版中包含的 Python 附加程序. -
blender-addons-contrib
— additional useful Python addons.
::提供更多有用的 Python 附加程序. -
blender-translations
— localized language translations for text messages.
::本地化语言翻译文本消息. -
blender-tests
— some interesting example
.blend
files used for testing and demonstrating Blender functionality.
::一些有趣的例子.blend文件用于测试和演示Blender的功能. -
blender-dev-tools
— tools that are useful for performing maintenance tasks on the Blender source, but are not actually needed for building Blender.
::blender-dev-tools 用于执行Blender源代码的维护任务的工具,但实际上不需要用于构建Blender. -
blender-cloud
— looks like a framework for offering a new cloud-based Blender service.
::提供基于云的新型Blender服务.
Layout of the Blender Source
::混合器源的布局
Say you’ve checked out a copy of the main Blender source tree. The top level looks like this:
::顶层看起来像这样:
-
build_files/
::构建文件
— files used during the build process
-
CMakeLists.txt
::编辑器
— top-level control file for CMake
-
COPYING
::复制
— note about Blender licensing (GPLv2)
-
doc/
::医生
— documentation files, among them:
-
-
doc/blender_file_format/
::文件格式
::文件格式 -
doc/blender_file_format/
— the format of .blend files
-
-
doc/build_systems/
::文件/构建_系统/
::文件/构建_系统/ -
doc/build_systems/
— how to build Blender, and hack the build system
-
-
doc/manpage/
::美国
::美国 -
doc/manpage/
— the man page
-
extern/
::外部/
— non-Blender-specific libraries, primarily developed elsewhere, included in the source
-
GNUmakefile
::编辑器
— simple build script for those who can’t be bothered to go through the CMake setup process
-
intern/
::实习生
— libraries which are non-Blender-specific but primarily developed here, also glue code for interfacing to external libraries not included in the Blender source. Notable subdirectories:
-
-
intern/bsp/
::内部/bsp/
::内部/bsp/ -
intern/bsp/
— Constructive Solid Geometry routines
-
-
intern/cycles/
::实习生/周期/
::实习生/周期/ -
intern/cycles/
— the Cycles renderer
-
-
intern/elbeem/
::内部/
::内部/ -
intern/elbeem/
— the fluid simulator
-
-
intern/ghost/
::实习生/幽灵/
::实习生/幽灵/ -
intern/ghost/
— Blender’s platform-independent GUI (including platform-dependent implementations). See intern/ghost/GHOST_ISystem.h for a more detailed description.
-
-
intern/guardedalloc/
::内部/守护区
::内部/守护区 -
intern/guardedalloc/
— thread-safe memory management with consistency checking
-
-
intern/iksolver/
::内部/解决者/
::内部/解决者/ -
intern/iksolver/
— the Inverse Kinematics library
-
-
intern/smoke/
::内部/烟雾/
::内部/烟雾/ -
intern/smoke/
— the library for simulating smoke and flames
-
release/
::释放/
— additional files to be included in the Blender distribution, including GUI icons and fonts
-
SConstruct
::构建
— top-level control file for SCons
-
source/
::源/ 时间
— the main part of the Blender source, further divided (ignoring the CMakeLists.txt and SConscript files which you will find just about everywhere) into
-
-
source/blender/
::源/混合器/
::源/混合器/ -
source/blender/
— the bulk of the source, of which some useful parts are
-
-
-
source/blender/blenlib/
::源/混合器/blenlib/
::源/混合器/blenlib/ -
source/blender/blenlib/
::源/混合器/blenlib/ -
— low-level stuff for file management, geometry algorithms, sorting and suchlike
-
-
-
source/blender/blenkernel/
::源/混合器/分核/
::源/混合器/分核/ -
source/blender/blenkernel/
::源/混合器/分核/ -
— core Blender-specific code (no UI stuff)
-
-
-
source/blender/blenloader/
::源/混合机/喷气机/
::源/混合机/喷气机/ -
source/blender/blenloader/
::源/混合机/喷气机/ -
— code for reading and writing .blend files
-
-
source/blenderplayer/
::源/混合器/
::源/混合器/ -
source/blenderplayer/
— some additional files for building the Blender Player executable
-
-
source/creator/
::源/创造者
::源/创造者 -
source/creator/
— the Blender mainline
-
-
source/gameengine/
::源/游戏引擎/
::源/游戏引擎/ -
source/gameengine/
— the Blender Game Engine
-
-
source/icons/
::源/图标/
::源/图标/ -
source/icons/
— some files specific to the Windows build
-
-
source/tests/
::源/测试/
::源/测试/ -
source/tests/
— some test scripts
Common Subdirectory Layout
::常用子目录布局
Within many of the subdirectories in
source/blender/
::在许多源/混合器/
and intern/
, you will see the following pattern:
::您将看到以下模式:
-
A bunch of
.h
files in the directory, and
::在目录中的一堆.h文件, -
an
intern
subdirectory.
::一个实习生子目录.
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.
::.h文件定义了导出到其他模块的功能,而内部子目录包含实际实现模块的.c或.cpp文件.有时.h文件被放入外部子目录,而不是上层目录.
(And yes, these meanings of
intern
and
extern
are not the same as the meanings of
intern
and
extern
at the top directory level.)
:是的,intern和extern的含义与顶级目录层面的intern和extern的含义不同.
Blender’s “Genetic Code”: “DNA” and “RNA”
::混合器的遗传代码:DNA和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:
::在Blender的源代码中,你会发现"DNA" (或"SDNA") 和"RNA"的引用.与遗传学术语的类比最好是微弱的,但它们所指的是:
-
“DNA” or “SDNA” (“structure” DNA?) is the system for mapping Blender’s in-memory data structures to the on-disk
.blend
file format. A
.blend
file is little more than a memory dump, which makes it quick to write. However, the file needs to be readable by Blender builds on machines with different
endianness
, 32 versus
64-bit
pointers, etc, not to mention future versions with different capabilities. Thus, the saved
.blend
file includes a detailed description of the layout of all the data structures saved in the file, and this description is stored in the “DNA1” block at the end. This block is generated by the
makesdna
tool, which is built and run automatically as part of the overall build process, so its output can be included directly into the Blender executable. It parses all the
.h
files in the directory
source/blender/makesdna/
::DNA或SDNA (structure DNA?) 是将Blender的内存数据结构映射到磁盘上的.blend文件格式的系统. .blend文件不过是内存倾倒,这使得它很快地写入.然而,该文件需要在Blender构建的机器上读取,具有不同的endianness,32比64位指针等,更不用说未来版本具有不同的功能.因此,保存的.blend文件包含了保存在文件中的所有数据结构的布局的详细描述,并且这个描述被存储在文件末尾的DNA1块中.这个块是由makeDNA工具生成的,它是构建和自动运行的整体过程的一部分,因此其输出可以直接包含在Blender中.它解析了Blender的源文件/nabl
, so all data structures that could get saved into
.blend
files must be defined here, and they must be careful to use a limited subset of C that the parsing tool can handle.
::因此所有可能被保存到.blend文件中的数据结构必须在这里定义,
-
“RNA” defines the Python interface to Blender’s internal data structures and routine calls.
::RNA定义了Python接口与Blender的内部数据结构和常规调用.
Here
is Ton “Mr Blender” Roosendaal explaining DNA and RNA.
::这里是Ton 先生Blender 罗森达尔解释DNA和RNA.
Special Globals: “G” and “U”
::特殊全球:G和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
.
::有一个经常引用的全球变量,名为 G,类型是 struct Global,声明在 source/blender/blenkernel/BKE_global.h 中.该变量定义在 source/blender/blenkernel/intern/blender.c 中.同一个文件也定义了全球变量 U,类型是 struct UserDef,声明在 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:
::用户界面代码由几个层组成.该代码还处理用户偏好文件和共享应用程序数据的查找.从最低开始,层是:
-
intern/ghost/
::实习生/幽灵/
-
source/blender/windowmanager/
::源/混合器/窗口管理器/
(see source/blender/windowmanager/WM_types.h for an overview)
-
source/blender/editors/screen/
::源/混合器/编辑器/屏幕/
-
source/blender/editors/interface/
::源/混合器/编辑器/接口/