Blend file format

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
FakeMajor
Posts: 8
Joined: Thu Sep 29, 2011 2:00 am

Blend file format

Post by FakeMajor » Thu Sep 29, 2011 2:20 am

Hey,

I was writing a .blend parser for a new game engine, but I ran into a little problem. I am able to find the structures for the things I need and associate them with a pointer, but the problem comes when trying to find the address of another pointer in that structure.

Here is an example of what I mean:

Code: Select all


/* snippet from blend_sdna.h */

#define SDNA_MESH			52

typedef struct sdna_mesh_s {
	sdna_id_t id;
	sdna_boundbox_t *bb;
	sdna_listbase_t effect;
	sdna_ipo_t *ipo;
	sdna_key_t *key;
	sdna_material_t **mat;
	sdna_mface_t *mface;
	sdna_mtface_t *mtface;
	sdna_tface_t *tface;
	sdna_mvert_t *mvert;
	sdna_medge_t *medge;
	sdna_mdeformvert_t *dvert;
	sdna_mcol_t *mcol;
	sdna_msticky_t *msticky;
	sdna_mesh_t *texcomesh;
	sdna_mselect_t *mselect;
	sdna_customdata_t vdata;
	sdna_customdata_t edata;
	sdna_customdata_t fdata;
	int totvert;
	int totedge;
	int totface;
	int totselect;
	int act_face;
	int texflag;
	float loc[3];
	float size[3];
	float rot[3];
	float cubemapsize;
	float pad;
	short smoothresh;
	short flag;
	short subdiv;
	short subdivr;
	short totcol;
	short subsurftype;
	void *mr;		// sdna_multires_t *mr;
	void *pv;		// sdna_partialvisibility_t *pv;
	void *vnode;
} sdna_mesh_t;


/* snippet from main.cpp */

.... some more code .....

blend_file_t blend;
block_t block;

if(!blend_load("test.blend", &blend)) // custom function
{
   std::cout << "Could not find test.blend";
   return 0;
}


do
{
	blend_readblock(&block, &blend);
} while(block.header.SDNA_index != SDNA_MESH);

sdna_mesh_t *mesh = (sdna_mesh_t *)block.code;

std::cout << mesh->id.name; // prints out MECube just fine.

The above works just fine. the problem is when I try to get another pointer inside the sdna_mesh_t struct (such as mesh->key->elemstr).

How would I go about mapping mesh->key to the correct location in the blend file?

Sorry about this question (I am sure it has been asked many times before), but I am on a deadline and need to focus on more than just this.

Any help would be much appreciated!

Thank you!
Christian Modas

FakeMajor
Posts: 8
Joined: Thu Sep 29, 2011 2:00 am

Post by FakeMajor » Thu Sep 29, 2011 5:22 am

Actually I think I just figured it out.

Code: Select all


	blend_file_t *blend = new blend_file_t;
	block_t block;

	if(!blend_open("test.blend", blend))
	{
		std::cout << "Could not load test.blend!";
		return 0;
	}

	std::cout << "Pointer Size: " << blend->header.pointer_size << "\nEndianness: " << blend->header.endianness << "\nBlender Version: " << blend->header.version_number << "\n\n";
	
	blend_skipblocks(6, blend);

	do
	{
		blend_readblock(&block, blend);
	} while(block.header.SDNA_index != SDNA_MESH);

	sdna_mesh_t *mesh = (sdna_mesh_t *)block.code;

	do
	{
		blend_readblock(&block, blend);
	} while(block.header.SDNA_index != SDNA_MVERT && block.header.old_memory_address != mesh->mvert);

	mesh->mvert = (sdna_mvert_t *)block.code;

	std::cout << mesh->mvert->co[0];

	blend_close(blend);

I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).

http://www.megafileupload.com/en/file/3 ... r-zip.html

Tcll
Posts: 63
Joined: Tue Aug 31, 2010 12:11 am
Location: The Forest of Darkness

Post by Tcll » Thu Sep 29, 2011 4:40 pm

sounds like the reason I needed to know the file format.

I'm working on a model converter of my own to support a variety of file formats based on the plugins
(like winamp)
Image

stiv
Posts: 3645
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Thu Sep 29, 2011 6:46 pm

The Crystal Space project did some work (C++, iirc) on a reader for .blend files. The Blender file format is a little tricky to deal with because:

* .blend files are designed to be forward & backward compatible betweenversions

* the .blend format was not designed as a file interchange format and is essentially a memory dump from a running instance of Blender

* the structure can (and does!) change between Blender versions to support new features.

The Blender DNA stuff is your friend here.

Tcll
Posts: 63
Joined: Tue Aug 31, 2010 12:11 am
Location: The Forest of Darkness

Post by Tcll » Fri Sep 30, 2011 1:37 am

>.>
are you telling me that, or him?
cause I think you've already told me that...
if not you, then I know somebody has >_>

is there any documentation on blender DNA that's not in C++??
Image

FakeMajor
Posts: 8
Joined: Thu Sep 29, 2011 2:00 am

Post by FakeMajor » Fri Sep 30, 2011 3:22 am


FakeMajor
Posts: 8
Joined: Thu Sep 29, 2011 2:00 am

Post by FakeMajor » Fri Sep 30, 2011 7:45 am

Actually all the stuff from the last link was using blender version 2.49. I would like to use version 2.59. I think the SDNA index is changed for the objects. Does anybody know how one would go about finding this? I think its somewhere stored in the blend file, but I really would just like some numbers.

FakeMajor
Posts: 8
Joined: Thu Sep 29, 2011 2:00 am

Post by FakeMajor » Fri Sep 30, 2011 9:52 am

well once again, the mystery has been solved. Here is the solution if anybody else is having the same problem:
Hi Cristian,

The script is inside Blenders source tree. To be exact see
https://svn.blender.org/svnroot/bf-blen ... le_format/

Best regards,
Jeroen
- At Mind B.V. -

Tcll
Posts: 63
Joined: Tue Aug 31, 2010 12:11 am
Location: The Forest of Darkness

Post by Tcll » Fri Sep 30, 2011 2:19 pm

YES! :D
thank you :)

just in the exact language I can read XDD
Image

marik89
Posts: 3
Joined: Thu Dec 08, 2011 9:22 pm

Post by marik89 » Thu Dec 08, 2011 9:26 pm

FakeMajor wrote:Actually I think I just figured it out.

...

I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).

http://www.megafileupload.com/en/file/3 ... r-zip.html
i need really help i completely parsed the .blend file but now i have problems to interpret the data.
can u please send me your code?

FakeMajor
Posts: 8
Joined: Thu Sep 29, 2011 2:00 am

Post by FakeMajor » Sat Feb 25, 2012 7:36 pm

marik89
Posted: Thu Dec 08, 2011 9:26 pm Post subject:
FakeMajor wrote:
Actually I think I just figured it out.

...

I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).

http://www.megafileupload.com/en/file/3 ... r-zip.html


i need really help i completely parsed the .blend file but now i have problems to interpret the data.
can u please send me your code?
Do you still need the code? its been a while since this was posted

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Post by ldo » Sun Feb 26, 2012 6:56 am

Have a look at this code https://github.com/ldo/blendparser.

marik89
Posts: 3
Joined: Thu Dec 08, 2011 9:22 pm

Post by marik89 » Wed May 16, 2012 11:23 am

FakeMajor wrote:
marik89
Posted: Thu Dec 08, 2011 9:26 pm Post subject:
FakeMajor wrote:
Actually I think I just figured it out.

...

I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).

http://www.megafileupload.com/en/file/3 ... r-zip.html


i need really help i completely parsed the .blend file but now i have problems to interpret the data.
can u please send me your code?
Do you still need the code? its been a while since this was posted
My Importer is running well but only with 32bit files.
Does your code Support 64Bit files?
If Yes i still need the code.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests