From BlenderWiki

Jump to: navigation, search

Intro

This document tries to give some insight in how a .blend is written and read.

outline

  • important files?
  • general write / read scheme
  • example write step by step
  • example read step by step
  • Additional Resources

important files

Everything in blenloader

read/write scheme

  • write. Convert below code in a more readable state. Obviously, include subsections where needed.
wd= bgnwrite(handle, compare, current, write_flags);
 
sprintf(buf, "BLENDER%c%c%.3d", (sizeof(void*)==8)?'-':'_', (G.order==B_ENDIAN)?'V':'v', G.version);
mywrite(wd, buf, 12);
 
write_renderinfo(wd);
 
if(current==NULL)
write_screens (wd, &G.main->screen);	// no UI save
write_scenes	(wd, &G.main->scene);
write_curves	(wd, &G.main->curve);
write_mballs	(wd, &G.main->mball);
write_images	(wd, &G.main->image);
write_cameras (wd, &G.main->camera);
write_lamps	 (wd, &G.main->lamp);
write_lattices (wd, &G.main->latt);
write_ikas	 (wd, &G.main->ika);
write_vfonts	(wd, &G.main->vfont);
write_ipos	 (wd, &G.main->ipo);
write_keys	 (wd, &G.main->key);
write_worlds	(wd, &G.main->world);
write_texts	 (wd, &G.main->text);
write_sounds	(wd, &G.main->sound);
write_groups	(wd, &G.main->group);
write_armatures(wd, &G.main->armature);
write_actions (wd, &G.main->action);
write_objects (wd, &G.main->object);
write_materials(wd, &G.main->mat);
write_textures (wd, &G.main->tex);
write_meshs	 (wd, &G.main->mesh);
write_libraries(wd, G.main->next);
 
write_global(wd);
if (write_user_block) {
write_userdef(wd);
}
 
/* dna as last, because (to be implemented) test for which structs are written */
writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data);
 
/* end of file */
memset(&bhead, 0, sizeof(BHead));
bhead.code= ENDB;
mywrite(wd, &bhead, sizeof(BHead));
 
blo_join_main(&mainlist);
G.main= mainlist.first;
 
return endwrite(wd);

Example Write Step by Step (in progress) -- JW

' The file write all starts in the int BLO_write_file(char dir, int write_flags, char 'error_r) function. The function is found in writefile.c and declared in BLO_writefile.h. This is the entry point for the file writing code.

  • Here is the call tree for a sample file write. (in progress) -- JW
    • WriteFileCallGraph

Additional Resources