[Bf-python] A Blender.Struct module?

joeedh joeeagar at prodigy.net
Fri Nov 5 12:59:56 CET 2004


Yann Vernier wrote:

>On Thu, Nov 04, 2004 at 06:05:44PM -0800, joeedh wrote:
>  
>
>>Hi.  Python has this really nice module called the "struct" module, that 
>>lets you save basic python types as C structs within a binary file.  
>>What if we made a module that would let users save basic python types 
>>within a .blend file? 
>>    
>>
>
>Not C structs, really, but binary data. They happen to be the same
>sometimes, but the struct module is considerably more flexible, with
>features like byteswapping and precise control over padding. The struct
>module is one of the essentials, and like zlib should be bundled where
>Blender comes with its own Python.
>  
>
>>Such a module would have it's own implementation of Struct-DNA, which 
>>means that the C struct format string would have to be pretty detailed, 
>>e.g. "Foo { int a; int b;}" would make a struct Foo with int members "a" 
>>and "b" (unlike python struct's format string, which I believe would 
>>simply be "ii").  This module would store all data within a list, each 
>>struct contained within a special struct, like so:
>>
>>typedef struct  _PythonStruct {
>>   int len; /*structure len*/
>>   char name[23]; /*the struct name*/
>>   void *struct; /*a pointer to the actual struct*/;
>>   char *formatstr; /*a format string saying what the struct is*/;
>>} PythonStruct;
>>
>>to facilitate saving the data in a .blend file.  This struct would be 
>>processed by makesdna.
>>    
>>
>
>You essentially wind up with a BLOB interface for the Blender dna
>format. I'm not sure how often this is really useful. Currently I've
>been storing things in Text objects, which isn't very elegant either,
>but can at least be recovered by people who don't have access to my
>code. Can you think of a use case?
>  
>
The idea was that we could then write, in python, code to save, say, the 
Blender Registry to packed binary data.  But, "print >> [something with 
a .write method, NOT a Text object], dict" does work just as well. . .so 
long as the Registry dictionaries that you're saving don't have any 
non-basic types in them. . .

I'm using Text objects right now as well, and I can tell you, saving 
things like morph targets and meshes in a text object isn't the most 
elegant solution, especially when you are doing per-object stuff, which 
means that you might have many objects each with a lot of data to save.

Although I have to admit, text objects do work.  I just don't have very 
much faith in storing large amounts of data in them.  Maybe I'm wrong 
about that. . .hmmm. ..

joeedh



More information about the Bf-python mailing list