def import_mod(file_path, base_dir, parent=None, mod_folder=None):
    model_name = os.path.basename(file_path)
    if mod_folder:
        model_name = posixpath.join(ensure_posixpath(mod_folder), model_name)
    mod = Mod156(file_path=file_path)
    if mod.version == 156:
        textures = _create_blender_textures_from_mod(mod, base_dir)
        materials = _create_blender_materials_from_mod(mod, model_name,
                                                       textures)

    meshes = []
    for i, mesh in enumerate(mod.meshes_array):
        name = create_mesh_name(mesh, i, file_path)
        try:
            m = _build_blender_mesh_from_mod(mod, mesh, i, name, materials)
            meshes.append(m)
        except BuildMeshError as err:
            # TODO: logging
            print('Error building mesh {0} for mod {1}'.format(i, file_path))
            print('Details:', err)
            m = bpy.data.objects.new(name, None)
            meshes.append(m)
    if mod.bone_count:
        root = _create_blender_armature_from_mod(mod, model_name, parent)
        root.show_x_ray = True
    else:
        root = bpy.data.objects.new(model_name, None)
        root.parent = parent
        # '_create_blender_armature_from_mod links the armature to the scene. Necessary?
        bpy.context.scene.objects.link(root)

    # saving imported data for export use (format not 100% figured out yet)
    root.albam_imported_item['data'] = bytes(mod)
    root.albam_imported_item.folder = ensure_posixpath(
        mod_folder)  # e.g. pawn/pl/pl00/model
    root.albam_imported_item.source_path = file_path
    root.albam_imported_item.name = model_name
    root.albam_imported_item.file_type = 'mtframework.mod'

    for mesh in meshes:
        bpy.context.scene.objects.link(mesh)
        mesh.parent = root
        if mod.bone_count and mesh.type != 'EMPTY':  # an empty mesh is a failed one
            modifier = mesh.modifiers.new(type="ARMATURE", name=model_name)
            modifier.object = root
            modifier.use_vertex_groups = True
Exemple #2
0
def import_mod(file_path, base_dir, parent=None, mod_folder=None):
    model_name = os.path.basename(file_path)
    if mod_folder:
        model_name = posixpath.join(ensure_posixpath(mod_folder), model_name)
    mod = Mod156(file_path=file_path)
    if mod.version == 156:
        textures = _create_blender_textures_from_mod(mod, base_dir)
        materials = _create_blender_materials_from_mod(mod, model_name, textures)

    meshes = []
    for i, mesh in enumerate(mod.meshes_array):
        name = create_mesh_name(mesh, i, file_path)
        try:
            m = _build_blender_mesh_from_mod(mod, mesh, i, name, materials)
            meshes.append(m)
        except BuildMeshError as err:
            # TODO: logging
            print('Error building mesh {0} for mod {1}'.format(i, file_path))
            print('Details:', err)
            m = bpy.data.objects.new(name, None)
            meshes.append(m)
    if mod.bone_count:
        root = _create_blender_armature_from_mod(mod, model_name, parent)
        root.show_x_ray = True
    else:
        root = bpy.data.objects.new(model_name, None)
        root.parent = parent
        # '_create_blender_armature_from_mod links the armature to the scene. Necessary?
        bpy.context.scene.objects.link(root)

    # saving imported data for export use (format not 100% figured out yet)
    root.albam_imported_item['data'] = bytes(mod)
    root.albam_imported_item.folder = ensure_posixpath(mod_folder)  # e.g. pawn/pl/pl00/model
    root.albam_imported_item.source_path = file_path
    root.albam_imported_item.name = model_name
    root.albam_imported_item.file_type = 'mtframework.mod'

    for mesh in meshes:
        bpy.context.scene.objects.link(mesh)
        mesh.parent = root
        if mod.bone_count and mesh.type != 'EMPTY':  # an empty mesh is a failed one
            modifier = mesh.modifiers.new(type="ARMATURE", name=model_name)
            modifier.object = root
            modifier.use_vertex_groups = True
Exemple #3
0
def test_ensure_posixpath_from_posixpath():
    path = 'foo/bar/spam/eggs'

    assert ensure_posixpath(path) == 'foo/bar/spam/eggs'
Exemple #4
0
def test_ensure_posixpath_from_ntpath():
    path = 'foo\\bar\\spam\\eggs'

    assert ensure_posixpath(path) == 'foo/bar/spam/eggs'
Exemple #5
0
def test_ensure_posixpath_from_posixpath():
    path = 'foo/bar/spam/eggs'

    assert ensure_posixpath(path) == 'foo/bar/spam/eggs'
Exemple #6
0
def test_ensure_posixpath_from_ntpath():
    path = 'foo\\bar\\spam\\eggs'

    assert ensure_posixpath(path) == 'foo/bar/spam/eggs'