Ejemplo n.º 1
0
    def process_nif(test_file, bone_list):
        print('Processing', test_file)
        target_nif = load_nif(test_file, template = template_mesh, settings = current_settings)
        if not target_nif.valid:
            print(test_file,'Could Not Be Processed')
        
        targets_found = 0
        for this_mesh in target_nif.meshes:
            targets_found += mainSearch(current_settings, template_mesh, this_mesh, search_resolution = 1, vertFunction = setWeightDictionary, side = side)

        save_file(target_nif, test_file, targets_found, current_settings)
Ejemplo n.º 2
0
    def process_nif(this_file, repair_doubles = False):
#         if findall(r_nif, test_file) and test_file != current_settings['template']:
        print('******NIF******')
        print('Processing', this_file)

        target_nif = load_nif(this_file, template = template_mesh, settings = current_settings)
        if not target_nif.valid:
            print(target_nif,'Could Not Be Processed')
            return
        nif_gender = target_nif.getGender()
        if gender_list:
            if nif_gender not in gender_list:
                print('Incorrect Gender:', this_file )
                print('Closing', this_file )
                return
            mesh_ = template_mesh.get(nif_gender)
            verts_ = template_verts.get(nif_gender)
        elif nif_gender != current_settings['gender']:
            print('Incorrect Gender:', this_file )
            print('Closing', this_file )
            return
                    
        
        targets_found = 0
        for this_mesh in target_nif.meshes:
            if gender_list:
                targets_found += mainSearch(current_settings, mesh_, this_mesh, search_resolution = 1, vertFunction = setSeams, nmv = target_nmv, act_verts = verts_)
            else:   
                targets_found += mainSearch(current_settings, template_mesh, this_mesh, search_resolution = 1, vertFunction = setSeams, nmv = target_nmv, act_verts = template_verts)       
        if repair_doubles:
            for this_mesh in target_nif.meshes:
                if current_settings.get('doubles'):
                    for tup in this_mesh.nmv_doubles:
                        average_normal = kg.math_util.vector3([0,0,0])
                        bad_normal = 0
                        for v in tup:
                            if v.normal:
                                average_normal += v.normal
                            else:
                                bad_normal += 1
                        if bad_normal == len(tup):
                            continue
                        for v in tup:
                            v.setNormal(kg.math_util.normalizeVector(average_normal))
                            targets_found += 1
        save_file(target_nif, this_file, targets_found, current_settings)
Ejemplo n.º 3
0
    def process_tri(this_file):
        if template_verts:
            print('******TRI******')
            
            mesh_ = template_mesh                         
            verts_ = template_verts
            
            if gender_list or current_settings['gender']:
                """
                Determine Gender of Tri File
                """

                root_nif_path = re.sub(r_tri_end, '.nif', this_file)
                tri_gender = getGenderFlag(root_nif_path)
                if tri_gender is 'NONE' and path.exists(root_nif_path):
                    target_nif = load_nif(root_nif_path, template = False, settings = {})
                    if not target_nif.valid:
                        tri_gender = 'NONE'
                    else:
                        tri_gender = target_nif.getGender()
                if gender_list:
                    mesh_ = template_mesh.get(tri_gender)
                    verts_ = template_verts.get(tri_gender)
                    if not mesh_ or not verts_:
                        print('Incorrect Gender:', this_file )
                        print('Closing', this_file )
                        return
                    
                elif tri_gender != current_settings['gender']:
                    print('Incorrect Gender:', this_file )
                    print('Closing', this_file )
                    return
        
            print('Processing', this_file)

            target_tri = load_tri(this_file, template = template_mesh, settings = current_settings)

            tri_mesh = target_tri.mesh
#             for a in zip(sorted([(vert.idx, vert.getLoc(world_loc = True).as_list()) for vert in tri_mesh.getVerts(nmv = True).values()], key = itemgetter(0)),
#             sorted([(vert.idx, vert.getLoc(world_loc = False).as_list()) for vert in template_mesh.getVerts(nmv = True).values()], key = itemgetter(0))):
#                 print (a)
            
            
            targets_found = mainSearch(current_settings, mesh_, tri_mesh, search_resolution = 1, vertFunction = setTriSeams, nmv = target_nmv, act_verts = verts_, tri = True, world_loc = True)

            save_file(target_tri, this_file, targets_found, current_settings)   
Ejemplo n.º 4
0
 def process_nif(this_path, test_file):
     #return
     if findall(r_nif, test_file) and test_file != current_settings['template']:
         print('Processing', test_file)
         target_nif = load_nif(path.join(this_path, test_file), template = template_mesh, settings = current_settings)
         #target_nif = load_nif(path.join(path, test_file))
         
         targets_found = 0
         for this_mesh in target_nif.meshes:
             mainSearch(current_settings, template_mesh, this_mesh, search_resolution = current_settings['res'], vertFunction = compareMatches)
             print('Displaying Results for', this_mesh.block.name)
             if current_settings.get('report'):
                 for v in this_mesh.verts.values():
                     print(v.idx, 'Exact Match: ', v.exact_match)
                     print('Detail View', v.match_results)
             else:
                 for v in this_mesh.verts.values():
                     if not v.exact_match:
                         print(v.idx, 'Exact Match: ', v.exact_match)
                         print('Detail View', v.match_results)
Ejemplo n.º 5
0
    def process_nif(this_file):
        #return
        print('Processing', test_file)
        target_nif = load_nif(this_file, template = template_mesh, settings = current_settings, init_skin = True)
        #target_nif = load_nif(path.join(path, test_file))
        target_bone_dict = dict([(bone_name, val['bone'])for this_mesh in target_nif.meshes
        for bone_name, val in this_mesh.bone_dict.items()])
                
        targets_found = 0
        for this_mesh in template_mesh.m_list:
            target_nif.copy_skin_instance(this_mesh.block)
            #list(target_nif.skeleton_root)[0].add_child(this_mesh.block)
            new_mesh = kg.mesh_util.mesh(target_nif, this_mesh.block)
            for bone_name, b in this_mesh.bone_dict.items():
                this_bone = target_bone_dict.get(bone_name, b['bone'])

                new_mesh.addBone( this_bone, dict([(v.index, v.weight) for v in b['weight' ]]))

        if current_settings['subfolder']:
            """Preserve the relative file structure in the output folder"""
            rel_path = path.relpath(this_path, start=current_settings['target'])
            output_folder = path.join(current_settings['destination'], rel_path)
            if not path.exists(output_folder):
                makedirs(output_folder)
                print ('Folder not found.  Adding ' + output_folder)
        else:
            output_folder = current_settings['destination']
            
        if current_settings.get('combine_material'):
            print('Merging Duplicate Blocks')
            toaster = NifToaster()
            SpellMergeDuplicates(data=target_nif.data, toaster=toaster).recurse()
            
        if current_settings.get('combine_name'):
            template_path, template_filename = path.split(current_settings['template'])
            test_file = sub(r_nif, '_', test_file) + template_filename
        target_nif.save(output_folder,test_file)
Ejemplo n.º 6
0
def Main():
    print (current_settings.get('Game'))
    def process_morph(test_file, bone_list, morph_dict):
        print('Processing', test_file)
        target_nif = load_nif(test_file, template = template_mesh, settings = current_settings)
        if not target_nif.valid:
            print(test_file,'Could Not Be Processed')
            return
        
        targets_found = 0
        for this_mesh in target_nif.meshes:
            targets_found += mainSearch(current_settings, template_mesh, this_mesh, search_resolution = 1, vertFunction = setWeightDictionary, side = side)
            
        save_file(target_nif, test_file, targets_found, current_settings, morph_dict = morph_dict)
            
    def process_nif(test_file, bone_list):
        print('Processing', test_file)
        target_nif = load_nif(test_file, template = template_mesh, settings = current_settings)
        if not target_nif.valid:
            print(test_file,'Could Not Be Processed')
        
        targets_found = 0
        for this_mesh in target_nif.meshes:
            targets_found += mainSearch(current_settings, template_mesh, this_mesh, search_resolution = 1, vertFunction = setWeightDictionary, side = side)

        save_file(target_nif, test_file, targets_found, current_settings)
    
    if not path.exists(current_settings['destination']):
        makedirs(current_settings['destination'])
        
    template_mesh = None
    
    if path.exists(current_settings['template']):
        template_mesh = loadTemplate(current_settings['template'], settings = current_settings)
        if not template_mesh:
            print('No Valid Blocks found on Template Mesh, Exiting')
            return
        skeleton = current_settings.get('template_s')
        template_mesh.loadSkeleton(skeleton)
    
        bone_list = current_settings['bone_list'] = sorted(list(template_mesh.bone_dict.keys()))
        #print(bone_list)
        if current_settings['select_bones']:
            bone_menu = ui_tools.boneMenu(bone_list, side = side)
            current_settings['bone_list'] = bone_menu.openMenu()
            #print (bone_list)
            try: bone_menu.destroy()
            except: pass

    if not template_mesh:
        print('Template Not Found, Exiting')
        return

    if current_settings.get('template_s'):
        print('Generating Bone Dictionary from Skeleton')
        skeleton = kg.file_util.load_nif(current_settings['template_s'], settings = current_settings, skeleton_only = True)
        for b_data in skeleton.bone_dict.values():
            if b_data.get('is_skel_root'):
                root = b_data
                break
                
        for bone_name, bone_data in template_mesh.lno.bone_dict.items():
            if bone_name not in skeleton.bone_dict and not bone_data.get('is_skel_root'):
                skeleton.bone_dict[bone_name] = bone_data
                root['children'].append(bone_name)
        template_mesh.lno.bone_dict = skeleton.bone_dict

        print('Skeleton Dictionary Generation Complete')

    nif_list, morph_set = kg.file_util.get_files(current_settings['target'], current_settings, tri = False)
    for test_file in nif_list:
        #print('test_file, test_file')
        process_nif(test_file, bone_list)
    if morph_set:
        morph_key = kg.file_util.getMorphType(current_settings.get('template'))
        if morph_key == 0:
            base = '_0.nif'
            morph = '_1.nif'
        else:
            base = '_1.nif'
            morph = '_0.nif'
        for this_morph in morph_set:
            base_file = this_morph + base
            morph_file = this_morph + morph
            #print(morph_file)
            morph_dict = {}
            print(morph_file)
            if path.exists(morph_file):
                morph_nif = load_nif(morph_file, template = False, settings = current_settings, init_skin = False, init_mesh = False)
                morph_dict = {}
                for mesh_ in morph_nif.meshes:
                    #print(mesh_.block.name)
                    morph_dict[mesh_.block.name] = dict([(v_idx, (vert_.getLoc(world_loc = False), vert_.getNormal(world_loc = False))) for v_idx, vert_ in mesh_.verts.items()])
                morph_nif.nif_file.close()    
            #print(morph_dict)
            process_morph(base_file, bone_list, morph_dict)