Wanted: a functional way to get simple 3D models from Blender to OSG. Nothing fancy, no animations or vertex shaders, just regular models. Blender writes a large number of 3D file formats, and OSG reads a large number, so it might be reasonably hoped that some combination will work.
In addition to historical formats, an interesting possibility is the relatively new COLLADA format. Blender exports to it as a standard format, and an OSG importer was released August 2006 with the osgdb-collada and collada-dom projects.
Test models are contained in BlenderTests.zip:
A simple, smooth-shaded penguin model from the Blender tutorials. It has a 'subdivide' modifier and a single yellow diffuse material.
The same model as yellow_penguin, with the modifier explicitly applied. A low-polygon model of a stop sign, with a small PNG texture used to display "STOP".
Testing the path from Blender (2.4.2) to OSG (1.1) showed these results:
yellow_penguin penguin_applied stopsign notes size (KB) result size (KB) result size (KB) result 3ds 129 ok 129 ok 1 no texture The very old 3DS format is known to have many limitations, so the loss of texture is not too surprising. Might be a filepath issue. collada
335 ok 13 no texture It was disappointing that the texture did not come through. The developers of the (relatively new) COLLADA exporter and importer could probably fix this easily. flt 49 nothing appears 692 nothing appears 9 nothing appears Besides being non-functional, the exporter was also very slow, and the reader complains about missing .attr file for the textured model. lwo 7 low-polygon (modifier lost) and flat shaded 105 flat shaded 3 ok Smoothing is lost somewhere, presumably on export. osg 37 ok
617 ok 12 missing texture
Version 2.41 of osgexport was used.
obj 215 ok 215 ok 2 ok OSG swaps Y/Z, so "up" orientation doesn't match Blender.
Things i learned about the Blender exporters:
- They require you have all the objects selected that you want exported, although only the OBJ and DAE exporters make this explicit. The rest just silently fail to export correctly if the objects are unselected.
- They don't necessarily apply the geometry modifiers in the model. 3DS and OBJ did, the rest of the formats did not.
The ancient, plain-text Wavefront OBJ format appears to be the only one that works usably between these two software packages. It suffers from a disagreement about whether Y or Z is "up", but other than that, geometry and textures did come through.
However, aside from the axis problem, OBJ suffers from another problem: Blender has to flatten all transforms on export! This means if you have a car with a wheel, load it into OSG, then rotate the wheel, it will orbit the car, rather than rotate around its own origin.
After lots more testing and help from seasoned Blender users, i now understand a great deal more about just how bizarre and confusing Blender's texture handling is.
The Collada (.dae) and .osg formats work the best for exporting the whole scene. However, care must be taken to define materials and textures in a very exact way, which explains a lot of the missing textures of the first test.
The document that resulted from all this testing is: How to use Blender with OSG/VTP.