BHM 文件格式

BHM File Format readme

The BHM file format was created by Scali and Samuel R�dal in 2003. At the time they were both involved in the demoscene group Bohemiq, which is where the BHM file format got its name from.
The goal was to create a file format which could store the various data required for a demo, most notably 3d geometry and animation. The file format was to be generic, flexible and hierarchical like XML, but compact and quick to process like a binary file.

The resulting file format consists of three parts:
First is a generic file header, describing the file format ("BHM"), the version number to indicate the particular revision of the file format used, and the size of the tree:

typedef struct {
 char description[4];
 unsigned int version;
 unsigned int treesize;
} FileInfo;

Secondly, the tree hierarchy which describes the different contents and their relation, much like how XML and its nested tag structure:

typedef struct {
 unsigned int numchildren;

 unsigned int chunkid;
 unsigned int type;
} TreeNodeInfo;


Lastly there's a collection of binary 'chunks', with each chunk containing an ID that relates it to its position in the tree:

typedef struct {
 unsigned int id;
 unsigned int type;

 unsigned int datasize;
 unsigned int totalsize;

 unsigned int dataoffs;
} ChunkInfo;

Since the tree nodes are all a fixed size, and the tree is stored as a flattened 'heap', the tree can be read from disk and parsed in a very simple and fast way.
The chunks contain the actual data, and can be of varying size. Chunks can be skipped easily when their data is not required or not understood by the reader, which should make it easier to remain backward and forward compatible to a certain extent, much like XML.

Since it is a binary format, you can store pretty much anything in a chunk. One major advantage of BHM over XML is in the handling of arrays. An entire array could easily be stored in a single chunk, and only require a single tree node. It can be read into memory in a single operation, and used by the application directly. There's no additional parsing involved. With BHM, one can store the data in a format that matches the way the application wants to use the data in-memory.

Since the BHM format was originally developed for a Bohemiq demo, one of its first applications was in an exporter for 3dsmax. This bhmexporter is included in this project. Parts of the bhmexporter code are based on examples from the 3dsmax SDK, ATi Radeon SDK and nVidia graphics SDK. You will require the 3dsmax SDK in order to build the plugin.

 

 

 

G-Spider
ASM Supporter

 Online

Posts: 15


     Re: BHM File Format
« Reply #51 on: 2011-03-26 09:12:16 » Quote Modify Remove 

--------------------------------------------------------------------------------

Hi ,Scali
I download the BHMSample-20100424.zip file ,and open the skin.bhm data file  .
I want to know the relationships between the data and BHM structure .

data:
42484D00 64000000 BC040000
05000000 00000000 01000000
07000000
01000000 00110000 00000000
02000000 20110000 00000000
03000000 18110000 00000000
04000000 12110000 00000000
05000000 13110000 00000000
06000000 15110000 00000000
07000000 19110000 00000000
08000000 11110000 0A000000
09000000 00110000 00000000
0A000000 20110000 00000000
0B000000 01120000 00000000
0C000000 12110000 00000000
0D000000 13110000 00000000
0E000000 11110000 04000000
0F000000 00110000 00000000
10000000 20110000 00000000
.......
struct:
typedef struct {
   char description[4];
   unsigned int version;
   unsigned int treesize;
} FileInfo;

typedef struct {
   unsigned int numchildren;

   unsigned int chunkid;
   unsigned int type;
} TreeNodeInfo;

typedef struct {
   unsigned int id;
   unsigned int type;

   unsigned int datasize;
   unsigned int totalsize;

   unsigned int dataoffs;
} ChunkInfo;

 
 
 Report to moderator    58.19.126.41 
 
 
 
Scali
Community Guru
Regular Member

 Offline

Posts: 983

 
      Re: BHM File Format
« Reply #52 on: 2011-03-27 18:02:04 » Quote 

--------------------------------------------------------------------------------

Well, it starts with the FileInfo struct.
This contains "BHM" in the description.
Then the version and the treesize.
The treesize is number of bytes for TreeNodeInfo structs that follow (so you can find where the chunks start in the file).
They are stored as depth-first. So you can parse then recursively. There is always one root node. So you start by parsing the first node, then you just parse the number of children for each node recursively, until all nodes are parsed (meaning you have parsed all children of the root node, which should also be as many bytes as the FileInfo said).
Then you will find the chunks in sequential order. Each chunk is a ChunkInfo node, followed by a raw blob of data bytes, the size of which is in the ChunkInfo. The next chunk follows immediately after the last byte of the previous chunk data. 

 


 G-Spider
ASM Supporter

 Online

Posts: 16


     Re: BHM File Format
« Reply #53 on: Today at 04:00:17 » Quote Modify Remove 

--------------------------------------------------------------------------------

aha?  Thx.
data:
42484D00 64000000 BC040000 ;//=101
;//101 TreeNodeInfo;
05000000 00000000 01000000
07000000 01000000 00110000
00000000 02000000 20110000
00000000 03000000 18110000
00000000 04000000 12110000
00000000 05000000 13110000
00000000 06000000 15110000
00000000 07000000 19110000
00000000 08000000 11110000
0A000000 09000000 00110000
00000000 0A000000 20110000
.......
00000000 63000000 15110000
00000000 64000000 11110000
;-------------------------
;//ChunkInfo
64000000 11110000 C0000000
C0000000 00000000 00000100
02000300 02000100 .......

63000000 15110000 C8000000
C8000000 00000000 00000000
0000403F 00000000 .......
......
 
 

G-Spider
ASM Supporter
*
Online Online

Posts: 16


View Profile Email Personal Message (Online)
« Reply #53 on: Today at 04:00:17 »
Reply with quoteQuote Modify messageModify Remove messageRemove

aha? Tongue Thx.
data:
42484D00 64000000 BC040000 ;//=101
;//101 TreeNodeInfo;
05000000 00000000 01000000
07000000 01000000 00110000
00000000 02000000 20110000
00000000 03000000 18110000
00000000 04000000 12110000
00000000 05000000 13110000
00000000 06000000 15110000
00000000 07000000 19110000
00000000 08000000 11110000
0A000000 09000000 00110000
00000000 0A000000 20110000
.......
00000000 63000000 15110000
00000000 64000000 11110000
;-------------------------
;//ChunkInfo
64000000 11110000 C0000000
C0000000 00000000 00000100
02000300 02000100 .......

63000000 15110000 C8000000
C8000000 00000000 00000000
0000403F 00000000 .......
......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值