Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for blender scripting #29

Open
Slluxx opened this issue Oct 13, 2024 · 3 comments
Open

Support for blender scripting #29

Slluxx opened this issue Oct 13, 2024 · 3 comments

Comments

@Slluxx
Copy link

Slluxx commented Oct 13, 2024

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.

bpy_struct: item.attr = val: enum "DDS" not found in ('BMP', 'IRIS', 'PNG', 'JPEG', 'JPEG2000', 'TARGA', 'TARGA_RAW', 'CINEON', 'DPX', 'OPEN_EXR_MULTILAYER', 'OPEN_EXR', 'HDR', 'TIFF', 'WEBP', 'FFMPEG')
@matyalatte
Copy link
Owner

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)

@Slluxx
Copy link
Author

Slluxx commented Oct 14, 2024

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.

@matyalatte
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants