Getting started

Exporting a mesh from blender:

An mesh from blender can be exported to a '.msh' file. To do this, open the object in the blender. With the object opened, open the text editor in the blender and copy the following python script in the text editor.

Python

import bpy
import struct
obj=bpy.context.object.data

bpy.ops.object.mode_set(mode="OBJECT")

print("*************************************")
print(len(obj.vertices),"vertices,",len(obj.polygons),"faces")
print(len(obj.uv_layers))
print(len(obj.loops))

for q in range(len(obj.vertices)):
    print("Vertex",q,":",obj.vertices[q].co,", vertex normal:",obj.vertices[q].normal)
for q in range(len(obj.polygons)):
    print("Face",q,"vertices: [ ",end='')
    for w in range(len(obj.polygons[q].vertices)):
        #print(obj.polygons[q].vertices[w]," ",end='')
        print(obj.loops[obj.polygons[q].loop_indices[w]].vertex_index," ",end='')
    print("], face normal:",obj.polygons[q].normal,", shading: ",end='')
    if obj.polygons[q].use_smooth:
        print("smooth")
    else:
        print("flat")

f = open("C:/YourLocation/mesh.msh", 'wb')
f.write(struct.pack('<l',len(obj.vertices)))
f.write(struct.pack('<l',len(obj.vertices)+len(obj.polygons)))
f.write(struct.pack('<l',len(obj.loops)))
f.write(struct.pack('<l',len(obj.polygons)))
for q in range(len(obj.vertices)):
    f.write(struct.pack('<f',obj.vertices[q].co[0]))
    f.write(struct.pack('<f',obj.vertices[q].co[1]))
    f.write(struct.pack('<f',obj.vertices[q].co[2]))
for q in range(len(obj.vertices)):
    f.write(struct.pack('<f',obj.vertices[q].normal[0]))
    f.write(struct.pack('<f',obj.vertices[q].normal[1]))
    f.write(struct.pack('<f',obj.vertices[q].normal[2]))
for q in range(len(obj.polygons)):
    f.write(struct.pack('<f',obj.polygons[q].normal[0]))
    f.write(struct.pack('<f',obj.polygons[q].normal[1]))
    f.write(struct.pack('<f',obj.polygons[q].normal[2]))
for q in range(len(obj.loops)):
    f.write(struct.pack('<f',obj.uv_layers[0].data[q].uv[0]))
    f.write(struct.pack('<f',obj.uv_layers[0].data[q].uv[1]))
for q in range(len(obj.polygons)):
    f.write(struct.pack('<l',len(obj.polygons[q].vertices)))
    for w in range(len(obj.polygons[q].vertices)):
        f.write(struct.pack('<l',obj.polygons[q].vertices[w]))
    for w in range(len(obj.polygons[q].vertices)):
        if obj.polygons[q].use_smooth:
            f.write(struct.pack('<l',obj.polygons[q].vertices[w]))
        else:
            f.write(struct.pack('<l',q+len(obj.vertices)))
    for w in range(len(obj.polygons[q].vertices)):
        f.write(struct.pack('<l',obj.polygons[q].loop_indices[w]))
    f.write(struct.pack('<l',obj.polygons[q].material_index))
f.close()


Now, select the object and switch to the edit mode by pressing the Tab key. Go to the material properties and add as many materials as the number of mFaces elements you want for the mesh. Now select all the faces of the object you want for a mFaces element and assign a distinct material to them. Do this for all the mFaces elements. Now go to the object mode by pressing the Tab key and apply all the transforms using Ctrl+A. Applying all transforms is very important. Now with the object selected, run the python script in the text editor.

Your mesh will be saved as 'C:/YourLocation/mesh.msh.' You can edit this location and file name on line#25 of this code. You can now open this mesh in the body design panel using 'Load mesh' button .