BHM File Format

Source: Internet
Author: User

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 cocould 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 participating 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 'chunk', 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 shocould 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 cocould 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 bhmexico Porter is already ded in this project. parts of the bhmexico Porter Code are based on examples from the 3 dsmax sdk, ATI radeon SDK and NVIDIA graphics SDK. you will require the 3 dsmax sdk in order to build the plugin.

 

 

 

G-spider
ASM supporter

Online

Posts: 15

Re: BHM File Format
«Reply #51 on: 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:
201784d00 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: 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 shoshould also be as 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:
201784d00 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
2017403f 00000000 .......
......
 
 

G-spider

ASM supporter

Online

Posts: 16

Re: BHM file format «Reply #53 on: TodayAt 04:00:17 <G id = "1"> </G>» Quote Modify{
Return confirm ('remove this message? ');
} "Href =" http://www.asmcommunity.net/board/index.php? Action = deletemsg; topic = 29830.45; MSG = 214228; sesc = 9b3cc032bfc1b897ba7c54dffa4317b1 ">Remove
Aha? THX.
Data:
201784d00 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
2017403f 00000000 .......
......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.