Skip to content
Snippets Groups Projects
io_import_scene_mhx.py 85.2 KiB
Newer Older
    ("armature", "Armature", "Use armature", T_Armature),
    ("replace", "Replace scene", "Replace scene", T_Replace),
    ("cage", "Cage", "Load mesh deform cage", T_Cage),
    ("clothes", "Clothes", "Include clothes", T_Clothes),
    ("stretch", "Stretchy limbs", "Stretchy limbs", T_Stretch),
    ("face", "Face shapes", "Include facial shapekeys", T_Face),
    ("shape", "Body shapes", "Include body shapekeys", T_Shape),
    ("symm", "Symmetric shapes", "Keep shapekeys symmetric", T_Symm),
    ("diamond", "Diamonds", "Keep joint diamonds", T_Diamond),
    ("rigify", "Rigify", "Create rigify control rig", T_Rigify),
    ("limit", "Limit constraints", "Keep limit constraints", T_Limit),
]

class ImportMhx(bpy.types.Operator, ImportHelper):
Luca Bonavita's avatar
Luca Bonavita committed
    '''Import from MHX file format (.mhx)'''
    bl_idname = "import_scene.makehuman_mhx"
    bl_description = 'Import from MHX file format (.mhx)'
    bl_label = "Import MHX"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_options = {'UNDO'}
Luca Bonavita's avatar
Luca Bonavita committed

    scale = FloatProperty(name="Scale", description="Default meter, decimeter = 1.0", default = theScale)
    enums = []
    for enum in BlenderVersions:
        enums.append((enum,enum,enum))
    bver = EnumProperty(name="Blender version", items=enums, default = BlenderVersions[0])
Luca Bonavita's avatar
Luca Bonavita committed

    filename_ext = ".mhx"
    filter_glob = StringProperty(default="*.mhx", options={'HIDDEN'})
    filepath = StringProperty(name="File Path", description="File path used for importing the MHX file", maxlen= 1024, default= "")
Luca Bonavita's avatar
Luca Bonavita committed

    for (prop, name, desc, flag) in MhxBoolProps:
        expr = '%s = BoolProperty(name="%s", description="%s", default=toggle&%s)' % (prop, name, desc, flag)
        exec(expr)
Luca Bonavita's avatar
Luca Bonavita committed
        
    def execute(self, context):
        global toggle, theScale, MhxBoolProps, theBlenderVersion, BlenderVersions
        toggle = 0
        for (prop, name, desc, flag) in MhxBoolProps:
            expr = '(%s if self.%s else 0)' % (flag, prop)
            toggle |=  eval(expr)
        print("execute flags %x" % toggle)
        theScale = self.scale
        theBlenderVersion = BlenderVersions.index(self.bver)
        try:
            readMhxFile(self.filepath)
            bpy.ops.mhx.success('INVOKE_DEFAULT', message = self.filepath)
        except NameError:
            print("Error when loading MHX file:\n" + theMessage)

Luca Bonavita's avatar
Luca Bonavita committed
        return {'FINISHED'}

    def invoke(self, context, event):
        global toggle, theScale, MhxBoolProps, theBlenderVersion, BlenderVersions
        readDefaults()
        self.scale = theScale
        self.bver = BlenderVersions[theBlenderVersion]
        for (prop, name, desc, flag) in MhxBoolProps:
            expr = 'self.%s = toggle&%s' % (prop, flag)
Luca Bonavita's avatar
Luca Bonavita committed
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}
    self.layout.operator(ImportMhx.bl_idname, text="MakeHuman (.mhx)...")
Brendon Murphy's avatar
Brendon Murphy committed
def register():
Luca Bonavita's avatar
Luca Bonavita committed
    bpy.types.INFO_MT_file_import.append(menu_func)
Brendon Murphy's avatar
Brendon Murphy committed
def unregister():
Luca Bonavita's avatar
Luca Bonavita committed
    bpy.types.INFO_MT_file_import.remove(menu_func)
Brendon Murphy's avatar
Brendon Murphy committed

if __name__ == "__main__":
Luca Bonavita's avatar
Luca Bonavita committed
    try:
        unregister()
    except:
        pass
    register()