surfacecurve-blender is a Javascript module for parsing data from .blend Blender files


surfacecurve-blender is a module for parsing data from .blend files saved by Blender. It makes it easier to load Blender data into the 3d model format or rendering library of your choice. The blend file format is described on the site.

The library parses the file from buffer, thus making it usable both in the browser or a NodeJS environment.

node examples/<filename>     # run an example script

node scripts/build.js        # build the distributable files and
                             # browser version of the library
node scripts/test.js         # run the unit tests
node scripts/benchmark.js    # run the benchmarks

Some of the above commands require that npm install --dev be run first.

The module is accessible in the browser via the global name surfacecurve.blender.

The parser is fairly low-level: its goal is to make traversing the Blender "SDNA" structures easier, not to convert the format to wholly new intermediate 3D format. It works by reading in the index of all types, structures, and blocks from the file and providing access methods for those blocks.

The client code still needs to direct the traversal of the blocks of interest. This is left to the client in order to (a) avoid loading what the client does not need, and (b) avoid enforcing use of some intermediate data structure for 3D points, normals, etc. that might require yet-another format conversion to get to the data format the client code needs.

The examples are the best way to understand the library:

In the module directory, run the examples:

$ node examples/example-01.js
$ node examples/example-02.js

The examples demonstrate how to extract data from the .blend file. For example, here's some of the partial output from example-01.js

Opening file:  data/unitCube-000.blend
File version:  257
Mesh at 0x2959559940 total vertices/faces/edges: 8/6/12
  mat: 4026607364,
  totvert: 8,
  totedge: 12,
  totface: 6,
  loc: [ 5.960464477539063e-8, -1.1920928955078125e-7, 0 ],
  size: [ 1.0000004768371582, 1.0000004768371582, 1 ],
  rot: [ 0, 0, 0 ],
  texflag: 1,
  drawflag: 67,
  smoothresh: 30,
  ... }

The field names in the JSON represent the field names extracted from the Blender SDNA format. Therefore, using the format documentation you should be able to extract any and all data you need.

Licensed under the MIT license.

I realize the convenient answer would be, "Call the function blender.renderModel('somefile.blend');" but that's not really the intent of this library...

This library provides an interface for getting data out of a .blend file in a structured manner. You'll need to use this library to traverse the blend file and build up the 3d model data structure used by the rendering library of your choice.