Esempio n. 1
0
def mendSeamDoubles(vert_list):
    if not vert_list:
        return
    divisor = 1.0 / float(len(vert_list))
    average_loc = vector([0, 0, 0])
    average_normal = vector([0, 0, 0])
    norm_list = []
    weight_dict = {}
    set_normal = 0
    for v in vert_list:

        average_loc += divisor * v.getLoc(world_loc=False)

        if v.getNormal():
            norm_list.append(v.getNormal())
            set_normal += 1

        for bone, weight in v.getWeight():
            weight *= divisor
            if bone not in weight_dict:
                weight_dict[bone] = weight
            else:
                weight_dict[bone] += weight

    if set_normal > 0:
        n_div = 1.0 / float(set_normal)
        for norm in norm_list:
            average_normal += n_div * norm
    else:
        average_normal = None

    for v in vert_list:
        v.setLoc(average_loc, world_loc=False)
        v.setNormal(average_normal, world_loc=False, normalize=True)
        v.weight_dict = weight_dict
Esempio n. 2
0
 def __init__(
     self,\
     vert_dict,\
     bone_dict\
 ):
 
     mesh_vert_dict = {}
     for mesh_name, v_dict in vert_dict.items():
         mesh_vert_dict[mesh_name] = {}
         for v_idx, v_data in v_dict.items():
             this_vert = vertex(v_idx, init = False)
             this_vert.loc = vector(v_data['loc'])
             if 'w_loc' in v_data:
                 this_vert.w_loc = vector(v_data['w_loc'])
             else:
                 this_vert.loc = vector(v_data['loc'])
             this_vert.normal = vector(v_data['norm'])
             this_vert.weight_dict = v_data['wd']
             this_vert.NMV = True
             mesh_vert_dict[mesh_name] = this_vert   
     self.mesh_vert_dict = mesh_vert_dict
     self.v_list = [v for v in self.mesh_vert_dict.values()]
     self.verts = dict([(i, vert) for i, vert in enumerate(self.v_list)])
     self.non_nmv_verts = {}
     self.nmv_verts = self.verts
     self.bone_dict = dict([(bone_name, {'bone': bone}) for bone_name, bone in bone_dict.items()])
Esempio n. 3
0
def combine_influences(influence_list, world_loc = True, travel_mod = False, Normal = False, BoneWeight = False, loc_list = False):

    #global time1
    #global time2
    #global time3
    #global time4
    if type(influence_list[0][0]) == vector2:
        average_vector = vector([0,0])
    else:   
        average_vector = vector([0,0,0])
    
    if not influence_list:
        if BoneWeight:
            return {}
        return average_vector

    influence_list = NormalizeInfluence(list(influence_list))

#     if loc_list:
#         for loc, influence in influence_list:
#             average_vector = average_vector + (loc * influence)
#         return average_vector

    if Normal:
        #Combine the Normal vectors from the vertexes on the influence list
        for vert, influence in influence_list:
            average_vector = average_vector + (vert.getNormal(world_loc = world_loc) * influence)
        return average_vector

    if BoneWeight:

        #print 'BoneWeight True'

        #Combine the weights from the vertexes on the influence list
        #timeA = time()
        """
        Build the skeleton of the dictionary
        """
        weightDictionary = dict([(this_group, 0.0)
            for this_group in set(
            this_group for inf_vert, influence in influence_list
            for this_group in inf_vert.getWeight().keys())
        ])
        #time1 += timeA - time()
        #timeA = time()
        """
        Add the weight values to the dictionary
        """
        for inf_vert, influence in influence_list:
            for this_group, weight in inf_vert.getWeight().items():
                weightDictionary[this_group] += weight * influence
        #time2 += timeA - time()

        return weightDictionary

    for vert, influence in influence_list:
        average_vector = average_vector + (vert.getLoc(world_loc = world_loc, travel_mod = travel_mod) * influence)

    return average_vector
Esempio n. 4
0
 def __init__(self, idx, vert=False, mesh=False, init=True):
     self.idx = idx
     if init:
         self.mesh = mesh
         self.data = mesh.niData
         self.vert = vert
         self.loc = vector([vert.x, vert.y, vert.z])
         # print(self.loc)
         self.w_loc = False
         try:
             self.normal = self.data.normals[idx]
         except:
             self.normal = False
     self.uv = False
     self.influence_list = []
     self.travel_mod = False
     self.searchModifiers = []
     self.search_mod = False
     self.doubles = None
     self.edges = set()
     self.NMV = None
     self.weight_dict = {}
     self.side = False
     self.BDPartition = []
     self.exact_match = False
     self.match_results = {}
Esempio n. 5
0
 def getSearchLoc(self, world_loc=True):
     if not self.search_mod:
         if self.searchModifiers:
             self.search_mod = getAverageVector(self.searchModifiers)
         else:
             return vector([0, 0, 0])
     if world_loc:
         return self.search_mod + self.getLoc(world_loc=True)
     return self.search_mod * self.mesh.mat_i + self.getLoc(world_loc=False)
Esempio n. 6
0
def unWrapBone(bone_values, root_transform = False, correction_vector = vector([0,0,0])):

    this_bone = NifFormat.NiNode()
    #this_bone.collision_object = bone_values['collision_object']
    #this_bone.controller = bone_values['controller']
    #this_bone.extra_data = bone_values['extra_data']
    this_bone.flags = bone_values['flags']
    this_bone.has_bounding_box = bone_values['has_bounding_box']
    this_bone.has_old_extra_data = bone_values['has_old_extra_data']
    this_bone.name = bone_values['name']
    #this_bone.num_children = bone_values['num_children']
    this_bone.num_effects = bone_values['num_effects']
    #this_bone.num_extra_data_list = bone_values['num_extra_data_list']
    this_bone.num_properties = bone_values['num_properties']
    this_bone.old_extra_internal_id = bone_values['old_extra_internal_id']
    this_bone.old_extra_prop_name = bone_values['old_extra_prop_name']
    this_bone.old_extra_string = bone_values['old_extra_string']
    #this_bone.scale = bone_values['scale']
    this_bone.unknown_2 = bone_values['unknown_2']
    this_bone.unknown_byte = bone_values['unknown_byte']
    this_bone.unknown_short_1 = bone_values['unknown_short_1']
    #this_bone.rotation = kg.math_util.matrix3x3(bone_values['rotation'])
    #this_bone.translation = kg.math_util.vector(bone_values['translation'])
    this_bone.velocity = kg.math_util.vector(bone_values['velocity'])
    update_array(this_bone.properties, bone_values['properties'])
    update_array(this_bone.unknown_1, bone_values['unknown_1'])
    #update_array(this_bone.extra_data_list, bone_values['extra_data_list'])
    #update_array(this_bone.effects, bone_values['effects'])
    update_array(this_bone.properties, bone_values['properties'])
    b_box_data = bone_values['bounding_box']
    b_box = NifFormat.BoundingBox()
    b_box.radius = kg.math_util.vector(b_box_data['radius'])
    b_box.rotation = kg.math_util.matrix3x3(b_box_data['rotation'])
    b_box.translation = kg.math_util.vector(b_box_data['translation'])
    b_box.unknown_int = b_box_data['unknown_int']
    
    if root_transform:
        this_bone.set_transform(kg.math_util.matrix4x4(bone_values['root_transform']))
    else:
        this_bone.scale = bone_values['scale']
        this_bone.rotation = kg.math_util.matrix3x3(bone_values['rotation'])
        this_bone.translation = kg.math_util.vector(bone_values['translation'])
    this_bone.translation += correction_vector
    return this_bone
Esempio n. 7
0
    def getLoc(self, world_loc=True, search_loc=False, travel_mod=False, flip_x_axis=False):

        if world_loc and not self.w_loc:
            self.w_loc = self.loc * self.mesh.mat

        if world_loc:
            temp_loc = self.w_loc
        else:
            temp_loc = self.loc

        if search_loc:
            temp_loc = temp_loc + self.getSearchLoc(world_loc=world_loc)
        elif travel_mod:
            temp_loc = temp_loc + self.getTravelMod()

        if flip_x_axis:
            temp_loc = vector(temp_loc.as_list())
            temp_loc.x = -1 * temp_loc.x

        return temp_loc
Esempio n. 8
0
 def getTravelMod(self):
     if self.travel_mod:
         return self.travel_mod
     self.travel_mod = vector([0, 0, 0])
     return self.travel_mod