This article is the third part of Parsing Blender 3D Files. If you have not read the first and second articles of this series, please do so to get a full understanding of this article.
If you understand how to parse Blender Objects within the previous article, then you already know how to parse Blender Components. While parsing the vector array of pointers to Blender data blocks and your application comes across “OB” then the application knows it is time to parse a list of Blender Objects. This is also true for the Blender Components – “ME” list of meshes, “LA” list of lamps, “CA” list of cameras, “MA” list of materials, etc.
Once you have your desired set of data blocks you can use the SDNA information that was previously built to find the data blocks’ data structures and the attributes to those data structures. Just like we did before with the Blender Objects within the previous article.
One item that is worth noting that was not previously mentioned that will become relevant when building Blender Components is the number of elements an attribute has. This becomes important with attributes such as vertices of a mesh. The number of elements of a Blender Component’s attribute were stored off within Pass One and is part of a data block’s header.
Attributes that require the “number of elements” information are within data blocks themselves and will directly follow their already parsed parent Blender Component. For example the data block with the SDNA structure name “MVert” will come after it’s parent Blender Component “Mesh” within the list of data blocks for meshes.
The example below shows how “MVert” uses the number of elements within the data block’s header to find the mesh’s vertices and the normals to those vertices.
To link a Blender Component to it’s parent Blender Object, use the old memory address of the Blender Component that was saved within the component’s data block header. Also, use the void pointer “data” within the Blender Object and compare the two addresses. If the two addresses match then you have found the relationship between the two objects.
There is also a similar pattern when there are two (or more) Blender Components that have a relationship. For example, when a mesh has a material component then “**mat” will have an old memory address that points to a position within the file that has another old memory address which is to a Blender Material Component.
Within Pass One your application saved off the relationship between data blocks and old memory addresses within a map.
You can use the data block map to access the data block’s needed to build your Blender Components (such as the before mentioned material component).
The second memory address is the old memory address of the Blender Material Component that is associated with this mesh. You can find the data block of the Blender Material Component by using the second old memory address and using it as an index with the data block map that you built within Pass One.
At this point you have everything that you need to decipher a Blender 3d File. If you have any questions please leave them within the comments below. I am currently not planning to share my source code. However, I will be happy to help where I can with any questions that you may have.
- Parsing Blender 3D Files (*.blend) – (1 of 3)
- Parsing Blender 3D Files (*.blend) – (2 of 3) Blender Objects
- The mystery of the blend, The blender file-format explained by Jeroen Bakker
- Blender’s Python API Documentation
- Blender’s Source Code: folders makesdna and makesrna under source/blender.
Please, keep your comments family friendly and respectful of each other and the author.