Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_character(self, data_source, reset_string = "nothing", reset_unassigned=True, mix=False, update_mode = "update_all"):
obj = self.get_object()
log_msg_type = "character data"
if type(data_source) == str: #TODO: better check of types
log_msg_type = algorithms.simple_path(data_source)
charac_data = algorithms.load_json_data(data_source,"Character data")
else:
charac_data = data_source
algorithms.print_log_report("INFO","Loading character from {0}".format(log_msg_type))
if "manuellab_vers" in charac_data:
if not algorithms.check_version(charac_data["manuellab_vers"]):
algorithms.print_log_report("WARNING","{0} created with vers. {1}. Current vers is {2}".format(log_msg_type,charac_data["manuellab_vers"],self.lab_vers))
else:
algorithms.print_log_report("INFO","No lab version specified in {0}".format(log_msg_type))
if "structural" in charac_data:
char_data = charac_data["structural"]
else:
algorithms.print_log_report("WARNING","No structural data in {0}".format(log_msg_type))
def load_measures(self, filepath):
char_data = algorithms.load_json_data(filepath, "Measures data")
if not ("measures" in char_data):
algorithms.print_log_report("ERROR","This json has not the measures info, {0}".format(algorithms.simple_path(filepath)))
return None
c_data = char_data["measures"]
return c_data
m_data = algorithms.load_json_data(morph_data_path,"Morph data")
if m_data:
for morph_name, deltas in m_data.items():
morph_deltas = []
modified_verts = set()
for d_data in deltas:
t_delta = mathutils.Vector(d_data[1:])
morph_deltas.append([d_data[0], t_delta])
modified_verts.add(d_data[0])
if morph_name in self.morph_data:
algorithms.print_log_report("WARNING","Morph {0} duplicated while loading morphs from file".format(morph_name))
self.morph_data[morph_name] = morph_deltas
self.morph_values[morph_name] = 0.0
self.morph_modified_verts[morph_name] = modified_verts
algorithms.print_log_report("INFO","Morph database {0} loaded in {1} secs".format(algorithms.simple_path(morph_data_path),time.time()-time1))
algorithms.print_log_report("INFO","Now local morph data contains {0} elements".format(len(self.morph_data)))
def generate_displacement_image(self):
disp_data_image_name = self.image_file_names["displ_data"]
if disp_data_image_name != "":
disp_data_image = algorithms.get_image(disp_data_image_name)
if disp_data_image:
disp_size = disp_data_image.size
algorithms.print_log_report("INFO","Creating the displacement image from data image {0} with size {1}x{2}".format(disp_data_image.name, disp_size[0], disp_size[1]))
disp_img = algorithms.new_image(self.image_file_names["body_displ"], disp_size)
else:
algorithms.print_log_report("WARNING","Cannot create the displacement modifier: data image not found: {0}".format(algorithms.simple_path(self.image_file_paths["displ_data"])))
group_names = sorted(g_data.keys())
for group_name in group_names:
new_group = algorithms.new_vertgroup(obj, group_name)
for vert_data in g_data[group_name]:
if use_weights:
if type(vert_data) == list:
new_group.add([vert_data[0]], vert_data[1], 'REPLACE')
else:
algorithms.print_log_report("INFO","Error: wrong format for vert weight")
else:
if type(vert_data) == int:
new_group.add([vert_data], 1.0, 'REPLACE')
else:
algorithms.print_log_report("INFO","Error: wrong format for vert group")
algorithms.print_log_report("INFO","Group loaded from {0}".format(algorithms.simple_path(filepath)))
else:
algorithms.print_log_report("WARNING","Vgroup file problem {0}".format(algorithms.simple_path(filepath)))
def load_expression(self, filepath):
charac_data = algorithms.load_json_data(filepath,"Character data")
expressions_ID = algorithms.simple_path(filepath)
if "manuellab_vers" in charac_data:
if not algorithms.check_version(charac_data["manuellab_vers"]):
algorithms.print_log_report("INFO","{0} created with vers. {1}.".format(expressions_ID,charac_data["manuellab_vers"]))
else:
algorithms.print_log_report("INFO","No lab version specified in {0}".format(expressions_ID))
if "structural" in charac_data:
char_data = charac_data["structural"]
else:
algorithms.print_log_report("WARNING","No structural data in {0}".format(expressions_ID))
char_data = None
return char_data
def error_msg(self, path):
algorithms.print_log_report("ERROR","Database file not found: {0}".format(algorithms.simple_path(path)))