Wednesday 13 July 2011

Blender M3G export error

I'm attempting to build a game atop Kajak3D framework. For that I'm creating models in Blender and exporting them to M3G format.

Well, exporting my very first model failed with "Python script error: Check console". After figuring out that this doesn't mean any Blender-internal console, but plain old console output, I closed Blender and started it from a terminal window. So, I received this message:
translate mesh ...[Object "Body"]
1 material(s) found.
Traceback (most recent call last):
  File "/usr/share/blender/scripts/export_m3g.py", line 3068, in file_callback_m3g
    exporter.start()
  File "/usr/share/blender/scripts/export_m3g.py", line 2680, in start
    world = Translator.start()
  File "/usr/share/blender/scripts/export_m3g.py", line 2022, in start
    self.translateMesh(obj)
  File "/usr/share/blender/scripts/export_m3g.py", line 2296, in translateMesh
    if material.getMode() & Material.Modes.TEXFACE: createUvs = True;
AttributeError: 'NoneType' object has no attribute 'getMode'

My first thought of that was that the first "material" is likely typed with wrong capitalization and should have been "Material". But it is not so: both capitalized and non-capitalized version are actually valid in that script at that point...

Google search didn't find anything on fixing that error, just one unanswered forum post asking how to fix it. Anyhow, I found the solution and decided to post it here, in case anyone else bumps into same issue.

The solution
Link the object material to object mesh, not to whole object.
Note the circled area: your settings should look like this. You can click on "OB" to see if there are any materials linked to the object and to remove them.