[Bf-python] Ideal way to store material data for matlib add-on?

Peter D. Cassetta peter at fingertipsoft.com
Fri May 10 19:41:17 CEST 2013


Hi everyone,

I'm working on ideas for the next version of my material library add-on. 
I am rewriting it from scratch (reusing some old code, of course) and 
would like some help figuring out which route I should take with 
material data storage.

I've been using an XML-based format up to now. It works, but is not 
exactly the best option, because it makes it less than easy to add new 
features into the material files. I had originally decided to use 
XML-based files instead of just .blend files. Because of their size, 
.blend files would have been a little bit overkill. (Downloading a 
.blend with one material; not the greatest plan either server-side or 
client-side.)

After looking into the overall architecture of the Blender file format, 
it seems like it might be possible to somehow splice out the "materials" 
section of the file, use that as its own file which can be downloaded 
and all. Then perhaps the add-on could replace the materials section of 
some .blend with the new downloaded material file, and save the edited 
.blend in an appropriate location.

The benefit of this method is that it makes it easy to distribute any 
material which Blender has saved. Multiple render engine support would 
be a breeze.

My question: is this workable? If so, would someone experienced with the 
.blend file architecture be willing to give me some pointers?

If it is not workable, or just too difficult, an alternative might be 
using a library.blend which stores all the materials. The only difficult 
part would be adding new materials to the library from time to time. 
Currently it's as simple as editing an XML file and uploading the 
XML-based material file, but you can imagine that appending would get a 
bit tedious after a while.

Lastly (and this one seems pretty far-fetched), would it be possible to 
save the raw data contained in bpy.data.materials['Material'] to a file 
somehow? If it could actually work, this might be the best option. To 
add that material to a scene, one would just have to load the file, 
create a new material, loop through all the attributes and apply them to 
the new material. Is this completely ridiculous, or possible?

Also, for any of these ideas I'd be using some kind of XML-based library 
file to provide information about each of the materials.

I'd be happy to hear what anyone else has to think about all this!

Regards,
Peter Cassetta



More information about the Bf-python mailing list