0

I am attempting to parse a .blend (Blender 3D Modelling Program Save File) in C#.

.blend follows a TLV pattern and using 3rd party tools I've managed to extract the majority of the data:

.blend File Format

Shown in the image; I have deserialized the .blend FileBlocks (The actual file data) and the Sdna Structs (The types of data present in a .blend file)

For example Block[1799] is sdna type sdnas[173] which means Block[1799] is a mesh.

Each block has a property "Body" which is a System.Byte[] and contains that FileBlocks data (In the case of a mesh, it's name and mesh properties, with pointers to other file blocks like it's vertices)

In this particular case I'm reading the body of a "Vec2s" sdna struct where the first 4 bytes are [31,5,246,25...]

I also know the Vec2 sdna has 2 properties (x and y) which are both of type short. So my intuition tells me that the first 4 bytes of my object are 2 shorts representing x and y. Reading these out returns (1311,9206)

All the fields of the sdna structs are of type uint, short etc. So how am I supposed to get the actual values like names, floats, vector2s, pointers etc?

As you can tell I really don't know what I'm doing.

  • 2
    I'm not sure what youre question is, but I think you want to create `struct`s or `class`es representing those binary structures, and then either read each field separately into instances of them, or use unsafe (in terms of platform data type sizes / endianness) of memory / spans to those `struct`s. Or is your question specific to Blender's dynamic declaration of structures you don't know at compile time? – Ray Jun 11 '22 at 00:20
  • @Simon This might help https://stackoverflow.com/questions/10390356/serializing-deserializing-with-memory-stream – Victor Wilson Jun 11 '22 at 00:39
  • 2
    @VictorWilson The .NET `BinaryFormatter` uses its own internal format to read / write objects, it does not aid reading other raw binary data formats, and is also obsolete due to [security vulnerabilities](https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0011). APIs for parsing custom binary data would be `System.Buffers.Binary.BinaryPrimitives` in combination with typed `Span`s or `Memory` and / or `System.Runtime.CompilerServices.Unsafe` for direct conversion after reading bytes from a `Stream` or another source. – Ray Jun 11 '22 at 00:51

0 Answers0