def execute(self, context): if hasattr(self, "pre_cb"): self.pre_cb(context) preset_menu_class = getattr(bpy.types, self.preset_menu) if not self.remove_active: if not self.name: return {'FINISHED'} filename = clean_name(self.name) target_path = os.path.join(sys.path[0], "yafaray", "presets", self.preset_subdir) if not target_path: self.report({'WARNING'}, "Failed to create presets path") return {'CANCELLED'} filepath = os.path.join(target_path, filename) + ".py" if hasattr(self, "add"): self.add(context, filepath) else: file_preset = open(filepath, 'w') file_preset.write("import bpy\n") if hasattr(self, "preset_defines"): for rna_path in self.preset_defines: exec(rna_path) file_preset.write("%s\n" % rna_path) file_preset.write("\n") for rna_path in self.preset_values: value = eval(rna_path) if type(value) == float: # formatting of the floating point values value = round(value, 4) if str(value).startswith('Color'): # formatting of the Color Vectors (r,g,b) r, g, b = round(value.r, 3), round(value.g, 3), round(value.b, 3) file_preset.write("%s = %r, %r, %r\n" % (rna_path, r, g, b)) else: try: # convert thin wrapped sequences to simple lists to repr() value = value[:] except: pass file_preset.write("%s = %r\n" % (rna_path, value)) file_preset.close() preset_menu_class.bl_label = display_name(filename) else: preset_active = preset_menu_class.bl_label target_path = os.path.join(sys.path[0], "yafaray", "presets", self.preset_subdir) filepath = yaf_preset_find(preset_active, target_path) if not filepath: filepath = yaf_preset_find(preset_active, target_path, disp_name=True) if not filepath: return {'CANCELLED'} if hasattr(self, "remove"): self.remove(context, filepath) else: try: os.remove(filepath) except: import traceback print("No Preset there to remove...") # XXX stupid: Print bl_label on menu selector... preset_menu_class.bl_label = self.bl_label if hasattr(self, "post_cb"): self.post_cb(context) return {'FINISHED'}
def writeTexture(self, scene, tex): name = tex.name if name in self.loadedTextures: return yi = self.yi yi.paramsClearAll() textureConfigured = False if tex.yaf_tex_type == 'BLEND': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "blend") switchBlendType = { 'LINEAR': 'lin', 'QUADRATIC': 'quad', 'EASING': 'ease', 'DIAGONAL': 'diag', 'SPHERICAL': 'sphere', 'QUADRATIC_SPHERE': 'halo', 'RADIAL': 'radial', } stype = switchBlendType.get(tex.progression, 'lin') # set blend type for blend texture, default is 'lin' yi.paramsSetString("stype", stype) textureConfigured = True elif tex.yaf_tex_type == 'CLOUDS': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "clouds") noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetBool("hard", hard) yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) textureConfigured = True elif tex.yaf_tex_type == 'WOOD': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "wood") yi.paramsSetInt("depth", 0) turb = 0.0 noise_size = 0.25 hard = True if tex.wood_type == 'BANDNOISE' or tex.wood_type == 'RINGNOISE': turb = tex.turbulence noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'SOFT_NOISE': hard = False yi.paramsSetFloat("turbulence", turb) yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) ts = "bands" if tex.wood_type == 'RINGS' or tex.wood_type == 'RINGNOISE': ts = "rings" yi.paramsSetString("wood_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) # shape parameter if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'MARBLE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "marble") yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetFloat("turbulence", tex.turbulence) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) sharp = 4.0 if tex.marble_type == 'SOFT': sharp = 2.0 elif tex.marble_type == 'SHARP': sharp = 4.0 elif tex.marble_type == 'SHARPER': sharp = 8.0 yi.paramsSetFloat("sharpness", sharp) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'VORONOI': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "voronoi") if tex.color_mode == 'POSITION': ts = "col1" elif tex.color_mode == 'POSITION_OUTLINE': ts = "col2" elif tex.color_mode == 'POSITION_OUTLINE_INTENSITY': ts = "col3" else: ts = "int" yi.paramsSetString("color_type", ts) yi.paramsSetFloat("weight1", tex.weight_1) yi.paramsSetFloat("weight2", tex.weight_2) yi.paramsSetFloat("weight3", tex.weight_3) yi.paramsSetFloat("weight4", tex.weight_4) yi.paramsSetFloat("mk_exponent", tex.minkovsky_exponent) yi.paramsSetFloat("intensity", tex.noise_intensity) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) switchDistMetric = { 'DISTANCE_SQUARED': 'squared', 'MANHATTAN': 'manhattan', 'CHEBYCHEV': 'chebychev', 'MINKOVSKY_HALF': 'minkovsky_half', 'MINKOVSKY_FOOUR': 'minkovsky_four', 'MINKOVSKY': 'minkovsky', } ts = switchDistMetric.get(tex.distance_metric, 'minkovsky') # set distance metric for VORONOI Texture, default is 'minkovsky' yi.paramsSetString("distance_metric", ts) textureConfigured = True elif tex.yaf_tex_type == 'MUSGRAVE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "musgrave") switchMusgraveType = { 'MULTIFRACTAL': 'multifractal', 'RIDGED_MULTIFRACTAL': 'ridgedmf', 'HYBRID_MULTIFRACTAL': 'hybridmf', 'HETERO_TERRAIN': 'heteroterrain', 'FBM': 'fBm', } ts = switchMusgraveType.get(tex.musgrave_type, 'multifractal') # set MusgraveType, default is 'multifractal' yi.paramsSetString("musgrave_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) yi.paramsSetFloat("H", tex.dimension_max) yi.paramsSetFloat("lacunarity", tex.lacunarity) yi.paramsSetFloat("octaves", tex.octaves) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetFloat("offset", tex.offset) yi.paramsSetFloat("intensity", tex.noise_intensity) yi.paramsSetFloat("gain", tex.gain) textureConfigured = True elif tex.yaf_tex_type == 'DISTORTED_NOISE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "distorted_noise") yi.paramsSetFloat("distort", tex.distortion) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetString("noise_type1", noise2string(tex.noise_basis)) yi.paramsSetString("noise_type2", noise2string(tex.noise_distortion)) textureConfigured = True elif tex.yaf_tex_type == 'IMAGE' and tex.image and tex.image.source in {'FILE', 'GENERATED'}: filename = os.path.splitext(os.path.basename(bpy.data.filepath))[0] if not any(filename): filename = "untitled" save_dir = os.path.expanduser("~") else: save_dir = "//" filename = clean_name(filename) fileformat = scene.render.image_settings.file_format.lower() extract_path = os.path.join(filename, "{:05d}".format(scene.frame_current)) if tex.image.source == 'GENERATED': image_tex = "yaf_baked_image_{0}.{1}".format(clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) if tex.image.source == 'FILE': if tex.image.packed_file: image_tex = "yaf_extracted_image_{0}.{1}".format(clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) else: if tex.image.library is not None: image_tex = abspath(tex.image.filepath, library=tex.image.library) else: image_tex = abspath(tex.image.filepath) if not os.path.exists(image_tex): yi.printError("Exporter: Image texture {0} not found on: {1}".format(tex.name, image_tex)) return False image_tex = os.path.realpath(image_tex) image_tex = os.path.normpath(image_tex) yi.printInfo("Exporter: Creating Texture: '{0}' type {1}: {2}".format(name, tex.yaf_tex_type, image_tex)) yi.paramsSetString("type", "image") yi.paramsSetString("filename", image_tex) yi.paramsSetBool("use_alpha", tex.yaf_use_alpha) yi.paramsSetBool("calc_alpha", tex.use_calculate_alpha) yi.paramsSetBool("normalmap", tex.yaf_is_normal_map) yi.paramsSetFloat("gamma", scene.gs_gamma_input) # repeat repeat_x = 1 repeat_y = 1 if tex.extension == 'REPEAT': repeat_x = tex.repeat_x repeat_y = tex.repeat_y yi.paramsSetInt("xrepeat", repeat_x) yi.paramsSetInt("yrepeat", repeat_y) # clipping extension = tex.extension switchExtension = { 'EXTEND': 'extend', 'CLIP': 'clip', 'CLIP_CUBE': 'clipcube', 'CHECKER': 'checker', } clipping = switchExtension.get(extension, 'repeat') # set default clipping to 'repeat' yi.paramsSetString("clipping", clipping) if clipping == 'checker': yi.paramsSetBool("even_tiles", tex.use_checker_even) yi.paramsSetBool("odd_tiles", tex.use_checker_odd) # crop min/max yi.paramsSetFloat("cropmin_x", tex.crop_min_x) yi.paramsSetFloat("cropmin_y", tex.crop_min_y) yi.paramsSetFloat("cropmax_x", tex.crop_max_x) yi.paramsSetFloat("cropmax_y", tex.crop_max_y) yi.paramsSetBool("rot90", tex.use_flip_axis) textureConfigured = True if textureConfigured: yi.createTexture(name) self.loadedTextures.add(name) return textureConfigured
def check(self, context): self.name = clean_name(self.name)
def execute(self, context): if hasattr(self, "pre_cb"): self.pre_cb(context) preset_menu_class = getattr(bpy.types, self.preset_menu) if not self.remove_active: if not self.name: return {'FINISHED'} filename = clean_name(self.name) home_dir = os.path.expanduser("~") target_path = os.path.join(home_dir, "yafaray_userdata", "presets", self.preset_subdir) if not os.path.exists(target_path): os.makedirs(target_path) if not target_path: self.report({'WARNING'}, "Failed to create presets path") return {'CANCELLED'} filepath = os.path.join(target_path, filename) + ".py" if hasattr(self, "add"): self.add(context, filepath) else: file_preset = open(filepath, 'w') file_preset.write("import bpy\n") if hasattr(self, "preset_defines"): for rna_path in self.preset_defines: exec(rna_path) file_preset.write("%s\n" % rna_path) file_preset.write("\n") for rna_path in self.preset_values: value = eval(rna_path) if type(value) == float: # formatting of the floating point values value = round(value, 4) if str(value).startswith('Color'): # formatting of the Color Vectors (r,g,b) r, g, b = round(value.r, 3), round(value.g, 3), round(value.b, 3) file_preset.write("%s = %r, %r, %r\n" % (rna_path, r, g, b)) else: try: # convert thin wrapped sequences to simple lists to repr() value = value[:] except: pass file_preset.write("%s = %r\n" % (rna_path, value)) file_preset.close() preset_menu_class.bl_label = display_name(filename) else: preset_active = preset_menu_class.bl_label home_dir = os.path.expanduser("~") target_path = os.path.join(home_dir, "yafaray_userdata", "presets", self.preset_subdir) if not os.path.exists(target_path): os.makedirs(target_path) filepath = yaf_preset_find(preset_active, target_path) if not filepath: filepath = yaf_preset_find(preset_active, target_path, disp_name=True) if not filepath: return {'CANCELLED'} if hasattr(self, "remove"): self.remove(context, filepath) else: try: os.remove(filepath) except: import traceback print("No Preset there to remove...") # XXX stupid: Print bl_label on menu selector... preset_menu_class.bl_label = self.bl_label if hasattr(self, "post_cb"): self.post_cb(context) return {'FINISHED'}
def writeTexture(self, scene, tex): name = tex.name if name in self.loadedTextures: return yi = self.yi yi.paramsClearAll() textureConfigured = False yi.paramsSetBool("img_grayscale", tex.yaf_img_grayscale) yi.paramsSetFloat("adj_mult_factor_red", tex.factor_red) yi.paramsSetFloat("adj_mult_factor_green", tex.factor_green) yi.paramsSetFloat("adj_mult_factor_blue", tex.factor_blue) yi.paramsSetFloat("adj_intensity", tex.intensity) yi.paramsSetFloat("adj_contrast", tex.contrast) yi.paramsSetFloat("adj_saturation", tex.saturation) yi.paramsSetFloat("adj_hue", math.degrees(tex.yaf_adj_hue)) yi.paramsSetFloat("trilinear_level_bias", tex.yaf_trilinear_level_bias) yi.paramsSetFloat("ewa_max_anisotropy", tex.yaf_ewa_max_anisotropy) yi.paramsSetBool("adj_clamp", tex.use_clamp) if tex.use_color_ramp: yi.paramsSetBool("use_color_ramp", tex.use_color_ramp) yi.paramsSetString("ramp_color_mode", tex.color_ramp.color_mode) yi.paramsSetString("ramp_hue_interpolation", tex.color_ramp.hue_interpolation) yi.paramsSetString("ramp_interpolation", tex.color_ramp.interpolation) i = 0 for item in tex.color_ramp.elements: yi.paramsSetColor("ramp_item_%x_color" % i, item.color[0], item.color[1], item.color[2], item.color[3]) yi.paramsSetFloat("ramp_item_%x_alpha" % i, item.alpha) yi.paramsSetFloat("ramp_item_%x_position" % i, item.position) i += 1 yi.paramsSetInt("ramp_num_items", i) if tex.yaf_tex_type == 'BLEND': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "blend") switchBlendType = { 'LINEAR': 'lin', 'QUADRATIC': 'quad', 'EASING': 'ease', 'DIAGONAL': 'diag', 'SPHERICAL': 'sphere', 'QUADRATIC_SPHERE': 'halo', 'RADIAL': 'radial', } stype = switchBlendType.get( tex.progression, 'lin') # set blend type for blend texture, default is 'lin' yi.paramsSetString("stype", stype) if tex.use_flip_axis == "HORIZONTAL": yi.paramsSetBool("use_flip_axis", False) if tex.use_flip_axis == "VERTICAL": yi.paramsSetBool("use_flip_axis", True) textureConfigured = True elif tex.yaf_tex_type == 'CLOUDS': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "clouds") noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetBool("hard", hard) yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) textureConfigured = True elif tex.yaf_tex_type == 'WOOD': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "wood") yi.paramsSetInt("depth", 0) turb = 0.0 noise_size = 0.25 hard = True if tex.wood_type == 'BANDNOISE' or tex.wood_type == 'RINGNOISE': turb = tex.turbulence noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'SOFT_NOISE': hard = False yi.paramsSetFloat("turbulence", turb) yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) ts = "bands" if tex.wood_type == 'RINGS' or tex.wood_type == 'RINGNOISE': ts = "rings" yi.paramsSetString("wood_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) # shape parameter if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'MARBLE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "marble") yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetFloat("turbulence", tex.turbulence) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) sharp = 4.0 if tex.marble_type == 'SOFT': sharp = 2.0 elif tex.marble_type == 'SHARP': sharp = 4.0 elif tex.marble_type == 'SHARPER': sharp = 8.0 yi.paramsSetFloat("sharpness", sharp) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'VORONOI': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "voronoi") if tex.color_mode == 'POSITION': ts = "col1" elif tex.color_mode == 'POSITION_OUTLINE': ts = "col2" elif tex.color_mode == 'POSITION_OUTLINE_INTENSITY': ts = "col3" else: ts = "int" yi.paramsSetString("color_type", ts) yi.paramsSetFloat("weight1", tex.weight_1) yi.paramsSetFloat("weight2", tex.weight_2) yi.paramsSetFloat("weight3", tex.weight_3) yi.paramsSetFloat("weight4", tex.weight_4) yi.paramsSetFloat("mk_exponent", tex.minkovsky_exponent) yi.paramsSetFloat("intensity", tex.noise_intensity) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) switchDistMetric = { 'DISTANCE_SQUARED': 'squared', 'MANHATTAN': 'manhattan', 'CHEBYCHEV': 'chebychev', 'MINKOVSKY_HALF': 'minkovsky_half', 'MINKOVSKY_FOOUR': 'minkovsky_four', 'MINKOVSKY': 'minkovsky', } ts = switchDistMetric.get( tex.distance_metric, 'minkovsky' ) # set distance metric for VORONOI Texture, default is 'minkovsky' yi.paramsSetString("distance_metric", ts) textureConfigured = True elif tex.yaf_tex_type == 'MUSGRAVE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "musgrave") switchMusgraveType = { 'MULTIFRACTAL': 'multifractal', 'RIDGED_MULTIFRACTAL': 'ridgedmf', 'HYBRID_MULTIFRACTAL': 'hybridmf', 'HETERO_TERRAIN': 'heteroterrain', 'FBM': 'fBm', } ts = switchMusgraveType.get( tex.musgrave_type, 'multifractal') # set MusgraveType, default is 'multifractal' yi.paramsSetString("musgrave_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) yi.paramsSetFloat("H", tex.dimension_max) yi.paramsSetFloat("lacunarity", tex.lacunarity) yi.paramsSetFloat("octaves", tex.octaves) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetFloat("offset", tex.offset) yi.paramsSetFloat("intensity", tex.noise_intensity) yi.paramsSetFloat("gain", tex.gain) textureConfigured = True elif tex.yaf_tex_type == 'DISTORTED_NOISE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "distorted_noise") yi.paramsSetFloat("distort", tex.distortion) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetString("noise_type1", noise2string(tex.noise_basis)) yi.paramsSetString("noise_type2", noise2string(tex.noise_distortion)) textureConfigured = True elif tex.yaf_tex_type == 'IMAGE' and tex.image and tex.image.source in { 'FILE', 'GENERATED' }: filename = os.path.splitext(os.path.basename(bpy.data.filepath))[0] if not any(filename): filename = "untitled" save_dir = os.path.expanduser("~") else: save_dir = "//" filename = clean_name(filename) fileformat = scene.render.image_settings.file_format.lower() extract_path = os.path.join(filename, "{:05d}".format(scene.frame_current)) if tex.image.source == 'GENERATED': image_tex = "yaf_baked_image_{0}.{1}".format( clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) if tex.image.source == 'FILE': if tex.image.packed_file: image_tex = "yaf_extracted_image_{0}.{1}".format( clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) else: if tex.image.library is not None: image_tex = abspath(tex.image.filepath, library=tex.image.library) else: image_tex = abspath(tex.image.filepath) if not os.path.exists(image_tex): yi.printError( "Exporter: Image texture {0} not found on: {1}". format(tex.name, image_tex)) return False image_tex = os.path.realpath(image_tex) image_tex = os.path.normpath(image_tex) yi.paramsSetString("type", "image") yi.paramsSetString("filename", image_tex) yi.paramsSetBool("use_alpha", tex.yaf_use_alpha) yi.paramsSetBool("calc_alpha", tex.use_calculate_alpha) yi.paramsSetBool("normalmap", tex.yaf_is_normal_map) yi.paramsSetString("fileformat", fileformat.upper()) texture_color_space = "sRGB" texture_gamma = 1.0 if tex.image.colorspace_settings.name == "sRGB" or tex.image.colorspace_settings.name == "VD16": texture_color_space = "sRGB" elif tex.image.colorspace_settings.name == "XYZ": texture_color_space = "XYZ" elif tex.image.colorspace_settings.name == "Linear" or tex.image.colorspace_settings.name == "Linear ACES" or tex.image.colorspace_settings.name == "Non-Color": texture_color_space = "LinearRGB" elif tex.image.colorspace_settings.name == "Raw": texture_color_space = "Raw_Manual_Gamma" texture_gamma = tex.yaf_gamma_input #We only use the selected gamma if the color space is set to "Raw" yi.paramsSetString("color_space", texture_color_space) yi.paramsSetFloat("gamma", texture_gamma) if tex.yaf_tex_optimization == "default": texture_optimization = scene.gs_tex_optimization else: texture_optimization = tex.yaf_tex_optimization yi.printInfo( "Exporter: Creating Texture: '{0}' type {1}: {2}. Texture Color Space: '{3}', gamma={4}. Texture optimization='{5}'" .format(name, tex.yaf_tex_type, image_tex, texture_color_space, texture_gamma, texture_optimization)) yi.paramsSetString("interpolate", tex.yaf_tex_interpolate) yi.paramsSetString("texture_optimization", texture_optimization) # repeat repeat_x = 1 repeat_y = 1 if tex.extension == 'REPEAT': repeat_x = tex.repeat_x repeat_y = tex.repeat_y yi.paramsSetInt("xrepeat", repeat_x) yi.paramsSetInt("yrepeat", repeat_y) # clipping extension = tex.extension switchExtension = { 'EXTEND': 'extend', 'CLIP': 'clip', 'CLIP_CUBE': 'clipcube', 'CHECKER': 'checker', } clipping = switchExtension.get( extension, 'repeat') # set default clipping to 'repeat' yi.paramsSetString("clipping", clipping) if clipping == 'checker': yi.paramsSetBool("even_tiles", tex.use_checker_even) yi.paramsSetBool("odd_tiles", tex.use_checker_odd) # crop min/max yi.paramsSetFloat("cropmin_x", tex.crop_min_x) yi.paramsSetFloat("cropmin_y", tex.crop_min_y) yi.paramsSetFloat("cropmax_x", tex.crop_max_x) yi.paramsSetFloat("cropmax_y", tex.crop_max_y) yi.paramsSetBool("rot90", tex.use_flip_axis) yi.paramsSetBool("mirror_x", tex.use_mirror_x) yi.paramsSetBool("mirror_y", tex.use_mirror_y) textureConfigured = True if textureConfigured: yi.createTexture(name) self.loadedTextures.add(name) return textureConfigured
def writeTexture(self, scene, tex): name = tex.name if name in self.loadedTextures: return yi = self.yi yi.paramsClearAll() textureConfigured = False if tex.yaf_tex_type == 'BLEND': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "blend") stype = switchBlendType.get(tex.progression, 'lin') # set blend type for blend texture, default is 'lin' yi.paramsSetString("stype", stype) textureConfigured = True elif tex.yaf_tex_type == 'CLOUDS': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "clouds") noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetBool("hard", hard) yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) textureConfigured = True elif tex.yaf_tex_type == 'WOOD': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "wood") yi.paramsSetInt("depth", 0) turb = 0.0 noise_size = 0.25 hard = True if tex.wood_type == 'BANDNOISE' or tex.wood_type == 'RINGNOISE': turb = tex.turbulence noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'SOFT_NOISE': hard = False yi.paramsSetFloat("turbulence", turb) yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) ts = "bands" if tex.wood_type == 'RINGS' or tex.wood_type == 'RINGNOISE': ts = "rings" yi.paramsSetString("wood_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) # shape parameter if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'MARBLE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "marble") yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetFloat("turbulence", tex.turbulence) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) sharp = 4.0 if tex.marble_type == 'SOFT': sharp = 2.0 elif tex.marble_type == 'SHARP': sharp = 4.0 elif tex.marble_type == 'SHARPER': sharp = 8.0 yi.paramsSetFloat("sharpness", sharp) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'VORONOI': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "voronoi") if tex.color_mode == 'POSITION': ts = "col1" elif tex.color_mode == 'POSITION_OUTLINE': ts = "col2" elif tex.color_mode == 'POSITION_OUTLINE_INTENSITY': ts = "col3" else: ts = "int" yi.paramsSetString("color_type", ts) yi.paramsSetFloat("weight1", tex.weight_1) yi.paramsSetFloat("weight2", tex.weight_2) yi.paramsSetFloat("weight3", tex.weight_3) yi.paramsSetFloat("weight4", tex.weight_4) yi.paramsSetFloat("mk_exponent", tex.minkovsky_exponent) yi.paramsSetFloat("intensity", tex.noise_intensity) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) ts = switchDistMetric.get(tex.distance_metric, 'minkovsky') yi.paramsSetString("distance_metric", ts) textureConfigured = True elif tex.yaf_tex_type == 'MUSGRAVE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "musgrave") ts = switchMusgraveType.get(tex.musgrave_type, 'multifractal') yi.paramsSetString("musgrave_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) yi.paramsSetFloat("H", tex.dimension_max) yi.paramsSetFloat("lacunarity", tex.lacunarity) yi.paramsSetFloat("octaves", tex.octaves) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetFloat("offset", tex.offset) yi.paramsSetFloat("intensity", tex.noise_intensity) yi.paramsSetFloat("gain", tex.gain) textureConfigured = True elif tex.yaf_tex_type == 'DISTORTED_NOISE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "distorted_noise") yi.paramsSetFloat("distort", tex.distortion) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetString("noise_type1", noise2string(tex.noise_basis)) yi.paramsSetString("noise_type2", noise2string(tex.noise_distortion)) textureConfigured = True elif tex.yaf_tex_type == 'IMAGE' and tex.image and tex.image.source in {'FILE', 'GENERATED'}: filename = os.path.splitext(os.path.basename(bpy.data.filepath))[0] if not any(filename): filename = "untitled" save_dir = os.path.expanduser("~") else: save_dir = "//" filename = clean_name(filename) # fileformat = lowerImageFileExtension.get(scene.render.image_settings.file_format,'PNG') extract_path = os.path.join(filename, "{:05d}".format(scene.frame_current)) if tex.image.source == 'GENERATED': image_tex = "baked_image_{0}.{1}".format(clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) # test for not overwrite current file (or non extract every time) if not os.path.exists(image_tex): tex.image.save_render(image_tex, scene) if tex.image.source == 'FILE': # image_tex = '' if tex.image.packed_file: # checking local path if not os.path.exists(abspath(tex.image.filepath)): tex.image.unpack(method='WRITE_LOCAL') image_tex = abspath(tex.image.filepath) else: if tex.image.library is not None: image_tex = abspath(tex.image.filepath, library=tex.image.library) else: image_tex = abspath(tex.image.filepath) if not os.path.exists(image_tex): yi.printError("Exporter: Image texture {0} not found on: {1}".format(tex.name, image_tex)) return False image_tex = os.path.realpath(image_tex) image_tex = os.path.normpath(image_tex) yi.printInfo("Exporter: Creating Texture: '{0}' type {1}: {2}".format(name, tex.yaf_tex_type, image_tex)) yi.paramsSetString("type", "image") yi.paramsSetString("filename", image_tex) yi.paramsSetBool("use_alpha", tex.yaf_use_alpha) yi.paramsSetBool("calc_alpha", tex.use_calculate_alpha) yi.paramsSetBool("normalmap", tex.yaf_is_normal_map) yi.paramsSetFloat("gamma", scene.bounty.gs_gamma_input) # repeat repeat_x = 1 repeat_y = 1 if tex.extension == 'REPEAT': repeat_x = tex.repeat_x repeat_y = tex.repeat_y yi.paramsSetInt("xrepeat", repeat_x) yi.paramsSetInt("yrepeat", repeat_y) # clipping clipping = switchExtension.get(tex.extension, 'repeat') # set default clipping to 'repeat' yi.paramsSetString("clipping", clipping) if clipping == 'checker': yi.paramsSetBool("even_tiles", tex.use_checker_even) yi.paramsSetBool("odd_tiles", tex.use_checker_odd) # crop min/max yi.paramsSetFloat("cropmin_x", tex.crop_min_x) yi.paramsSetFloat("cropmin_y", tex.crop_min_y) yi.paramsSetFloat("cropmax_x", tex.crop_max_x) yi.paramsSetFloat("cropmax_y", tex.crop_max_y) yi.paramsSetBool("rot90", tex.use_flip_axis) #yi.paramsSetString("interpolate", tex.interpolation_type) textureConfigured = True if textureConfigured: yi.createTexture(name) self.loadedTextures.add(name) return textureConfigured
def writeTexture(self, scene, tex): name = tex.name if name in self.loadedTextures: return yi = self.yi yi.paramsClearAll() textureConfigured = False yi.paramsSetBool("img_grayscale", tex.yaf_img_grayscale) yi.paramsSetFloat("adj_mult_factor_red", tex.factor_red) yi.paramsSetFloat("adj_mult_factor_green", tex.factor_green) yi.paramsSetFloat("adj_mult_factor_blue", tex.factor_blue) yi.paramsSetFloat("adj_intensity", tex.intensity) yi.paramsSetFloat("adj_contrast", tex.contrast) yi.paramsSetFloat("adj_saturation", tex.saturation) yi.paramsSetFloat("adj_hue", math.degrees(tex.yaf_adj_hue)) yi.paramsSetFloat("trilinear_level_bias", tex.yaf_trilinear_level_bias) yi.paramsSetFloat("ewa_max_anisotropy", tex.yaf_ewa_max_anisotropy) yi.paramsSetBool("adj_clamp", tex.use_clamp) if tex.use_color_ramp: yi.paramsSetBool("use_color_ramp", tex.use_color_ramp) yi.paramsSetString("ramp_color_mode", tex.color_ramp.color_mode) yi.paramsSetString("ramp_hue_interpolation", tex.color_ramp.hue_interpolation) yi.paramsSetString("ramp_interpolation", tex.color_ramp.interpolation) i = 0 for item in tex.color_ramp.elements: yi.paramsSetColor("ramp_item_%x_color" % i, item.color[0], item.color[1], item.color[2], item.color[3]) yi.paramsSetFloat("ramp_item_%x_alpha" % i, item.alpha) yi.paramsSetFloat("ramp_item_%x_position" % i, item.position) i += 1 yi.paramsSetInt("ramp_num_items", i) if tex.yaf_tex_type == 'BLEND': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "blend") switchBlendType = { 'LINEAR': 'lin', 'QUADRATIC': 'quad', 'EASING': 'ease', 'DIAGONAL': 'diag', 'SPHERICAL': 'sphere', 'QUADRATIC_SPHERE': 'halo', 'RADIAL': 'radial', } stype = switchBlendType.get(tex.progression, 'lin') # set blend type for blend texture, default is 'lin' yi.paramsSetString("stype", stype) if tex.use_flip_axis == "HORIZONTAL": yi.paramsSetBool("use_flip_axis", False) if tex.use_flip_axis == "VERTICAL": yi.paramsSetBool("use_flip_axis", True) textureConfigured = True elif tex.yaf_tex_type == 'CLOUDS': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "clouds") noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetBool("hard", hard) yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) textureConfigured = True elif tex.yaf_tex_type == 'WOOD': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "wood") yi.paramsSetInt("depth", 0) turb = 0.0 noise_size = 0.25 hard = True if tex.wood_type == 'BANDNOISE' or tex.wood_type == 'RINGNOISE': turb = tex.turbulence noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'SOFT_NOISE': hard = False yi.paramsSetFloat("turbulence", turb) yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) ts = "bands" if tex.wood_type == 'RINGS' or tex.wood_type == 'RINGNOISE': ts = "rings" yi.paramsSetString("wood_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) # shape parameter if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'MARBLE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "marble") yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetFloat("turbulence", tex.turbulence) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) sharp = 4.0 if tex.marble_type == 'SOFT': sharp = 2.0 elif tex.marble_type == 'SHARP': sharp = 4.0 elif tex.marble_type == 'SHARPER': sharp = 8.0 yi.paramsSetFloat("sharpness", sharp) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'VORONOI': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "voronoi") if tex.color_mode == 'POSITION': ts = "col1" elif tex.color_mode == 'POSITION_OUTLINE': ts = "col2" elif tex.color_mode == 'POSITION_OUTLINE_INTENSITY': ts = "col3" else: ts = "int" yi.paramsSetString("color_type", ts) yi.paramsSetFloat("weight1", tex.weight_1) yi.paramsSetFloat("weight2", tex.weight_2) yi.paramsSetFloat("weight3", tex.weight_3) yi.paramsSetFloat("weight4", tex.weight_4) yi.paramsSetFloat("mk_exponent", tex.minkovsky_exponent) yi.paramsSetFloat("intensity", tex.noise_intensity) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) switchDistMetric = { 'DISTANCE_SQUARED': 'squared', 'MANHATTAN': 'manhattan', 'CHEBYCHEV': 'chebychev', 'MINKOVSKY_HALF': 'minkovsky_half', 'MINKOVSKY_FOOUR': 'minkovsky_four', 'MINKOVSKY': 'minkovsky', } ts = switchDistMetric.get(tex.distance_metric, 'minkovsky') # set distance metric for VORONOI Texture, default is 'minkovsky' yi.paramsSetString("distance_metric", ts) textureConfigured = True elif tex.yaf_tex_type == 'MUSGRAVE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "musgrave") switchMusgraveType = { 'MULTIFRACTAL': 'multifractal', 'RIDGED_MULTIFRACTAL': 'ridgedmf', 'HYBRID_MULTIFRACTAL': 'hybridmf', 'HETERO_TERRAIN': 'heteroterrain', 'FBM': 'fBm', } ts = switchMusgraveType.get(tex.musgrave_type, 'multifractal') # set MusgraveType, default is 'multifractal' yi.paramsSetString("musgrave_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) yi.paramsSetFloat("H", tex.dimension_max) yi.paramsSetFloat("lacunarity", tex.lacunarity) yi.paramsSetFloat("octaves", tex.octaves) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetFloat("offset", tex.offset) yi.paramsSetFloat("intensity", tex.noise_intensity) yi.paramsSetFloat("gain", tex.gain) textureConfigured = True elif tex.yaf_tex_type == 'DISTORTED_NOISE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format(name, tex.yaf_tex_type)) yi.paramsSetString("type", "distorted_noise") yi.paramsSetFloat("distort", tex.distortion) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetString("noise_type1", noise2string(tex.noise_basis)) yi.paramsSetString("noise_type2", noise2string(tex.noise_distortion)) textureConfigured = True elif tex.yaf_tex_type == 'IMAGE' and tex.image and tex.image.source in {'FILE', 'SEQUENCE', 'GENERATED'}: filename = os.path.splitext(os.path.basename(bpy.data.filepath))[0] if not any(filename): filename = "untitled" save_dir = os.path.expanduser("~") else: save_dir = "//" filename = clean_name(filename) fileformat = scene.render.image_settings.file_format.lower() extract_path = os.path.join(filename, "{:05d}".format(scene.frame_current)) if tex.image.source == 'GENERATED': image_tex = "yaf_baked_image_{0}.{1}".format(clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) if tex.image.source == 'FILE': if tex.image.packed_file: image_tex = "yaf_extracted_image_{0}.{1}".format(clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) else: if tex.image.library is not None: image_tex = abspath(tex.image.filepath, library=tex.image.library) else: image_tex = abspath(tex.image.filepath) if not os.path.exists(image_tex): yi.printError("Exporter: Image texture {0} not found on: {1}".format(tex.name, image_tex)) return False if tex.image.source == 'SEQUENCE': if tex.image.packed_file: image_tex = "yaf_extracted_image_{0}.{1}".format(clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) tex.image.save_render(image_tex, scene) else: #Try to figure out the correct file name depending on the frame, guessing the calculations done by Blender if tex.image_user.use_cyclic: image_number = scene.frame_current - tex.image_user.frame_start if image_number < 0: image_number += (divmod(-1 * image_number, tex.image_user.frame_duration)[0]+1) * tex.image_user.frame_duration image_number = (image_number % tex.image_user.frame_duration) + tex.image_user.frame_offset + 1 else: image_number = scene.frame_current - (tex.image_user.frame_start - 1) + tex.image_user.frame_offset if image_number < tex.image_user.frame_start: image_number = tex.image_user.frame_start elif image_number > (tex.image_user.frame_duration + tex.image_user.frame_offset): image_number = (tex.image_user.frame_duration + tex.image_user.frame_offset) tex_image_filepath = abspath(tex.image.filepath) tex_image_filepath_splitext = os.path.splitext(tex_image_filepath) tex_image_filepath_searchnumber = re.search(r'\d+$', tex_image_filepath_splitext[0]) tex_image_filepath_base = tex_image_filepath[0:tex_image_filepath_searchnumber.span()[0]] if tex_image_filepath_searchnumber else tex_image_filepath_splitext[0] tex_image_filepath_number = tex_image_filepath_searchnumber.group() if tex_image_filepath_searchnumber else None tex_image_filepath_number_numdigits = len(tex_image_filepath_number) if tex_image_filepath_number else 0 tex_image_filepath_ext = tex_image_filepath_splitext[1] if tex_image_filepath_number is not None: tex_image_filepath_sequence = tex_image_filepath_base + str(image_number).zfill(tex_image_filepath_number_numdigits) + tex_image_filepath_ext else: tex_image_filepath_sequence = tex_image_filepath_base + str(image_number) + tex_image_filepath_ext if tex.image.library is not None: image_tex = abspath(tex_image_filepath_sequence, library=tex.image.library) else: image_tex = abspath(tex_image_filepath_sequence) if not os.path.exists(image_tex): yi.printError("Exporter: Image texture {0} not found on: {1}".format(tex.name, image_tex)) return False image_tex = os.path.realpath(image_tex) image_tex = os.path.normpath(image_tex) yi.paramsSetString("type", "image") yi.paramsSetString("filename", image_tex) yi.paramsSetBool("use_alpha", tex.yaf_use_alpha) yi.paramsSetBool("calc_alpha", tex.use_calculate_alpha) yi.paramsSetBool("normalmap", tex.yaf_is_normal_map) yi.paramsSetString("fileformat", fileformat.upper()) texture_color_space = "sRGB" texture_gamma = 1.0 if tex.image.colorspace_settings.name == "sRGB" or tex.image.colorspace_settings.name == "VD16": texture_color_space = "sRGB" elif tex.image.colorspace_settings.name == "XYZ": texture_color_space = "XYZ" elif tex.image.colorspace_settings.name == "Linear" or tex.image.colorspace_settings.name == "Linear ACES" or tex.image.colorspace_settings.name == "Non-Color": texture_color_space = "LinearRGB" elif tex.image.colorspace_settings.name == "Raw": texture_color_space = "Raw_Manual_Gamma" texture_gamma = tex.yaf_gamma_input #We only use the selected gamma if the color space is set to "Raw" yi.paramsSetString("color_space", texture_color_space) yi.paramsSetFloat("gamma", texture_gamma) if tex.yaf_tex_optimization == "default": texture_optimization = scene.gs_tex_optimization else: texture_optimization = tex.yaf_tex_optimization yi.printInfo("Exporter: Creating Texture: '{0}' type {1}: {2}. Texture Color Space: '{3}', gamma={4}. Texture optimization='{5}'".format(name, tex.yaf_tex_type, image_tex, texture_color_space, texture_gamma, texture_optimization)) yi.paramsSetString("interpolate", tex.yaf_tex_interpolate) yi.paramsSetString("texture_optimization", texture_optimization) # repeat repeat_x = 1 repeat_y = 1 if tex.extension == 'REPEAT': repeat_x = tex.repeat_x repeat_y = tex.repeat_y yi.paramsSetInt("xrepeat", repeat_x) yi.paramsSetInt("yrepeat", repeat_y) # clipping extension = tex.extension switchExtension = { 'EXTEND': 'extend', 'CLIP': 'clip', 'CLIP_CUBE': 'clipcube', 'CHECKER': 'checker', } clipping = switchExtension.get(extension, 'repeat') # set default clipping to 'repeat' yi.paramsSetString("clipping", clipping) if clipping == 'checker': yi.paramsSetBool("even_tiles", tex.use_checker_even) yi.paramsSetBool("odd_tiles", tex.use_checker_odd) # crop min/max yi.paramsSetFloat("cropmin_x", tex.crop_min_x) yi.paramsSetFloat("cropmin_y", tex.crop_min_y) yi.paramsSetFloat("cropmax_x", tex.crop_max_x) yi.paramsSetFloat("cropmax_y", tex.crop_max_y) yi.paramsSetBool("rot90", tex.use_flip_axis) yi.paramsSetBool("mirror_x", tex.use_mirror_x) yi.paramsSetBool("mirror_y", tex.use_mirror_y) textureConfigured = True if textureConfigured: yi.createTexture(name) self.loadedTextures.add(name) return textureConfigured
def execute(self, context): print('execute miura') scene = context.scene sequence_editor = scene.sequence_editor active_strip = sequence_editor.active_strip target_path = abspath(active_strip.directory) processed_dir = join(target_path, clean_name(active_strip.name)) window_manager = context.window_manager makedirs(processed_dir, exist_ok=True) elements = active_strip.elements frame_offset_start = active_strip.frame_offset_start frame_final_start = active_strip.frame_final_start frame_final_duration = active_strip.frame_final_duration elements_to_process = elements[ frame_offset_start:frame_final_duration + frame_offset_start] window_manager.progress_begin(0, len(elements_to_process)) module_name = self.module_name if module_name in loaded_modules and self.reload_if_loaded: module = importlib.reload(loaded_modules.get(module_name)) else: module = importlib.import_module(module_name) loaded_modules[module_name] = module use_multiview = active_strip.use_multiview if use_multiview: print('stereo strip\n', active_strip, dir(active_strip)) print(active_strip) print('—' * 10) print(dir(active_strip)) print(active_strip.views_format) print(active_strip.stereo_3d_format) print(active_strip.stereo_3d_format.display_mode) print('^' * 10) assert active_strip.views_format == 'STEREO_3D', 'Only STEREO_3D views formatsupported' assert active_strip.stereo_3d_format.display_mode == 'TOPBOTTOM', 'Only TOPBOTTOM display mode supported' for i, element in enumerate(elements_to_process): window_manager.progress_update(i) image_path = join(target_path, element.filename) print('image_path', image_path) orig = imageio.imread(image_path) original_file_name = display_name_from_filepath(element.filename) process_name = 'hcy_' + original_file_name print('--- cer cebprff', orig, orig.shape) processed = module.process_frame( orig, frame_final_start + i, process_name, is_topbottom=use_multiview) print('--- cbfg cebprff') new_file_name = process_name + '.png' process_full_path = path.join(processed_dir, new_file_name) print('path to save', process_full_path) imageio.imsave(process_full_path, processed) print('saved image', process_full_path) if i == 0: new_sequence_name = active_strip.name + '_processed.000' print('Creating new image sequence "{}"', new_sequence_name) new_sequence = sequence_editor.sequences.new_image( name=new_sequence_name, filepath=relpath(process_full_path), frame_start=frame_final_start, channel=active_strip.channel + 1) else: new_sequence.elements.append(new_file_name) if use_multiview: new_sequence.use_multiview = use_multiview new_sequence.views_format = 'STEREO_3D' new_sequence.stereo_3d_format.display_mode = 'TOPBOTTOM' new_sequence.blend_type = 'ALPHA_OVER' window_manager.progress_end() print('Done!') return {'FINISHED'}
def writeTexture(self, scene, tex): name = tex.name if name in self.loadedTextures: return yi = self.yi yi.paramsClearAll() textureConfigured = False if tex.yaf_tex_type == 'BLEND': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "blend") stype = switchBlendType.get( tex.progression, 'lin') # set blend type for blend texture, default is 'lin' yi.paramsSetString("stype", stype) textureConfigured = True elif tex.yaf_tex_type == 'CLOUDS': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "clouds") noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetBool("hard", hard) yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) textureConfigured = True elif tex.yaf_tex_type == 'WOOD': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "wood") yi.paramsSetInt("depth", 0) turb = 0.0 noise_size = 0.25 hard = True if tex.wood_type == 'BANDNOISE' or tex.wood_type == 'RINGNOISE': turb = tex.turbulence noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'SOFT_NOISE': hard = False yi.paramsSetFloat("turbulence", turb) yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) ts = "bands" if tex.wood_type == 'RINGS' or tex.wood_type == 'RINGNOISE': ts = "rings" yi.paramsSetString("wood_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) # shape parameter if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'MARBLE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "marble") yi.paramsSetInt("depth", tex.noise_depth) yi.paramsSetFloat("turbulence", tex.turbulence) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size if tex.noise_type == 'HARD_NOISE': hard = True else: hard = False yi.paramsSetFloat("size", noise_size) yi.paramsSetBool("hard", hard) sharp = 4.0 if tex.marble_type == 'SOFT': sharp = 2.0 elif tex.marble_type == 'SHARP': sharp = 4.0 elif tex.marble_type == 'SHARPER': sharp = 8.0 yi.paramsSetFloat("sharpness", sharp) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) if tex.noise_basis_2 == 'SAW': ts = "saw" elif tex.noise_basis_2 == 'TRI': ts = "tri" else: ts = "sin" yi.paramsSetString("shape", ts) textureConfigured = True elif tex.yaf_tex_type == 'VORONOI': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "voronoi") if tex.color_mode == 'POSITION': ts = "col1" elif tex.color_mode == 'POSITION_OUTLINE': ts = "col2" elif tex.color_mode == 'POSITION_OUTLINE_INTENSITY': ts = "col3" else: ts = "int" yi.paramsSetString("color_type", ts) yi.paramsSetFloat("weight1", tex.weight_1) yi.paramsSetFloat("weight2", tex.weight_2) yi.paramsSetFloat("weight3", tex.weight_3) yi.paramsSetFloat("weight4", tex.weight_4) yi.paramsSetFloat("mk_exponent", tex.minkovsky_exponent) yi.paramsSetFloat("intensity", tex.noise_intensity) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) ts = switchDistMetric.get(tex.distance_metric, 'minkovsky') yi.paramsSetString("distance_metric", ts) textureConfigured = True elif tex.yaf_tex_type == 'MUSGRAVE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "musgrave") ts = switchMusgraveType.get(tex.musgrave_type, 'multifractal') yi.paramsSetString("musgrave_type", ts) yi.paramsSetString("noise_type", noise2string(tex.noise_basis)) yi.paramsSetFloat("H", tex.dimension_max) yi.paramsSetFloat("lacunarity", tex.lacunarity) yi.paramsSetFloat("octaves", tex.octaves) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetFloat("offset", tex.offset) yi.paramsSetFloat("intensity", tex.noise_intensity) yi.paramsSetFloat("gain", tex.gain) textureConfigured = True elif tex.yaf_tex_type == 'DISTORTED_NOISE': yi.printInfo("Exporter: Creating Texture: '{0}' type {1}".format( name, tex.yaf_tex_type)) yi.paramsSetString("type", "distorted_noise") yi.paramsSetFloat("distort", tex.distortion) noise_size = tex.noise_scale if noise_size > 0: noise_size = 1.0 / noise_size yi.paramsSetFloat("size", noise_size) yi.paramsSetString("noise_type1", noise2string(tex.noise_basis)) yi.paramsSetString("noise_type2", noise2string(tex.noise_distortion)) textureConfigured = True elif tex.yaf_tex_type == 'IMAGE' and tex.image and tex.image.source in { 'FILE', 'GENERATED' }: filename = os.path.splitext(os.path.basename(bpy.data.filepath))[0] if not any(filename): filename = "untitled" save_dir = os.path.expanduser("~") else: save_dir = "//" filename = clean_name(filename) # fileformat = lowerImageFileExtension.get( scene.render.image_settings.file_format, 'PNG') extract_path = os.path.join(filename, "{:05d}".format(scene.frame_current)) if tex.image.source == 'GENERATED': image_tex = "baked_image_{0}.{1}".format( clean_name(tex.name), fileformat) image_tex = os.path.join(save_dir, extract_path, image_tex) image_tex = abspath(image_tex) # test for not overwrite current file (or non extract every time) if not os.path.exists(image_tex): tex.image.save_render(image_tex, scene) if tex.image.source == 'FILE': # image_tex = '' if tex.image.packed_file: # checking local path if not os.path.exists(abspath(tex.image.filepath)): tex.image.unpack(method='WRITE_LOCAL') image_tex = abspath(tex.image.filepath) else: if tex.image.library is not None: image_tex = abspath(tex.image.filepath, library=tex.image.library) else: image_tex = abspath(tex.image.filepath) if not os.path.exists(image_tex): yi.printError( "Exporter: Image texture {0} not found on: {1}". format(tex.name, image_tex)) return False image_tex = os.path.realpath(image_tex) image_tex = os.path.normpath(image_tex) yi.printInfo( "Exporter: Creating Texture: '{0}' type {1}: {2}".format( name, tex.yaf_tex_type, image_tex)) yi.paramsSetString("type", "image") yi.paramsSetString("filename", image_tex) yi.paramsSetBool("use_alpha", tex.yaf_use_alpha) yi.paramsSetBool("calc_alpha", tex.use_calculate_alpha) yi.paramsSetBool("normalmap", tex.yaf_is_normal_map) yi.paramsSetFloat("gamma", scene.bounty.gs_gamma_input) # repeat repeat_x = 1 repeat_y = 1 if tex.extension == 'REPEAT': repeat_x = tex.repeat_x repeat_y = tex.repeat_y yi.paramsSetInt("xrepeat", repeat_x) yi.paramsSetInt("yrepeat", repeat_y) # clipping clipping = switchExtension.get( tex.extension, 'repeat') # set default clipping to 'repeat' yi.paramsSetString("clipping", clipping) if clipping == 'checker': yi.paramsSetBool("even_tiles", tex.use_checker_even) yi.paramsSetBool("odd_tiles", tex.use_checker_odd) # crop min/max yi.paramsSetFloat("cropmin_x", tex.crop_min_x) yi.paramsSetFloat("cropmin_y", tex.crop_min_y) yi.paramsSetFloat("cropmax_x", tex.crop_max_x) yi.paramsSetFloat("cropmax_y", tex.crop_max_y) yi.paramsSetBool("rot90", tex.use_flip_axis) #yi.paramsSetString("interpolate", tex.interpolation_type) textureConfigured = True if textureConfigured: yi.createTexture(name) self.loadedTextures.add(name) return textureConfigured
def execute(self, context): scene = context.scene sequence_editor = scene.sequence_editor curve_by_key = find_custom_curves(scene) active_strip = sequence_editor.active_strip target_path = abspath(active_strip.directory) effective_strip_name = self.new_strip_name or active_strip.name processed_dir = join(target_path, clean_name(effective_strip_name)) makedirs(processed_dir, exist_ok=True) elements = active_strip.elements frame_offset_start = active_strip.frame_offset_start frame_final_start = active_strip.frame_final_start frame_final_duration = active_strip.frame_final_duration window_manager = context.window_manager elements_to_process = elements[ frame_offset_start:frame_final_duration + frame_offset_start] window_manager.progress_begin(0, len(elements_to_process)) use_multiview = active_strip.use_multiview if use_multiview: assert active_strip.views_format == 'STEREO_3D', 'Only STEREO_3D views formatsupported' assert active_strip.stereo_3d_format.display_mode == 'TOPBOTTOM', 'Only TOPBOTTOM display mode supported' for i, element in enumerate(elements_to_process): window_manager.progress_update(i) image_path = join(target_path, element.filename) original_file_name = display_name_from_filepath(element.filename) frame_number = frame_final_start + i payload = { 'original_file_name': original_file_name, 'image_path': image_path, 'processed_dir': processed_dir, 'use_multiview': use_multiview, 'frame_number': frame_number } payload.update(extract_curve_for_frame(curve_by_key, frame_number)) r = post(f'http://0.0.0.0:{self.server_port}/process', json=payload) process_full_path = r.text assert isfile(process_full_path), 'Image not created!' if i == 0: new_sequence_name = effective_strip_name + '.000' new_sequence = sequence_editor.sequences.new_image( name=new_sequence_name, filepath=relpath(process_full_path), frame_start=frame_final_start, channel=active_strip.channel + 1) else: new_sequence.elements.append(basename(process_full_path)) if use_multiview: new_sequence.use_multiview = use_multiview new_sequence.views_format = 'STEREO_3D' new_sequence.stereo_3d_format.display_mode = 'TOPBOTTOM' new_sequence.blend_type = 'ALPHA_OVER' if self.copy_transform_and_crop: new_sequence.crop.max_x = active_strip.crop.max_x new_sequence.crop.max_y = active_strip.crop.max_y new_sequence.crop.min_x = active_strip.crop.min_x new_sequence.crop.min_y = active_strip.crop.min_y new_sequence.transform.offset_x = active_strip.transform.offset_x new_sequence.transform.offset_y = active_strip.transform.offset_y new_sequence.transform.scale_x = active_strip.transform.scale_x new_sequence.transform.scale_y = active_strip.transform.scale_y new_sequence.transform.rotation = active_strip.transform.rotation new_sequence.transform.origin = active_strip.transform.origin window_manager.progress_end() return {'FINISHED'}
def execute(self, context): path, base = split(bpy.data.filepath) filepath = bpy.data.filepath base_dir = os.path.dirname(filepath) version_path = os.path.join(base_dir, version_file) version = None if os.path.isfile(os.path.join(base_dir, version_path)): version = open(version_path, 'r').read().strip() if version: target_path = join(path, clean_name(self.target_name), version) else: target_path = join(path, clean_name(self.target_name)) os.makedirs(target_path, exist_ok=True) all_elements = [] ordered_sequences = sorted(context.selected_sequences, key=lambda s: s.frame_final_start) for active_strip in ordered_sequences: strip_directory = abspath(active_strip.directory) elements = active_strip.elements frame_offset_start = active_strip.frame_offset_start frame_final_start = active_strip.frame_final_start frame_final_duration = active_strip.frame_final_duration first_selection_index = frame_offset_start final_selection_index = frame_final_duration + frame_offset_start selected_elements = elements[ first_selection_index : final_selection_index ] if self.pad_with_copies: target_length = final_selection_index - first_selection_index current_length = len(selected_elements) missing_length = target_length - current_length if missing_length > 0: pad = [selected_elements[-1]] * missing_length selected_elements += pad all_elements += [ join(strip_directory, element.filename) for element in selected_elements ] wm = context.window_manager wm.progress_begin(0, len(all_elements)) for i, element in enumerate(all_elements): extension = splitext(element)[1] file_name = 'frame-{:08d}{}'.format(i, extension) destination_path = join(target_path, file_name) copy(element, destination_path) if i == 0: first_strip = ordered_sequences[0] new_sequence_name = self.target_name + '.000' print('Creating new image sequence "{}"'.format(new_sequence_name)) new_sequence = context.scene.sequence_editor.sequences.new_image( name=new_sequence_name, filepath=relpath(destination_path), frame_start=first_strip.frame_final_start, channel=active_strip.channel + 1) else: new_sequence.elements.append(file_name) wm.progress_update(i) wm.progress_end() return {'FINISHED'}