返回列表 发新帖
楼主: kidux

Blender开发常见问题-blender dev FAQ

 楼主| 发表于 2015-5-16 12:42:00 | 显示全部楼层
What documentation is there?

Dev:Source/Architecture has a bunch of documentation on the concepts behind Blender's C code. It is not easy for a newcomer to understand, there is a lot to read, and it is not completely up to date. But you should keep coming back to it - the more you understand pieces of Blender, the more all of this will make sense and be helpful.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-16 12:42:10 | 显示全部楼层
Where does blender start and what happens next?

The file source/creator/creator.c has the main() routine in it.

After parsing args, a bunch of initialization, and reading a .blend file, main() passes control to WM_main() in source/blender/windowmanager/intern/wm.c. That is an infinite loop that just processes events and notifications and draws updates on the screen. Events and notifications are things caused either by the user doing something (e.g., mouse click) or the internal blender systems signaling to other parts of blender that something has changed and that means something has to be recalculated, redrawn, or something else.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-16 12:42:16 | 显示全部楼层
What is an overview of how the files and subsystems are organized?

Here is a great picture.

Most of the code you will care about is under the source/blender/ subdirectory, though some Python code you may want to look at is under release/scripts/.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-16 12:42:23 | 显示全部楼层
Where is the UI code?

The UI layout is defined in Python but the drawing is done in C, and some of the UI is defined in C too.

The Python code is in

    release/scripts/modules/bl_ui/. E.g., in that directory is the code for the 3D View editor type (space).

The C interface drawing code is in:


The glue code defining the API python uses to create interfaces


The Python UI code mostly just lays out user-interaction widgets that adjust properties of operators. Operators are Blender tools. At some point you should read Dev:2.5/Source/Architecture/Operators.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-16 12:42:32 | 显示全部楼层
How are Operators connected to C code?

If you hover over a button like Spin in the user interface, it shows you the Python name for the operator that will be invoked if you hit the button - bpy.ops.mesh.spin(). This is implemented in C by an operator named MESH_OT_spin (see the naming convention in Dev:2.5/Source/Architecture/Operators). If you look for that name, you'll find it as a function that fills in various function pointers and flags in a wmOperatorType struct. The important one is the invoke function, in this case spin_mesh_invoke(). If you put a breakpoint on that you'll find that it gets called soon after you push the Spin button.

The Python bpy_operator.c code knows how to go back and forth between module.func and MODULE_OT_func.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-16 12:42:39 | 显示全部楼层
What is this DNA and RNA stuff?

The names come from the genetic nucleic acids and hint at their function: DNA, as in genetics, is the code that lets you reproduce something. In the case of Blender, this is essentially what is written to and read from disk as a .blend file - it has all of the user settings and mesh, object, scene, etc. data. RNA, as in genetics, is a helper to transmit the DNA code into the rest of the internal Blender system.

The .h files in source/blender/makesdna/ define the structs, enums, etc., for all the data that needs to be persisted to disk. These are usually used in memory in the running system too. For example, DNA_mesh_types.h defines the Mesh struct that has enough information to store a user's mesh on disk. While running, there may be a Mesh in memory, but there will likely be various derived mesh structures that are more efficient to use during editing, say.

Another aspect of DNA is that it is also a system for helping compatibility between different versions of Blender. The way this works is that a coded description of the layout of each struct is also written to and read from disk. This means that the layout does not have to stay fixed. The C files in the makesdna directory are for generating and interpreting the structure descriptions. See Dev:Source/Data_Structures/DNAStructs.

RNA is also something that is partially made by code generation, using code in source/blender/makesrna. It is supposed to be a somewhat more abstract and nicer interface to the DNA data. For example, where a DNA struct might use a particular bit in a short for some flag, RNA would expose that as a bool property. So far, this nicer Data API isn't used too much in the C source code. Where it is heavily used is as the interface to and from Python. Most of the Python access to Blender data is generated automatically to use the RNA system. See Dev:2.5/Source/Architecture/RNA for more information about RNA.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-5-16 12:42:46 | 显示全部楼层
Where are the icons?

The icons are stored in a file called blender_icons.svg is one large SVG file with almost all of the button icons in a kind of matrix arrangement in it. There is a shell file to convert that file into 16x16 and 32x32 per icon versions of the SVG file as data files (not user editable), these are stored in release/datafiles/blender_icons16, release/datafiles/blender_icons32.

The brush icons are separate PNG files in the brushicons subdirectory. The datafiles directory also has the splash image and some TrueType fonts.

All of these data files are turned into C files that declare their data as char arrays at build time, so any modifications to these files will be visible after rebuilding.

The code for initializing the icons is in source/blender/editors/interface/interface_icons.c, in the init_internal_icons() function. The order of the icons in the image is, bottom to top, left to right, the order of the DEF_ICON declarations in source/blender/editors/include/UI_icons.h.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-6-10 12:27:36 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册



站长推荐上一条 /1 下一条

Blender最新中文教学视频|Blender头条|小黑屋|手机版|Archiver|Blender中国 ( 蜀ICP备17002929号 )360网站安全检测平台

GMT+8, 2020-3-31 10:15 , Processed in 0.021651 second(s), 14 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表