Blender 3D:從新手到專業/駭客Blender
|
|
適用Blender版本:2.68。 |
Blender是一個開源專案。這不僅僅意味著你可以免費使用它,你還可以看到它的工作原理,甚至可以自己進行修改並與他人分享。
Blender也是一個大型軟體專案(程式碼超過一百萬行),在十多年的生命週期中擁有眾多活躍的貢獻者,並且以驚人的速度不斷發展。這可能會讓經驗不足的程式設計師感到有些害怕。
本單元假設您有一定的程式設計經驗。Blender主要使用C、C++和Python程式語言編寫。它可以使用CMake或SCons構建系統進行構建。
官方的Blender原始碼儲存在Git儲存庫中,位於developer.blender.org. 實際上,有幾個單獨的儲存庫
- blender-main — Blender原始碼的主要部分,不包括大多數Python外掛。
- blender-addons — 標準Blender發行版中包含的Python外掛。
- blender-addons-contrib — 額外的有用Python外掛。
- blender-translations — 文字訊息的本地化語言翻譯。
- blender-tests — 一些有趣的示例.blend用於測試和演示Blender功能的檔案。
- blender-dev-tools — 用於對Blender原始碼執行維護任務的工具,但實際上並不需要用於構建Blender。
- blender-cloud — 看起來像是一個提供新的基於雲的Blender服務的框架。
假設您已檢出一個主Blender原始碼樹的副本。頂層看起來像這樣
— files used during the build process
— top-level control file for CMake
— note about Blender licensing (GPLv2)
— documentation files, among them:
— the format of .blend files
— how to build Blender, and hack the build system
— the man page
— non-Blender-specific libraries, primarily developed elsewhere, included in the source
— simple build script for those who can’t be bothered to go through the CMake setup process
— 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:
— Constructive Solid Geometry routines
— the Cycles renderer
— the fluid simulator
— Blender’s platform-independent GUI (including platform-dependent implementations). See intern/ghost/GHOST_ISystem.h for a more detailed description.
— thread-safe memory management with consistency checking
— the Inverse Kinematics library
— the library for simulating smoke and flames
— additional files to be included in the Blender distribution, including GUI icons and fonts
— top-level control file for SCons
— the main part of the Blender source, further divided (ignoring the CMakeLists.txt and SConscript files which you will find just about everywhere) into
— the bulk of the source, of which some useful parts are
— low-level stuff for file management, geometry algorithms, sorting and suchlike
— core Blender-specific code (no UI stuff)
— code for reading and writing .blend files
— some additional files for building the Blender Player executable
— the Blender mainline
— the Blender Game Engine
— some files specific to the Windows build
— some test scripts
and intern/
中的許多子目錄中,您會看到以下模式
- 一堆.h目錄中的檔案,以及
- 一個intern子目錄。
這些.h檔案定義了匯出到其他模組的功能,而intern子目錄包含.c或.cpp實際實現模組的檔案。有時,這些.h檔案被放在extern子目錄中而不是上層目錄級別。
(是的,這些intern和extern的含義與intern和extern在頂層目錄級別的含義不同。)
您將在Blender的原始碼中找到對“DNA”(或“SDNA”)和“RNA”的引用。與遺傳學中的術語的類比充其量是薄弱的,但它們指的是
- “DNA”或“SDNA”(“結構”DNA?)是將Blender的記憶體中資料結構對映到磁碟上的系統.blend檔案格式。一個.blend檔案只不過是一個記憶體轉儲,這使得它可以快速寫入。但是,該檔案需要能夠被在具有不同位元組序、32位與64位指標等的機器上的Blender構建讀取,更不用說具有不同功能的未來版本了。因此,儲存的.blend檔案包括對儲存在檔案中的所有資料結構佈局的詳細描述,並且此描述儲存在末尾的“DNA1”塊中。該塊由makesdna工具生成,該工具作為整體構建過程的一部分自動構建和執行,因此其輸出可以直接包含到Blender可執行檔案中。它解析目錄source/blender/makesdna/.h中的所有
檔案,因此所有可以儲存到.blend檔案中的資料結構都必須在此定義,並且它們必須謹慎地使用解析工具可以處理的C語言的有限子集。
- “RNA”定義了Blender內部資料結構和例程呼叫的Python介面。
此處是Ton“Mr Blender”Roosendaal解釋DNA和RNA。
有一個經常引用的名為“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 中宣告。
一些(但並非所有)全域性符號在其名稱上帶有字首,表示(大致)它們來自哪裡。以下是部分列表。
| 字首 | 含義 | 發現位置 |
|---|---|---|
| AUD_ | audaspace聲音庫 | intern/audaspace/ |
| BKE_ | 最低級別(非UI)Blender操作 | source/blender/blenkernel/ |
| BLF_ | 字型/文字處理 | source/blender/blenfont/ |
| BLI_ | 通用庫例程 | source/blender/blenlib/ |
| BLO_ | 載入/儲存.blend檔案 | source/blender/blenloader/ |
| COM_ | 合成器 | source/blender/compositor/ |
| CTX_ | 處理bContext物件 | source/blender/blenkernel/BKE_context.h |
| DNA_ | 包含所有儲存到.blend檔案 | source/blender/makesdna/ |
| 中的型別定義的標頭檔案 | ED_ | 編輯器UI例程 |
| source/blender/editors/ | FRS_ | Freestyle渲染器 |
| source/blender/freestyle/ | GHOST_ | intern/ghost/ |
| 平臺無關的UI層 | IMB_ | 影像格式處理 |
| source/blender/imbuf/ | MEM_ | 記憶體管理 |
| intern/memutil/ | MOD_ | 修改器 |
| source/blender/modifiers/ | NOD_ | 節點編輯器 |
| source/blender/nodes/ | PIL_ | 平臺無關的計時 |
| RE_ | 通用渲染器處理 | source/blender/render/ |
| RNA_ | Python 介面 | source/blender/makesrna/ |
| STR_ | 字串例程 | intern/string/ |
| WM_ | 視窗管理 | source/blender/windowmanager/ |
使用者介面實現
[edit | edit source]UI 程式碼結構分層,程式碼還處理使用者偏好檔案和共享應用程式資料的查詢。從最底層開始,各層級分別是
(see source/blender/windowmanager/WM_types.h for an overview)
另請參見
[edit | edit source]- 構建 Blender — Blender Wiki 上的平臺特定說明
- 開發資源 在blender.org,包括
- 郵件列表