青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

的筆記

隨時隨地編輯

The mystery of the blend

The mystery of the blend
The blender file-format explained
Jeroen Bakker
j.bakker@atmind.nl
http://www.atmind.nl/blender
27-03-2009

Jeroen (Amsterdam, the Netherlands, 33 years old) worked as coder in the demo scene. He is interested in open source and 3d animations. At the moment he is working on products supporting impact analysis and change management around a fully automated render pipeline.

The mystery of the blend

The blend-file-format explained

Introduction

I'm working on a product what integrates Blender in a render pipeline by using the Blender command line and blend-files (.blend). The command line is not a problem as it is commonly used, but using blend-files outside Blender is difficult, because it is not that well documented. On the Internet, I've only found some clues about it on the Blender architecture pages [ref: http://www.blender.org/development/architecture/]. These were not sufficient. To really understand the file format I had to go through Blender's source code. In this article I will describe the blend-file-format with a request to tool-makers to support blend-file.

First I'll describe how Blender works with blend-files. You'll notice why the blend-file-format is not that well documented, as from Blender's perspective this is not needed. We look at the global file-structure of a blend-file (the file-header and file-blocks). After this is explained, we go deeper to the core of the blend-file, the DNA-structures. They hold the blue-prints of the blend-file and the key asset of understanding blend-files. When that's done we can use these DNA-structures to read information from elsewhere in the blend-file.

In this article we'll be using the default blend-file from Blender 2.48, with the goal to read the output resolution from the Scene. The article is written to be programming language independent and I've setup a web-site for support.

Loading and saving in Blender

Loading and saving in Blender is very fast and Blender is known to have excellent downward and upward compatibility. Ton Roosendaal demonstrated that in December 2008 by loading a 1.0 blend-file using Blender 2.48a [ref: http://www.blendernation.com/2008/12/01/blender-dna-rna-and-backward-compatibility/].

Saving complex scenes in Blender is done within seconds. Blender achieves this by saving data in memory to disk without any transformations or translations. Blender only adds file-block-headers to this data. A file-block-header contains clues on how to interpret the data. After the data, all internally Blender structures are stored. These structures will act as blue-prints when Blender loads the file. Blend-files can be different when stored on different hardware platforms or Blender releases. There is no effort taken to make blend-files binary the same. Blender creates the blend-files in this manner since release 1.0. Backward and upwards compatibility is not implemented when saving the file, this is done during loading.

When Blender loads a blend-file, the DNA-structures are read first. Blender creates a catalog of these DNA-structures. Blender uses this catalog together with the data in the file, the internal Blender structures of the Blender release you're using and a lot of transformation and translation logic to implement the backward and upward compatibility. In the source code of blender there is actually logic which can transform and translate every structure used by a Blender release to the one of the release you're using [ref:http://download.blender.org/source/blender-2.48a.tar.gz /blender-2.48a/source/blender/blenloader/intern/readfile.c lines 4946-7960]. The more difference between releases the more logic is executed.

The blend-file-format is not well documented, as it does not differ from internally used structures and the file can really explain itself.

Global file-structure

Let us look at the global file-structure. A blend-file always start with the file-header followed by file-blocks. The default blend file of Blender 2.48 contains more than 400 of these file-blocks. Each file-block has a file-block-header and data. This section explains how the global file-structure can be read.

File-Header

The first 12 bytes of every blend-file is the file-header. The file-header has information on Blender (version-number) and the PC the blend-file was saved on (pointer-size and endianness). This is required as all data inside the blend-file is ordered in that way, because no translation or transformation is done during saving. The next table describes the information in the file-header.

File-header
reference structure type offset size
identifier char[7] File identifier (always 'BLENDER') 0 7
pointer-size char Size of a pointer; all pointers in the file are stored in this format. '_' means 4 bytes or 32 bit and '-' means 8 bytes or 64 bits. 7 1
endianness char Type of byte ordering used; 'v' means little endian and 'V' means big endian. 8 1
version-number char[3] Version of Blender the file was created in; '248' means version 2.48 9 3

Endianness addresses the way values are ordered in a sequence of bytes [ref: http://en.wikipedia.org/wiki/Endianness]. Blender supports little-endian and big-endian. In a big endian ordering, the largest part of the value is placed on the first byte and the lowest part of the value is placed on the last byte. In a little endian ordering, largest part of the value is placed on the last byte and the smallest part of the value is placed on the first byte. Example: writing the integer 0x4A3B2C1Dh, will be ordered in Big endian as 0x4Ah, 0x3Bh, 0x2Ch, 0x1Dhand be ordered in little endian as 0x1Dh, 0x2Ch, 0x3Bh, 0x4Ah.

The endianness can be different between the blend-file and the PC your using. When these are different, Blender changes it to the byte ordering of your PC. Nowadays, little-endian is the most commonly used.

The next hex-dump describes a file-header created with blender 2.48 on little-endian hardware with a 32 bits pointer length. pointer-size version-number 0000 0000: [42 4C 45 4E 44 45 52] [5F] [76] [32 34 38] BLEN DER_ v248 identifier endianness

File-block

File-blocks contain a file-block-header and data. The start of a file-block is always aligned at 4 bytes. The file-block-header describes the total length of the data, the type of information stored in the file-block, the number of items of this information and the old memory pointer at the moment the data was written to disk. Depending on the pointer-size stored in the file-header, a file-block-header can be 20 or 24 bytes long. The next table describes how a file-block-header is structured.

File-block-header
reference structure type offset size
code char[4] Identifier of the file-block 0 4
size integer Total length of the data after the file-block-header 4 4
old memory address void* Memory address the structure was located when written to disk 8 pointer-size (4/8)
SDNA index integer Index of the SDNA structure 8+pointer-size 4
count integer Number of structure located in this file-block 12+pointer-size 4

Code describes different types of file-blocks. The code determines with what logic the data must be read. These codes also allows fast finding of data like Library, Scenes, Object or Materials as they all have a specific code.

The size contains the total length of data after the file-block-header. After the data a new file-block starts. The last file-block in the file has code 'ENDB'.

The old memory address contains the memory address when the structure was last stored. When loading the file the structures can be placed on different memory addresses. Blender updates pointers to these structures to the new memory addresses.

SDNA index contains the index in the DNA structures to be used when reading this file-block-data. More information about this subject will be explained in the Reading scene information section.

Count tells how many elements of the specific SDNA structure can be found in the data.

The next section is an example of a file-block-header. The code 'SC'+0x00h identifies that it is a Scene. Size of the data is 1376 bytes (0x05h X 256 + 0x60h = 1280 + 96); the old pointer is 0x0A042FA0h and the SDNA index is 139 (8 X 16 + 11). The section contains a single scene. Before we can interpreted the data of this file-block we first have to read the DNA structures in the file. The section structure DNA will show how to do that.0000 4420: [53 43 00 00] [60 05 00 00] [A0 2F 04 0A] [8B 00 00 00] SC.. `... ./.. .... 0000 4430: [01 00 00 00] [xx xx xx xx xx xx xx xx xx xx xx xx .... xxxx xxxx xxxx

Structure DNA

Structure DNA is stored in a file-block with code 'DNA1'. It can be just before the 'ENDB' file-block. It contains all internal structures of the Blender release the file was created in. The data in this file-block must be interpreted as described in the this section. In a blend-file created with Blender 2.48a this section is 43468 bytes long and contains 309 structures. These structure can be described as C-structures. They can hold fields, arrays and pointers to other structures, just like a normal C-structure.structure Scene { ID id; // 52 bytes long (ID is different a structure) Object *camera; // 4 bytes long (pointer to an Object structure) World *world; // 4 bytes long (pointer to a World structure) ... float cursor[3]; // 12 bytes long (array of 3 floats) ... }

The next section describes how this information is ordered in the data of the 'DNA1' file-block.

Structure of the DNA file-block-data
repeat condition name type length description
identifier char[4] 4 'SDNA'
name identifier char[4] 4 'NAME'
#names integer 4 Number of names follows
for(#names) name char[] ? Zero terminating string of name, also contains pointer and simple array definitions (e.g. '*vertex[3]\0')
type identifier char[4] 4 'TYPE' this field is aligned at 4 bytes
#types integer 4 Number of types follows
for(#types) type char[] ? Zero terminating string of type (e.g. 'int\0')
length identifier char[4] 4 'TLEN' this field is aligned at 4 bytes
for(#types) length short 2 Length in bytes of type (e.g. 4)
structure identifier char[4] 4 'STRC' this field is aligned at 4 bytes
#structures integer 4 Number of structures follows
for(#structures) structure type short 2 Index in types containing the name of the structure
.. #fields short 2 Number of fields in this structure
.. for(#field) field type short 2 Index in type
for end for end field name short 2 Index in name

As you can see, the structures are stored in 4 arrays: names, types, lengths and structures. Every structure also contains an array of fields. A field is the combination of a type and a name. From this information a catalog of all structures can be constructed. The names are stored as how a C-developer defines them. This means that the name also defines pointers and arrays. (When a name starts with '*' it is used as a pointer. when the name contains for example '[3]' it is used as a array of 3 long.) In the types you'll find simple-types (like: 'integer', 'char', 'float'), but also complex-types like 'Scene' and 'MetaBall'. 'TLEN' part describes the length of the types. A 'char' is 1 byte, an 'integer' is 4 bytes and a 'Scene' is 1376 bytes long.

  • Note: While reading the DNA you'll will come across some strange names like '(*doit)()'. These are method pointers and Blender updates them to the correct methods.
  • Note: The fields 'type identifier', 'length identifier' and 'structure identifier' are aligned at 4 bytes.

The DNA structures inside a Blender 2.48 blend-file can be found at http://www.atmind.nl/blender/blender-sdna.html. If we understand the DNA part of the file it is now possible to read information from other parts file-blocks. The next section will tell us how.

Reading scene information

Let us look at the file-block we have seen earlier. The code is 'SC'+0x00h and the SDNA index is 139. The 139th structure in the DNA is a structure of type 'Scene'. The associated type ('Scene') has the length of 1376 bytes. This is exact the same length as the data in the file-block. We can map the Scene-structure on the data of the file-blocks. But before we can do that, we have to flatten the Scene-structure.

The first field in the Scene-structure is of type 'ID' with the name 'id'. Inside the list of DNA structures there is a structure defined for type 'ID' (structure index 17). The first field in this structure has type 'void' and name '*next'. Looking in the structure list there is no structure defined for type 'void'. It is a simple type and therefore the data should be read. '*next' describes a pointer. the first 4 bytes of the data can be mapped to 'id.next'. Using this method we'll map a structure to its data. If we want to read a specific field we know at what offset in the data it is located and how much space it takes.

The next table shows the output of this flattening process for some parts of the Scene-structure. Not all rows are described in the table as there is a lot of information in a Scene-structure.

flattened SDNA structure 139: Scene
reference structure type name offset size description
id.next ID void *next 0 4 Refers to the next scene
id.prev ID void *prev 4 4 Refers to the previous scene
id.newid ID ID *newid 8 4
id.lib ID Library *lib 12 4
id.name ID char name[24] 16 24 'SC'+the name of the scene as displayed in Blender
id.us ID short us 40 2
id.flag ID short flag 42 2
id.icon_id ID int icon_id 44 4
id.properties ID IDProperty *properties 48 4
camera Scene Object *camera 52 4 Pointer to the current camera
world Scene World *world 56 4 Pointer to the current world
set Scene Scene *set 60 4 Pointer to the current set
Skipped rows
r.sfra RenderData int sfra 248 4 Start frame of the scene
r.efra RenderData int efra 252 4 End frame of the scene
Skipped rows
r.xsch RenderData short xsch 326 2 X-resolution of the output when rendered at 100%
r.ysch RenderData short ysch 328 2 Y-resolution of the output when rendered at 100%
r.xparts RenderData short xparts 330 2 Number of x-part the renderer uses
r.yparts RenderData short yparts 332 2 Number of y-part the renderer uses
Skipped rows
sculptdata.axislock SculptData char axislock 1365 1
sculptdata.pad SculptData char pad[2] 1366 2
frame_step Scene int frame_step 1368 4
pad Scene int pad 1372 4

We can now read the X and Y resolution of the Scene. The X-resolution is located on offset 326 of the file-block-data and must be read as a short. The Y-resolution is located on offset 328 and is also a short.

  • Note: An array of chars can mean 2 things. The field contains readable text or it contains an array of flags (not humanly readable).
  • Note: A file-block containing a list refers to the DNA structure and has a count larger than 1. For example Vertexes and Faces are stored in this way.

Next steps

The implementation of saving in Blender is easy, but loading is difficult. When implementing loading and saving blend-files in a custom tool the difficulty is the opposite. In a custom tool loading a blend-file is easy, and saving a blend-file is difficult. If you want to save blend-files I suggest to start with understanding the the global file structure and parsing the DNA section of the file. After this is done it should be easy to read information from existing blend files like scene data, materials and meshes. When you feel familiar with this you can start creating blend-libraries using the internal Blender structures of a specific release. If you don't want to dive into the Blender source code you can find them all athttp://www.atmind.nl/blender/blender-sdna.html.

There is a feature request on supporting an XML based import/export system in Blender. I dont support the request, but it is interesting to look at how this can be implemented. An XML export can be implemented with low effort as an XSD can be used as DNA structures and the data can be written into XML [see http://www.atmind.nl/blender/blender-file.zip to download JAVA example including source code]. Implementing an XML import system uses a lot of memory and CPU. If you really want to implement it, I expect that the easiest way is to convert the XML-file back to a normal blend-file and then load it using the current implementation. One real drawback is that parsing a XML based blend-file uses a lot of memory and CPU and the files can become very large.

At this moment I'm using this information in an automated render pipeline. The render pipeline is build around a web-server and SVN. When an artist commits a new blend-file in SVN, it is picked up by the web-server and it will extract resolutions, frames scenes and libraries from the blend-file. This information is matched with the other files in SVN and the blend-file will be placed in the render pipeline.

posted on 2011-03-18 16:04 的筆記 閱讀(576) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            夜夜嗨av一区二区三区中文字幕 | 亚洲欧美综合精品久久成人| 1000精品久久久久久久久| 中日韩视频在线观看| 亚洲国产91| 欧美中文字幕视频在线观看| 亚洲自拍电影| 欧美日韩国产不卡| 亚洲电影av| 亚洲成色www8888| 欧美在线观看视频| 久久国产精品网站| 国产精品亚洲综合天堂夜夜| 亚洲美洲欧洲综合国产一区| 亚洲精选在线观看| 欧美精品黄色| 日韩视频一区二区三区在线播放| 亚洲人成在线免费观看| 欧美/亚洲一区| 欧美激情视频给我| 亚洲国产精品视频| 欧美不卡视频一区发布| 欧美黄网免费在线观看| 最新中文字幕亚洲| 欧美国产日韩一区二区在线观看| 亚洲国产成人精品女人久久久 | 亚洲美女黄网| 99精品免费视频| 欧美日韩在线不卡| 亚洲视频在线观看免费| 亚洲欧美一区二区原创| 国产乱人伦精品一区二区| 亚洲综合色在线| 久久久www免费人成黑人精品| 国产一区二区黄色| 久久看片网站| 欧美好骚综合网| 在线亚洲美日韩| 国产精品国产亚洲精品看不卡15| 亚洲一区精品在线| 久久久久久自在自线| 韩日视频一区| 欧美黄色影院| 亚洲欧美日韩视频二区| 久久久久国产精品一区二区| 在线观看日韩一区| 欧美日韩国产va另类| 亚洲欧美韩国| 欧美激情麻豆| 欧美一区二区成人6969| 伊甸园精品99久久久久久| 久热爱精品视频线路一| 99精品国产一区二区青青牛奶| 亚洲淫性视频| **性色生活片久久毛片| 欧美日韩亚洲三区| 久久精品日韩一区二区三区| 亚洲国产日韩欧美在线动漫| 欧美一级夜夜爽| 亚洲福利专区| 国产精品美女久久福利网站| 久久综合九色综合久99| 亚洲天堂免费观看| 欧美成人中文字幕| 欧美一区2区三区4区公司二百| 亚洲国产精品久久精品怡红院| 欧美午夜电影一区| 久久视频这里只有精品| 一本大道久久a久久综合婷婷| 久久一区国产| 亚洲欧美国产视频| 亚洲精品影视在线观看| 国产一区av在线| 欧美视频一区在线| 欧美成人一区二区| 久久国产一区二区| 亚洲网站在线看| 亚洲国产精品第一区二区| 欧美综合77777色婷婷| 99综合电影在线视频| 亚洲第一久久影院| 韩国美女久久| 国产日韩欧美在线一区| 欧美日韩中文字幕综合视频 | 欧美日韩一区二区三区| 久久久精品国产一区二区三区 | 久久精品五月婷婷| 亚洲一区二区精品| 妖精视频成人观看www| 亚洲国产欧美在线| 欧美国产日韩精品| 欧美不卡一区| 麻豆国产精品va在线观看不卡| 欧美一区在线直播| 香蕉久久一区二区不卡无毒影院| 亚洲视频一起| 一本色道久久综合亚洲91| 亚洲人精品午夜在线观看| 亚洲第一福利社区| 亚洲丁香婷深爱综合| 精品成人a区在线观看| 激情五月综合色婷婷一区二区| 国产视频一区二区在线观看 | 欧美国产日韩一区二区| 麻豆精品91| 欧美va天堂| 亚洲第一区色| 亚洲黄色av一区| 亚洲欧洲一区二区三区| 91久久香蕉国产日韩欧美9色| 91久久精品www人人做人人爽| 亚洲动漫精品| 亚洲精品永久免费| a91a精品视频在线观看| 中日韩视频在线观看| 亚洲午夜免费福利视频| 午夜久久久久久久久久一区二区| 午夜在线观看欧美| 久久精品视频免费播放| 欧美aⅴ一区二区三区视频| 欧美成人自拍| 欧美午夜一区二区福利视频| 国产精品美女久久福利网站| 国产婷婷色一区二区三区四区| 国产曰批免费观看久久久| 极品少妇一区二区三区| 亚洲人成在线观看| 亚洲一区二三| 久久青青草原一区二区| 亚洲电影在线看| 亚洲小视频在线观看| 欧美在线亚洲| 欧美精品1区| 国产欧美一区视频| 亚洲国产成人91精品| 一区二区三区四区国产| 欧美在线二区| 欧美激情精品久久久久久变态| 一本久久a久久免费精品不卡| 亚洲欧美日韩在线综合| 免费观看不卡av| 国产精品福利片| 在线成人免费视频| 亚洲网站视频| 你懂的亚洲视频| 一卡二卡3卡四卡高清精品视频| 欧美影院久久久| 欧美三级乱人伦电影| 一区二区三区在线观看视频 | 久久久久国产精品一区二区| 亚洲第一网站| 欧美一区二区在线免费播放| 欧美黄色aaaa| 依依成人综合视频| 亚洲欧美综合一区| 亚洲成色最大综合在线| 午夜精品美女久久久久av福利| 欧美刺激性大交免费视频| 国产日韩成人精品| 亚洲一区尤物| 亚洲国产经典视频| 久久精品一区二区| 国产伦精品一区二区| 一本色道久久综合一区| 免费看的黄色欧美网站| 亚洲在线网站| 欧美亚一区二区| 日韩视频在线观看国产| 欧美成年人在线观看| 午夜一区二区三视频在线观看| 欧美日韩免费看| 亚洲国产天堂久久综合| 麻豆精品网站| 欧美中文字幕在线播放| 国产女主播一区二区| 亚洲自拍电影| 在线亚洲成人| 欧美色中文字幕| 亚洲一二区在线| 亚洲美女一区| 欧美日韩高清不卡| 在线视频精品| 亚洲免费高清| 欧美国产日韩一区二区| 亚洲精品免费看| 亚洲黄色免费电影| 久久综合九色欧美综合狠狠| 一区二区三区在线观看国产| 久久人人爽国产| 久久久久久久一区| 樱桃视频在线观看一区| 麻豆九一精品爱看视频在线观看免费| 久久精品91| 伊甸园精品99久久久久久| 模特精品裸拍一区| 欧美成人午夜激情视频| 99国产精品国产精品毛片| 99国产精品自拍| 国产精品捆绑调教| 久久激情视频久久|