diff --git a/addon/panels/scene.py b/addon/panels/scene.py index 340df86..2debd7d 100644 --- a/addon/panels/scene.py +++ b/addon/panels/scene.py @@ -378,6 +378,10 @@ def draw(self, context): if sceneProperties.tlm_encoding_mode_a == "HDR": row = layout.row(align=True) row.prop(sceneProperties, "tlm_format") + + if(sceneProperties.tlm_format == "KTX"): + row = layout.row(align=True) + row.prop(sceneProperties, "tlm_ktx_path") else: if sceneProperties.tlm_encoding_mode_b == "RGBM": diff --git a/addon/properties/scene.py b/addon/properties/scene.py index cb782c1..c2744bc 100644 --- a/addon/properties/scene.py +++ b/addon/properties/scene.py @@ -78,6 +78,12 @@ class TLM_SceneProperties(bpy.types.PropertyGroup): description="Supersamples the baked lightmap. Increases bake time", default="2x") + tlm_ktx_path : StringProperty( + name="KTX Path", + description="The path to the KTX2 binaries", + default="", + subtype="FILE_PATH") + tlm_setting_savedir : StringProperty( name="Lightmap Directory", description="Your baked lightmaps will be stored here.", @@ -293,6 +299,7 @@ class TLM_SceneProperties(bpy.types.PropertyGroup): tlm_format : EnumProperty( items = [('RGBE', 'HDR', '32-bit RGBE encoded .hdr files. No compression available.'), + ('KTX', 'KTX', 'KTX2 Format'), ('EXR', 'EXR', '32-bit OpenEXR format.')], name = "Format", description="Select default 32-bit format", diff --git a/addon/utility/build.py b/addon/utility/build.py index c172b6a..a64d2e8 100644 --- a/addon/utility/build.py +++ b/addon/utility/build.py @@ -437,6 +437,56 @@ def begin_build(): if sceneProperties.tlm_encoding_mode_a == "HDR": + if sceneProperties.tlm_format == "KTX": + + tlm_log.append("KTX Format") + if bpy.context.scene.TLM_SceneProperties.tlm_verbose: + + print("KTX Format") + + ren = bpy.context.scene.render + ren.image_settings.file_format = "OPEN_EXR" + #ren.image_settings.exr_codec = "scene.TLM_SceneProperties.tlm_exr_codec" + + end = "_baked" + + baked_image_array = [] + + if sceneProperties.tlm_denoise_use: + + end = "_denoised" + + if sceneProperties.tlm_filtering_use: + + end = "_filtered" + + #For each image in folder ending in denoised/filtered + dirfiles = [f for f in listdir(dirpath) if isfile(join(dirpath, f))] + + for file in dirfiles: + if file.endswith(end + ".hdr"): + + img = bpy.data.images.load(os.path.join(dirpath,file)) + img.save_render(img.filepath_raw[:-4] + ".exr") + + if(sceneProperties.tlm_ktx_path != ""): + + ktx_path = sceneProperties.tlm_ktx_path + exr_path = img.filepath_raw[:-4] + ".exr" + + # Build the KTX command + ktx_command = [ + ktx_path, + "create", + "--format", "R32G32B32A32_SFLOAT", + exr_path, + exr_path[:-4] + ".ktx2" + ] + + # Execute the KTX conversion command + subprocess.run(ktx_command, check=True) + print(f"Converted {exr_path} to KTX2 format.") + if sceneProperties.tlm_format == "EXR": tlm_log.append("EXR Format") @@ -799,6 +849,10 @@ def manage_build(background_pass=False, load_atlas=0): if sceneProperties.tlm_encoding_mode_b == "HDR": + if sceneProperties.tlm_format == "KTX": + + formatEnc = ".ktx2" + if sceneProperties.tlm_format == "EXR": formatEnc = ".exr"