def __call__(self, images_to_convert, refresh_rc, save_tiff): for image in images_to_convert: rc_params = self.__get_rc_params(refresh_rc, image.filepath) tiff_image_path = self.__get_temp_tiff_image_path(image) tiff_image_for_rc = utils.get_absolute_path_for_rc(tiff_image_path) try: create_normal_texture() except: cbPrint("Failed to invert green channel") rc_process = utils.run_rc(self.__rc_exe, tiff_image_for_rc, rc_params) # re-save the original image after running the RC to # prevent the original one from getting lost try: if ("_ddn" in image.name): image.save() except: cbPrint("Failed to invert green channel") rc_process.wait() if save_tiff: self.__save_tiffs() self.__remove_tmp_files()
def fix_weights(): for object_ in get_type("skins"): override = get_3d_context(object_) try: bpy.ops.object.vertex_group_normalize_all(override, lock_active=False) except: raise exceptions.CryBlendException("Please fix weightless vertices first.") cbPrint("Weights Corrected.")
def __remove_tmp_files(self): for tmp_image in self.__tmp_images: try: cbPrint("Removing tmp image: {!r}".format(tmp_image), 'debug') os.remove(tmp_image) except FileNotFoundError: pass os.removedirs(self.__tmp_dir) self.__tmp_images.clear()
def fix_weights(): for object_ in get_type("skins"): override = get_3d_context(object_) try: bpy.ops.object.vertex_group_normalize_all(override, lock_active=False) except: raise exceptions.CryBlendException( "Please fix weightless vertices first.") cbPrint("Weights Corrected.")
def __load(self, current_configuration): new_configuration = {} new_configuration.update(self.__DEFAULT_CONFIGURATION) new_configuration.update(current_configuration) if os.path.isfile(self.__CONFIG_FILEPATH): try: with open(self.__CONFIG_FILEPATH, 'rb') as f: new_configuration.update(pickle.load(f)) cbPrint('Configuration file loaded.') except: cbPrint("[IO] can not read: %s" % self.__CONFIG_FILEPATH, 'error') return new_configuration
def save(self): cbPrint("Saving configuration file.", 'debug') if os.path.isdir(self.__CONFIG_PATH): try: with open(self.__CONFIG_FILEPATH, 'wb') as f: pickle.dump(self.__CONFIG, f, -1) cbPrint("Configuration file saved.") cbPrint('Saved %s' % self.__CONFIG_FILEPATH) except: cbPrint("[IO] can not write: %s" % self.__CONFIG_FILEPATH, 'error') else: cbPrint("Configuration file path is missing %s" % self.__CONFIG_PATH, 'error')
def save(self): cbPrint("Saving configuration file.", 'debug') if os.path.isdir(self.__CONFIG_PATH): try: with open(self.__CONFIG_FILEPATH, 'wb') as f: pickle.dump(self.__CONFIG, f, -1) cbPrint("Configuration file saved.") cbPrint('Saved %s' % self.__CONFIG_FILEPATH) except: cbPrint("[IO] can not write: %s" % self.__CONFIG_FILEPATH, 'error') else: cbPrint( "Configuration file path is missing %s" % self.__CONFIG_PATH, 'error')
def __get_temp_tiff_image_path(self, image): # check if the image already is a .tif image_extension = utils.get_extension_from_path(image.filepath) cbPrint(image_extension) if ".tif" == image_extension: cbPrint("Image {!r} is already a tif, not converting".format(image.name), "debug") return image.filepath tiff_image_path = utils.get_path_with_new_extension(image.filepath, "tif") tiff_image_absolute_path = utils.get_absolute_path(tiff_image_path) tiff_file_name = os.path.basename(tiff_image_path) tmp_file_path = os.path.join(self.__tmp_dir, tiff_file_name) if tiff_image_path != image.filepath: self.__save_as_tiff(image, tmp_file_path) self.__tmp_images[tmp_file_path] = tiff_image_absolute_path return tmp_file_path
def __get_temp_tiff_image_path(self, image): # check if the image already is a .tif image_extension = utils.get_extension_from_path(image.filepath) cbPrint(image_extension) if ".tif" == image_extension: cbPrint("Image {!r} is already a tif, not converting".format(image.name), 'debug') return image.filepath tiff_image_path = utils.get_path_with_new_extension(image.filepath, "tif") tiff_image_absolute_path = utils.get_absolute_path(tiff_image_path) tiff_file_name = os.path.basename(tiff_image_path) tmp_file_path = os.path.join(self.__tmp_dir, tiff_file_name) if tiff_image_path != image.filepath: self.__save_as_tiff(image, tmp_file_path) self.__tmp_images[tmp_file_path] = (tiff_image_absolute_path) return tmp_file_path
def run_rc(rc_path, files_to_process, params=None): cbPrint(rc_path) process_params = [rc_path] if isinstance(files_to_process, list): process_params.extend(files_to_process) else: process_params.append(files_to_process) process_params.extend(params) cbPrint(params) cbPrint(files_to_process) try: run_object = subprocess.Popen(process_params) except: raise exceptions.NoRcSelectedException return run_object
def __save_tiffs(self): for tmp_image, dest_image in self.__tmp_images.items(): cbPrint("Moving tmp image: {!r} to {!r}".format(tmp_image, dest_image), 'debug') shutil.move(tmp_image, dest_image)