Open Slluxx opened 1 month ago
You can call save_dds
from export_dds.py
. As far as I know, there is no way to override built-in features (like the enum you mentioned) to export textures.
import os
import bpy
from blender_dds_addon.ui.export_dds import save_dds
tex = bpy.data.images.load(os.path.abspath("my_texture.png"))
save_dds(tex, "my_texture.dds", "BC1_UNORM")
bpy.data.images.remove(tex)
I dont want to save the dds, just get the data to then write the bytes in a specific format into a file (which is handled by a few functions i already have). I have not looked too much into your plugin, so forgive me if this is already possible.
You mean, you want to embed dds data into another file format, like game assets? Even in that case, you need to export textures as dds files because my addon uses a file converter, not a dds library.
import os
import tempfile
import bpy
from blender_dds_addon.ui.export_dds import save_dds
from blender_dds_addon.directx.dds import DDSHeader
tex = bpy.data.images.load(os.path.abspath("my_texture.png"))
with tempfile.TemporaryDirectory() as temp_dir:
temp_dds = os.path.join(temp_dir, "temp.dds")
save_dds(tex, temp_dds, "BC1_UNORM")
with open(temp_dds, 'rb') as f:
header = DDSHeader.read(f)
pixel_data = f.read() # compressed pixel data
bpy.data.images.remove(tex)
I need to convert a PNG to a DDS file in my plugin for a custom export. It would be helpful if DDS integrates like a native file format supported by blender.